megengine.module.init

>>> import megengine.module as M
>>> m = M.Conv2d(16, 33, 3, stride=2)
>>> M.init.msra_normal_(m.weight, mode="fan_out", nonlinearity="relu")

注解

良好的初始化策略有助于你的模型在训练时更快地收敛。

Initialization

fill_

val 填入到给定的 tensor

zeros_

使用标量值 0 填入给定 tensor

ones_

使用标量值 1 填入给定的 tensor

uniform_

从均匀分布 \(\mathcal{U}(\text{a}, \text{b})\) 中采样随机值填充给定张量,其中:

normal_

从正态分布 \(\mathcal{N}(\text{mean}, \text{std}^2)\) 中采样随机值填充给定 tensor

calculate_gain

对于给定的非线性函数返回一个推荐的增益值(见下表)。

calculate_fan_in_and_fan_out

对于给定的权重张量,计算fan_in / fan_out值。

calculate_correct_fan

计算对于给定的权重张量fan_in或fan_out值,这取决于给定的 mode

xavier_uniform_

使用从 \(\mathcal{U}(-a, a)\) 中随机采样值填入 tensor 。其中,

xavier_normal_

从正太分布 \(\mathcal{N}(0, \text{std}^2)\) 中采样随机值填充给定 tensor

msra_uniform_

从均匀分布 \(\mathcal{U}(-\text{bound}, \text{bound})\) 中采样填充给定 tensor

msra_normal_

从正态分布 \(\mathcal{N}(0, \text{std}^2)\) 中采样随机值填充给定张量,其中