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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layer

#build, #built?

Constructor Details

#initialize(output_shape) ⇒ Reshape

Returns a new instance of Reshape.



254
255
256
257
# File 'lib/dnn/core/layers.rb', line 254

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

Class Method Details

.load_hash(hash) ⇒ Object



250
251
252
# File 'lib/dnn/core/layers.rb', line 250

def self.load_hash(hash)
  self.new(hash[:output_shape])
end

Instance Method Details

#backward(dout) ⇒ Object



263
264
265
# File 'lib/dnn/core/layers.rb', line 263

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

#forward(x) ⇒ Object



259
260
261
# File 'lib/dnn/core/layers.rb', line 259

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

#output_shape ⇒ Object



267
268
269
# File 'lib/dnn/core/layers.rb', line 267

def output_shape
  @output_shape
end

#to_hash ⇒ Object



271
272
273
# File 'lib/dnn/core/layers.rb', line 271

def to_hash
  super({output_shape: @output_shape})
end