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

SpatialSubSampling.lua - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 19aa2f56363f3a6b5ae2ba5bbe5552df6c6d26d9 (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
46
47
48
49
50
51
52
53
54
local SpatialSubSampling, parent = torch.class('nn.SpatialSubSampling', 'nn.Module')

function SpatialSubSampling:__init(nInputPlane, kW, kH, dW, dH)
   parent.__init(self)

   dW = dW or 1
   dH = dH or 1

   self.nInputPlane = nInputPlane
   self.kW = kW
   self.kH = kH
   self.dW = dW
   self.dH = dH

   self.weight = torch.Tensor(nInputPlane)
   self.bias = torch.Tensor(nInputPlane)
   self.gradWeight = torch.Tensor(nInputPlane)
   self.gradBias = torch.Tensor(nInputPlane)
   
   self:reset()
end

function SpatialSubSampling:reset(stdv)
   if stdv then
      stdv = stdv * math.sqrt(3)
   else
      stdv = 1/math.sqrt(self.kW*self.kH)
   end
   if nn.oldSeed then
      self.weight:apply(function()
         return torch.uniform(-stdv, stdv)
      end)
      self.bias:apply(function()
         return torch.uniform(-stdv, stdv)
      end) 
   else
      self.weight:uniform(-stdv, stdv)
      self.bias:uniform(-stdv, stdv)
   end
end

function SpatialSubSampling:updateOutput(input)
   return input.nn.SpatialSubSampling_updateOutput(self, input)
end

function SpatialSubSampling:updateGradInput(input, gradOutput)
   if self.gradInput then
      return input.nn.SpatialSubSampling_updateGradInput(self, input, gradOutput)
   end
end

function SpatialSubSampling:accGradParameters(input, gradOutput, scale)
   return input.nn.SpatialSubSampling_accGradParameters(self, input, gradOutput, scale)
end