-
Notifications
You must be signed in to change notification settings - Fork 2
/
VolumetricMaxUnpooling.lua
52 lines (45 loc) · 1.75 KB
/
VolumetricMaxUnpooling.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
local VolumetricMaxUnpooling, parent = torch.class('nn.VolumetricMaxUnpooling', 'nn.Module')
function VolumetricMaxUnpooling:__init(poolingModule)
parent.__init(self)
assert(torch.type(poolingModule)=='nn.VolumetricMaxPooling', 'Argument must be a nn.VolumetricMaxPooling module')
assert(poolingModule.kT==poolingModule.dT and poolingModule.kH==poolingModule.dH and poolingModule.kW==poolingModule.dW, "The size of pooling module's kernel must be equal to its stride")
self.pooling = poolingModule
poolingModule.updateOutput = function(pool, input)
local dims = input:dim()
pool.itime = input:size(dims-2)
pool.iheight = input:size(dims-1)
pool.iwidth = input:size(dims)
return nn.VolumetricMaxPooling.updateOutput(pool, input)
end
end
function VolumetricMaxUnpooling:setParams()
self.indices = self.pooling.indices
self.otime = self.pooling.itime
self.oheight = self.pooling.iheight
self.owidth = self.pooling.iwidth
self.dT = self.pooling.dT
self.dH = self.pooling.dH
self.dW = self.pooling.dW
self.padT = self.pooling.padT
self.padH = self.pooling.padH
self.padW = self.pooling.padW
end
function VolumetricMaxUnpooling:updateOutput(input)
self:setParams()
input.nn.VolumetricMaxUnpooling_updateOutput(self, input)
return self.output
end
function VolumetricMaxUnpooling:updateGradInput(input, gradOutput)
self:setParams()
input.nn.VolumetricMaxUnpooling_updateGradInput(self, input, gradOutput)
return self.gradInput
end
function VolumetricMaxUnpooling:empty()
self.gradInput:resize()
self.gradInput:storage():resize(0)
self.output:resize()
self.output:storage():resize(0)
end
function VolumetricMaxUnpooling:__tostring__()
return 'nn.VolumetricMaxUnpooling associated to '..tostring(self.pooling)
end