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

github.com/clementfarabet/lua---nnx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael 'myrhev' Mathieu <michael.mathieu@ens.fr>2012-03-24 06:17:20 +0400
committerMichael 'myrhev' Mathieu <michael.mathieu@ens.fr>2012-03-24 06:17:20 +0400
commitdb5715c6030574da048d1f710c49fddb86f3de05 (patch)
tree33a86b21f15212f9e8909291db5b9990191be020 /SpatialDownSampling.lua
parent12ba058c41397436cd3c80c14f7375cb77e81cbb (diff)
Add SpatialDownSampling module, a simple down-sampling averaging the pixels
Diffstat (limited to 'SpatialDownSampling.lua')
-rw-r--r--SpatialDownSampling.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/SpatialDownSampling.lua b/SpatialDownSampling.lua
new file mode 100644
index 0000000..b18849f
--- /dev/null
+++ b/SpatialDownSampling.lua
@@ -0,0 +1,39 @@
+local SpatialDownSampling, parent = torch.class('nn.SpatialDownSampling', 'nn.Module')
+
+local help_desc = [[
+Applies a 2D down-sampling over an input image composed of
+several input planes. The input tensor in forward(input) is
+expected to be a 3D tensor (nInputPlane x width x height).
+The number of output planes will be the same as nInputPlane.
+
+The downsampling is done using the simple average
+technique. For interpolated (bicubic) downsampling, use
+nn.SpatialReSampling().
+
+If the input image is a 3D tensor nInputPlane x width x height,
+the output image size will be nInputPlane x owidth x oheight where
+
+owidth = floor(width/rW)
+oheight = floor(height/rH) ]]
+
+function SpatialDownSampling:__init(...)
+ parent.__init(self)
+
+ -- get args
+ xlua.unpack_class(self, {...}, 'nn.SpatialDownSampling', help_desc,
+ {arg='rW', type='number', help='ratio width', req=true},
+ {arg='rH', type='number', help='ratio height', req=true})
+end
+
+function SpatialDownSampling:updateOutput(input)
+ self.output:resize(input:size(1), math.floor(input:size(2) / self.rH),
+ math.floor(input:size(3) / self.rW))
+ input.nn.SpatialDownSampling_updateOutput(self, input)
+ return self.output
+end
+
+function SpatialDownSampling:updateGradInput(input, gradOutput)
+ self.gradInput:resizeAs(input)
+ input.nn.SpatialDownSampling_updateGradInput(self, gradOutput)
+ return self.gradInput
+end