diff options
author | nicholas-leonard <nick@nikopia.org> | 2014-09-23 04:56:38 +0400 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2014-10-27 17:05:16 +0300 |
commit | e85b059511fce2f7b846118bf6521e4abe30c08f (patch) | |
tree | 9e157941d621aec50e2a9e88e1d557053a4631b3 /test | |
parent | aa26ff3d388b28488ab88f455149ff68c9655319 (diff) |
Faster unit tests
Diffstat (limited to 'test')
-rw-r--r-- | test/test.lua | 452 |
1 files changed, 227 insertions, 225 deletions
diff --git a/test/test.lua b/test/test.lua index 99b4bd5..aebc755 100644 --- a/test/test.lua +++ b/test/test.lua @@ -21,10 +21,11 @@ local function equal(t1, t2, msg) end end + function nntest.Add() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj,ink):zero() local module = nn.Add(ini*inj*ink) @@ -47,9 +48,9 @@ function nntest.Add() end function nntest.CMul() - local ini = math.random(5,15) - local inj = math.random(5,15) - local ink = math.random(5,15) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj,ink):zero() local module = nn.CMul(ini*inj*ink) @@ -103,9 +104,9 @@ function nntest.ReLU() end function nntest.Exp() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj,ink):zero() local module = nn.Exp() @@ -118,9 +119,9 @@ function nntest.Exp() end function nntest.Log() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj,ink):zero() local module = nn.Log() @@ -133,9 +134,9 @@ function nntest.Log() end function nntest.HardTanh() - local ini = math.random(5,10) - local inj = math.random(5,10) - local ink = math.random(5,10) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, inj, ini):zero() local module = nn.HardTanh() @@ -149,9 +150,9 @@ function nntest.HardTanh() end function nntest.Abs() - local ini = math.random(5,10) - local inj = math.random(5,10) - local ink = math.random(5,10) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, inj, ini):zero() local module = nn.Abs() @@ -165,9 +166,9 @@ function nntest.Abs() end function nntest.Threshold() - local ini = math.random(5,10) - local inj = math.random(5,10) - local ink = math.random(5,10) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, inj, ini):zero() local module = nn.Threshold(torch.uniform(-2,2),torch.uniform(-2,2)) @@ -181,9 +182,9 @@ function nntest.Threshold() end function nntest.HardShrink() - local ini = math.random(5,10) - local inj = math.random(5,10) - local ink = math.random(5,10) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, inj, ini):zero() local module = nn.HardShrink(math.random()/2) @@ -197,9 +198,9 @@ function nntest.HardShrink() end function nntest.SoftShrink() - local ini = math.random(5,10) - local inj = math.random(5,10) - local ink = math.random(5,10) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, inj, ini):zero() local module = nn.SoftShrink(math.random()/2) @@ -213,15 +214,15 @@ function nntest.SoftShrink() end function nntest.Power() - local in1 = torch.rand(10,20) + local in1 = torch.rand(5,7) local module = nn.Power(2) local out = module:forward(in1) local err = out:dist(in1:cmul(in1)) mytester:asserteq(err, 0, torch.typename(module) .. ' - forward err ') - local ini = math.random(5,10) - local inj = math.random(5,10) - local ink = math.random(5,10) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local pw = torch.uniform()*math.random(1,10) local input = torch.Tensor(ink, inj, ini):zero() @@ -236,15 +237,15 @@ function nntest.Power() end function nntest.Square() - local in1 = torch.rand(10,20) + local in1 = torch.rand(5,7) local module = nn.Square() local out = module:forward(in1) local err = out:dist(in1:cmul(in1)) mytester:asserteq(err, 0, torch.typename(module) .. ' - forward err ') - local ini = math.random(5,10) - local inj = math.random(5,10) - local ink = math.random(5,10) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, inj, ini):zero() local module = nn.Square() @@ -258,15 +259,15 @@ function nntest.Square() end function nntest.Sqrt() - local in1 = torch.rand(10,20) + local in1 = torch.rand(5,7) local module = nn.Sqrt() local out = module:forward(in1) local err = out:dist(in1:sqrt()) mytester:asserteq(err, 0, torch.typename(module) .. ' - forward err ') - local ini = math.random(5,10) - local inj = math.random(5,10) - local ink = math.random(5,10) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, inj, ini):zero() local module = nn.Sqrt() @@ -280,8 +281,8 @@ function nntest.Sqrt() end function nntest.Linear() - local ini = math.random(5,7) - local inj_vals = {math.random(5,7), 1} -- Also test the inj = 1 spatial case + local ini = math.random(3,5) + local inj_vals = {math.random(3,5), 1} -- Also test the inj = 1 spatial case local input = torch.Tensor(ini):zero() for ind, inj in pairs(inj_vals) do @@ -350,9 +351,9 @@ function nntest.Linear() end function nntest.SparseLinear() - local ini = math.random(5000,10000) - local inj = math.random(50,100) - local numNonzero = math.random(5,20) + local ini = math.random(50,100) + local inj = math.random(5,10) + local numNonzero = math.random(3,5) local module = nn.SparseLinear(ini,inj) @@ -412,8 +413,8 @@ function nntest.SparseLinear() end function nntest.Euclidean() - local ini = math.random(50,70) - local inj = math.random(50,70) + local ini = math.random(5,7) + local inj = math.random(5,7) local input = torch.Tensor(ini):zero() local module = nn.Euclidean(ini,inj) @@ -429,8 +430,8 @@ function nntest.Euclidean() end function nntest.WeightedEuclidean() - local ini = math.random(10,20) - local inj = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(13,5) local input = torch.Tensor(ini):zero() local module = nn.WeightedEuclidean(ini,inj) @@ -475,8 +476,8 @@ local function criterionJacobianTest1D(cri, input, target) end function nntest.MSECriterion() - local input = torch.rand(100) - local target = input:clone():add(torch.rand(100)) + local input = torch.rand(10) + local target = input:clone():add(torch.rand(10)) local cri = nn.MSECriterion() criterionJacobianTest1D(cri, input, target) end @@ -489,23 +490,23 @@ function nntest.MarginCriterion() end function nntest.WeightedMSECriterion() - local input = torch.rand(100) - local target = input:clone():add(torch.rand(100)) - local cri = nn.WeightedMSECriterion(torch.rand(100)) + local input = torch.rand(10) + local target = input:clone():add(torch.rand(10)) + local cri = nn.WeightedMSECriterion(torch.rand(10)) criterionJacobianTest1D(cri, input, target) end function nntest.BCECriterion() local eps = 1e-2 - local input = torch.rand(100)*(1-eps) + eps/2 - local target = torch.rand(100)*(1-eps) + eps/2 + local input = torch.rand(10)*(1-eps) + eps/2 + local target = torch.rand(10)*(1-eps) + eps/2 local cri = nn.BCECriterion() criterionJacobianTest1D(cri, input, target) end function nntest.DistKLDivCriterion() - local input = torch.rand(100) - local target = input:clone():add(torch.rand(100)) + local input = torch.rand(10) + local target = input:clone():add(torch.rand(10)) local cri = nn.DistKLDivCriterion(true) -- sizeAverage = true criterionJacobianTest1D(cri, input, target) cri = nn.DistKLDivCriterion(false) -- sizeAverage = false @@ -529,9 +530,9 @@ function nntest.ClassNLLCriterion() end function nntest.LogSigmoid() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj,ink):zero() local module = nn.LogSigmoid() @@ -544,8 +545,8 @@ function nntest.LogSigmoid() end function nntest.LogSoftmax() - local ini = math.random(10,20) - local inj = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) local input = torch.Tensor(ini,inj):zero() local module = nn.LogSoftMax() @@ -572,9 +573,9 @@ end -- end function nntest.Max() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj*ink):zero() local module = nn.Max(1) @@ -587,9 +588,9 @@ function nntest.Max() end function nntest.Min() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj*ink):zero() local module = nn.Min(1) @@ -602,9 +603,9 @@ function nntest.Min() end function nntest.Mean() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj,ink):zero() local module = nn.Mean(torch.random(1,3)) @@ -617,9 +618,9 @@ function nntest.Mean() end function nntest.Mul() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj,ink):zero() local module = nn.Mul(ini*inj*ink) @@ -641,9 +642,9 @@ function nntest.Mul() end function nntest.Sigmoid() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj,ink):zero() local module = nn.Sigmoid() @@ -656,8 +657,8 @@ function nntest.Sigmoid() end function nntest.Softmax() - local ini = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, ini):zero() local module = nn.SoftMax() @@ -670,8 +671,8 @@ function nntest.Softmax() end function nntest.Softmin() - local ini = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, ini):zero() local module = nn.SoftMin() @@ -684,8 +685,8 @@ function nntest.Softmin() end function nntest.Softsign() - local ini = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, ini):zero() local module = nn.SoftSign() @@ -698,9 +699,9 @@ function nntest.Softsign() end function nntest.SoftPlus() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj,ink):zero() local module = nn.SoftPlus() @@ -713,9 +714,9 @@ function nntest.SoftPlus() end function nntest.SpatialSubtractiveNormalization_2dkernel() - local inputSize = math.random(11,20) - local kersize = 9 - local nbfeatures = math.random(5,10) + local inputSize = math.random(6,9) + local kersize = 3 + local nbfeatures = math.random(3,5) local kernel = torch.Tensor(kersize,kersize):fill(1) local module = nn.SpatialSubtractiveNormalization(nbfeatures,kernel) local input = torch.rand(nbfeatures,inputSize,inputSize) @@ -729,9 +730,9 @@ function nntest.SpatialSubtractiveNormalization_2dkernel() end function nntest.SpatialSubtractiveNormalization_1dkernel() - local inputSize = math.random(11,20) - local kersize = 9 - local nbfeatures = math.random(5,10) + local inputSize = math.random(6,9) + local kersize = 3 + local nbfeatures = math.random(3,5) local kernel = torch.Tensor(kersize):fill(1) local module = nn.SpatialSubtractiveNormalization(nbfeatures,kernel) local input = torch.rand(nbfeatures,inputSize,inputSize) @@ -745,9 +746,9 @@ function nntest.SpatialSubtractiveNormalization_1dkernel() end function nntest.SpatialDivisiveNormalization_2dkernel() - local inputSize = math.random(11,20) - local kersize = 9 - local nbfeatures = math.random(5,10) + local inputSize = math.random(6,9) + local kersize = 3 + local nbfeatures = math.random(3,5) local kernel = torch.Tensor(kersize,kersize):fill(1) local module = nn.SpatialDivisiveNormalization(nbfeatures,kernel) local input = torch.rand(nbfeatures,inputSize,inputSize) @@ -761,9 +762,9 @@ function nntest.SpatialDivisiveNormalization_2dkernel() end function nntest.SpatialDivisiveNormalization_1dkernel() - local inputSize = math.random(11,20) - local kersize = 9 - local nbfeatures = math.random(5,10) + local inputSize = math.random(6,9) + local kersize = 3 + local nbfeatures = math.random(3,5) local kernel = torch.Tensor(kersize):fill(1) local module = nn.SpatialDivisiveNormalization(nbfeatures,kernel) local input = torch.rand(nbfeatures,inputSize,inputSize) @@ -777,14 +778,14 @@ function nntest.SpatialDivisiveNormalization_1dkernel() end function nntest.SpatialConvolution() - local from = math.random(1,10) - local to = math.random(1,10) - local ki = math.random(1,10) - local kj = math.random(1,10) + local from = math.random(1,5) + local to = math.random(1,5) + local ki = math.random(1,5) + local kj = math.random(1,5) local si = math.random(1,4) local sj = math.random(1,4) - local outi = math.random(10,20) - local outj = math.random(10,20) + local outi = math.random(5,7) + local outj = math.random(5,7) local ini = (outi-1)*si+ki local inj = (outj-1)*sj+kj local module = nn.SpatialConvolution(from, to, ki, kj, si, sj) @@ -863,34 +864,31 @@ function nntest.SpatialConvolution() end function nntest.SpatialConvolutionMM() - local from = math.random(2,10) - local to = math.random(1,10) - local ki = math.random(1,5) - local kj = math.random(1,5) - local di = 1 -- NOTE: dw/dh still not supported - local dj = 1 - local padding = math.random(0,2) - local outi = math.random(10,20) - local outj = math.random(10,20) - local ini = outi-padding*2-1+ki - local inj = outj-padding*2-1+kj - local module = nn.SpatialConvolutionMM(from, to, ki, kj, di, dj, padding) + local from = math.random(1,5) + local to = math.random(1,5) + local ki = math.random(1,3) + local kj = math.random(1,3) + local outi = math.random(5,9) + local outj = math.random(5,9) + local ini = outi-1+ki + local inj = outj-1+kj + local module = nn.SpatialConvolutionMM(from, to, ki, kj) local input = torch.Tensor(from, inj, ini):zero() -- stochastic - + local err = jac.testJacobian(module, input) mytester:assertlt(err, precision, 'error on state ') - + local err = jac.testJacobianParameters(module, input, module.weight, module.gradWeight) mytester:assertlt(err , precision, 'error on weight ') - + local err = jac.testJacobianParameters(module, input, module.bias, module.gradBias) mytester:assertlt(err , precision, 'error on bias ') local err = jac.testJacobianUpdateParameters(module, input, module.weight) mytester:assertlt(err , precision, 'error on weight [direct update] ') - + local err = jac.testJacobianUpdateParameters(module, input, module.bias) mytester:assertlt(err , precision, 'error on bias [direct update] ') @@ -905,24 +903,28 @@ function nntest.SpatialConvolutionMM() end -- batch - + --verbose = true - local batch = math.random(2,6) - module = nn.SpatialConvolutionMM(from, to, ki, kj, di, dj, padding) + local batch = math.random(2,5) + outi = math.random(4,8) + outj = math.random(4,8) + ini = outi-1+ki + inj = outj-1+kj + module = nn.SpatialConvolutionMM(from, to, ki, kj) input = torch.Tensor(batch,from,inj,ini):zero() local err = jac.testJacobian(module, input) mytester:assertlt(err, precision, 'batch error on state ') - + local err = jac.testJacobianParameters(module, input, module.weight, module.gradWeight) mytester:assertlt(err , precision, 'batch error on weight ') - + local err = jac.testJacobianParameters(module, input, module.bias, module.gradBias) mytester:assertlt(err , precision, 'batch error on bias ') local err = jac.testJacobianUpdateParameters(module, input, module.weight) mytester:assertlt(err , precision, 'batch error on weight [direct update] ') - + local err = jac.testJacobianUpdateParameters(module, input, module.bias) mytester:assertlt(err , precision, 'batch error on bias [direct update] ') @@ -935,22 +937,22 @@ function nntest.SpatialConvolutionMM() mytester:assertlt(err, precision, string.format( 'batch error on bias [%s]', t)) end - + local ferr, berr = jac.testIO(module, input) mytester:asserteq(0, ferr, torch.typename(module) .. ' - i/o forward err ') mytester:asserteq(0, berr, torch.typename(module) .. ' - i/o backward err ') end function nntest.SpatialConvolutionMap() - local from = math.random(1,10) + local from = math.random(1,5) local fanin = math.random(1, from) - local to = math.random(1,10) - local ki = math.random(1,10) - local kj = math.random(1,10) - local si = math.random(1,4) - local sj = math.random(1,4) - local outi = math.random(10,20) - local outj = math.random(10,20) + local to = math.random(1,5) + local ki = math.random(1,5) + local kj = math.random(1,5) + local si = math.random(1,3) + local sj = math.random(1,3) + local outi = math.random(5,9) + local outj = math.random(5,9) local ini = (outi-1)*si+ki local inj = (outj-1)*sj+kj @@ -983,14 +985,14 @@ end function nntest.SpatialFullConvolution() - local from = math.random(1,10) - local to = math.random(1,10) - local ki = math.random(1,10) - local kj = math.random(1,10) + local from = math.random(1,5) + local to = math.random(1,5) + local ki = math.random(1,5) + local kj = math.random(1,5) local si = math.random(1,4) local sj = math.random(1,4) - local ini = math.random(10,18) - local inj = math.random(10,18) + local ini = math.random(5,8) + local inj = math.random(5,8) local module = nn.SpatialFullConvolution(from, to, ki, kj, si, sj) local input = torch.Tensor(from, inj, ini):zero() @@ -1058,16 +1060,16 @@ function nntest.SpatialFullConvolution() end function nntest.SpatialFullConvolutionMap() - local from = math.ceil(torch.uniform(2,5)) - local to = math.ceil(torch.uniform(2,7)) + local from = math.ceil(torch.uniform(2,4)) + local to = math.ceil(torch.uniform(2,5)) local fanin = math.ceil(torch.uniform(1, from)) local tt = nn.tables.random(from, to, fanin) - local ki = math.ceil(torch.uniform(2,7)) - local kj = math.ceil(torch.uniform(2,7)) + local ki = math.ceil(torch.uniform(2,5)) + local kj = math.ceil(torch.uniform(2,5)) local si = math.ceil(torch.uniform(1,3)) local sj = math.ceil(torch.uniform(1,3)) - local ini = math.ceil(torch.uniform(10,18)) - local inj = math.ceil(torch.uniform(10,18)) + local ini = math.ceil(torch.uniform(5,7)) + local inj = math.ceil(torch.uniform(5,7)) local module = nn.SpatialFullConvolutionMap(tt, ki, kj, si, sj) local input = torch.Tensor(from, inj, ini):zero() @@ -1103,15 +1105,15 @@ function nntest.SpatialFullConvolutionMap() end function nntest.SpatialFullConvolutionCompare() - local from = math.ceil(torch.uniform(2,5)) - local to = math.ceil(torch.uniform(2,7)) + local from = math.ceil(torch.uniform(2,4)) + local to = math.ceil(torch.uniform(2,5)) local tt = nn.tables.full(from, to) - local ki = math.ceil(torch.uniform(2,7)) - local kj = math.ceil(torch.uniform(2,7)) + local ki = math.ceil(torch.uniform(2,5)) + local kj = math.ceil(torch.uniform(2,5)) local si = math.ceil(torch.uniform(1,3)) local sj = math.ceil(torch.uniform(1,3)) - local ini = math.ceil(torch.uniform(10,18)) - local inj = math.ceil(torch.uniform(10,18)) + local ini = math.ceil(torch.uniform(7,8)) + local inj = math.ceil(torch.uniform(7,8)) local module1 = nn.SpatialFullConvolutionMap(tt, ki, kj, si, sj) local module2 = nn.SpatialFullConvolution(from, to, ki, kj, si, sj) local input = torch.rand(from, inj, ini) @@ -1171,14 +1173,14 @@ local function batchcompare(smod, sin, plist) end function nntest.SpatialConvolutionBatchCompare() - local from = math.random(1,10) - local to = math.random(1,10) - local ki = math.random(1,10) - local kj = math.random(1,10) + local from = math.random(1,5) + local to = math.random(1,5) + local ki = math.random(1,5) + local kj = math.random(1,5) local si = math.random(1,4) local sj = math.random(1,4) - local outi = math.random(10,20) - local outj = math.random(10,20) + local outi = math.random(5,9) + local outj = math.random(5,9) local ini = (outi-1)*si+ki local inj = (outj-1)*sj+kj @@ -1189,14 +1191,14 @@ function nntest.SpatialConvolutionBatchCompare() end function nntest.SpatialFullConvolutionBatchCompare() - local from = math.random(1,10) - local to = math.random(1,10) - local ki = math.random(1,10) - local kj = math.random(1,10) + local from = math.random(1,5) + local to = math.random(1,5) + local ki = math.random(1,5) + local kj = math.random(1,5) local si = math.random(1,4) local sj = math.random(1,4) - local ini = math.random(10,18) - local inj = math.random(10,18) + local ini = math.random(5,9) + local inj = math.random(5,9) local module = nn.SpatialFullConvolution(from, to, ki, kj, si, sj) local input = torch.randn(from, inj, ini) @@ -1207,13 +1209,13 @@ end function nntest.SpatialSubSamplingBatchCompare() - local from = math.random(1,10) + local from = math.random(1,6) local ki = math.random(1,5) local kj = math.random(1,5) local si = math.random(1,4) local sj = math.random(1,4) - local outi = math.random(10,20) - local outj = math.random(10,20) + local outi = math.random(6,10) + local outj = math.random(6,10) local ini = (outi-1)*si+ki local inj = (outj-1)*sj+kj local module = nn.SpatialSubSampling(from, ki, kj, si, sj) @@ -1223,13 +1225,13 @@ function nntest.SpatialSubSamplingBatchCompare() end function nntest.SpatialSubSampling() - local from = math.random(1,10) + local from = math.random(1,6) local ki = math.random(1,5) local kj = math.random(1,5) local si = math.random(1,4) local sj = math.random(1,4) - local outi = math.random(10,20) - local outj = math.random(10,20) + local outi = math.random(6,10) + local outj = math.random(6,10) local ini = (outi-1)*si+ki local inj = (outj-1)*sj+kj local module = nn.SpatialSubSampling(from, ki, kj, si, sj) @@ -1307,10 +1309,10 @@ function nntest.SpatialMaxPooling() local from = math.random(1,5) local ki = math.random(1,5) local kj = math.random(1,5) - local si = math.random(1,4) - local sj = math.random(1,4) - local outi = math.random(10,20) - local outj = math.random(10,20) + local si = math.random(1,3) + local sj = math.random(1,3) + local outi = math.random(2,4) + local outj = math.random(2,4) local ini = (outi-1)*si+ki local inj = (outj-1)*sj+kj @@ -1343,8 +1345,8 @@ function nntest.SpatialLPPooling() local osizex = math.random(1,4) local osizey = math.random(1,4) local p = 2 - local mx = math.random(2,8) - local my = math.random(2,8) + local mx = math.random(2,6) + local my = math.random(2,6) local dx = math.random(2,mx) local dy = math.random(2,my) local sizex = osizex*mx @@ -1361,9 +1363,9 @@ function nntest.SpatialLPPooling() end function nntest.Sum() - local ini = math.random(10,20) - local inj = math.random(10,20) - local ink = math.random(10,20) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ini,inj,ink):zero() local module = nn.Sum(torch.random(1,3)) @@ -1376,9 +1378,9 @@ function nntest.Sum() end function nntest.Tanh() - local ini = math.random(5,10) - local inj = math.random(5,10) - local ink = math.random(5,10) + local ini = math.random(3,5) + local inj = math.random(3,5) + local ink = math.random(3,5) local input = torch.Tensor(ink, inj, ini):zero() local module = nn.Tanh() @@ -1393,11 +1395,11 @@ end function nntest.TemporalConvolution() -- 1D - local from = math.random(1,10) - local to = math.random(1,10) - local ki = math.random(1,10) + local from = math.random(1,5) + local to = math.random(1,5) + local ki = math.random(1,5) local si = math.random(1,4) - local outi = math.random(10,20) + local outi = math.random(5,7) local ini = (outi-1)*si+ki local module = nn.TemporalConvolution(from, to, ki,si) local input = torch.Tensor(ini, from):zero() @@ -1428,7 +1430,7 @@ function nntest.TemporalConvolution() end -- 2D - local nBatchFrame = 8 + local nBatchFrame = 4 local input = torch.Tensor(nBatchFrame, ini, from):zero() local err = jac.testJacobian(module, input) @@ -1476,9 +1478,9 @@ end function nntest.TemporalSubSampling() local from = math.random(1,5) - local ki = math.random(1,10) + local ki = math.random(1,6) local si = math.random(1,4) - local outi = math.random(10,20) + local outi = math.random(6,9) local ini = (outi-1)*si+ki local module = nn.TemporalSubSampling(from, ki, si) local input = torch.Tensor(ini, from):zero() @@ -1514,10 +1516,10 @@ function nntest.TemporalSubSampling() end function nntest.TemporalMaxPooling() - local from = math.random(10,10) - local ki = math.random(5,10) + local from = math.random(2,4) + local ki = math.random(5,7) local si = math.random(1,2) - local outi = math.random(50,90) + local outi = math.random(30,40) local ini = (outi-1)*si+ki local module = nn.TemporalMaxPooling(ki, si) local input = torch.Tensor(ini, from):zero() @@ -1555,17 +1557,17 @@ function nntest.TemporalMaxPooling() end function nntest.VolumetricConvolution() - local from = math.random(2,5) - local to = math.random(2,5) - local kt = math.random(3,7) - local ki = math.random(3,7) - local kj = math.random(3,7) - local st = math.random(2,4) - local si = math.random(2,4) - local sj = math.random(2,4) - local outt = math.random(3,7) - local outi = math.random(3,7) - local outj = math.random(3,7) + local from = math.random(2,3) + local to = math.random(2,3) + local kt = math.random(3,4) + local ki = math.random(3,4) + local kj = math.random(3,4) + local st = math.random(2,3) + local si = math.random(2,3) + local sj = math.random(2,3) + local outt = math.random(3,4) + local outi = math.random(3,4) + local outj = math.random(3,4) local int = (outt-1)*st+kt local ini = (outi-1)*si+ki local inj = (outj-1)*sj+kj @@ -1603,17 +1605,17 @@ function nntest.VolumetricConvolution() end function nntest.VolumetricMaxPooling() - local from = math.random(2,5) + local from = math.random(2,3) local to = from - local kt = math.random(3,7) - local ki = math.random(3,7) - local kj = math.random(3,7) - local st = math.random(2,4) - local si = math.random(2,4) - local sj = math.random(2,4) - local outt = math.random(3,7) - local outi = math.random(3,7) - local outj = math.random(3,7) + local kt = math.random(3,4) + local ki = math.random(3,4) + local kj = math.random(3,4) + local st = math.random(2,3) + local si = math.random(2,3) + local sj = math.random(2,3) + local outt = math.random(3,4) + local outi = math.random(3,4) + local outj = math.random(3,4) local int = (outt-1)*st+kt local ini = (outi-1)*si+ki local inj = (outj-1)*sj+kj @@ -1806,7 +1808,7 @@ function nntest.PairwiseDistance() -- test will break. for p = 1,4 do -- test a few Lp norms -- TEST CASE 1: non-batch input, same code path but includes a resize - local ini = math.random(10,20) + local ini = math.random(3,5) local input = torch.Tensor(2, ini):zero() local module = nn.Sequential() module:add(nn.SplitTable(1)) @@ -1826,7 +1828,7 @@ function nntest.PairwiseDistance() mytester:assertlt(err,precision, ' error on non-batch fprop ') -- TEST CASE 2: batch input - local inj = math.random(10,20) + local inj = math.random(3,5) input = torch.Tensor(2, inj, ini):zero() -- (Rebuild the module to avoid correlated tests) @@ -1854,9 +1856,9 @@ function nntest.PairwiseDistance() end function nntest.LookupTable() - local totalIndex = math.random(10,100) - local nIndex = math.random(5,7) - local entry_size = math.random(5,7) + local totalIndex = math.random(6,9) + local nIndex = math.random(3,5) + local entry_size = math.random(2,5) local input = torch.IntTensor(nIndex):zero() local module = nn.LookupTable(totalIndex, entry_size) local minval = 1 @@ -1876,7 +1878,7 @@ function nntest.LookupTable() end -- 2D - local nframe = math.random(50,70) + local nframe = math.random(2,5) local input = torch.IntTensor(nframe, nIndex):zero() local err = jac.testJacobianParameters(module, input, module.weight, module.gradWeight, minval, maxval) @@ -1908,8 +1910,8 @@ end function nntest.AddConstant() local nbatch = torch.random(3, 5) local f = torch.random(3, 5) - local h = torch.random(10,20) - local w = torch.random(10,20) + local h = torch.random(7,9) + local w = torch.random(7,9) local input = torch.rand(nbatch, f, h, w):mul(20):add(-10) -- [-10, 10] local constant = torch.randn(1):squeeze() @@ -1928,8 +1930,8 @@ end function nntest.MulConstant() local nbatch = torch.random(3, 5) local f = torch.random(3, 5) - local h = torch.random(10,20) - local w = torch.random(10,20) + local h = torch.random(7,9) + local w = torch.random(7,9) local input = torch.rand(nbatch, f, h, w):mul(20):add(-10) -- [-10, 10] local constant = torch.randn(1):squeeze() @@ -2218,7 +2220,7 @@ end function nntest.ConcatTable() -- Test tensor input - local input = torch.rand(10, 10, 10) + local input = torch.rand(5, 5, 5) local m = nn.Sequential() local concat = nn.ConcatTable() |