diff options
author | soumith <soumith@gmail.com> | 2015-12-01 08:56:10 +0300 |
---|---|---|
committer | soumith <soumith@gmail.com> | 2015-12-01 08:56:10 +0300 |
commit | 62497562ceb4d5460b2f0f3ec2ea77b0a898473f (patch) | |
tree | cb6b6f7f3644e8bbb0f879c2c56a8988c678ed5a /VolumetricFullConvolution.lua | |
parent | 6ac61a5904cda94f83f26660b667b633217f5ccc (diff) |
refactoring Deconvolution -> FullConvolution
Diffstat (limited to 'VolumetricFullConvolution.lua')
-rw-r--r-- | VolumetricFullConvolution.lua | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/VolumetricFullConvolution.lua b/VolumetricFullConvolution.lua new file mode 100644 index 0000000..e8e91e3 --- /dev/null +++ b/VolumetricFullConvolution.lua @@ -0,0 +1,66 @@ +local VolumetricFullConvolution, parent = torch.class('nn.VolumetricFullConvolution', 'nn.Module') + +function VolumetricFullConvolution:__init(nInputPlane, nOutputPlane, kT, kH, kW, dT, dH, dW, pT, pH, pW) + parent.__init(self) + + dT = dT or 1 + dW = dW or 1 + dH = dH or 1 + + pT = pT or 0 + pW = pW or 0 + pH = pH or 0 + + self.nInputPlane = nInputPlane + self.nOutputPlane = nOutputPlane + self.kT = kT + self.kW = kW + self.kH = kH + self.dT = dT + self.dW = dW + self.dH = dH + self.pT = pT + self.pW = pW + self.pH = pH + + self.weight = torch.Tensor(nOutputPlane, nInputPlane, kT, kH, kW) + self.bias = torch.Tensor(nOutputPlane) + self.gradWeight = torch.Tensor(nOutputPlane, nInputPlane, kT, kH, kW) + self.gradBias = torch.Tensor(nOutputPlane) + -- temporary buffers for unfolding (CUDA) + self.finput = torch.Tensor() + self.fgradInput = torch.Tensor() + self:reset() +end + +function VolumetricFullConvolution:reset(stdv) + -- initialization of parameters + if stdv then + stdv = stdv * math.sqrt(3) + else + stdv = 1/math.sqrt(self.kT*self.kW*self.kH*self.nInputPlane) + 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 VolumetricFullConvolution:updateOutput(input) + return input.nn.VolumetricFullConvolution_updateOutput(self, input) +end + +function VolumetricFullConvolution:updateGradInput(input, gradOutput) + return input.nn.VolumetricFullConvolution_updateGradInput(self, input, gradOutput) +end + +function VolumetricFullConvolution:accGradParameters(input, gradOutput, scale) + return input.nn.VolumetricFullConvolution_accGradParameters(self, input, gradOutput, scale) +end |