Class: DNN::Layers::Reshape

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

Instance Attribute Summary

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.



286
287
288
289
# File 'lib/dnn/core/layers.rb', line 286

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

Instance Method Details

#backward(dy) ⇒ Object



295
296
297
# File 'lib/dnn/core/layers.rb', line 295

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

#forward(x) ⇒ Object



291
292
293
# File 'lib/dnn/core/layers.rb', line 291

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

#load_hash(hash) ⇒ Object



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

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

#output_shape ⇒ Object



299
300
301
# File 'lib/dnn/core/layers.rb', line 299

def output_shape
  @output_shape
end

#to_hash ⇒ Object



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

def to_hash
  super(output_shape: @output_shape)
end