From 91b494dd4d53ace615651ba2574f90ffc7d4a2df Mon Sep 17 00:00:00 2001 From: Jonathan Tompson Date: Thu, 26 Mar 2015 17:39:43 -0400 Subject: Added SpatialDropout + doc + test. --- test.lua | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'test.lua') diff --git a/test.lua b/test.lua index a15cd61..27a1747 100644 --- a/test.lua +++ b/test.lua @@ -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) -- cgit v1.2.3