Class: DNN::Layers::UnPool2D
Instance Attribute Summary collapse
-
#unpool_size ⇒ Object
readonly
Returns the value of attribute unpool_size.
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.
250 251 252 253 |
# File 'lib/dnn/core/cnn_layers.rb', line 250 def initialize(unpool_size) super() @unpool_size = unpool_size.is_a?(Integer) ? [unpool_size, unpool_size] : unpool_size end |
Instance Attribute Details
#unpool_size ⇒ Object (readonly)
Returns the value of attribute unpool_size.
248 249 250 |
# File 'lib/dnn/core/cnn_layers.rb', line 248 def unpool_size @unpool_size end |
Class Method Details
Instance Method Details
#backward(dout) ⇒ Object
277 278 279 280 281 |
# File 'lib/dnn/core/cnn_layers.rb', line 277 def backward(dout) unpool_h, unpool_w = @unpool_size dout = dout.reshape(dout.shape[0], @x_shape[0], unpool_h, @x_shape[1], unpool_w, @num_channel) dout[true, true, 0, true, 0, true].clone end |
#build(model) ⇒ Object
259 260 261 262 263 264 265 266 267 |
# File 'lib/dnn/core/cnn_layers.rb', line 259 def build(model) super prev_h, prev_w = prev_layer.shape[0..1] unpool_h, unpool_w = @unpool_size out_h = prev_h * unpool_h out_w = prev_w * unpool_w @out_size = [out_h, out_w] @num_channel = prev_layer.shape[2] end |
#forward(x) ⇒ Object
269 270 271 272 273 274 275 |
# File 'lib/dnn/core/cnn_layers.rb', line 269 def forward(x) @x_shape = x.shape unpool_h, unpool_w = @unpool_size x2 = Xumo::SFloat.zeros(x.shape[0], x.shape[1], unpool_h, x.shape[2], unpool_w, @num_channel) x2[true, true, 0, true, 0, true] = x x2.reshape(x.shape[0], *@out_size, x.shape[3]) end |
#shape ⇒ Object
283 284 285 |
# File 'lib/dnn/core/cnn_layers.rb', line 283 def shape [@out_width, @out_height, @num_channel] end |
#to_hash ⇒ Object
287 288 289 |
# File 'lib/dnn/core/cnn_layers.rb', line 287 def to_hash super({unpool_size: @unpool_size}) end |