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

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

function TemporalSubSampling:__init(inputFrameSize, kW, dW)
   parent.__init(self)

   dW = dW or 1

   self.inputFrameSize = inputFrameSize
   self.kW = kW
   self.dW = dW

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

function TemporalSubSampling:reset(stdv)
   if stdv then
      stdv = stdv * math.sqrt(3)
   else
      stdv = 1/math.sqrt(self.kW)
   end

   self.weight:apply(function()
                        return torch.uniform(-stdv, stdv)
                     end)

   self.bias:apply(function()
                      return torch.uniform(-stdv, stdv)
                   end)   
end

function TemporalSubSampling:updateOutput(input)
   return input.nn.TemporalSubSampling_updateOutput(self, input)
end

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

function TemporalSubSampling:accGradParameters(input, gradOutput, scale)
   return input.nn.TemporalSubSampling_accGradParameters(self, input, gradOutput, scale)
end