class DNN::Layers::UnPool2D
Attributes
unpool_size[R]
Public Class Methods
new(unpool_size)
click to toggle source
@param [Array | Integer] unpool_size
Unpooling size. unpooling size is of the form [height, width].
Calls superclass method
DNN::Layers::Layer::new
# File lib/dnn/core/layers/cnn_layers.rb, line 442 def initialize(unpool_size) super() @unpool_size = unpool_size.is_a?(Integer) ? [unpool_size, unpool_size] : unpool_size end
Public Instance Methods
backward_node(dy)
click to toggle source
# File lib/dnn/core/layers/cnn_layers.rb, line 472 def backward_node(dy) in_size = @input_shape[0..1] col = im2col(dy, *in_size, *@unpool_size, @unpool_size) col = col.reshape(dy.shape[0] * in_size.reduce(:*), @unpool_size.reduce(:*), dy.shape[3]) col.sum(1).reshape(dy.shape[0], *in_size, dy.shape[3]) end
build(input_shape)
click to toggle source
Calls superclass method
DNN::Layers::Layer#build
# File lib/dnn/core/layers/cnn_layers.rb, line 447 def build(input_shape) unless input_shape.length == 3 raise DNNShapeError, "Input shape is #{input_shape}. But input shape must be 3 dimensional." end prev_h, prev_w = input_shape[0..1] unpool_h, unpool_w = @unpool_size out_h = prev_h * unpool_h out_w = prev_w * unpool_w @out_size = [out_h, out_w] @num_channel = input_shape[2] super end
compute_output_shape()
click to toggle source
# File lib/dnn/core/layers/cnn_layers.rb, line 479 def compute_output_shape [*@out_size, @num_channel] end
forward_node(x)
click to toggle source
# File lib/dnn/core/layers/cnn_layers.rb, line 460 def forward_node(x) @x_shape = x.shape unpool_h, unpool_w = @unpool_size x2 = Xumo::SFloat.zeros(x.shape[0], x.shape[1], unpool_h, x.shape[2], unpool_w, @num_channel) unpool_h.times do |i| unpool_w.times do |j| x2[true, true, i, true, j, true] = x end end x2.reshape(x.shape[0], *@out_size, x.shape[3]) end
load_hash(hash)
click to toggle source
# File lib/dnn/core/layers/cnn_layers.rb, line 487 def load_hash(hash) initialize(hash[:unpool_size]) end
to_hash()
click to toggle source
Calls superclass method
DNN::Layers::Layer#to_hash
# File lib/dnn/core/layers/cnn_layers.rb, line 483 def to_hash super(unpool_size: @unpool_size) end