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, #learning_phase

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.



243
244
245
246
# File 'lib/dnn/core/layers.rb', line 243

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

Class Method Details

.from_hash(hash) ⇒ Object



239
240
241
# File 'lib/dnn/core/layers.rb', line 239

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

Instance Method Details

#backward(dy) ⇒ Object



252
253
254
# File 'lib/dnn/core/layers.rb', line 252

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

#forward(x) ⇒ Object



248
249
250
# File 'lib/dnn/core/layers.rb', line 248

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

#output_shape ⇒ Object



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

def output_shape
  @output_shape
end

#to_hash ⇒ Object



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

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