diff options
author | Ronan Collobert <ronan@collobert.com> | 2012-01-25 17:55:20 +0400 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2012-01-25 17:55:20 +0400 |
commit | 4df3893abd1b9f840f1d9a8c1859799ccbf941de (patch) | |
tree | e8a1e1cc1b6ea6e47855347b157eaf419fdb357b /SpatialSubSampling.lua |
initial revamp of torch7 tree
Diffstat (limited to 'SpatialSubSampling.lua')
-rw-r--r-- | SpatialSubSampling.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/SpatialSubSampling.lua b/SpatialSubSampling.lua new file mode 100644 index 0000000..48b32b9 --- /dev/null +++ b/SpatialSubSampling.lua @@ -0,0 +1,49 @@ +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 + self.weight:apply(function() + return torch.uniform(-stdv, stdv) + end) + self.bias:apply(function() + return torch.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 |