Class: DNN::Layers::MaxPool2D
- Defined in:
- lib/dnn/core/cnn_layers.rb
Instance Attribute Summary
Attributes inherited from Pool2D
Attributes inherited from Layer
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Pool2D
#build, #initialize, #output_shape, #padding?, #to_hash
Methods inherited from Layer
#build, #built?, #initialize, #output_shape, #to_hash
Constructor Details
This class inherits a constructor from DNN::Layers::Pool2D
Class Method Details
Instance Method Details
#backward(dout) ⇒ Object
249 250 251 252 253 254 255 |
# File 'lib/dnn/core/cnn_layers.rb', line 249 def backward(dout) dmax = Xumo::SFloat.zeros(dout.size * @pool_size.reduce(:*)) dmax[@max_index] = dout.flatten dcol = dmax.reshape(dout.shape[0..2].reduce(:*), @pool_size.reduce(:*) * dout.shape[3]) dx = col2im(dcol, @x_shape, *@out_size, *@pool_size, @strides) @padding ? back_padding(dx, @pad_size) : dx end |
#forward(x) ⇒ Object
239 240 241 242 243 244 245 246 247 |
# File 'lib/dnn/core/cnn_layers.rb', line 239 def forward(x) x = 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]).transpose(0, 2, 1) .reshape(x.shape[0] * @out_size.reduce(:*) * x.shape[3], @pool_size.reduce(:*)) @max_index = col.max_index(1) col.max(1).reshape(x.shape[0], *@out_size, x.shape[3]) end |