Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SpatialMaxUnpooling.lua - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 408bcc0521bfe6331a6a53ee4bc315e506f8f2ca (plain)
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
local SpatialMaxUnpooling, parent = torch.class('nn.SpatialMaxUnpooling', 'nn.Module')

function SpatialMaxUnpooling:__init(poolingModule)
   parent.__init(self)
   assert(torch.type(poolingModule)=='nn.SpatialMaxPooling', 'Argument must be a nn.SpatialMaxPooling module')
   assert(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
end

function SpatialMaxUnpooling:setParams()
   self.indices = self.pooling.indices
   self.oheight = self.pooling.iheight
   self.owidth = self.pooling.iwidth
end

function SpatialMaxUnpooling:updateOutput(input)
   self:setParams()
   input.THNN.SpatialMaxUnpooling_updateOutput(
   input:cdata(),
   self.output:cdata(),
   self.indices:cdata(),
   self.owidth, self.oheight
   )
   return self.output
end

function SpatialMaxUnpooling:updateGradInput(input, gradOutput)
   self:setParams()
   input.THNN.SpatialMaxUnpooling_updateGradInput(
   input:cdata(),
   gradOutput:cdata(),
   self.gradInput:cdata(),
   self.indices:cdata(),
   self.owidth, self.oheight
   )
   return self.gradInput
end

function SpatialMaxUnpooling:empty()
   self:clearState()
end

function SpatialMaxUnpooling:__tostring__()
   return 'nn.SpatialMaxUnpooling associated to '..tostring(self.pooling)
end