Class: DNN::Layers::MaxPool2D
- Includes:
- LayerNode
- Defined in:
- lib/dnn/core/layers/cnn_layers.rb
Instance Attribute Summary
Attributes inherited from Pool2D
#padding, #pool_size, #strides
Attributes inherited from Layer
Instance Method Summary collapse
Methods included from LayerNode
Methods inherited from Pool2D
#build, #initialize, #load_hash, #output_shape, #to_hash
Methods inherited from Layer
#build, #built?, call, #call, #clean, #forward, from_hash, #initialize, #load_hash, #output_shape, #to_hash
Constructor Details
This class inherits a constructor from DNN::Layers::Pool2D
Instance Method Details
#backward_node(dy) ⇒ Object
362 363 364 365 366 367 368 |
# File 'lib/dnn/core/layers/cnn_layers.rb', line 362 def backward_node(dy) dmax = Xumo::SFloat.zeros(dy.size * @pool_size.reduce(:*)) dmax[@max_index.flatten] = dy.flatten dcol = dmax.reshape(dy.shape[0..2].reduce(:*), @pool_size.reduce(:*) * dy.shape[3]) dx = col2im(dcol, @x_shape, *@out_size, *@pool_size, @strides) @padding ? zero_padding_bwd(dx, @pad_size) : dx end |
#forward_node(x) ⇒ Object
353 354 355 356 357 358 359 360 |
# File 'lib/dnn/core/layers/cnn_layers.rb', line 353 def forward_node(x) x = zero_padding(x, @pad_size) if @padding @x_shape = x.shape col = im2col(x, *@out_size, *@pool_size, @strides) col = col.reshape(x.shape[0] * @out_size.reduce(:*), @pool_size.reduce(:*), x.shape[3]) @max_index = col.max_index(1) col.max(1).reshape(x.shape[0], *@out_size, x.shape[3]) end |