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

Function msra_uniform_

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

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

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

Source from the content-addressed store, hash-verified

218
219
220def msra_uniform_(
221 tensor: Tensor, a: float = 0, mode: str = "fan_in", nonlinearity: str = "leaky_relu"
222) -> None:
223 r"""Fills tensor wilth random values sampled from
224 :math:`\mathcal{U}(-\text{bound}, \text{bound})` where
225
226 .. math::
227
228 \text{bound} = \sqrt{\frac{6}{(1 + a^2) \times \text{fan_in}}}
229
230 Detailed information can be retrieved from
231 `Delving deep into rectifiers: Surpassing human-level performance on ImageNet
232 classification`
233
234 Args:
235 tensor: tensor to be initialized.
236 a: optional parameter for calculating gain for leaky_relu. See
237 :func:`calculate_gain` for details.
238 mode: fan_in" or "fan_out", used to calculate :math:`gain`, the
239 scaling factor for :math:`bound`. See :func:`calculate_fan_in_and_fan_out` for
240 details.
241 nonlinearity: name of the non-linear function used to calculate :math:`gain`.
242 See :func:`calculate_gain` for details.
243 """
244 fan = calculate_correct_fan(tensor, mode)
245 gain = calculate_gain(nonlinearity, a)
246 std = gain / math.sqrt(fan)
247 bound = math.sqrt(3.0) * std
248 uniform_(tensor, -bound, bound)
249
250
251def msra_normal_(

Callers

nothing calls this directly

Calls 4

calculate_correct_fanFunction · 0.85
calculate_gainFunction · 0.85
uniform_Function · 0.85
sqrtMethod · 0.45

Tested by

no test coverage detected