Class: DNN::Layers::AvgPool2D
- 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, #compute_output_shape, #initialize, #load_hash, #to_hash
Methods included from Conv2DUtils
calc_conv2d_out_size, calc_conv2d_padding_size, calc_conv2d_transpose_out_size, calc_conv2d_transpose_padding_size, col2im, col2im_cpu, col2im_gpu, im2col, im2col_cpu, im2col_gpu, zero_padding, zero_padding_bwd
Methods inherited from Layer
#<<, #build, #built?, #call, call, #clean, #compute_output_shape, #forward, from_hash, #initialize, #load_hash, #to_hash
Constructor Details
This class inherits a constructor from DNN::Layers::Pool2D
Instance Method Details
#backward_node(dy) ⇒ Object
409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/dnn/core/layers/cnn_layers.rb', line 409 def backward_node(dy) row_length = @pool_size.reduce(:*) dy /= row_length davg = Xumo::SFloat.zeros(dy.size, row_length) row_length.times do |i| davg[true, i] = dy.flatten end dcol = davg.reshape(dy.shape[0..2].reduce(:*), dy.shape[3] * @pool_size.reduce(:*)) dx = col2im(dcol, @x_shape, *@out_size, *@pool_size, @strides) @padding ? zero_padding_bwd(dx, @pad_size) : dx end |
#forward_node(x) ⇒ Object
401 402 403 404 405 406 407 |
# File 'lib/dnn/core/layers/cnn_layers.rb', line 401 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]) col.mean(1).reshape(x.shape[0], *@out_size, x.shape[3]) end |