Sample input to random shape.
nn.RSampling(minShape, maxShape, diff=false, verbose=false)
When diff = false
, RSampling layer will use identity transformation during test.
Adaptively Crop or pad its input to the given shape.
nn.AutoPadding(shape, diff=false, verbose=false)
When diff = false
, AutoPadding layer will use identity transformation during test.
This layer first computes the statistic of feature maps for each stream. Then, the statistics of all streams are compared through the given mode. Finally, only the winner stream is outputted.
The statistics computed can be max
, min
, mean
, or median
.
The comparison mode can be >(max)
, <(min)
, or random
The mode is encoded by [comparison mode + statistic]
For example, trainmode='maxmin'
and testmode='randommax'
mean that compute the min value of feature maps of each stream,
and output the stream having the max statistics during training, but randomly output an stream (max is ignored) during test.
nn.SwitcherTable(trainmode='maxmax', testmode='maxmax', inplace=false, verbose=false)
x = torch.rand(10)
diff = torch.rand(10)
-- two streams
n = nn.ConcatTable()
n:add(nn.Linear(10,10))
n:add(nn.Linear(10,10))
m = nn.Sequential()
m:add(n):add(nn.SwitcherTable('maxmin', 'minmax'))
m:forward(x)
m:backward(x, diff)
Randomly crop or pad its input to the given shape. This layer is similar to the AutoPadding. The difference is that the AutoPadding module perform center cropping or padding while this layer does this randomly.
nn.RandCropping(shape, diff=false, verbose=false)
Sample a random value from the given distribution. This layer uses the name Diffraction
since its function is similar to the diffraction of light. During backward, the returned gradInput is a zero Tensor of the same size as the input.
nn.Diffraction(min, max, nInputDim, isangle=false, diff=false, verbose=false)
The parameters are the following:
min
: the min value of uniform distributionmax
: the max value of uniform distributionnInputDIm
: if nInputDim is specified, it uses the input to determine the size of the batch.isangle
: if isangle istrue
, the min and max will be converted to radian value.diff
: ifdiff
is true, this layer will performIdentity()
transformation during backward.verbose
: ifversbose
is true, DEBUG information will be outputted.
- Copy layers you want to
torch/extra/nn
- Add
require('nn.LAYERNAME')
totorch/extra/nn/init.lua
CD
totorch/extra/nn/
directory and runluarocks make rocks/nn-scm-1.rockspec