Class: Torch::NN::Upsample

Inherits:
Module
  • Object
show all
Defined in:
lib/torch/nn/upsample.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(size: nil, scale_factor: nil, mode: "nearest", align_corners: nil) ⇒ Upsample

Returns a new instance of Upsample.



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

def initialize(size: nil, scale_factor: nil, mode: "nearest", align_corners: nil)
  super()
  @size = size
  if scale_factor.is_a?(Array)
    @scale_factor = scale_factor.map(&:to_f)
  else
    @scale_factor = scale_factor ? scale_factor.to_f : nil
  end
  @mode = mode
  @align_corners = align_corners
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



20
21
22
23
24
25
26
27
28
# File 'lib/torch/nn/upsample.rb', line 20

def extra_inspect
  if !@scale_factor.nil?
    info = "scale_factor: #{@scale_factor.inspect}"
  else
    info = "size: #{@size.inspect}"
  end
  info += ", mode: #{@mode.inspect}"
  info
end

#forward(input) ⇒ Object



16
17
18
# File 'lib/torch/nn/upsample.rb', line 16

def forward(input)
  F.interpolate(input, size: @size, scale_factor: @scale_factor, mode: @mode, align_corners: @align_corners)
end