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.



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

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

Instance Attribute Details

#shape ⇒ Object (readonly)

Returns the value of attribute shape.



237
238
239
# File 'lib/dnn/core/layers.rb', line 237

def shape
  @shape
end

Class Method Details

.load_hash(hash) ⇒ Object



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

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

Instance Method Details

#backward(dout) ⇒ Object



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

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

#forward(x) ⇒ Object



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

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

#to_hash ⇒ Object



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

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