diff options
author | Clement Farabet <clement.farabet@gmail.com> | 2013-02-20 17:07:16 +0400 |
---|---|---|
committer | Clement Farabet <clement.farabet@gmail.com> | 2013-02-20 17:07:16 +0400 |
commit | f328917848bf4b05a097445414210e7f9d1effdc (patch) | |
tree | d62c41734a1a2dd7dccb94489bfeedf7ee03d00b | |
parent | 1ee64da4abbafd92c6bea5121e9a11e55ef1cbcb (diff) | |
parent | 362fe09df4809393ba5091485cbf46c78767912b (diff) |
Merge branch 'nn_fast_reset'
-rw-r--r-- | Euclidean.lua | 13 | ||||
-rw-r--r-- | Linear.lua | 18 | ||||
-rw-r--r-- | LookupTable.lua | 10 | ||||
-rw-r--r-- | SparseLinear.lua | 18 | ||||
-rw-r--r-- | SpatialConvolution.lua | 17 | ||||
-rw-r--r-- | SpatialConvolutionMM.lua | 17 | ||||
-rw-r--r-- | SpatialConvolutionMap.lua | 29 | ||||
-rw-r--r-- | SpatialSubSampling.lua | 17 | ||||
-rw-r--r-- | TemporalConvolution.lua | 17 | ||||
-rw-r--r-- | TemporalSubSampling.lua | 19 | ||||
-rw-r--r-- | VolumetricConvolution.lua | 17 | ||||
-rw-r--r-- | WeightedEuclidean.lua | 14 |
12 files changed, 128 insertions, 78 deletions
diff --git a/Euclidean.lua b/Euclidean.lua index 808b7ab..c0dd99c 100644 --- a/Euclidean.lua +++ b/Euclidean.lua @@ -20,11 +20,14 @@ function Euclidean:reset(stdv) else stdv = 1./math.sqrt(self.weight:size(1)) end - - for i=1,self.weight:size(2) do - self.weight:select(2, i):apply(function() - return torch.uniform(-stdv, stdv) - end) + if nn.oldSeed then + for i=1,self.weight:size(2) do + self.weight:select(2, i):apply(function() + return torch.uniform(-stdv, stdv) + end) + end + else + self.weight:uniform(-stdv, stdv) end end @@ -17,14 +17,16 @@ function Linear:reset(stdv) else stdv = 1./math.sqrt(self.weight:size(2)) end - - -- we do this so the initialization is exactly - -- the same than in previous torch versions - for i=1,self.weight:size(1) do - self.weight:select(1, i):apply(function() - return torch.uniform(-stdv, stdv) - end) - self.bias[i] = torch.uniform(-stdv, stdv) + if nn.oldSeed then + for i=1,self.weight:size(1) do + self.weight:select(1, i):apply(function() + return torch.uniform(-stdv, stdv) + end) + self.bias[i] = torch.uniform(-stdv, stdv) + end + else + self.weight:uniform(-stdv, stdv) + self.bias:uniform(-stdv, stdv) end end diff --git a/LookupTable.lua b/LookupTable.lua index 7dfda7a..671783f 100644 --- a/LookupTable.lua +++ b/LookupTable.lua @@ -29,9 +29,13 @@ end function LookupTable:reset(stdv) stdv = stdv or 1 - self.weight:apply(function() - return torch.normal(0, stdv) - end) + if nn.oldSeed then + self.weight:apply(function() + return torch.normal(0, stdv) + end) + else + self.weight:normal(0, stdv) + end end function LookupTable:updateOutput(input) diff --git a/SparseLinear.lua b/SparseLinear.lua index ec8845e..f1a2be5 100644 --- a/SparseLinear.lua +++ b/SparseLinear.lua @@ -22,14 +22,16 @@ function SparseLinear:reset(stdv) else stdv = 1./math.sqrt(self.weight:size(1)) end - - -- we do this so the initialization is exactly - -- the same than in previous torch versions - for i=1,self.weight:size(1) do - self.weight:select(1, i):apply(function() - return torch.uniform(-stdv, stdv) - end) - self.bias[i] = torch.uniform(-stdv, stdv) * 0.000001 + if nn.oldSeed then + for i=1,self.weight:size(1) do + self.weight:select(1, i):apply(function() + return torch.uniform(-stdv, stdv) + end) + self.bias[i] = torch.uniform(-stdv, stdv) * 0.000001 + end + else + self.weight:uniform(-stdv, stdv) + self.bias:uniform(-stdv, stdv):mul(0.000001) end end diff --git a/SpatialConvolution.lua b/SpatialConvolution.lua index 38d2737..e5e8fc9 100644 --- a/SpatialConvolution.lua +++ b/SpatialConvolution.lua @@ -27,12 +27,17 @@ function SpatialConvolution:reset(stdv) else stdv = 1/math.sqrt(self.kW*self.kH*self.nInputPlane) end - self.weight:apply(function() - return torch.uniform(-stdv, stdv) - end) - self.bias:apply(function() - return torch.uniform(-stdv, stdv) - end) + if nn.oldSeed then + self.weight:apply(function() + return torch.uniform(-stdv, stdv) + end) + self.bias:apply(function() + return torch.uniform(-stdv, stdv) + end) + else + self.weight:uniform(-stdv, stdv) + self.bias:uniform(-stdv, stdv) + end end function SpatialConvolution:updateOutput(input) diff --git a/SpatialConvolutionMM.lua b/SpatialConvolutionMM.lua index aa358e5..cc6a718 100644 --- a/SpatialConvolutionMM.lua +++ b/SpatialConvolutionMM.lua @@ -25,12 +25,17 @@ function SpatialConvolutionMM:reset(stdv) else stdv = 1/math.sqrt(self.kW*self.kH*self.nInputPlane) end - self.weight:apply(function() - return torch.uniform(-stdv, stdv) - end) - self.bias:apply(function() - return torch.uniform(-stdv, stdv) - end) + if nn.oldSeed then + self.weight:apply(function() + return torch.uniform(-stdv, stdv) + end) + self.bias:apply(function() + return torch.uniform(-stdv, stdv) + end) + else + self.weight:uniform(-stdv, stdv) + self.bias:uniform(-stdv, stdv) + end end function SpatialConvolutionMM:updateOutput(input) diff --git a/SpatialConvolutionMap.lua b/SpatialConvolutionMap.lua index 4f6609e..f99668b 100644 --- a/SpatialConvolutionMap.lua +++ b/SpatialConvolutionMap.lua @@ -110,22 +110,31 @@ end function SpatialConvolutionMap:reset(stdv) if stdv then stdv = stdv * math.sqrt(3) - self.weight:apply(function() - return torch.uniform(-stdv, stdv) - end) - self.bias:apply(function() - return torch.uniform(-stdv, stdv) - end) + if nn.oldSeed then + self.weight:apply(function() + return torch.uniform(-stdv, stdv) + end) + self.bias:apply(function() + return torch.uniform(-stdv, stdv) + end) + else + self.weight:uniform(-stdv, stdv) + self.bias:uniform(-stdv, stdv) + end else local ninp = torch.Tensor(self.nOutputPlane):zero() for i=1,self.connTable:size(1) do ninp[self.connTable[i][2]] = ninp[self.connTable[i][2]]+1 end for k=1,self.connTable:size(1) do - stdv = 1/math.sqrt(self.kW*self.kH*ninp[self.connTable[k][2]]) - self.weight:select(1,k):apply(function() return torch.uniform(-stdv,stdv) end) + stdv = 1/math.sqrt(self.kW*self.kH*ninp[self.connTable[k][2]]) + if nn.oldSeed then + self.weight:select(1,k):apply(function() return torch.uniform(-stdv,stdv) end) + else + self.weight:select(1,k):uniform(-stdv,stdv) + end end for k=1,self.bias:size(1) do - stdv = 1/math.sqrt(self.kW*self.kH*ninp[k]) - self.bias[k] = torch.uniform(-stdv,stdv) + stdv = 1/math.sqrt(self.kW*self.kH*ninp[k]) + self.bias[k] = torch.uniform(-stdv,stdv) end end end diff --git a/SpatialSubSampling.lua b/SpatialSubSampling.lua index 48b32b9..19aa2f5 100644 --- a/SpatialSubSampling.lua +++ b/SpatialSubSampling.lua @@ -26,12 +26,17 @@ function SpatialSubSampling:reset(stdv) else stdv = 1/math.sqrt(self.kW*self.kH) end - self.weight:apply(function() - return torch.uniform(-stdv, stdv) - end) - self.bias:apply(function() - return torch.uniform(-stdv, stdv) - end) + if nn.oldSeed then + self.weight:apply(function() + return torch.uniform(-stdv, stdv) + end) + self.bias:apply(function() + return torch.uniform(-stdv, stdv) + end) + else + self.weight:uniform(-stdv, stdv) + self.bias:uniform(-stdv, stdv) + end end function SpatialSubSampling:updateOutput(input) diff --git a/TemporalConvolution.lua b/TemporalConvolution.lua index a3aaa7f..b71e4c7 100644 --- a/TemporalConvolution.lua +++ b/TemporalConvolution.lua @@ -24,12 +24,17 @@ function TemporalConvolution:reset(stdv) else stdv = 1/math.sqrt(self.kW*self.inputFrameSize) end - self.weight:apply(function() - return torch.uniform(-stdv, stdv) - end) - self.bias:apply(function() - return torch.uniform(-stdv, stdv) - end) + if nn.oldSeed then + self.weight:apply(function() + return torch.uniform(-stdv, stdv) + end) + self.bias:apply(function() + return torch.uniform(-stdv, stdv) + end) + else + self.weight:uniform(-stdv, stdv) + self.bias:uniform(-stdv, stdv) + end end function TemporalConvolution:updateOutput(input) diff --git a/TemporalSubSampling.lua b/TemporalSubSampling.lua index 3d06f6e..29df8b1 100644 --- a/TemporalSubSampling.lua +++ b/TemporalSubSampling.lua @@ -23,14 +23,17 @@ function TemporalSubSampling:reset(stdv) else stdv = 1/math.sqrt(self.kW) end - - self.weight:apply(function() - return torch.uniform(-stdv, stdv) - end) - - self.bias:apply(function() - return torch.uniform(-stdv, stdv) - end) + if nn.oldSeed then + self.weight:apply(function() + return torch.uniform(-stdv, stdv) + end) + self.bias:apply(function() + return torch.uniform(-stdv, stdv) + end) + else + self.weight:uniform(-stdv, stdv) + self.bias:uniform(-stdv, stdv) + end end function TemporalSubSampling:updateOutput(input) diff --git a/VolumetricConvolution.lua b/VolumetricConvolution.lua index 4262199..4dec9e3 100644 --- a/VolumetricConvolution.lua +++ b/VolumetricConvolution.lua @@ -30,12 +30,17 @@ function VolumetricConvolution:reset(stdv) else stdv = 1/math.sqrt(self.kT*self.kW*self.kH*self.nInputPlane) end - self.weight:apply(function() - return torch.uniform(-stdv, stdv) - end) - self.bias:apply(function() - return torch.uniform(-stdv, stdv) - end) + if nn.oldSeed then + self.weight:apply(function() + return torch.uniform(-stdv, stdv) + end) + self.bias:apply(function() + return torch.uniform(-stdv, stdv) + end) + else + self.weight:uniform(-stdv, stdv) + self.bias:uniform(-stdv, stdv) + end end function VolumetricConvolution:updateOutput(input) diff --git a/WeightedEuclidean.lua b/WeightedEuclidean.lua index 5337eec..c4a1dbc 100644 --- a/WeightedEuclidean.lua +++ b/WeightedEuclidean.lua @@ -30,13 +30,15 @@ function WeightedEuclidean:reset(stdv) else stdv = 1./math.sqrt(self.templates:size(1)) end - - for i=1,self.templates:size(2) do - self.templates:select(2, i):apply(function() - return torch.uniform(-stdv, stdv) - end) + if nn.oldSeed then + for i=1,self.templates:size(2) do + self.templates:select(2, i):apply(function() + return torch.uniform(-stdv, stdv) + end) + end + else + self.templates:uniform(-stdv, stdv) end - self.diagCov:fill(1) end |