Class: DNN::Layers::Reshape

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

Instance Attribute Summary collapse

Attributes inherited from Layer

#input_shape

Instance Method Summary collapse

Methods included from LayerNode

#backward, #forward

Methods inherited from Layer

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

Constructor Details

#initialize(output_shape) ⇒ Reshape

Returns a new instance of Reshape.



349
350
351
352
# File 'lib/dnn/core/layers/basic_layers.rb', line 349

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

Instance Attribute Details

#output_shapeObject (readonly)

Returns the value of attribute output_shape.



347
348
349
# File 'lib/dnn/core/layers/basic_layers.rb', line 347

def output_shape
  @output_shape
end

Instance Method Details

#backward_node(dy) ⇒ Object



358
359
360
# File 'lib/dnn/core/layers/basic_layers.rb', line 358

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

#forward_node(x) ⇒ Object



354
355
356
# File 'lib/dnn/core/layers/basic_layers.rb', line 354

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

#load_hash(hash) ⇒ Object



366
367
368
# File 'lib/dnn/core/layers/basic_layers.rb', line 366

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

#to_hashObject



362
363
364
# File 'lib/dnn/core/layers/basic_layers.rb', line 362

def to_hash
  super(output_shape: @output_shape)
end