Skip to content

Commit

Permalink
adding VolumetricDeconvolution + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soumith committed Oct 23, 2015
1 parent 2795741 commit 16399ef
Show file tree
Hide file tree
Showing 6 changed files with 480 additions and 0 deletions.
66 changes: 66 additions & 0 deletions VolumetricDeconvolution.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
local VolumetricDeconvolution, parent = torch.class('nn.VolumetricDeconvolution', 'nn.Module')

function VolumetricDeconvolution:__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 VolumetricDeconvolution: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 VolumetricDeconvolution:updateOutput(input)
return input.nn.VolumetricDeconvolution_updateOutput(self, input)
end

function VolumetricDeconvolution:updateGradInput(input, gradOutput)
return input.nn.VolumetricDeconvolution_updateGradInput(self, input, gradOutput)
end

function VolumetricDeconvolution:accGradParameters(input, gradOutput, scale)
return input.nn.VolumetricDeconvolution_accGradParameters(self, input, gradOutput, scale)
end
32 changes: 32 additions & 0 deletions doc/convolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ a kernel for computing the weighted average in a neighborhood ;
* [SpatialUpsamplingNearest](#nn.SpatialUpSamplingNearest): A simple upsampler applied to every channel of the feature map.
* [Volumetric Modules](#nn.VolumetricModules) apply to inputs with three-dimensional relationships (e.g. videos) :
* [VolumetricConvolution](#nn.VolumetricConvolution) : a 3D convolution over an input video (a sequence of images) ;
* [VolumetricDeconvolution](#nn.VolumetricDeconvolution) : a 3D convolution over an input video (a sequence of images) ;
* [VolumetricMaxPooling](#nn.VolumetricMaxPooling) : a 3D max-pooling operation over an input video.
* [VolumetricAveragePooling](#nn.VolumetricAveragePooling) : a 3D average-pooling operation over an input video.

Expand Down Expand Up @@ -610,6 +611,37 @@ size `nOutputPlane x nInputPlane x kT x kH x kW`) and `self.bias` (Tensor of
size `nOutputPlane`). The corresponding gradients can be found in
`self.gradWeight` and `self.gradBias`.

<a name="nn.VolumetricDeconvolution"></a>
### VolumetricDeconvolution ###

```lua
module = nn.VolumetricDeconvolution(nInputPlane, nOutputPlane, kT, kW, kH, [dT], [dW], [dH], [padT], [padW], [padH])
```

Applies a 3D deconvolution over an input image composed of several input planes. The `input` tensor in
`forward(input)` is expected to be a 4D or 5D tensor.

The parameters are the following:
* `nInputPlane`: The number of expected input planes in the image given into `forward()`.
* `nOutputPlane`: The number of output planes the convolution layer will produce.
* `kT`: The kernel depth of the deconvolution
* `kW`: The kernel width of the deconvolution
* `kH`: The kernel height of the deconvolution
* `dT`: The step of the deconvolution in the depth dimension. Default is `1`.
* `dW`: The step of the deconvolution in the width dimension. Default is `1`.
* `dH`: The step of the deconvolution in the height dimension. Default is `1`.
* `padT`: The additional zeros added per depth to the input planes. Default is `0`, a good number is `(kT-1)/2`.
* `padW`: The additional zeros added per width to the input planes. Default is `0`, a good number is `(kW-1)/2`.
* `padH`: The additional zeros added per height to the input planes. Default is `0`, a good number is `(kH-1)/2`.

If the input image is a 3D tensor `nInputPlane x depth x height x width`, the output image size
will be `nOutputPlane x odepth x oheight x owidth` where
```lua
odepth = (depth - 1) * dT - 2*padT + kT
owidth = (width - 1) * dW - 2*padW + kW
oheight = (height - 1) * dH - 2*padH + kH
```

<a name="nn.VolumetricMaxPooling"></a>
### VolumetricMaxPooling ###

Expand Down
Loading

0 comments on commit 16399ef

Please sign in to comment.