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.



191
192
193
194
195
# File 'lib/dnn/core/layers.rb', line 191

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

Instance Attribute Details

#shape ⇒ Object (readonly)

Returns the value of attribute shape.



189
190
191
# File 'lib/dnn/core/layers.rb', line 189

def shape
  @shape
end

Class Method Details

.load_hash(hash) ⇒ Object



197
198
199
# File 'lib/dnn/core/layers.rb', line 197

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

Instance Method Details

#backward(dout) ⇒ Object



206
207
208
# File 'lib/dnn/core/layers.rb', line 206

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

#forward(x) ⇒ Object



201
202
203
204
# File 'lib/dnn/core/layers.rb', line 201

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

#to_hash ⇒ Object



210
211
212
# File 'lib/dnn/core/layers.rb', line 210

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