Class: Chainer::Functions::Pooling::MaxPooling2D
- Inherits:
-
Pooling2D
- Object
- Chainer::FunctionNode
- Pooling2D
- Chainer::Functions::Pooling::MaxPooling2D
- Defined in:
- lib/chainer/functions/pooling/max_pooling_2d.rb
Instance Attribute Summary collapse
-
#in_dtype ⇒ Object
readonly
Returns the value of attribute in_dtype.
-
#in_shape ⇒ Object
readonly
Returns the value of attribute in_shape.
-
#indexes ⇒ Object
readonly
Returns the value of attribute indexes.
Attributes inherited from Pooling2D
#cover_all, #kh, #kw, #ph, #pw, #sx, #sy
Attributes inherited from Chainer::FunctionNode
Class Method Summary collapse
-
.max_pooling_2d(x, ksize, stride: nil, pad: 0, cover_all: true) ⇒ Chainer::Variable
Spatial max pooling function.
Instance Method Summary collapse
Methods inherited from Pooling2D
Methods inherited from Chainer::FunctionNode
#apply, #backward_accumulate, #forward_cpu, #get_retained_inputs, #get_retained_outputs, #initialize, #label, #output_data, #retain_inputs, #retain_outputs, #unchain
Constructor Details
This class inherits a constructor from Chainer::Functions::Pooling::Pooling2D
Instance Attribute Details
#in_dtype ⇒ Object (readonly)
Returns the value of attribute in_dtype.
5 6 7 |
# File 'lib/chainer/functions/pooling/max_pooling_2d.rb', line 5 def in_dtype @in_dtype end |
#in_shape ⇒ Object (readonly)
Returns the value of attribute in_shape.
5 6 7 |
# File 'lib/chainer/functions/pooling/max_pooling_2d.rb', line 5 def in_shape @in_shape end |
#indexes ⇒ Object (readonly)
Returns the value of attribute indexes.
5 6 7 |
# File 'lib/chainer/functions/pooling/max_pooling_2d.rb', line 5 def indexes @indexes end |
Class Method Details
.max_pooling_2d(x, ksize, stride: nil, pad: 0, cover_all: true) ⇒ Chainer::Variable
Spatial max pooling function
14 15 16 |
# File 'lib/chainer/functions/pooling/max_pooling_2d.rb', line 14 def self.max_pooling_2d(x, ksize, stride: nil, pad: 0, cover_all: true) self.new(ksize, stride: stride, pad: pad, cover_all: cover_all).apply([x]).first end |
Instance Method Details
#backward(indexes, gy) ⇒ Object
36 37 38 |
# File 'lib/chainer/functions/pooling/max_pooling_2d.rb', line 36 def backward(indexes, gy) MaxPooling2DGrad.new(self).apply(gy) end |
#forward(x) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chainer/functions/pooling/max_pooling_2d.rb', line 18 def forward(x) @in_shape = x[0].shape @in_dtype = x[0].class col = Chainer::Utils::Conv.im2col(x[0], @kh, @kw, @sy, @sx, @ph, @pw, pval: -Float::INFINITY, cover_all: @cover_all) n, c, kh, kw, out_h, out_w = col.shape col = col.reshape(n , c, kh * kw, out_h, out_w) # TODO: numpy.argmax(axis=2) d = col.shape[3..-1].reduce(:*) || 1 dx = col.shape[2..-1].reduce(:*) || 1 max_index = col.max_index(2) @indexes = max_index.flatten.map_with_index { |val, idx| (val - (dx * (idx / d))) / d }.reshape(*max_index.shape) y = col.max(axis: 2) [y] end |