Class: DNN::Layers::Reshape

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

Instance Attribute Summary collapse

Attributes inherited from Layer

#input_shape, #name

Instance Method Summary collapse

Methods inherited from Layer

#build, #built?, #call, call, from_hash

Constructor Details

#initialize(output_shape) ⇒ Reshape

Returns a new instance of Reshape.



303
304
305
306
# File 'lib/dnn/core/layers.rb', line 303

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

Instance Attribute Details

#output_shapeObject (readonly)

Returns the value of attribute output_shape.



301
302
303
# File 'lib/dnn/core/layers.rb', line 301

def output_shape
  @output_shape
end

Instance Method Details

#backward(dy) ⇒ Object



312
313
314
# File 'lib/dnn/core/layers.rb', line 312

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

#forward(x) ⇒ Object



308
309
310
# File 'lib/dnn/core/layers.rb', line 308

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

#load_hash(hash) ⇒ Object



320
321
322
# File 'lib/dnn/core/layers.rb', line 320

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

#to_hashObject



316
317
318
# File 'lib/dnn/core/layers.rb', line 316

def to_hash
  super(output_shape: @output_shape)
end