Class: DNN::Layers::UnPool2D
- Includes:
- Convert
- Defined in:
- lib/dnn/core/layers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #backward(dout) ⇒ Object
- #build(model) ⇒ Object
- #forward(x) ⇒ Object
-
#initialize(unpool_size) ⇒ UnPool2D
constructor
A new instance of UnPool2D.
- #shape ⇒ Object
- #to_hash ⇒ Object
Methods inherited from Layer
Constructor Details
#initialize(unpool_size) ⇒ UnPool2D
Returns a new instance of UnPool2D.
378 379 380 381 |
# File 'lib/dnn/core/layers.rb', line 378 def initialize(unpool_size) super() @unpool_size = unpool_size.is_a?(Integer) ? [unpool_size, unpool_size] : unpool_size end |
Class Method Details
Instance Method Details
#backward(dout) ⇒ Object
405 406 407 408 409 |
# File 'lib/dnn/core/layers.rb', line 405 def backward(dout) unpool_w, unpool_h = @unpool_size dout = dout.reshape(dout.shape[0], @x_shape[0], unpool_w, @x_shape[1], unpool_h, @num_channel) dout[true, true, 0, true, 0, true].clone end |
#build(model) ⇒ Object
387 388 389 390 391 392 393 394 395 |
# File 'lib/dnn/core/layers.rb', line 387 def build(model) super prev_w, prev_h = prev_layer.shape[0..1] unpool_w, unpool_h = @unpool_size out_w = prev_w * unpool_w out_h = prev_h * unpool_h @out_size = [out_w, out_h] @num_channel = prev_layer.shape[2] end |
#forward(x) ⇒ Object
397 398 399 400 401 402 403 |
# File 'lib/dnn/core/layers.rb', line 397 def forward(x) @x_shape = x.shape unpool_w, unpool_h = @unpool_size x2 = SFloat.zeros(x.shape[0], x.shape[1], unpool_w, x.shape[2], unpool_h, @num_channel) x2[true, true, 0, true, 0, true] = x x2.reshape(x.shape[0], *@out_size, x.shape[3]) end |
#shape ⇒ Object
411 412 413 |
# File 'lib/dnn/core/layers.rb', line 411 def shape [@out_width, @out_height, @num_channel] end |
#to_hash ⇒ Object
415 416 417 418 419 420 |
# File 'lib/dnn/core/layers.rb', line 415 def to_hash { name: self.class.name, unpool_size: @unpool_size, } end |