diff options
Diffstat (limited to 'test.lua')
-rw-r--r-- | test.lua | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -37,7 +37,6 @@ for test_name, component in pairs(tostringTestModules) do end end - function nntest.Add() local inj_vals = {math.random(3,5), 1} -- Also test the inj = 1 spatial case local ini = math.random(3,5) @@ -172,6 +171,35 @@ function nntest.Dropout() mytester:assert(math.abs(gradInput:mean() - (1-p)) < 0.05, 'dropout gradInput') end +function nntest.SpatialDropout() + local p = 0.2 --prob of dropiing out a neuron + local w = math.random(1,5) + local h = math.random(1,5) + local nfeats = 1000 + local input = torch.Tensor(nfeats, w, h):fill(1) + local module = nn.SpatialDropout(p) + module.train = true + local output = module:forward(input) + mytester:assert(math.abs(output:mean() - (1-p)) < 0.05, 'dropout output') + local gradInput = module:backward(input, input) + mytester:assert(math.abs(gradInput:mean() - (1-p)) < 0.05, 'dropout gradInput') +end + +function nntest.SpatialDropoutBatch() + local p = 0.2 --prob of dropiing out a neuron + local bsz = math.random(1,5) + local w = math.random(1,5) + local h = math.random(1,5) + local nfeats = 1000 + local input = torch.Tensor(bsz, nfeats, w, h):fill(1) + local module = nn.SpatialDropout(p) + module.train = true + local output = module:forward(input) + mytester:assert(math.abs(output:mean() - (1-p)) < 0.05, 'dropout output') + local gradInput = module:backward(input, input) + mytester:assert(math.abs(gradInput:mean() - (1-p)) < 0.05, 'dropout gradInput') +end + function nntest.ReLU() local input = torch.randn(3,4) local gradOutput = torch.randn(3,4) |