torch.nn.init.
calculate_gain
(nonlinearity, param=None)[source]
Return the recommended gain value for the given nonlinearity function. The values are as follows:
nonlinearity |
gain |
---|---|
Linear / Identity |
1 |
Conv{1,2,3}D |
1 |
Sigmoid |
1 |
Tanh |
|
ReLU |
|
Leaky Relu |
Parameters
-
nonlinearity – the non-linear function (nn.functional name)
-
param – optional parameter for the non-linear function
Examples
>>> gain = nn.init.calculate_gain('leaky_relu', 0.2) # leaky_relu with negative_slope=0.2
torch.nn.init.
uniform_
(tensor, a=0.0, b=1.0)[source]
Fills the input Tensor with values drawn from the uniform distribution U(a,b)\mathcal{U}(a, b)U(a,b) .
Parameters
-
tensor – an n-dimensional torch.Tensor
-
a – the lower bound of the uniform distribution
-
b – the upper bound of the uniform distribution
Examples
>>> w = torch.empty(3, 5)
>>> nn.init.uniform_(w)
torch.nn.init.
normal_
(tensor, mean=0.0, std=1.0)[source]
Fills the input Tensor with values drawn from the normal distribution