MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / xavier_normal_

Function xavier_normal_

imperative/python/megengine/module/init.py:199–217  ·  view source on GitHub ↗

r"""Fills tensor with random values sampled from :math:`\mathcal{N}(0, \text{std}^2)` where .. math:: \text{std} = \text{gain} \times \sqrt{\frac{2}{\text{fan_in} + \text{fan_out}}} Also known as Glorot initialization. Detailed information can be retrieved from `Understand

(tensor: Tensor, gain: float = 1.0)

Source from the content-addressed store, hash-verified

197
198
199def xavier_normal_(tensor: Tensor, gain: float = 1.0) -> None:
200 r"""Fills tensor with random values sampled from
201 :math:`\mathcal{N}(0, \text{std}^2)` where
202
203 .. math::
204
205 \text{std} = \text{gain} \times \sqrt{\frac{2}{\text{fan_in} + \text{fan_out}}}
206
207 Also known as Glorot initialization. Detailed information can be retrieved from
208 `Understanding the difficulty of training deep feedforward neural networks` -
209 Glorot, X. & Bengio, Y. (2010).
210
211 Args:
212 tensor: tensor to be initialized.
213 gain: scaling factor for :math:`std`.
214 """
215 fan_in, fan_out = calculate_fan_in_and_fan_out(tensor)
216 std = gain * math.sqrt(2.0 / float(fan_in + fan_out))
217 normal_(tensor, 0.0, std)
218
219
220def msra_uniform_(

Callers

nothing calls this directly

Calls 3

normal_Function · 0.85
sqrtMethod · 0.45

Tested by

no test coverage detected