Last active
February 21, 2016 18:15
-
-
Save andreaskoepf/5ba9864c561766f9260e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'cunn' | |
--test cuda & non-cuda version | |
function testVolumetricFullConvolution() | |
local input = torch.rand(1,2,10,10,10) * 2 - 1 | |
local a = nn.VolumetricFullConvolution(2,3, 3,3,3, 1,1,1) | |
local b = nn.VolumetricFullConvolution(2,3, 3,3,3, 1,1,1) | |
b:cuda() | |
b.weight = a.weight:cuda() | |
b.bias = a.bias:cuda() | |
local out1 = a:forward(input) | |
local out2 = b:forward(input:cuda()):double() | |
print("VolumetricFullConvolution: " .. (out1-out2):abs():sum()) | |
end | |
function testSpatialFullConvolution() | |
local input = torch.rand(1,2,10,10) * 2 - 1 | |
local a = nn.SpatialFullConvolution(2,3, 3,3, 1,1) | |
local b = nn.SpatialFullConvolution(2,3, 3,3, 1,1) | |
b:cuda() | |
b.weight = a.weight:cuda() | |
b.bias = a.bias:cuda() | |
local out1 = a:forward(input) | |
local out2 = b:forward(input:cuda()):double() | |
print("SpatialFullConvolution: " .. (out1-out2):abs():sum()) | |
end | |
testSpatialFullConvolution() | |
testVolumetricFullConvolution() | |
--[[ prints on my machine something like: | |
SpatialFullConvolution: 5.9598770636923e-06 | |
VolumetricFullConvolution: 1150.674565644 ]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment