Class: DNN::Layers::Reshape

Inherits:
Layer
  • Object
show all
Includes:
LayerNode
Defined in:
lib/dnn/core/layers/basic_layers.rb

Instance Attribute Summary

Attributes inherited from Layer

#input_shape, #output_shape

Instance Method Summary collapse

Methods included from LayerNode

#forward

Methods inherited from Layer

#build, #built?, #call, call, #clean, #forward, from_hash

Constructor Details

#initialize(shape) ⇒ Reshape

Returns a new instance of Reshape.



322
323
324
325
# File 'lib/dnn/core/layers/basic_layers.rb', line 322

def initialize(shape)
  super()
  @shape = shape
end

Instance Method Details

#backward_node(dy) ⇒ Object



335
336
337
# File 'lib/dnn/core/layers/basic_layers.rb', line 335

def backward_node(dy)
  dy.reshape(dy.shape[0], *@input_shape)
end

#compute_output_shapeObject



327
328
329
# File 'lib/dnn/core/layers/basic_layers.rb', line 327

def compute_output_shape
  @shape
end

#forward_node(x) ⇒ Object



331
332
333
# File 'lib/dnn/core/layers/basic_layers.rb', line 331

def forward_node(x)
  x.reshape(x.shape[0], *@output_shape)
end

#load_hash(hash) ⇒ Object



343
344
345
# File 'lib/dnn/core/layers/basic_layers.rb', line 343

def load_hash(hash)
  initialize(hash[:shape])
end

#to_hashObject



339
340
341
# File 'lib/dnn/core/layers/basic_layers.rb', line 339

def to_hash
  super(shape: @shape)
end