Module: Torch::NN::Init
- Defined in:
- lib/torch/nn/init.rb
Class Method Summary collapse
-
._calculate_fan_in_and_fan_out(tensor) ⇒ Object
TODO move to C++ when released.
- .calculate_gain(nonlinearity, param: 0.01) ⇒ Object
- .constant!(tensor, val) ⇒ Object
- .dirac!(tensor) ⇒ Object
- .eye!(tensor) ⇒ Object
- .kaiming_normal!(tensor, a: 0, mode: "fan_in", nonlinearity: "leaky_relu") ⇒ Object
- .kaiming_uniform!(tensor, a: 0, mode: "fan_in", nonlinearity: "leaky_relu") ⇒ Object
- .normal!(tensor, mean: 0.0, std: 1.0) ⇒ Object
- .ones!(tensor) ⇒ Object
- .orthogonal!(tensor, gain: 1) ⇒ Object
- .sparse!(tensor, sparsity, std: 0.01) ⇒ Object
- .uniform!(tensor, a: 0.0, b: 1.0) ⇒ Object
- .xavier_normal!(tensor, gain: 1.0) ⇒ Object
- .xavier_uniform!(tensor, gain: 1.0) ⇒ Object
- .zeros!(tensor) ⇒ Object
Class Method Details
._calculate_fan_in_and_fan_out(tensor) ⇒ Object
TODO move to C++ when released
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/torch/nn/init.rb', line 62 def _calculate_fan_in_and_fan_out(tensor) dimensions = tensor.dim if dimensions < 2 raise Error, "Fan in and fan out can not be computed for tensor with fewer than 2 dimensions" end if dimensions == 2 fan_in = tensor.size(1) fan_out = tensor.size(0) else num_input_fmaps = tensor.size(1) num_output_fmaps = tensor.size(0) receptive_field_size = 1 if tensor.dim > 2 receptive_field_size = tensor[0][0].numel end fan_in = num_input_fmaps * receptive_field_size fan_out = num_output_fmaps * receptive_field_size end [fan_in, fan_out] end |
.calculate_gain(nonlinearity, param: 0.01) ⇒ Object
5 6 7 |
# File 'lib/torch/nn/init.rb', line 5 def calculate_gain(nonlinearity, param: 0.01) _calculate_gain(nonlinearity, param) end |
.constant!(tensor, val) ⇒ Object
17 18 19 |
# File 'lib/torch/nn/init.rb', line 17 def constant!(tensor, val) _constant!(tensor, val) end |
.dirac!(tensor) ⇒ Object
33 34 35 |
# File 'lib/torch/nn/init.rb', line 33 def dirac!(tensor) _dirac!(tensor) end |
.eye!(tensor) ⇒ Object
29 30 31 |
# File 'lib/torch/nn/init.rb', line 29 def eye!(tensor) _eye!(tensor) end |
.kaiming_normal!(tensor, a: 0, mode: "fan_in", nonlinearity: "leaky_relu") ⇒ Object
49 50 51 |
# File 'lib/torch/nn/init.rb', line 49 def kaiming_normal!(tensor, a: 0, mode: "fan_in", nonlinearity: "leaky_relu") _kaiming_normal!(tensor, a, mode, nonlinearity) end |
.kaiming_uniform!(tensor, a: 0, mode: "fan_in", nonlinearity: "leaky_relu") ⇒ Object
45 46 47 |
# File 'lib/torch/nn/init.rb', line 45 def kaiming_uniform!(tensor, a: 0, mode: "fan_in", nonlinearity: "leaky_relu") _kaiming_uniform!(tensor, a, mode, nonlinearity) end |
.normal!(tensor, mean: 0.0, std: 1.0) ⇒ Object
13 14 15 |
# File 'lib/torch/nn/init.rb', line 13 def normal!(tensor, mean: 0.0, std: 1.0) _normal!(tensor, mean, std) end |
.ones!(tensor) ⇒ Object
21 22 23 |
# File 'lib/torch/nn/init.rb', line 21 def ones!(tensor) _ones!(tensor) end |
.orthogonal!(tensor, gain: 1) ⇒ Object
53 54 55 |
# File 'lib/torch/nn/init.rb', line 53 def orthogonal!(tensor, gain: 1) _orthogonal!(tensor, gain) end |
.sparse!(tensor, sparsity, std: 0.01) ⇒ Object
57 58 59 |
# File 'lib/torch/nn/init.rb', line 57 def sparse!(tensor, sparsity, std: 0.01) _sparse!(tensor, sparsity, std) end |
.uniform!(tensor, a: 0.0, b: 1.0) ⇒ Object
9 10 11 |
# File 'lib/torch/nn/init.rb', line 9 def uniform!(tensor, a: 0.0, b: 1.0) _uniform!(tensor, a, b) end |
.xavier_normal!(tensor, gain: 1.0) ⇒ Object
41 42 43 |
# File 'lib/torch/nn/init.rb', line 41 def xavier_normal!(tensor, gain: 1.0) _xavier_normal!(tensor, gain) end |
.xavier_uniform!(tensor, gain: 1.0) ⇒ Object
37 38 39 |
# File 'lib/torch/nn/init.rb', line 37 def xavier_uniform!(tensor, gain: 1.0) _xavier_uniform!(tensor, gain) end |
.zeros!(tensor) ⇒ Object
25 26 27 |
# File 'lib/torch/nn/init.rb', line 25 def zeros!(tensor) _zeros!(tensor) end |