-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpatialAveragePooling.lua
37 lines (32 loc) · 1.04 KB
/
SpatialAveragePooling.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local SpatialAveragePooling, parent = torch.class('nn.SpatialAveragePooling', 'nn.Module')
function SpatialAveragePooling:__init(kW, kH, dW, dH)
parent.__init(self)
self.kW = kW
self.kH = kH
self.dW = dW or 1
self.dH = dH or 1
self.divide = true
end
function SpatialAveragePooling:updateOutput(input)
input.nn.SpatialAveragePooling_updateOutput(self, input)
-- for backward compatibility with saved models
-- which are not supposed to have "divide" field
if not self.divide then
self.output:mul(self.kW*self.kH)
end
return self.output
end
function SpatialAveragePooling:updateGradInput(input, gradOutput)
if self.gradInput then
input.nn.SpatialAveragePooling_updateGradInput(self, input, gradOutput)
-- for backward compatibility
if not self.divide then
self.gradInput:mul(self.kW*self.kH)
end
return self.gradInput
end
end
function SpatialAveragePooling:__tostring__()
return string.format('%s(%d,%d,%d,%d)', torch.type(self),
self.kW, self.kH, self.dW, self.dH)
end