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

github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Tompson <jonathantompson@gmail.com>2015-03-27 00:39:43 +0300
committerJonathan Tompson <jonathantompson@gmail.com>2015-03-27 00:39:43 +0300
commit91b494dd4d53ace615651ba2574f90ffc7d4a2df (patch)
tree40566777bdb0734c7a278fa50723e41a62815760 /test.lua
parent6577b5535eb136e4668dbd1fe509c79df19678e1 (diff)
Added SpatialDropout + doc + test.
Diffstat (limited to 'test.lua')
-rw-r--r--test.lua30
1 files changed, 29 insertions, 1 deletions
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)