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, #builded?, #prev_layer

Constructor Details

#initialize(shape) ⇒ Reshape

Returns a new instance of Reshape.



388
389
390
391
# File 'lib/dnn/core/layers.rb', line 388

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

Instance Attribute Details

#shapeObject (readonly)

Returns the value of attribute shape.



386
387
388
# File 'lib/dnn/core/layers.rb', line 386

def shape
  @shape
end

Class Method Details

.load_hash(hash) ⇒ Object



393
394
395
# File 'lib/dnn/core/layers.rb', line 393

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

Instance Method Details

#backward(dout) ⇒ Object



402
403
404
# File 'lib/dnn/core/layers.rb', line 402

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

#forward(x) ⇒ Object



397
398
399
400
# File 'lib/dnn/core/layers.rb', line 397

def forward(x)
  @x_shape = x.shape
  x.reshape(*@shape)
end

#to_hashObject



406
407
408
# File 'lib/dnn/core/layers.rb', line 406

def to_hash
  {name: self.class.name, shape: @shape}
end