Class: Chainer::Functions::Pooling::AveragePooling2DGrad

Inherits:
Chainer::FunctionNode show all
Defined in:
lib/chainer/functions/pooling/average_pooling_2d.rb

Instance Attribute Summary

Attributes inherited from Chainer::FunctionNode

#inputs, #outputs, #rank

Instance Method Summary collapse

Methods inherited from Chainer::FunctionNode

#apply, #backward_accumulate, #forward_cpu, #get_retained_inputs, #get_retained_outputs, #label, #output_data, #retain_inputs, #retain_outputs, #unchain

Constructor Details

#initialize(apool2d) ⇒ AveragePooling2DGrad

Returns a new instance of AveragePooling2DGrad.

[View source]

39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chainer/functions/pooling/average_pooling_2d.rb', line 39

def initialize(apool2d)
  @kh = apool2d.kh
  @kw = apool2d.kw
  @sy = apool2d.sy
  @sx = apool2d.sx
  @ph = apool2d.ph
  @pw = apool2d.pw
  @in_shape = apool2d.in_shape
  @in_dtype = apool2d.in_dtype
  @apool2d = apool2d
end

Instance Method Details

#backward(indexes, grad_outputs) ⇒ Object

[View source]

62
63
64
# File 'lib/chainer/functions/pooling/average_pooling_2d.rb', line 62

def backward(indexes, grad_outputs)
  AveragePooling2D.new([@kh, @kw], stride: [@sy, @sx], pad: [@ph, @pw], cover_all: false).apply(grad_outputs)
end

#forward(gy) ⇒ Object

[View source]

51
52
53
54
55
56
57
58
59
60
# File 'lib/chainer/functions/pooling/average_pooling_2d.rb', line 51

def forward(gy)
  h, w  = @in_shape[2..-1]
  shape = gy[0].shape
  shape.insert(2, 1, 1)
  gcol = gy[0].reshape(*shape).tile(1, 1, @kh, @kw, 1, 1)

  gx = Chainer::Utils::Conv.col2im(gcol, @sy, @sx, @ph, @pw, h, w)
  gx /= @kh * @kw
  [gx]
end