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

Function msra_normal_

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

r"""Fills tensor wilth random values sampled from :math:`\mathcal{N}(0, \text{std}^2)` where .. math:: \text{std} = \sqrt{\frac{2}{(1 + a^2) \times \text{fan_in}}} Detailed information can be retrieved from `Delving deep into rectifiers: Surpassing human-level performance

(
    tensor: Tensor, a: float = 0, mode: str = "fan_in", nonlinearity: str = "leaky_relu"
)

Source from the content-addressed store, hash-verified

249
250
251def msra_normal_(
252 tensor: Tensor, a: float = 0, mode: str = "fan_in", nonlinearity: str = "leaky_relu"
253) -> None:
254 r"""Fills tensor wilth random values sampled from
255 :math:`\mathcal{N}(0, \text{std}^2)` where
256
257 .. math::
258
259 \text{std} = \sqrt{\frac{2}{(1 + a^2) \times \text{fan_in}}}
260
261 Detailed information can be retrieved from
262 `Delving deep into rectifiers: Surpassing human-level performance on ImageNet
263 classification`
264
265 Args:
266 tensor: tensor to be initialized
267 a: optional parameter for calculating gain for leaky_relu. See
268 :func:`calculate_gain` for details.
269 mode: fan_in" or "fan_out", used to calculate :math:`gain`, the
270 scaling factor for :math:`gain`. See :func:`calculate_fan_in_and_fan_out` for
271 details.
272 nonlinearity: name of the non-linear function used to calculate :math:`gain`.
273 See :func:`calculate_gain` for details.
274 """
275 fan = calculate_correct_fan(tensor, mode)
276 gain = calculate_gain(nonlinearity, a)
277 std = gain / math.sqrt(fan)
278 normal_(tensor, 0, std)

Callers

nothing calls this directly

Calls 4

calculate_correct_fanFunction · 0.85
calculate_gainFunction · 0.85
normal_Function · 0.85
sqrtMethod · 0.45

Tested by

no test coverage detected