Class: Torch::NN::GroupNorm

Inherits:
Module
  • Object
show all
Defined in:
lib/torch/nn/group_norm.rb

Instance Attribute Summary

Attributes inherited from Module

#training

Instance Method Summary collapse

Methods inherited from Module

#_apply, #add_module, #apply, #buffers, #call, #children, #cpu, #cuda, #deep_dup, #double, #eval, #float, #half, #inspect, #load_state_dict, #method_missing, #modules, #named_buffers, #named_children, #named_modules, #named_parameters, #parameters, #register_buffer, #register_parameter, #requires_grad!, #respond_to?, #share_memory, #state_dict, #to, #train, #type, #zero_grad

Methods included from Utils

#_activation_fn, #_clones, #_ntuple, #_pair, #_quadrupal, #_single, #_triple

Constructor Details

#initialize(num_groups, num_channels, eps: 1e-5, affine: true) ⇒ GroupNorm

Returns a new instance of GroupNorm.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/torch/nn/group_norm.rb', line 4

def initialize(num_groups, num_channels, eps: 1e-5, affine: true)
  super()
  @num_groups = num_groups
  @num_channels = num_channels
  @eps = eps
  @affine = affine
  if @affine
    @weight = Parameter.new(Torch::Tensor.new(num_channels))
    @bias = Parameter.new(Torch::Tensor.new(num_channels))
  else
    register_parameter("weight", nil)
    register_parameter("bias", nil)
  end
  reset_parameters
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Torch::NN::Module

Instance Method Details

#extra_inspectObject



31
32
33
# File 'lib/torch/nn/group_norm.rb', line 31

def extra_inspect
  format("%{num_groups}, %{num_channels}, eps: %{eps}, affine: %{affine}", **dict)
end

#forward(input) ⇒ Object



27
28
29
# File 'lib/torch/nn/group_norm.rb', line 27

def forward(input)
  F.group_norm(input, @num_groups, weight: @weight, bias: @bias, eps: @eps)
end

#reset_parametersObject



20
21
22
23
24
25
# File 'lib/torch/nn/group_norm.rb', line 20

def reset_parameters
  if @affine
    Init.ones!(@weight)
    Init.zeros!(@bias)
  end
end