Skip to content

Instantly share code, notes, and snippets.

@nagadomi
Last active May 9, 2016 13:11
Show Gist options
  • Save nagadomi/299a5e185987d81b79fa01d1f7a340c7 to your computer and use it in GitHub Desktop.
Save nagadomi/299a5e185987d81b79fa01d1f7a340c7 to your computer and use it in GitHub Desktop.
require 'nn'
torch.setdefaulttensortype("torch.FloatTensor")
upconv = nn.SpatialFullConvolution(1, 1, 2, 2, 2, 2, 0, 0)
input = torch.Tensor({{1, 10},{100, 1000}}):reshape(1, 1, 2, 2) -- (batch_size, input_dim, height, width)
weight = torch.Tensor({{1, 2}, {3, 4}}) -- 1x1x2x2 filter
bias = torch.Tensor({0.5})
upconv.weight:copy(weight)
upconv.bias:copy(bias)
print(upconv:forward(input))
--[[ output
(1,1,.,.) =
1.5000 2.5000 10.5000 20.5000
3.5000 4.5000 30.5000 40.5000
100.5000 200.5000 1000.5000 2000.5000
300.5000 400.5000 3000.5000 4000.5000
[torch.FloatTensor of size 1x1x4x4]
--]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment