Class: Torch::NN::Conv2d

Inherits:
ConvNd show all
Defined in:
lib/torch/nn/conv2d.rb

Instance Attribute Summary

Attributes inherited from ConvNd

#dilation, #groups, #in_channels, #kernel_size, #out_channels, #output_paddding, #padding, #padding_mode, #stride, #transposed

Attributes inherited from Module

#training

Instance Method Summary collapse

Methods inherited from ConvNd

#reset_parameters

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(in_channels, out_channels, kernel_size, stride: 1, padding: 0, dilation: 1, groups: 1, bias: true, padding_mode: "zeros") ⇒ Conv2d

Returns a new instance of Conv2d.



4
5
6
7
8
9
10
11
12
# File 'lib/torch/nn/conv2d.rb', line 4

def initialize(in_channels, out_channels, kernel_size, stride: 1,
  padding: 0, dilation: 1, groups: 1, bias: true, padding_mode: "zeros")

  kernel_size = _pair(kernel_size)
  stride = _pair(stride)
  padding = _pair(padding)
  dilation = _pair(dilation)
  super(in_channels, out_channels, kernel_size, stride, padding, dilation, false, _pair(0), groups, bias, padding_mode)
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



21
22
23
24
25
26
27
28
29
30
# File 'lib/torch/nn/conv2d.rb', line 21

def extra_inspect
  s = String.new("%{in_channels}, %{out_channels}, kernel_size: %{kernel_size}, stride: %{stride}")
  s += ", padding: %{padding}" if @padding != [0] * @padding.size
  s += ", dilation: %{dilation}" if @dilation != [1] * @dilation.size
  s += ", output_padding: %{output_padding}" if @output_padding != [0] * @output_padding.size
  s += ", groups: %{groups}" if @groups != 1
  s += ", bias: false" unless @bias
  s += ", padding_mode: %{padding_mode}" if @padding_mode != "zeros"
  format(s, **dict)
end

#forward(input) ⇒ Object



14
15
16
17
18
19
# File 'lib/torch/nn/conv2d.rb', line 14

def forward(input)
  if @padding_mode == "circular"
    raise NotImplementedError
  end
  F.conv2d(input, @weight, @bias, @stride, @padding, @dilation, @groups)
end