Class: DNN::Layers::Reshape
Instance Attribute Summary
Attributes inherited from Layer
#input_shape, #output_shape
Instance Method Summary
collapse
Methods included from LayerNode
#forward
Methods inherited from Layer
#<<, #build, #built?, #call, call, #clean, #forward, from_hash
Constructor Details
#initialize(shape) ⇒ Reshape
Returns a new instance of Reshape.
308
309
310
311
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 308
def initialize(shape)
super()
@shape = shape
end
|
Instance Method Details
#_backward_cpu(dy) ⇒ Object
337
338
339
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 337
def _backward_cpu(dy)
dy.reshape(dy.shape[0], *@input_shape)
end
|
#_backward_gpu(dy) ⇒ Object
345
346
347
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 345
def _backward_gpu(dy)
dy.flatten.reshape(dy.shape[0], *@input_shape)
end
|
#_forward_cpu(x) ⇒ Object
333
334
335
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 333
def _forward_cpu(x)
x.reshape(x.shape[0], *@output_shape)
end
|
#_forward_gpu(x) ⇒ Object
341
342
343
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 341
def _forward_gpu(x)
x.flatten.reshape(x.shape[0], *@output_shape)
end
|
#backward_node(dy) ⇒ Object
325
326
327
328
329
330
331
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 325
def backward_node(dy)
if DNN.use_cumo?
_backward_gpu(dy)
else
_backward_cpu(dy)
end
end
|
#compute_output_shape ⇒ Object
313
314
315
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 313
def compute_output_shape
@shape
end
|
#forward_node(x) ⇒ Object
317
318
319
320
321
322
323
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 317
def forward_node(x)
if DNN.use_cumo?
_forward_gpu(x)
else
_forward_cpu(x)
end
end
|
#load_hash(hash) ⇒ Object
353
354
355
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 353
def load_hash(hash)
initialize(hash[:shape])
end
|
#to_hash ⇒ Object
349
350
351
|
# File 'lib/dnn/core/layers/basic_layers.rb', line 349
def to_hash
super(shape: @shape)
end
|