Class: DNN::Layers::Reshape

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layer

#build, #built?, #prev_layer

Constructor Details

#initialize(shape) ⇒ Reshape

Returns a new instance of Reshape.



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

def initialize(shape)
  super()
  @shape = shape
  @x_shape = nil
end

Instance Attribute Details

#shapeObject (readonly)

Returns the value of attribute shape.



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

def shape
  @shape
end

Class Method Details

.load_hash(hash) ⇒ Object



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

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

Instance Method Details

#backward(dout) ⇒ Object



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

def backward(dout)
  dout.reshape(*@x_shape)
end

#forward(x) ⇒ Object



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

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

#to_hashObject



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

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