gpt4 book ai didi

initialization - 如何决定使用哪种模式进行 'kaiming_normal' 初始化

转载 作者:行者123 更新时间:2023-12-03 21:55:18 24 4
gpt4 key购买 nike

我已经阅读了几个使用 nn.init.kaiming_normal_() 进行层初始化的代码来自 PyTorch。一些代码使用 fan in模式,这是默认的。在众多示例中,可以找到一个 here并如下所示。

init.kaiming_normal(m.weight.data, a=0, mode='fan_in')

但是,有时我看到有人使用 fan out所见模式 here并如下所示。
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')


有人可以给我一些指导方针或提示来帮助我决定选择哪种模式吗?此外,我正在使用 PyTorch 进行图像超分辨率和去噪任务,哪种模式更有益。

最佳答案

根据 documentation :

Choosing 'fan_in' preserves the magnitude of the variance of the weights in the forward pass. Choosing 'fan_out' preserves the magnitudes in the backwards pass.



并根据 Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification - He, K. et al. (2015) :

We note that it is sufficient to use either Eqn.(14) or Eqn.(10)



其中方程(10)和方程(14)是 fan_infan_out适本地。此外:

This means that if the initialization properly scales the backward signal, then this is also the case for the forward signal; and vice versa. For all models in this paper, both forms can make them converge



所以总而言之没有多大关系但更多的是关于你所追求的。我假设如果您怀疑您的反向传递可能更“困惑”(更大的差异),那么值得将模式更改为 fan_out .当损失波动很大时可能会发生这种情况(例如,非常简单的例子后面跟着非常困难的例子)。

正确选择 nonlinearity更重要的是,这里 nonlinearity是您使用的激活 您当前正在初始化的图层。当前默认设置为 leaky_relua=0 ,实际上与 relu 相同.如果您正在使用 leaky_relu你应该换 a到它的坡度。

关于initialization - 如何决定使用哪种模式进行 'kaiming_normal' 初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61848635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com