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

github.com/soumith/cudnn.torch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Zagoruyko <zagoruyko2@gmail.com>2015-12-30 11:10:22 +0300
committerSergey Zagoruyko <zagoruyko2@gmail.com>2015-12-30 11:10:22 +0300
commit5df9db13503323b0ba4b3166bedd3a96d1dae09a (patch)
treefd84b231d500063db3259794451cb56920525cdc
parenta1f57105816109f4f1d86109ce4e2b6a3365d006 (diff)
test SpatialCrossMapLRN against nn
-rw-r--r--test/test.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test.lua b/test/test.lua
index 6f75057..c4c4a79 100644
--- a/test/test.lua
+++ b/test/test.lua
@@ -608,6 +608,45 @@ function cudnntest.Sigmoid_batch()
nonlinBatch('Sigmoid')
end
+function cudnntest.SpatialCrossMapLRN_batch()
+ local bs = math.random(4,10)
+ local inputSize = math.random(6,9)
+ local size = math.random(1,3)*2+1
+ local nbfeatures = math.random(3,8)
+ local alpha = math.random(1,100)/100
+ local beta = math.random(0,100)/100
+ local k = math.random(1,3)
+
+ local tm = {}
+ local title = string.format('SpatialCrossMapLRN.forward')
+ times[title] = tm
+
+ local input = torch.rand(bs, nbfeatures, inputSize, inputSize):cuda()
+ local gradOutput = torch.rand(input:size()):cuda()
+ local sconv = nn.SpatialCrossMapLRN(size, alpha, beta, k):cuda()
+ local gconv = cudnn.SpatialCrossMapLRN(size, alpha, beta, k):cuda()
+
+ local groundtruth = sconv:forward(input):clone()
+ local groundgrad = sconv:backward(input, gradOutput)
+ cutorch.synchronize()
+ gconv:forward(input)
+ -- serialize and deserialize
+ torch.save('modelTemp.t7', gconv)
+ gconv = torch.load('modelTemp.t7')
+ local rescuda = gconv:forward(input)
+ local resgrad = gconv:backward(input, gradOutput)
+ cutorch.synchronize()
+ mytester:asserteq(rescuda:dim(), 4, 'error in dimension')
+ mytester:asserteq(resgrad:dim(), 4, 'error in dimension')
+ local error = rescuda:float() - groundtruth:float()
+ mytester:assertlt(error:abs():max(), precision_forward,
+ 'error on state (forward) ')
+ error = resgrad:float() - groundgrad:float()
+ mytester:assertlt(error:abs():max(), precision_backward,
+ 'error on state (backward) ')
+end
+
+
function cudnntest.SoftMax_single()
local sz = math.random(1,64)
local input = torch.randn(sz):cuda()
@@ -801,6 +840,7 @@ function cudnntest.SpatialLogSoftMax()
mytester:assertlt(err, precision_backward, 'error in difference between central difference and :backward')
end
+--[[
function cudnntest.SpatialCrossEntropyCriterion()
-- batch
local numLabels = math.random(5,10)
@@ -832,6 +872,7 @@ function cudnntest.SpatialCrossEntropyCriterion()
mytester:assertlt(err, precision_backward, 'error in difference between central difference and :backward')
end
+]]