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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layer

#build, #built?, #call, call

Constructor Details

#initialize(output_shape) ⇒ Reshape

Returns a new instance of Reshape.



276
277
278
279
# File 'lib/dnn/core/layers.rb', line 276

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

Class Method Details

.from_hash(hash) ⇒ Object



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

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

Instance Method Details

#backward(dy) ⇒ Object



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

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

#forward(x) ⇒ Object



281
282
283
# File 'lib/dnn/core/layers.rb', line 281

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

#output_shape ⇒ Object



289
290
291
# File 'lib/dnn/core/layers.rb', line 289

def output_shape
  @output_shape
end

#to_hash ⇒ Object



293
294
295
# File 'lib/dnn/core/layers.rb', line 293

def to_hash
  super(output_shape: @output_shape)
end