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

github.com/clementfarabet/lua---nnx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClement Farabet <clement.farabet@gmail.com>2011-11-11 19:38:11 +0400
committerClement Farabet <clement.farabet@gmail.com>2011-11-11 19:38:11 +0400
commit98fb40a126afb2f33800af2f081d3119a8b55448 (patch)
treeb811fd62ac82766bc9d1a49f4d9e99cdc52ec8fa
parenta8ab27537e16f4440565fbebe6313b2172b489a1 (diff)
Upgraded all code to new torch master.torch-master
-rw-r--r--Abs.lua30
-rw-r--r--BatchOptimization.lua3
-rw-r--r--CAddTable.lua33
-rw-r--r--CDivTable.lua30
-rw-r--r--CMulTable.lua35
-rw-r--r--CSubTable.lua30
-rw-r--r--ConfusionMatrix.lua18
-rw-r--r--DataSet.lua22
-rw-r--r--DiagHessian.lua42
-rw-r--r--DistMarginCriterion.lua8
-rw-r--r--DistNLLCriterion.lua30
-rw-r--r--GeneticSGDOptimization.lua2
-rw-r--r--HardShrink.lua11
-rw-r--r--KLDivCriterion.lua10
-rw-r--r--Minus.lua4
-rw-r--r--Narrow.lua70
-rw-r--r--OnlineTrainer.lua16
-rw-r--r--Power.lua37
-rw-r--r--Probe.lua26
-rw-r--r--Replicate.lua40
-rw-r--r--SGDOptimization.lua12
-rw-r--r--SparseCriterion.lua18
-rw-r--r--SpatialClassNLLCriterion.lua27
-rw-r--r--SpatialClassifier.lua8
-rw-r--r--SpatialColorTransform.lua31
-rw-r--r--SpatialFovea.lua73
-rw-r--r--SpatialGraph.lua22
-rw-r--r--SpatialLinear.lua30
-rw-r--r--SpatialMSECriterion.lua32
-rw-r--r--SpatialMaxSampling.lua8
-rw-r--r--SpatialNormalization.lua97
-rw-r--r--SpatialPadding.lua21
-rw-r--r--SpatialReSampling.lua20
-rw-r--r--SpatialRecursiveFovea.lua111
-rw-r--r--SpatialSparseCriterion.lua24
-rw-r--r--SpatialUpSampling.lua20
-rw-r--r--Sqrt.lua34
-rw-r--r--Square.lua33
-rw-r--r--SuperCriterion.lua12
-rw-r--r--Threshold.lua36
-rw-r--r--Trainer.lua12
-rw-r--r--Type.lua22
-rw-r--r--generic/Abs.c8
-rw-r--r--generic/DistMarginCriterion.c8
-rw-r--r--generic/HardShrink.c8
-rw-r--r--generic/SparseCriterion.c8
-rw-r--r--generic/SpatialClassNLLCriterion.c8
-rw-r--r--generic/SpatialGraph.c8
-rw-r--r--generic/SpatialLinear.c8
-rw-r--r--generic/SpatialMSECriterion.c8
-rw-r--r--generic/SpatialMaxSampling.c8
-rw-r--r--generic/SpatialReSampling.c8
-rw-r--r--generic/SpatialSparseCriterion.c8
-rw-r--r--generic/SpatialUpSampling.c8
-rw-r--r--generic/Template.c8
-rw-r--r--generic/Threshold.c8
-rw-r--r--init.lua40
57 files changed, 210 insertions, 1142 deletions
diff --git a/Abs.lua b/Abs.lua
deleted file mode 100644
index ca17acf..0000000
--- a/Abs.lua
+++ /dev/null
@@ -1,30 +0,0 @@
-local Abs, parent = torch.class('nn.Abs', 'nn.Module')
-
-function Abs:__init(args)
- parent.__init(self)
- if args then
- error(xlua.usage('nn.Abs',
- 'a simple component-wise mapping: abs()',
- 'abs = nn.Abs()\n'..
- 'rectified = abs:forward(sometensor)',
- {type='nil', help='no arg required'}))
- end
-end
-
-function Abs:forward(input)
- input.nn.Abs_forward(self, input)
- return self.output
-end
-
-function Abs:backward(input, gradOutput)
- input.nn.Abs_backward(self, input, gradOutput)
- return self.gradInput
-end
-
-function Abs:write(file)
- parent.write(self, file)
-end
-
-function Abs:read(file)
- parent.read(self, file)
-end
diff --git a/BatchOptimization.lua b/BatchOptimization.lua
index b0c2a12..032b61e 100644
--- a/BatchOptimization.lua
+++ b/BatchOptimization.lua
@@ -98,7 +98,6 @@ function Batch:forward_sequential(inputs, targets, options)
-- estimate df/dW
local df_do = self.criterion:backward(output, targets[i])
self.module:backward(inputs[i], df_do)
- self.module:accGradParameters(inputs[i], df_do)
-- user hook
if self.posthook then
self.posthook(self, {inputs[i], targets[i], options[i]})
@@ -118,7 +117,6 @@ function Batch:forward_sequential(inputs, targets, options)
-- estimate df/dW
local df_do = self.criterion:backward(output, targets)
self.module:backward(inputs, df_do)
- self.module:accGradParameters(inputs, df_do)
-- update evaluation counter
self.evalCounter = self.evalCounter + inputs:size(1)
end
@@ -369,7 +367,6 @@ function Batch:setup_mapreduce ()
-- estimate df/dW
local df_do = criterion:backward(output, targets[i])
module:backward(inputs[i], df_do)
- module:accGradParameters(inputs[i], df_do)
-- user hook
if posthook then
posthook(optimizer, {inputs[i], targets[i], options[i]})
diff --git a/CAddTable.lua b/CAddTable.lua
deleted file mode 100644
index 9603b4b..0000000
--- a/CAddTable.lua
+++ /dev/null
@@ -1,33 +0,0 @@
-
-local CAddTable, parent = torch.class('nn.CAddTable', 'nn.Module')
-
-function CAddTable:__init()
- parent.__init(self)
- self.gradInput = {}
-end
-
-function CAddTable:forward(input)
- self.output:resizeAs(input[1]):copy(input[1])
- for i=2,#input do
- self.output:add(input[i])
- end
- return self.output
-end
-
-function CAddTable:backward(input, gradOutput)
- for i=1,#input do
- self.gradInput[i] = self.gradInput[i] or torch.Tensor()
- self.gradInput[i]:resizeAs(input[i])
- self.gradInput[i]:copy(gradOutput)
- end
- return self.gradInput
-end
-
-function CAddTable:write(file)
- parent.write(self, file)
-end
-
-function CAddTable:read(file)
- parent.read(self, file)
- self.gradInput = {}
-end
diff --git a/CDivTable.lua b/CDivTable.lua
deleted file mode 100644
index bae13c6..0000000
--- a/CDivTable.lua
+++ /dev/null
@@ -1,30 +0,0 @@
-
-local CDivTable, parent = torch.class('nn.CDivTable', 'nn.Module')
-
-function CDivTable:__init()
- parent.__init(self)
- self.gradInput = {}
-end
-
-function CDivTable:forward(input)
- self.output:resizeAs(input[1]):copy(input[1])
- self.output:cdiv(input[2])
- return self.output
-end
-
-function CDivTable:backward(input, gradOutput)
- self.gradInput[1] = self.gradInput[1] or torch.Tensor()
- self.gradInput[2] = self.gradInput[2] or torch.Tensor()
- self.gradInput[1]:resizeAs(input[1]):copy(gradOutput):cdiv(input[2])
- self.gradInput[2]:resizeAs(input[2]):zero():addcdiv(-1,self.gradInput[1],input[2]):cmul(input[1])
- return self.gradInput
-end
-
-function CDivTable:write(file)
- parent.write(self, file)
-end
-
-function CDivTable:read(file)
- parent.read(self, file)
- self.gradInput = {}
-end
diff --git a/CMulTable.lua b/CMulTable.lua
deleted file mode 100644
index 500eea2..0000000
--- a/CMulTable.lua
+++ /dev/null
@@ -1,35 +0,0 @@
-
-local CMulTable, parent = torch.class('nn.CMulTable', 'nn.Module')
-
-function CMulTable:__init()
- parent.__init(self)
- self.gradInput = {}
-end
-
-function CMulTable:forward(input)
- self.output:resizeAs(input[1]):copy(input[1])
- for i=2,#input do
- self.output:cmul(input[i])
- end
- return self.output
-end
-
-function CMulTable:backward(input, gradOutput)
- local tout = torch.Tensor():resizeAs(self.output)
- for i=1,#input do
- self.gradInput[i] = self.gradInput[i] or torch.Tensor()
- self.gradInput[i]:resizeAs(input[i]):copy(gradOutput)
- tout:copy(self.output):cdiv(input[i])
- self.gradInput[i]:cmul(tout)
- end
- return self.gradInput
-end
-
-function CMulTable:write(file)
- parent.write(self, file)
-end
-
-function CMulTable:read(file)
- parent.read(self, file)
- self.gradInput = {}
-end
diff --git a/CSubTable.lua b/CSubTable.lua
deleted file mode 100644
index ecdd378..0000000
--- a/CSubTable.lua
+++ /dev/null
@@ -1,30 +0,0 @@
-
-local CSubTable, parent = torch.class('nn.CSubTable', 'nn.Module')
-
-function CSubTable:__init()
- parent.__init(self)
- self.gradInput = {}
-end
-
-function CSubTable:forward(input)
- self.output:resizeAs(input[1]):copy(input[1])
- self.output:add(-1,input[2])
- return self.output
-end
-
-function CSubTable:backward(input, gradOutput)
- self.gradInput[1] = self.gradInput[1] or torch.Tensor()
- self.gradInput[2] = self.gradInput[2] or torch.Tensor()
- self.gradInput[1]:resizeAs(input[1]):copy(gradOutput)
- self.gradInput[2]:resizeAs(input[1]):copy(gradOutput):mul(-1)
- return self.gradInput
-end
-
-function CSubTable:write(file)
- parent.write(self, file)
-end
-
-function CSubTable:read(file)
- parent.read(self, file)
- self.gradInput = {}
-end
diff --git a/ConfusionMatrix.lua b/ConfusionMatrix.lua
index b6c841d..f887dc5 100644
--- a/ConfusionMatrix.lua
+++ b/ConfusionMatrix.lua
@@ -92,21 +92,3 @@ function ConfusionMatrix:__tostring__()
str = str .. ' + global correct: ' .. (self.totalValid*100) .. '%'
return str
end
-
-function ConfusionMatrix:write(file)
- file:writeObject(self.mat)
- file:writeObject(self.valids)
- file:writeInt(self.nclasses)
- file:writeInt(self.totalValid)
- file:writeInt(self.averageValid)
- file:writeObject(self.classes)
-end
-
-function ConfusionMatrix:read(file)
- self.mat = file:readObject()
- self.valids = file:readObject()
- self.nclasses = file:readInt()
- self.totalValid = file:readInt()
- self.averageValid = file:readInt()
- self.classes = file:readObject()
-end
diff --git a/DataSet.lua b/DataSet.lua
index 4efb85d..13a29f7 100644
--- a/DataSet.lua
+++ b/DataSet.lua
@@ -297,28 +297,6 @@ function lDataSet:useCacheFile(fileName)
self.cacheFileName = fileName
end
-
-function lDataSet:save(fileName)
- local fileName = fileName or self.fileName
- self.fileName = fileName
- print('<DataSet> Saving DataSet to:',fileName)
- local file = torch.DiskFile(fileName, 'w')
- file:binary()
- self:write(file)
- file:close()
-end
-
-function lDataSet:open(fileName)
- local fileName = fileName or self.fileName
- self.fileName = fileName
- print('<DataSet> Loading DataSet from File:',fileName)
- local file = torch.DiskFile(fileName, 'r')
- file:binary()
- self:read(file)
- file:close()
- print('<DataSet> '..self.nbSamples..' samples loaded')
-end
-
function lDataSet:write(file)
file:writeBool(self.resized)
file:writeInt(self.nbSamples)
diff --git a/DiagHessian.lua b/DiagHessian.lua
index 26aed3e..2b9aca9 100644
--- a/DiagHessian.lua
+++ b/DiagHessian.lua
@@ -1,6 +1,6 @@
-- Module
-function nn.Module.backwardDiagHessian(self, input, diagHessianOutput)
+function nn.Module.updateDiagHessianInput(self, input, diagHessianOutput)
self.diagHessianInput = self.diagHessianInput or diagHessianOutput
return self.diagHessianInput
end
@@ -12,20 +12,20 @@ function nn.Module.initDiagHessianParameters(self)
end
-- Criterion
-function nn.Criterion.backwardDiagHessian(self, input, diagHessianOutput)
+function nn.Criterion.updateDiagHessianInput(self, input, diagHessianOutput)
self.diagHessianInput = self.diagHessianInput or self.output.new()
return self.diagHessianInput
end
-- MSECriterion
-function nn.MSECriterion.backwardDiagHessian(self, input, diagHessianOutput)
+function nn.MSECriterion.updateDiagHessianInput(self, input, diagHessianOutput)
self.diagHessianInput = self.diagHessianInput or input.new()
self.diagHessianInput:resizeAs(input):fill(1)
return self.diagHessianInput
end
-- Linear
-function nn.Linear.backwardDiagHessian(self, input, diagHessianOutput)
+function nn.Linear.updateDiagHessianInput(self, input, diagHessianOutput)
self.diagHessianInput = self.diagHessianInput or self.output.new()
self.weightSq = self.weightSq or self.output.new():resizeAs(self.weight)
self.weightSq:copy(self.weight):cmul(self.weightSq)
@@ -60,7 +60,7 @@ function nn.Linear.accDiagHessianParameters(self, input, diagHessianOutput, scal
end
-- Tanh
-function nn.Tanh.backwardDiagHessian(self, input, diagHessianOutput)
+function nn.Tanh.updateDiagHessianInput(self, input, diagHessianOutput)
self.diagHessianInput = self.diagHessianInput or self.output.new()
self.derivativeSq = self.derivativeSq or self.output.new()
self.derivativeSq:resizeAs(self.output):copy(self.output):cmul(self.output):mul(-1):add(1)
@@ -70,15 +70,15 @@ function nn.Tanh.backwardDiagHessian(self, input, diagHessianOutput)
end
-- Sequential
-function nn.Sequential.backwardDiagHessian(self, input, diagHessianOutput)
+function nn.Sequential.updateDiagHessianInput(self, input, diagHessianOutput)
local currentDiagHessianOutput = diagHessianOutput
local currentModule = self.modules[#self.modules]
for i=#self.modules-1,1,-1 do
local previousModule = self.modules[i]
- currentDiagHessianOutput = currentModule:backwardDiagHessian(previousModule.output, currentDiagHessianOutput)
+ currentDiagHessianOutput = currentModule:updateDiagHessianInput(previousModule.output, currentDiagHessianOutput)
currentModule = previousModule
end
- currentDiagHessianOutput = currentModule:backwardDiagHessian(input, currentDiagHessianOutput)
+ currentDiagHessianOutput = currentModule:updateDiagHessianInput(input, currentDiagHessianOutput)
self.diagHessianInput = currentDiagHessianOutput
return currentDiagHessianOutput
end
@@ -101,29 +101,3 @@ function nn.Sequential.accDiagHessianParameters(self, input, diagHessianOutput,
end
currentModule:accDiagHessianParameters(input, currentDiagHessianOutput, scale)
end
-
--- ConcatTable
-function nn.ConcatTable.backwardDiagHessian(self, input, diagHessianOutput)
- for i,module in ipairs(self.modules) do
- local currentDiagHessianInput = module:backward(input, diagHessianOutput[i])
- if i == 1 then
- self.diagHessianInput:resizeAs(currentDiagHessianInput):copy(currentDiagHessianInput)
- else
- self.diagHessianInput:add(currentDiagHessianInput)
- end
- end
- return self.diagHessianInput
-end
-
-function nn.ConcatTable.initDiagHessianParameters(self)
- for i=1,#self.modules do
- self.modules[i]:initDiagHessianParameters()
- end
-end
-
-function nn.ConcatTable.accDiagHessianParameters(self, input, diagHessianOutput, scale)
- scale = scale or 1
- for i,module in ipairs(self.modules) do
- module:accDiagHessianParameters(input, diagHessianOutput[i], scale)
- end
-end
diff --git a/DistMarginCriterion.lua b/DistMarginCriterion.lua
index 6b38771..acd943c 100644
--- a/DistMarginCriterion.lua
+++ b/DistMarginCriterion.lua
@@ -5,10 +5,10 @@ function DistMarginCriterion:__init()
self.sizeAverage = true
end
-function DistMarginCriterion:forward(input, target)
- return input.nn.DistMarginCriterion_forward(self, input, target)
+function DistMarginCriterion:updateOutput(input, target)
+ return input.nn.DistMarginCriterion_updateOutput(self, input, target)
end
-function DistMarginCriterion:backward(input, target)
- return input.nn.DistMarginCriterion_backward(self, input, target)
+function DistMarginCriterion:updateGradInput(input, target)
+ return input.nn.DistMarginCriterion_updateGradInput(self, input, target)
end
diff --git a/DistNLLCriterion.lua b/DistNLLCriterion.lua
index 01290c4..22204fc 100644
--- a/DistNLLCriterion.lua
+++ b/DistNLLCriterion.lua
@@ -17,7 +17,7 @@ end
function DistNLLCriterion:normalize(input, target)
-- normalize target
if not self.targetIsProbability then
- self.probTarget = self.targetSoftMax:forward(target)
+ self.probTarget = self.targetSoftMax:updateOutput(target)
else
self.probTarget = target
end
@@ -31,7 +31,7 @@ function DistNLLCriterion:normalize(input, target)
-- normalize input
if not self.inputIsLogProbability and not self.inputIsProbability then
- self.logProbInput = self.inputLogSoftMax:forward(self.input)
+ self.logProbInput = self.inputLogSoftMax:updateOutput(self.input)
elseif not self.inputIsLogProbability then
print('TODO: implement nn.Log()')
else
@@ -42,7 +42,7 @@ end
function DistNLLCriterion:denormalize()
-- denormalize gradients
if not self.inputIsLogProbability and not self.inputIsProbability then
- self.gradInput = self.inputLogSoftMax:backward(self.input, self.gradLogInput)
+ self.gradInput = self.inputLogSoftMax:updateGradInput(self.input, self.gradLogInput)
elseif not self.inputIsLogProbability then
print('TODO: implement nn.Log()')
else
@@ -55,7 +55,7 @@ function DistNLLCriterion:denormalize()
end
end
-function DistNLLCriterion:forward(input, target)
+function DistNLLCriterion:updateOutput(input, target)
self:normalize(input, target)
self.output = 0
for i = 1,input:size(1) do
@@ -64,7 +64,7 @@ function DistNLLCriterion:forward(input, target)
return self.output
end
-function DistNLLCriterion:backward(input, target)
+function DistNLLCriterion:updateGradInput(input, target)
self:normalize(input, target)
self.gradLogInput:resizeAs(input)
for i = 1,input:size(1) do
@@ -73,23 +73,3 @@ function DistNLLCriterion:backward(input, target)
self:denormalize()
return self.gradInput
end
-
-function DistNLLCriterion:write(file)
- parent.write(self, file)
- file:writeBool(self.inputIsProbability)
- file:writeBool(self.inputIsLogProbability)
- file:writeBool(self.targetIsProbability)
- file:writeObject(self.targetSoftMax)
- file:writeObject(self.inputLogSoftMax)
- file:writeObject(self.gradLogInput)
-end
-
-function DistNLLCriterion:read(file)
- parent.read(self, file)
- self.inputIsProbability = file:readBool()
- self.inputIsLogProbability = file:readBool()
- self.targetIsProbability = file:readBool()
- self.targetSoftMax = file:readObject()
- self.inputLogSoftMax = file:readObject()
- self.gradLogInput = file:readObject()
-end
diff --git a/GeneticSGDOptimization.lua b/GeneticSGDOptimization.lua
index d7816f8..0ddced7 100644
--- a/GeneticSGDOptimization.lua
+++ b/GeneticSGDOptimization.lua
@@ -267,7 +267,6 @@ function GenSGD:setup_mapreduce ()
-- estimate df/dW
local df_do = criterion:backward(output, targets[i])
module:backward(inputs[i], df_do)
- module:accGradParameters(inputs[i], df_do)
optimizer(module,opt_param)
if opt_param.adaptive_batchSize and
not opt_param.exact_batchSize then
@@ -290,7 +289,6 @@ function GenSGD:setup_mapreduce ()
if opt_param.adaptive_batchSize and opt_param.exact_batchsize then
local df_do = criterion:backward(output, targets[i])
module:backward(inputs[i], df_do)
- module:accGradParameters(inputs[i], df_do)
partialGrads[i]:copy(gradParameters)
end
end
diff --git a/HardShrink.lua b/HardShrink.lua
deleted file mode 100644
index b33fd6c..0000000
--- a/HardShrink.lua
+++ /dev/null
@@ -1,11 +0,0 @@
-local HardShrink = torch.class('nn.HardShrink', 'nn.Module')
-
-function HardShrink:forward(input)
- input.nn.HardShrink_forward(self, input)
- return self.output
-end
-
-function HardShrink:backward(input, gradOutput)
- input.nn.HardShrink_backward(self, input, gradOutput)
- return self.gradInput
-end
diff --git a/KLDivCriterion.lua b/KLDivCriterion.lua
index b4ce815..5dcf3b8 100644
--- a/KLDivCriterion.lua
+++ b/KLDivCriterion.lua
@@ -14,14 +14,14 @@ end
function KLDivCriterion:normalize(input, target)
-- normalize target
if not self.targetIsProbability then
- self.probTarget = self.targetSoftMax:forward(target)
+ self.probTarget = self.targetSoftMax:updateOutput(target)
else
self.probTarget = target
end
-- normalize input
if not self.inputIsProbability then
- self.probInput = self.inputSoftMax:forward(input)
+ self.probInput = self.inputSoftMax:updateOutput(input)
else
self.probInput = input
end
@@ -30,13 +30,13 @@ end
function KLDivCriterion:denormalize(input)
-- denormalize gradients
if not self.inputIsProbability then
- self.gradInput = self.inputSoftMax:backward(input, self.gradProbInput)
+ self.gradInput = self.inputSoftMax:updateGradInput(input, self.gradProbInput)
else
self.gradInput = self.gradProbInput
end
end
-function KLDivCriterion:forward(input, target)
+function KLDivCriterion:updateOutput(input, target)
self:normalize(input, target)
self.output = 0
for i = 1,input:size(1) do
@@ -49,7 +49,7 @@ function KLDivCriterion:forward(input, target)
return self.output
end
-function KLDivCriterion:backward(input, target)
+function KLDivCriterion:updateGradInput(input, target)
self:normalize(input, target)
self.gradProbInput:resizeAs(input)
for i = 1,input:size(1) do
diff --git a/Minus.lua b/Minus.lua
index fa1be52..d268146 100644
--- a/Minus.lua
+++ b/Minus.lua
@@ -1,11 +1,11 @@
local Minus, parent = torch.class('nn.Minus', 'nn.Module')
-function Minus:forward(input)
+function Minus:updateOutput(input)
self.output:resizeAs(input):copy(input):mul(-1)
return self.output
end
-function Minus:backward(input, gradOutput)
+function Minus:updateGradInput(input, gradOutput)
self.gradInput:resizeAs(input):copy(gradOutput):mul(-1)
return self.gradInput
end
diff --git a/Narrow.lua b/Narrow.lua
deleted file mode 100644
index 5c6d07e..0000000
--- a/Narrow.lua
+++ /dev/null
@@ -1,70 +0,0 @@
-local Narrow, parent = torch.class('nn.Narrow', 'nn.Module')
-
-local help_desc =
-[[Selects a subset of a dimension of a nxpxqx.. Tensor.]]
-
-local help_example =
-[[mlp=nn.Sequential();
-mlp:add(nn.Narrow(1,3,2))
-
-require "lab"
-x=lab.randn(10,5)
-print(x)
-print(mlp:forward(x))
-
--- gives the output:
- 0.9720 -0.0836 0.0831 -0.2059 -0.0871
- 0.8750 -2.0432 -0.1295 -2.3932 0.8168
- 0.0369 1.1633 0.6483 1.2862 0.6596
- 0.1667 -0.5704 -0.7303 0.3697 -2.2941
- 0.4794 2.0636 0.3502 0.3560 -0.5500
--0.1898 -1.1547 0.1145 -1.1399 0.1711
--1.5130 1.4445 0.2356 -0.5393 -0.6222
--0.6587 0.4314 1.1916 -1.4509 1.9400
- 0.2733 1.0911 0.7667 0.4002 0.1646
- 0.5804 -0.5333 1.1621 1.5683 -0.1978
-[torch.Tensor of dimension 10x5]
-
- 0.0369 1.1633 0.6483 1.2862 0.6596
- 0.1667 -0.5704 -0.7303 0.3697 -2.2941
-[torch.Tensor of dimension 2x5] ]]
-
-function Narrow:__init(dimension,offset,length)
- parent.__init(self)
- self.dimension=dimension
- self.index=offset
- self.length=length or 1
- if not dimension or not offset then
- error(xlua.usage('nn.Narrow', help_desc, help_example,
- {type='number', help='dimension', req=true},
- {type='number', help='offset', req=true},
- {type='number', help='length', default=1}))
- end
-end
-
-function Narrow:forward(input)
- local output=input:narrow(self.dimension,self.index,self.length);
- self.output:resizeAs(output)
- return self.output:copy(output)
-end
-
-function Narrow:backward(input, gradOutput)
- self.gradInput:resizeAs(input)
- self.gradInput:zero();
- self.gradInput:narrow(self.dimension,self.index,self.length):copy(gradOutput)
- return self.gradInput
-end
-
-function Narrow:write(file)
- parent.write(self, file)
- file:writeInt(self.dimension)
- file:writeLong(self.index)
- file:writeLong(self.length)
-end
-
-function Narrow:read(file, version)
- parent.read(self, file)
- self.dimension = file:readInt()
- self.index = file:readLong()
- self.length = file:readLong()
-end
diff --git a/OnlineTrainer.lua b/OnlineTrainer.lua
index dc6e860..920a523 100644
--- a/OnlineTrainer.lua
+++ b/OnlineTrainer.lua
@@ -49,9 +49,7 @@ function OnlineTrainer:log()
end
end
print('<trainer> saving network to '..filename)
- local file = torch.DiskFile(filename,'w')
- self.module:write(file)
- file:close()
+ torch.save(filename, self.module)
end
function OnlineTrainer:train(dataset)
@@ -173,15 +171,3 @@ function OnlineTrainer:test(dataset)
return self.currentError
end
-
-function OnlineTrainer:write(file)
- parent.write(self,file)
- file:writeObject(self.module)
- file:writeObject(self.criterion)
-end
-
-function OnlineTrainer:read(file)
- parent.read(self,file)
- self.module = file:readObject()
- self.criterion = file:readObject()
-end
diff --git a/Power.lua b/Power.lua
deleted file mode 100644
index c0b60a1..0000000
--- a/Power.lua
+++ /dev/null
@@ -1,37 +0,0 @@
-
-local Power, parent = torch.class('nn.Power','nn.Module')
-
-function Power:__init(p)
- parent.__init(self)
- self.pow = p
- if args then
- error(xlua.usage('nn.Power',
- 'a simple component-wise mapping: power(p)',
- 'pow = nn.Power(p)\n'..
- 'powered = pow:forward(sometensor)',
- {type='nil', help='no arg required'}))
- end
-end
-
-function Power:forward(input)
- self.output:resizeAs(input):copy(input)
- self.output:pow(self.pow)
- return self.output
-end
-
-function Power:backward(input, gradOutput)
- self.gradInput:resizeAs(input):copy(gradOutput)
- self.gradInput:cmul(self.output):cdiv(input):mul(self.pow)
- return self.gradInput
-end
-
-
-function Power:write(file)
- parent.write(self,file)
- file:writeDouble(self.pow)
-end
-
-function Power:read(file)
- parent.read(self,file)
- self.pow = file:readDouble()
-end
diff --git a/Probe.lua b/Probe.lua
index 3c93cd3..ea8527c 100644
--- a/Probe.lua
+++ b/Probe.lua
@@ -11,11 +11,11 @@ function Probe:__init(...)
{arg='backw', type='boolean', help='activates probe for backward()', default=false})
end
-function Probe:forward(input)
+function Probe:updateOutput(input)
self.output = input
if self.size or self.content then
print('')
- print('<probe::' .. self.name .. '> forward()')
+ print('<probe::' .. self.name .. '> updateOutput()')
if self.content then print(input)
elseif self.size then print(#input)
end
@@ -26,12 +26,12 @@ function Probe:forward(input)
return self.output
end
-function Probe:backward(input, gradOutput)
+function Probe:updateGradInput(input, gradOutput)
self.gradInput = gradOutput
if self.backw then
if self.size or self.content then
print('')
- print('<probe::' .. self.name .. '> backward()')
+ print('<probe::' .. self.name .. '> updateGradInput()')
if self.content then print(gradOutput)
elseif self.size then print(#gradOutput)
end
@@ -42,21 +42,3 @@ function Probe:backward(input, gradOutput)
end
return self.gradInput
end
-
-function Probe:write(file)
- parent.write(self, file)
- file:writeObject(self.name)
- file:writeBool(self.content)
- file:writeBool(self.display)
- file:writeBool(self.size)
- file:writeBool(self.backw)
-end
-
-function Probe:read(file)
- parent.read(self, file)
- self.name = file:readObject()
- self.content = file:readBool()
- self.display = file:readBool()
- self.size = file:readBool()
- self.backw = file:readBool()
-end
diff --git a/Replicate.lua b/Replicate.lua
deleted file mode 100644
index 2f8db97..0000000
--- a/Replicate.lua
+++ /dev/null
@@ -1,40 +0,0 @@
-
-local Replicate, parent = torch.class('nn.Replicate','nn.Module')
-
-function Replicate:__init(nf)
- parent.__init(self)
- self.nfeatures = nf
-end
-
-function Replicate:forward(input)
- local sz = torch.LongStorage(input:dim()+1)
- sz[1] = self.nfeatures
- for i = 1,input:dim() do
- sz[i+1] = input:size(i)
- end
- local st = torch.LongStorage(input:dim()+1)
- st[1] = 0
- for i = 1,input:dim() do
- st[i+1] = input:stride(i)
- end
- self.output = torch.Tensor(input:storage(),input:storageOffset(),sz,st)
- return self.output
-end
-
-function Replicate:backward(input, gradOutput)
- self.gradInput:resizeAs(input):zero()
- for k = 1,gradOutput:size(1) do
- self.gradInput:add(gradOutput[k])
- end
- return self.gradInput
-end
-
-function Replicate:write(file)
- parent.write(self,file)
- file:writeInt(self.nfeatures)
-end
-
-function Replicate:read(file)
- parent.read(self,file)
- self.nfeatures = file:readInt()
-end
diff --git a/SGDOptimization.lua b/SGDOptimization.lua
index 1309ae9..3e4a1e9 100644
--- a/SGDOptimization.lua
+++ b/SGDOptimization.lua
@@ -108,16 +108,16 @@ function SGD:diagHessian(inputs, targets)
for i = 1,#inputs do
local output = self.module:forward(inputs[i])
local critDiagHessian =
- self.criterion:backwardDiagHessian(output, targets[i])
- self.module:backwardDiagHessian(inputs[i], critDiagHessian)
+ self.criterion:updateDiagHessianInput(output, targets[i])
+ self.module:updateDiagHessianInput(inputs[i], critDiagHessian)
self.module:accDiagHessianParameters(inputs[i], critDiagHessian)
end
self.diagHessianParameters:div(#inputs)
else
local output = self.module:forward(inputs)
-- not sure if we can do the fast version yet
- local critDiagHessian = criterion:backwardDiagHessian(output, targets)
- module:backwardDiagHessian(inputs, critDiagHessian)
+ local critDiagHessian = criterion:updateDiagHessianInput(output, targets)
+ module:updateDiagHessianInput(inputs, critDiagHessian)
module:accDiagHessianParameters(inputs, critDiagHessian)
self.diagHessianParameters:div(inputs:size(1))
end
@@ -189,7 +189,6 @@ function SGD:optimalLearningRate(inputs, targets)
-- estimate df/dW
local df_do = self.criterion:backward(output, targets[i])
self.module:backward(inputs[i], df_do)
- self.module:accGradParameters(inputs[i], df_do)
end
-- normalize gradients
-- self.gradParameters:div(#inputs)
@@ -223,7 +222,6 @@ function SGD:optimalLearningRate(inputs, targets)
-- estimate df/dW
df_do = self.criterion:backward(output, targets[i])
self.module:backward(inputs[i], df_do)
- self.module:accGradParameters(inputs[i], df_do)
end
-- normalize gradients
-- self.gradParameters:div(#inputs)
@@ -255,7 +253,6 @@ function SGD:optimalLearningRate(inputs, targets)
-- estimate df/dW
local df_do = self.criterion:backward(output, targets)
self.module:backward(inputs, df_do)
- self.module:accGradParameters(inputs, df_do)
-- backup gradient and weights
self.param_bkup:copy(self.parameters)
self.grad_bkup:copy(self.gradParameters)
@@ -279,7 +276,6 @@ function SGD:optimalLearningRate(inputs, targets)
-- re-estimate df/dW
df_do = self.criterion:backward(output, targets)
self.module:backward(inputs, df_do)
- self.module:accGradParameters(inputs, df_do)
-- self.gradParameters:div(inputs:size(1))
-- (3) phi - 1/alpha(dE/dw(w + alpha * oldphi / || oldphi ||) - dE/dw(w))
diff --git a/SparseCriterion.lua b/SparseCriterion.lua
index ddaa75c..d086f28 100644
--- a/SparseCriterion.lua
+++ b/SparseCriterion.lua
@@ -5,22 +5,12 @@ function SparseCriterion:__init()
self.sizeAverage = true
end
-function SparseCriterion:forward(input)
- input.nn.SparseCriterion_forward(self, input)
+function SparseCriterion:updateOutput(input)
+ input.nn.SparseCriterion_updateOutput(self, input)
return self.output
end
-function SparseCriterion:backward(input)
- input.nn.SparseCriterion_backward(self, input)
+function SparseCriterion:updateGradInput(input)
+ input.nn.SparseCriterion_updateGradInput(self, input)
return self.gradInput
end
-
-function SparseCriterion:write(file)
- parent.write(self, file)
- file:writeBool(self.sizeAverage)
-end
-
-function SparseCriterion:read(file)
- parent.read(self, file)
- self.sizeAverage = file:readBool()
-end
diff --git a/SpatialClassNLLCriterion.lua b/SpatialClassNLLCriterion.lua
index b8a4c87..71e6320 100644
--- a/SpatialClassNLLCriterion.lua
+++ b/SpatialClassNLLCriterion.lua
@@ -42,7 +42,7 @@ function SpatialClassNLLCriterion:adjustTarget(input, target)
return target
end
-function SpatialClassNLLCriterion:forward(input,target)
+function SpatialClassNLLCriterion:updateOutput(input,target)
-- (1) adjust target: class -> distributions of classes
-- compensate for convolution losses
-- compensate for striding effects
@@ -54,7 +54,7 @@ function SpatialClassNLLCriterion:forward(input,target)
self.fullOutput = self.fullOutput or torch.Tensor()
self.fullOutput:resizeAs(target)
-- (3) compute the dense errors:
- input.nn.SpatialClassNLLCriterion_forward(self,input,target)
+ input.nn.SpatialClassNLLCriterion_updateOutput(self,input,target)
-- (4) prune the errors, either by averaging, or accumulation:
if self.sizeAverage then
self.output = self.fullOutput:mean()
@@ -64,7 +64,7 @@ function SpatialClassNLLCriterion:forward(input,target)
return self.output
end
-function SpatialClassNLLCriterion:backward(input,target)
+function SpatialClassNLLCriterion:updateGradInput(input,target)
-- (1) retrieve adjusted target
target = self.target
-- (2) resize input gradient map
@@ -72,12 +72,12 @@ function SpatialClassNLLCriterion:backward(input,target)
-- (3) compute input gradients, based on the nbGradients param
if self.nbGradients == -1 then
-- dense gradients
- input.nn.SpatialClassNLLCriterion_backward(self,input,target,self.gradInput)
+ input.nn.SpatialClassNLLCriterion_updateGradInput(self,input,target,self.gradInput)
elseif self.nbGradients == 1 then
-- only 1 gradient is computed, sampled in the center
self.fullGradInput = torch.Tensor() or self.fullGradInput
self.fullGradInput:resizeAs(input):zero()
- input.nn.SpatialClassNLLCriterion_backward(self,input,target,self.fullGradInput)
+ input.nn.SpatialClassNLLCriterion_updateGradInput(self,input,target,self.fullGradInput)
local y = math.ceil(self.gradInput:size(2)/2)
local x = math.ceil(self.gradInput:size(3)/2)
self.gradInput:select(3,x):select(2,y):copy(self.fullGradInput:select(3,x):select(2,y))
@@ -85,7 +85,7 @@ function SpatialClassNLLCriterion:backward(input,target)
-- only N gradients are computed, sampled in random locations
self.fullGradInput = torch.Tensor() or self.fullGradInput
self.fullGradInput:resizeAs(input):zero()
- input.nn.SpatialClassNLLCriterion_backward(self,input,target,self.fullGradInput)
+ input.nn.SpatialClassNLLCriterion_updateGradInput(self,input,target,self.fullGradInput)
for i = 1,self.nbGradients do
local x = math.random(1,self.gradInput:size(1))
local y = math.random(1,self.gradInput:size(2))
@@ -94,18 +94,3 @@ function SpatialClassNLLCriterion:backward(input,target)
end
return self.gradInput
end
-
-function SpatialClassNLLCriterion:write(file)
- parent.write(self, file)
- file:writeDouble(self.resampleTarget)
- file:writeInt(self.nbGradients)
- file:writeBool(self.sizeAverage)
-end
-
-function SpatialClassNLLCriterion:read(file)
- parent.read(self, file)
- self.resampleTarget= file:readDouble()
- self.nbGradients = file:readInt()
- self.fullOutput = torch.Tensor()
- self.sizeAverage = file:readBool()
-end
diff --git a/SpatialClassifier.lua b/SpatialClassifier.lua
index 9d39f80..da15852 100644
--- a/SpatialClassifier.lua
+++ b/SpatialClassifier.lua
@@ -22,7 +22,7 @@ function Classifier:add(module)
self.classifier:add(module)
end
-function Classifier:forward(input)
+function Classifier:updateOutput(input)
-- get dims:
if input:nDimension() ~= 3 then
error('<nn.SpatialClassifier> input should be 3D: KxHxW')
@@ -37,7 +37,7 @@ function Classifier:forward(input)
self.inputT:resize(HW, K):copy(self.inputF:t())
-- classify all locations:
- self.outputT = self.classifier:forward(self.inputT)
+ self.outputT = self.classifier:updateOutput(self.inputT)
if self.spatialOutput then
-- transpose output:
@@ -51,7 +51,7 @@ function Classifier:forward(input)
return self.output
end
-function Classifier:backward(input, gradOutput)
+function Classifier:updateGradInput(input, gradOutput)
-- get dims:
local K = input:size(1)
local H = input:size(2)
@@ -72,7 +72,7 @@ function Classifier:backward(input, gradOutput)
end
-- backward through classifier:
- self.gradInputT = self.classifier:backward(self.inputT, self.gradOutputT)
+ self.gradInputT = self.classifier:updateGradInput(self.inputT, self.gradOutputT)
-- transpose gradInput
self.gradInputF:resize(K, HW):copy(self.gradInputT:t())
diff --git a/SpatialColorTransform.lua b/SpatialColorTransform.lua
index a06efd4..941a391 100644
--- a/SpatialColorTransform.lua
+++ b/SpatialColorTransform.lua
@@ -89,9 +89,9 @@ function SpatialColorTransform:__init(type)
end
end
-function SpatialColorTransform:forward(input)
+function SpatialColorTransform:updateOutput(input)
if self.islinear then
- self.output = self.linear:forward(input)
+ self.output = self.linear:updateOutput(input)
else
if self.transform == 'rgb2hsl' then
self.output = image.rgb2hsl(input, self.output)
@@ -112,12 +112,12 @@ function SpatialColorTransform:forward(input)
return self.output
end
-function SpatialColorTransform:backward(input, gradOutput)
+function SpatialColorTransform:updateGradInput(input, gradOutput)
if self.islinear then
- self.gradInput = self.linear:backward(input, gradOutput)
+ self.gradInput = self.linear:updateGradInput(input, gradOutput)
else
- xlua.error('backward not implemented for non-linear transforms',
- 'SpatialColorTransform.backward')
+ xlua.error('updateGradInput not implemented for non-linear transforms',
+ 'SpatialColorTransform.updateGradInput')
end
return self.gradInput
end
@@ -128,22 +128,3 @@ function SpatialColorTransform:type(type)
self.linear:type(type)
end
end
-
-function SpatialColorTransform:write(file)
- parent.write(self, file)
- file:writeObject(self.transform)
- file:writeBool(self.islinear)
- if self.islinear then
- file:writeObject(self.linear)
- end
-end
-
-function SpatialColorTransform:read(file)
- parent.read(self, file)
- self.transform = file:readObject()
- self.islinear = file:readBool()
- if self.islinear then
- self.linear = file:readObject()
- end
- self.type = nil
-end
diff --git a/SpatialFovea.lua b/SpatialFovea.lua
index c4ebcb8..dc03301 100644
--- a/SpatialFovea.lua
+++ b/SpatialFovea.lua
@@ -124,7 +124,7 @@ function SpatialFovea:configure(width,height)
end
end
-function SpatialFovea:forward(input)
+function SpatialFovea:updateOutput(input)
-- input must be 3D
if input:nDimension() ~= 3 then
xerror('input must be 3d','nn.SpatialFovea')
@@ -163,13 +163,13 @@ function SpatialFovea:forward(input)
if not retrieved then
-- (1) generate pyramid
for idx = 1,nscales do
- self.pyramid[idx] = self.downsamplers[idx]:forward(input)
+ self.pyramid[idx] = self.downsamplers[idx]:updateOutput(input)
end
-- (2) preprocess
for idx = 1,nscales do
if self.preProcessors[idx] then
- self.preProcessed[idx] = self.preProcessors[idx]:forward(self.pyramid[idx])
+ self.preProcessed[idx] = self.preProcessors[idx]:updateOutput(self.pyramid[idx])
else
self.preProcessed[idx] = self.pyramid[idx]
end
@@ -177,7 +177,7 @@ function SpatialFovea:forward(input)
-- (3) pad inputs
for idx = 1,nscales do
- self.padded[idx] = self.padders[idx]:forward(self.preProcessed[idx])
+ self.padded[idx] = self.padders[idx]:updateOutput(self.preProcessed[idx])
end
-- store preprocessed input for future use
@@ -205,7 +205,7 @@ function SpatialFovea:forward(input)
-- (5) apply processors to pyramid
for idx = 1,nscales do
- self.processed[idx] = self.processors[idx]:forward(self.narrowed[idx])
+ self.processed[idx] = self.processors[idx]:updateOutput(self.narrowed[idx])
end
-- (6) upscale, only if fovea is not focused
@@ -215,7 +215,7 @@ function SpatialFovea:forward(input)
end
else
for idx = 1,nscales do
- self.upsampled[idx] = self.upsamplers[idx]:forward(self.processed[idx])
+ self.upsampled[idx] = self.upsamplers[idx]:updateOutput(self.processed[idx])
end
end
@@ -234,7 +234,7 @@ function SpatialFovea:forward(input)
return self.output
end
-function SpatialFovea:backward(input, gradOutput)
+function SpatialFovea:updateGradInput(input, gradOutput)
-- nb of scales
local nscales = #self.ratios
@@ -252,13 +252,13 @@ function SpatialFovea:backward(input, gradOutput)
end
else
for idx = 1,nscales do
- self.gradProcessed[idx] = self.upsamplers[idx]:backward(self.processed[idx], self.gradUpsampled[idx])
+ self.gradProcessed[idx] = self.upsamplers[idx]:updateGradInput(self.processed[idx], self.gradUpsampled[idx])
end
end
-- (5) bprop through processors
for idx = 1,nscales do
- self.gradNarrowed[idx] = self.processors[idx]:backward(self.narrowed[idx], self.gradProcessed[idx])
+ self.gradNarrowed[idx] = self.processors[idx]:updateGradInput(self.narrowed[idx], self.gradProcessed[idx])
end
-- (beta) if caching preprocessed input, no need to compute
@@ -285,13 +285,13 @@ function SpatialFovea:backward(input, gradOutput)
-- (3) bprop through padders
for idx = 1,nscales do
- self.gradPreProcessed[idx] = self.padders[idx]:backward(self.preProcessed[idx], self.gradPadded[idx])
+ self.gradPreProcessed[idx] = self.padders[idx]:updateGradInput(self.preProcessed[idx], self.gradPadded[idx])
end
-- (2) bprop through preProcessors
for idx = 1,nscales do
if self.preProcessors[idx] then
- self.gradPyramid[idx] = self.preProcessors[idx]:backward(self.pyramid[idx], self.gradPreProcessed[idx])
+ self.gradPyramid[idx] = self.preProcessors[idx]:updateGradInput(self.pyramid[idx], self.gradPreProcessed[idx])
else
self.gradPyramid[idx] = self.gradPreProcessed[idx]
end
@@ -300,7 +300,7 @@ function SpatialFovea:backward(input, gradOutput)
-- (1) bprop through pyramid
self.gradInput:resizeAs(self.gradPyramid[1]):zero()
for idx = 1,nscales do
- self.gradInput:add( self.downsamplers[idx]:backward(input, self.gradPyramid[idx]) )
+ self.gradInput:add( self.downsamplers[idx]:updateGradInput(input, self.gradPyramid[idx]) )
end
return self.gradInput
end
@@ -345,52 +345,3 @@ function SpatialFovea:type(type)
end
return self
end
-
-function SpatialFovea:write(file)
- parent.write(self, file)
- file:writeInt(self.nInputPlane)
- file:writeInt(self.padding)
- file:writeInt(self.fov)
- file:writeInt(self.sub)
- file:writeBool(self.bilinear)
- file:writeObject(self.ratios)
- file:writeObject(self.downsamplers)
- file:writeObject(self.padders)
- file:writeObject(self.upsamplers)
- file:writeObject(self.processors)
- file:writeObject(self.preProcessors)
- file:writeObject(self.pyramid)
- file:writeObject(self.preProcessed)
- file:writeObject(self.padded)
- file:writeObject(self.narrowed)
- file:writeObject(self.processed)
- file:writeObject(self.upsampled)
-end
-
-function SpatialFovea:read(file)
- parent.read(self, file)
- self.nInputPlane = file:readInt()
- self.padding = file:readInt()
- self.fov = file:readInt()
- self.sub = file:readInt()
- self.bilinear = file:readBool()
- self.ratios = file:readObject()
- self.downsamplers = file:readObject()
- self.padders = file:readObject()
- self.upsamplers = file:readObject()
- self.processors = file:readObject()
- self.preProcessors = file:readObject()
- self.pyramid = file:readObject()
- self.preProcessed = file:readObject()
- self.padded = file:readObject()
- self.narrowed = file:readObject()
- self.processed = file:readObject()
- self.upsampled = file:readObject()
- self.gradUpsampled = {}
- self.gradProcessed = {}
- self.gradNarrowed = {}
- self.gradPadded = {}
- self.gradPreProcessed = {}
- self.gradPyramid = {}
- self.modules = self.processors
-end
diff --git a/SpatialGraph.lua b/SpatialGraph.lua
index 253a800..6501313 100644
--- a/SpatialGraph.lua
+++ b/SpatialGraph.lua
@@ -42,28 +42,14 @@ function SpatialGraph:__init(...)
end
end
-function SpatialGraph:forward(input)
+function SpatialGraph:updateOutput(input)
self.output:resize(self.connex / 2, input:size(2), input:size(3))
- input.nn.SpatialGraph_forward(self, input)
+ input.nn.SpatialGraph_updateOutput(self, input)
return self.output
end
-function SpatialGraph:backward(input, gradOutput)
+function SpatialGraph:updateGradInput(input, gradOutput)
self.gradInput:resizeAs(input)
- input.nn.SpatialGraph_backward(self, input, gradOutput)
+ input.nn.SpatialGraph_updateGradInput(self, input, gradOutput)
return self.gradInput
end
-
-function SpatialGraph:write(file)
- parent.write(self, file)
- file:writeInt(self.connex)
- file:writeInt(self.dist)
- file:writeInt(self.normalize)
-end
-
-function SpatialGraph:read(file)
- parent.read(self, file)
- self.connex = file:readInt()
- self.dist = file:readInt()
- self.normalize = file:readInt()
-end
diff --git a/SpatialLinear.lua b/SpatialLinear.lua
index 1cf850e..4fb12f9 100644
--- a/SpatialLinear.lua
+++ b/SpatialLinear.lua
@@ -52,36 +52,14 @@ function SpatialLinear:decayParameters(decay)
self.bias:add(-decay, self.bias)
end
-function SpatialLinear:forward(input)
+function SpatialLinear:updateOutput(input)
self.output:resize(self.fanout, input:size(2), input:size(3))
- input.nn.SpatialLinear_forward(self, input)
+ input.nn.SpatialLinear_updateOutput(self, input)
return self.output
end
-function SpatialLinear:backward(input, gradOutput)
+function SpatialLinear:updateGradInput(input, gradOutput)
self.gradInput:resize(self.fanin, input:size(2), input:size(3))
- input.nn.SpatialLinear_backward(self, input, gradOutput)
+ input.nn.SpatialLinear_updateGradInput(self, input, gradOutput)
return self.gradInput
end
-
-function SpatialLinear:write(file)
- parent.write(self, file)
- file:writeInt(self.fanin)
- file:writeInt(self.fanout)
- file:writeDouble(self.weightDecay)
- file:writeObject(self.weight)
- file:writeObject(self.bias)
- file:writeObject(self.gradWeight)
- file:writeObject(self.gradBias)
-end
-
-function SpatialLinear:read(file)
- parent.read(self, file)
- self.fanin = file:readInt()
- self.fanout = file:readInt()
- self.weightDecay = file:readDouble()
- self.weight = file:readObject()
- self.bias = file:readObject()
- self.gradWeight = file:readObject()
- self.gradBias = file:readObject()
-end
diff --git a/SpatialMSECriterion.lua b/SpatialMSECriterion.lua
index 4c2ced8..634bfc5 100644
--- a/SpatialMSECriterion.lua
+++ b/SpatialMSECriterion.lua
@@ -58,7 +58,7 @@ function SpatialMSECriterion:adjustTarget(input, target)
return target
end
-function SpatialMSECriterion:forward(input,target)
+function SpatialMSECriterion:updateOutput(input,target)
-- (1) adjust target: class -> distributions of classes
-- compensate for convolution losses
-- compensate for striding effects
@@ -70,7 +70,7 @@ function SpatialMSECriterion:forward(input,target)
self.fullOutput = self.fullOutput or torch.Tensor()
self.fullOutput:resizeAs(input)
-- (3) compute the dense errors:
- input.nn.SpatialMSECriterion_forward(self, input, target)
+ input.nn.SpatialMSECriterion_updateOutput(self, input, target)
-- (4) prune the errors, either by averaging, or accumulation:
if self.sizeAverage then
self.output = self.fullOutput:mean()
@@ -80,7 +80,7 @@ function SpatialMSECriterion:forward(input,target)
return self.output
end
-function SpatialMSECriterion:backward(input,target)
+function SpatialMSECriterion:updateGradInput(input,target)
-- (1) retrieve adjusted target
target = self.target
-- (2) resize input gradient map
@@ -88,12 +88,12 @@ function SpatialMSECriterion:backward(input,target)
-- (3) compute input gradients, based on the nbGradients param
if self.nbGradients == -1 then
-- dense gradients
- input.nn.SpatialMSECriterion_backward(self, input, target, self.gradInput)
+ input.nn.SpatialMSECriterion_updateGradInput(self, input, target, self.gradInput)
elseif self.nbGradients == 1 then
-- only 1 gradient is computed, sampled in the center
self.fullGradInput = torch.Tensor() or self.fullGradInput
self.fullGradInput:resizeAs(input):zero()
- input.nn.SpatialMSECriterion_backward(self, input, target, self.fullGradInput)
+ input.nn.SpatialMSECriterion_updateGradInput(self, input, target, self.fullGradInput)
local y = math.ceil(self.gradInput:size(2)/2)
local x = math.ceil(self.gradInput:size(3)/2)
self.gradInput:select(3,x):select(2,y):copy(self.fullGradInput:select(3,x):select(2,y))
@@ -101,7 +101,7 @@ function SpatialMSECriterion:backward(input,target)
-- only N gradients are computed, sampled in random locations
self.fullGradInput = torch.Tensor() or self.fullGradInput
self.fullGradInput:resizeAs(input):zero()
- input.nn.SpatialMSECriterion_backward(self, input, target, self.fullGradInput)
+ input.nn.SpatialMSECriterion_updateGradInput(self, input, target, self.fullGradInput)
for i = 1,self.nbGradients do
local x = math.random(1,self.gradInput:size(1))
local y = math.random(1,self.gradInput:size(2))
@@ -110,23 +110,3 @@ function SpatialMSECriterion:backward(input,target)
end
return self.gradInput
end
-
-function SpatialMSECriterion:write(file)
- parent.write(self, file)
- file:writeDouble(self.resampleTarget)
- file:writeInt(self.nbGradients)
- if not self.ignoreClass then
- file:writeInt(-1)
- end
-end
-
-function SpatialMSECriterion:read(file)
- parent.read(self, file)
- self.resampleTarget= file:readDouble()
- self.nbGradients = file:readInt()
- self.ignoreClass = file:readInt()
- if self.ignoreClass == -1 then
- self.ignoreClass = false
- end
- self.fullOutput = torch.Tensor()
-end
diff --git a/SpatialMaxSampling.lua b/SpatialMaxSampling.lua
index aa16701..d6dc512 100644
--- a/SpatialMaxSampling.lua
+++ b/SpatialMaxSampling.lua
@@ -11,12 +11,12 @@ function SpatialMaxSampling:__init(...)
self.indices = torch.Tensor()
end
-function SpatialMaxSampling:forward(input)
- input.nn.SpatialMaxSampling_forward(self, input)
+function SpatialMaxSampling:updateOutput(input)
+ input.nn.SpatialMaxSampling_updateOutput(self, input)
return self.output
end
-function SpatialMaxSampling:backward(input, gradOutput)
- input.nn.SpatialMaxSampling_backward(self, input, gradOutput)
+function SpatialMaxSampling:updateGradInput(input, gradOutput)
+ input.nn.SpatialMaxSampling_updateGradInput(self, input, gradOutput)
return self.gradInput
end
diff --git a/SpatialNormalization.lua b/SpatialNormalization.lua
index e0e5c60..012b609 100644
--- a/SpatialNormalization.lua
+++ b/SpatialNormalization.lua
@@ -182,7 +182,7 @@ function SpatialNormalization:__init(...) -- kernel for weighted mean | nb of fe
self.thstd = torch.Tensor()
end
-function SpatialNormalization:forward(input)
+function SpatialNormalization:updateOutput(input)
-- auto switch to 3-channel
self.input = input
if (input:nDimension() == 2) then
@@ -192,32 +192,32 @@ function SpatialNormalization:forward(input)
-- recompute coef only if necessary
if (self.input:size(3) ~= self.coef:size(2)) or (self.input:size(2) ~= self.coef:size(1)) then
local intVals = self.input.new(self.nfeatures,self.input:size(2),self.input:size(3)):fill(1)
- self.coef = self.convo:forward(intVals)
+ self.coef = self.convo:updateOutput(intVals)
self.coef = self.coef:clone()
end
-- compute mean
- self.inConvo = self.convo:forward(self.input)
- self.inMean = self.meanDiviseMod:forward{self.inConvo,self.coef}
- self.inputZeroMean = self.subtractMod:forward{self.input,self.inMean}
+ self.inConvo = self.convo:updateOutput(self.input)
+ self.inMean = self.meanDiviseMod:updateOutput{self.inConvo,self.coef}
+ self.inputZeroMean = self.subtractMod:updateOutput{self.input,self.inMean}
-- compute std dev
- self.inputZeroMeanSq = self.squareMod:forward(self.inputZeroMean)
- self.inConvoVar = self.convostd:forward(self.inputZeroMeanSq)
- self.inStdDevNotUnit = self.sqrtMod:forward(self.inConvoVar)
- self.inStdDev = self.stdDiviseMod:forward({self.inStdDevNotUnit,self.coef})
+ self.inputZeroMeanSq = self.squareMod:updateOutput(self.inputZeroMean)
+ self.inConvoVar = self.convostd:updateOutput(self.inputZeroMeanSq)
+ self.inStdDevNotUnit = self.sqrtMod:updateOutput(self.inConvoVar)
+ self.inStdDev = self.stdDiviseMod:updateOutput({self.inStdDevNotUnit,self.coef})
local meanstd = self.inStdDev:mean()
self.thresMod.threshold = self.fixedThres or math.max(meanstd,1e-3)
self.thresMod.val = self.fixedThres or math.max(meanstd,1e-3)
- self.stdDev = self.thresMod:forward(self.inStdDev)
+ self.stdDev = self.thresMod:updateOutput(self.inStdDev)
--remove std dev
- self.diviseMod:forward{self.inputZeroMean,self.stdDev}
+ self.diviseMod:updateOutput{self.inputZeroMean,self.stdDev}
self.output = self.diviseMod.output
return self.output
end
-function SpatialNormalization:backward(input, gradOutput)
+function SpatialNormalization:updateGradInput(input, gradOutput)
-- auto switch to 3-channel
self.input = input
if (input:nDimension() == 2) then
@@ -226,23 +226,23 @@ function SpatialNormalization:backward(input, gradOutput)
self.gradInput:resizeAs(self.input):zero()
-- backprop all
- local gradDiv = self.diviseMod:backward({self.inputZeroMean,self.stdDev},gradOutput)
+ local gradDiv = self.diviseMod:updateGradInput({self.inputZeroMean,self.stdDev},gradOutput)
local gradThres = gradDiv[2]
local gradZeroMean = gradDiv[1]
- local gradinStdDev = self.thresMod:backward(self.inStdDev,gradThres)
- local gradstdDiv = self.stdDiviseMod:backward({self.inStdDevNotUnit,self.coef},gradinStdDev)
+ local gradinStdDev = self.thresMod:updateGradInput(self.inStdDev,gradThres)
+ local gradstdDiv = self.stdDiviseMod:updateGradInput({self.inStdDevNotUnit,self.coef},gradinStdDev)
local gradinStdDevNotUnit = gradstdDiv[1]
- local gradinConvoVar = self.sqrtMod:backward(self.inConvoVar,gradinStdDevNotUnit)
- local gradinputZeroMeanSq = self.convostd:backward(self.inputZeroMeanSq,gradinConvoVar)
- gradZeroMean:add(self.squareMod:backward(self.inputZeroMean,gradinputZeroMeanSq))
- local gradDiff = self.subtractMod:backward({self.input,self.inMean},gradZeroMean)
+ local gradinConvoVar = self.sqrtMod:updateGradInput(self.inConvoVar,gradinStdDevNotUnit)
+ local gradinputZeroMeanSq = self.convostd:updateGradInput(self.inputZeroMeanSq,gradinConvoVar)
+ gradZeroMean:add(self.squareMod:updateGradInput(self.inputZeroMean,gradinputZeroMeanSq))
+ local gradDiff = self.subtractMod:updateGradInput({self.input,self.inMean},gradZeroMean)
local gradinMean = gradDiff[2]
- local gradinConvoNotUnit = self.meanDiviseMod:backward({self.inConvo,self.coef},gradinMean)
+ local gradinConvoNotUnit = self.meanDiviseMod:updateGradInput({self.inConvo,self.coef},gradinMean)
local gradinConvo = gradinConvoNotUnit[1]
-- first part of the gradInput
self.gradInput:add(gradDiff[1])
-- second part of the gradInput
- self.gradInput:add(self.convo:backward(self.input,gradinConvo))
+ self.gradInput:add(self.convo:updateGradInput(self.input,gradinConvo))
return self.gradInput
end
@@ -259,58 +259,3 @@ function SpatialNormalization:type(type)
self.diviseMod:type(type)
return self
end
-
-function SpatialNormalization:write(file)
- parent.write(self,file)
- file:writeObject(self.kernel)
- file:writeInt(self.nfeatures)
- file:writeInt(self.padW)
- file:writeInt(self.padH)
- file:writeInt(self.kerWisPair)
- file:writeInt(self.kerHisPair)
- file:writeObject(self.convo)
- file:writeObject(self.convostd)
- file:writeObject(self.squareMod)
- file:writeObject(self.sqrtMod)
- file:writeObject(self.subtractMod)
- file:writeObject(self.meanDiviseMod)
- file:writeObject(self.stdDiviseMod)
- file:writeObject(self.thresMod)
- file:writeObject(self.diviseMod)
- file:writeObject(self.coef)
- if type(self.kernel) == 'table' then
- file:writeInt(self.pad2W)
- file:writeInt(self.pad2H)
- file:writeInt(self.ker2WisPair)
- file:writeInt(self.ker2HisPair)
- end
- file:writeInt(self.fixedThres or 0)
-end
-
-function SpatialNormalization:read(file)
- parent.read(self,file)
- self.kernel = file:readObject()
- self.nfeatures = file:readInt()
- self.padW = file:readInt()
- self.padH = file:readInt()
- self.kerWisPair = file:readInt()
- self.kerHisPair = file:readInt()
- self.convo = file:readObject()
- self.convostd = file:readObject()
- self.squareMod = file:readObject()
- self.sqrtMod = file:readObject()
- self.subtractMod = file:readObject()
- self.meanDiviseMod = file:readObject()
- self.stdDiviseMod = file:readObject()
- self.thresMod = file:readObject()
- self.diviseMod = file:readObject()
- self.coef = file:readObject()
- if type(self.kernel) == 'table' then
- self.pad2W = file:readInt()
- self.pad2H = file:readInt()
- self.ker2WisPair = file:readInt()
- self.ker2HisPair = file:readInt()
- end
- self.fixedThres = file:readInt()
- if self.fixedThres == 0 then self.fixedThres = nil end
-end
diff --git a/SpatialPadding.lua b/SpatialPadding.lua
index 9c87c2b..ecea707 100644
--- a/SpatialPadding.lua
+++ b/SpatialPadding.lua
@@ -19,7 +19,7 @@ function SpatialPadding:__init(pad_l, pad_r, pad_t, pad_b)
self.pad_b = pad_b or self.pad_l
end
-function SpatialPadding:forward(input)
+function SpatialPadding:updateOutput(input)
if input:dim() ~= 3 then error('input must be 3-dimensional') end
local h = input:size(2) + self.pad_t + self.pad_b
local w = input:size(3) + self.pad_l + self.pad_r
@@ -43,7 +43,7 @@ function SpatialPadding:forward(input)
return self.output
end
-function SpatialPadding:backward(input, gradOutput)
+function SpatialPadding:updateGradInput(input, gradOutput)
if input:dim() ~= 3 then error('input must be 3-dimensional') end
self.gradInput:resizeAs(input):zero()
-- crop gradInput if necessary
@@ -62,20 +62,3 @@ function SpatialPadding:backward(input, gradOutput)
cg_input:copy(cg_output)
return self.gradInput
end
-
-function SpatialPadding:write(file)
- parent.write(self, file)
- file:writeInt(self.pad_l)
- file:writeInt(self.pad_r)
- file:writeInt(self.pad_t)
- file:writeInt(self.pad_b)
-end
-
-function SpatialPadding:read(file)
- parent.read(self, file)
- self.pad_l = file:readInt()
- self.pad_r = file:readInt()
- self.pad_t = file:readInt()
- self.pad_b = file:readInt()
-end
-
diff --git a/SpatialReSampling.lua b/SpatialReSampling.lua
index 9aef63c..b738eab 100644
--- a/SpatialReSampling.lua
+++ b/SpatialReSampling.lua
@@ -30,26 +30,14 @@ function SpatialReSampling:__init(...)
)
end
-function SpatialReSampling:forward(input)
+function SpatialReSampling:updateOutput(input)
self.oheight = self.oheight or self.rheight*input:size(2)
self.owidth = self.owidth or self.rwidth*input:size(3)
- input.nn.SpatialReSampling_forward(self, input)
+ input.nn.SpatialReSampling_updateOutput(self, input)
return self.output
end
-function SpatialReSampling:backward(input, gradOutput)
- input.nn.SpatialReSampling_backward(self, input, gradOutput)
+function SpatialReSampling:updateGradInput(input, gradOutput)
+ input.nn.SpatialReSampling_updateGradInput(self, input, gradOutput)
return self.gradInput
end
-
-function SpatialReSampling:write(file)
- parent.write(self, file)
- file:writeInt(self.owidth)
- file:writeInt(self.oheight)
-end
-
-function SpatialReSampling:read(file)
- parent.read(self, file)
- self.owidth = file:readInt()
- self.oheight = file:readInt()
-end
diff --git a/SpatialRecursiveFovea.lua b/SpatialRecursiveFovea.lua
index c9490c2..ef7243b 100644
--- a/SpatialRecursiveFovea.lua
+++ b/SpatialRecursiveFovea.lua
@@ -275,7 +275,7 @@ function SpatialRecursiveFovea:focus(x,y)
self.corners = corners
end
-function SpatialRecursiveFovea:forward(input,target,x,y)
+function SpatialRecursiveFovea:updateOutput(input,target,x,y)
-- input must be 3D
if input:nDimension() ~= 3 or input:size(1) ~= self.nInputPlane then
xerror('input must be 3d and have ' .. self.nInputPlane .. ' input planes','nn.SpatialRecursiveFovea')
@@ -299,11 +299,11 @@ function SpatialRecursiveFovea:forward(input,target,x,y)
-- (1-2) create preprocessed pyramid
for idx = 1,nscales do
-- (1) generate pyramid
- self.pyramid[idx] = self.downsamplers[idx]:forward(input)
+ self.pyramid[idx] = self.downsamplers[idx]:updateOutput(input)
-- (2) preprocess
if self.preProcessors[idx] then
- self.preProcessed[idx] = self.preProcessors[idx]:forward(self.pyramid[idx])
+ self.preProcessed[idx] = self.preProcessors[idx]:updateOutput(self.pyramid[idx])
else
self.preProcessed[idx] = self.pyramid[idx]
end
@@ -312,7 +312,7 @@ function SpatialRecursiveFovea:forward(input,target,x,y)
-- (3-7) walk through recursion
for idx = 1,nscales do
-- (3) pad inputs
- self.padded[idx] = self.padders[idx]:forward(self.preProcessed[idx])
+ self.padded[idx] = self.padders[idx]:updateOutput(self.preProcessed[idx])
-- (4) is fovea focused ?
self.narrowed[idx]
@@ -336,15 +336,15 @@ function SpatialRecursiveFovea:forward(input,target,x,y)
end
-- (6) apply processors to pyramid
- self.processed[idx] = self.processors[idx]:forward(self.concatenated[idx])
+ self.processed[idx] = self.processors[idx]:updateOutput(self.concatenated[idx])
-- (7) upsample, pad and narrow, for next stage
if idx < nscales then
-- (7.a)
- self.upsampled[idx] = self.upsamplers[idx]:forward(self.processed[idx])
+ self.upsampled[idx] = self.upsamplers[idx]:updateOutput(self.processed[idx])
-- (7.b)
- self.upsampledPadded[idx] = self.upsampledPadders[idx]:forward(self.upsampled[idx])
+ self.upsampledPadded[idx] = self.upsampledPadders[idx]:updateOutput(self.upsampled[idx])
-- (7.c)
self.upsampledNarrowed[idx]
@@ -355,7 +355,7 @@ function SpatialRecursiveFovea:forward(input,target,x,y)
-- (8) optional post processors
for idx = 1,nscales do
if self.postProcessors[idx] then
- self.postProcessed[idx] = self.postProcessors[idx]:forward(self.processed[idx])
+ self.postProcessed[idx] = self.postProcessors[idx]:updateOutput(self.processed[idx])
else
self.postProcessed[idx] = self.processed[idx]
end
@@ -410,7 +410,7 @@ function SpatialRecursiveFovea:forward(input,target,x,y)
self.targets[idx] = self.targets_scaled[idx]
end
-- then evaluate the criterion's error
- error = error + self.criterions[idx]:forward(self.predicted[idx], self.targets[idx])
+ error = error + self.criterions[idx]:updateOutput(self.predicted[idx], self.targets[idx])
end
-- normalize error
@@ -434,17 +434,17 @@ function SpatialRecursiveFovea:forward(input,target,x,y)
return self.output, error
end
-function SpatialRecursiveFovea:backward(input)
+function SpatialRecursiveFovea:updateGradInput(input)
-- local params
local nscales = #self.ratios
local fov = self.fov
local sub = self.sub
local corners = self.corners
- -- (9) backprop through criterions using generated targets (from prev forward call)
+ -- (9) backprop through criterions using generated targets (from prev updateOutput call)
for idx = 1,nscales do
-- bprop through criterion
- self.gradPredicted[idx] = self.criterions[idx]:backward(self.predicted[idx], self.targets[idx])
+ self.gradPredicted[idx] = self.criterions[idx]:updateGradInput(self.predicted[idx], self.targets[idx])
-- then remap partial grad vector
self.gradPostProcessed[idx] = self.gradPostProcessed[idx] or torch.Tensor()
@@ -460,7 +460,7 @@ function SpatialRecursiveFovea:backward(input)
-- (8) backprop through post processors
for idx = 1,nscales do
if self.postProcessors[idx] then
- self.gradProcessed[idx] = self.postProcessors[idx]:backward(self.processed[idx], self.gradPostProcessed[idx])
+ self.gradProcessed[idx] = self.postProcessors[idx]:updateGradInput(self.processed[idx], self.gradPostProcessed[idx])
else
self.gradProcessed[idx] = self.gradPostProcessed[idx]
end
@@ -471,7 +471,7 @@ function SpatialRecursiveFovea:backward(input)
-- (6) backprop through processors
for idx = 1,nscales do
- self.gradConcatenated[idx] = self.processors[idx]:backward(self.concatenated[idx], self.gradProcessed[idx])
+ self.gradConcatenated[idx] = self.processors[idx]:updateGradInput(self.concatenated[idx], self.gradProcessed[idx])
end
-- (5) bprop through concatenators
@@ -488,13 +488,13 @@ function SpatialRecursiveFovea:backward(input)
-- (3) bprop through padders
for idx = 1,nscales do
- self.gradPreProcessed[idx] = self.padders[idx]:backward(self.preProcessed[idx], self.gradPadded[idx])
+ self.gradPreProcessed[idx] = self.padders[idx]:updateGradInput(self.preProcessed[idx], self.gradPadded[idx])
end
-- (2) bprop through preProcessors
for idx = 1,nscales do
if self.preProcessors[idx] then
- self.gradPyramid[idx] = self.preProcessors[idx]:backward(self.pyramid[idx], self.gradPreProcessed[idx])
+ self.gradPyramid[idx] = self.preProcessors[idx]:updateGradInput(self.pyramid[idx], self.gradPreProcessed[idx])
else
self.gradPyramid[idx] = self.gradPreProcessed[idx]
end
@@ -503,7 +503,7 @@ function SpatialRecursiveFovea:backward(input)
-- (1) bprop through pyramid
self.gradInput:resizeAs(input):zero()
for idx = 1,nscales do
- local partialGrad = self.downsamplers[idx]:backward(input, self.gradPyramid[idx])
+ local partialGrad = self.downsamplers[idx]:updateGradInput(input, self.gradPyramid[idx])
self.gradInput:add(partialGrad)
end
return self.gradInput
@@ -534,80 +534,3 @@ function SpatialRecursiveFovea:decayParameters(decay)
end
end
end
-
-function SpatialRecursiveFovea:write(file)
- parent.write(self, file)
- -- params
- file:writeInt(self.nInputPlane)
- file:writeInt(self.nRecursivePlane)
- file:writeInt(self.fov)
- file:writeInt(self.sub)
- file:writeObject(self.ratios)
- -- modules
- file:writeObject(self.downsamplers)
- file:writeObject(self.padders)
- file:writeObject(self.upsamplers)
- file:writeObject(self.upsampledPadders)
- file:writeObject(self.processors)
- file:writeObject(self.preProcessors)
- file:writeObject(self.postProcessors)
- file:writeObject(self.criterions)
- -- states
- file:writeObject(self.pyramid)
- file:writeObject(self.preProcessed)
- file:writeObject(self.padded)
- file:writeObject(self.narrowed)
- file:writeObject(self.concatenated)
- file:writeObject(self.processed)
- file:writeObject(self.upsampled)
- file:writeObject(self.upsampledPadded)
- file:writeObject(self.upsampledNarrowed)
- file:writeObject(self.postProcessed)
- file:writeObject(self.predicted)
-end
-
-function SpatialRecursiveFovea:read(file)
- parent.read(self, file)
- -- params
- self.nInputPlane = file:readInt()
- self.nRecursivePlane = file:readInt()
- self.fov = file:readInt()
- self.sub = file:readInt()
- self.ratios = file:readObject()
- self.batchSize = self.fov
- -- modules
- self.downsamplers = file:readObject()
- self.padders = file:readObject()
- self.upsamplers = file:readObject()
- self.upsampledPadders = file:readObject()
- self.processors = file:readObject()
- self.preProcessors = file:readObject()
- self.postProcessors = file:readObject()
- self.criterions = file:readObject()
- -- states
- self.pyramid = file:readObject()
- self.preProcessed = file:readObject()
- self.padded = file:readObject()
- self.narrowed = file:readObject()
- self.concatenated = file:readObject()
- self.processed = file:readObject()
- self.upsampled = file:readObject()
- self.upsampledPadded = file:readObject()
- self.upsampledNarrowed = file:readObject()
- self.postProcessed = file:readObject()
- self.predicted = file:readObject()
- -- grad states
- self.gradPostProcessed = {}
- self.gradUpsampledNarrowed = {}
- self.gradUpsampledPadded = {}
- self.gradUpsampled = {}
- self.gradProcessed = {}
- self.gradConcatenated = {}
- self.gradNarrowed = {}
- self.gradPadded = {}
- self.gradPreProcessed = {}
- self.gradPyramid = {}
- self.gradPredicted = {}
- self.targets_scaled = {}
- self.targets = {}
-end
diff --git a/SpatialSparseCriterion.lua b/SpatialSparseCriterion.lua
index abb2301..f19475e 100644
--- a/SpatialSparseCriterion.lua
+++ b/SpatialSparseCriterion.lua
@@ -12,10 +12,10 @@ function SpatialSparseCriterion:__init(...)
)
end
-function SpatialSparseCriterion:forward(input)
+function SpatialSparseCriterion:updateOutput(input)
self.fullOutput = self.fullOutput or torch.Tensor()
self.fullOutput:resize(input:size(2), input:size(3))
- input.nn.SpatialSparseCriterion_forward(self, input)
+ input.nn.SpatialSparseCriterion_updateOutput(self, input)
if self.sizeAverage then
self.output = self.fullOutput:mean()
else
@@ -24,7 +24,7 @@ function SpatialSparseCriterion:forward(input)
return self.output
end
-function SpatialSparseCriterion:backward(input,target)
+function SpatialSparseCriterion:updateGradInput(input,target)
-- (1) retrieve adjusted target
target = self.target
-- (2) resize input gradient map
@@ -32,12 +32,12 @@ function SpatialSparseCriterion:backward(input,target)
-- (3) compute input gradients, based on the nbGradients param
if self.nbGradients == -1 then
-- dense gradients
- input.nn.SpatialSparseCriterion_backward(self, input, self.gradInput)
+ input.nn.SpatialSparseCriterion_updateGradInput(self, input, self.gradInput)
elseif self.nbGradients == 1 then
-- only 1 gradient is computed, sampled in the center
self.fullGradInput = torch.Tensor() or self.fullGradInput
self.fullGradInput:resizeAs(input):zero()
- input.nn.SpatialSparseCriterion_backward(self, input, self.fullGradInput)
+ input.nn.SpatialSparseCriterion_updateGradInput(self, input, self.fullGradInput)
local y = math.ceil(self.gradInput:size(2)/2)
local x = math.ceil(self.gradInput:size(3)/2)
self.gradInput:select(3,x):select(2,y):copy(self.fullGradInput:select(3,x):select(2,y))
@@ -45,7 +45,7 @@ function SpatialSparseCriterion:backward(input,target)
-- only N gradients are computed, sampled in random locations
self.fullGradInput = torch.Tensor() or self.fullGradInput
self.fullGradInput:resizeAs(input):zero()
- input.nn.SpatialSparseCriterion_backward(self, input, self.fullGradInput)
+ input.nn.SpatialSparseCriterion_updateGradInput(self, input, self.fullGradInput)
for i = 1,self.nbGradients do
local x = math.random(1,self.gradInput:size(1))
local y = math.random(1,self.gradInput:size(2))
@@ -54,15 +54,3 @@ function SpatialSparseCriterion:backward(input,target)
end
return self.gradInput
end
-
-function SpatialSparseCriterion:write(file)
- parent.write(self, file)
- file:writeDouble(self.resampleTarget)
- file:writeInt(self.nbGradients)
-end
-
-function SpatialSparseCriterion:read(file)
- parent.read(self, file)
- self.resampleTarget= file:readDouble()
- self.nbGradients = file:readInt()
-end
diff --git a/SpatialUpSampling.lua b/SpatialUpSampling.lua
index 90d0126..0d26bcd 100644
--- a/SpatialUpSampling.lua
+++ b/SpatialUpSampling.lua
@@ -25,26 +25,14 @@ function SpatialUpSampling:__init(...)
{arg='dH', type='number', help='stride height', req=true})
end
-function SpatialUpSampling:forward(input)
+function SpatialUpSampling:updateOutput(input)
self.output:resize(input:size(1), input:size(2) * self.dH, input:size(3) * self.dW)
- input.nn.SpatialUpSampling_forward(self, input)
+ input.nn.SpatialUpSampling_updateOutput(self, input)
return self.output
end
-function SpatialUpSampling:backward(input, gradOutput)
+function SpatialUpSampling:updateGradInput(input, gradOutput)
self.gradInput:resizeAs(input)
- input.nn.SpatialUpSampling_backward(self, input, gradOutput)
+ input.nn.SpatialUpSampling_updateGradInput(self, input, gradOutput)
return self.gradInput
end
-
-function SpatialUpSampling:write(file)
- parent.write(self, file)
- file:writeInt(self.dW)
- file:writeInt(self.dH)
-end
-
-function SpatialUpSampling:read(file)
- parent.read(self, file)
- self.dW = file:readInt()
- self.dH = file:readInt()
-end
diff --git a/Sqrt.lua b/Sqrt.lua
deleted file mode 100644
index 4c0427b..0000000
--- a/Sqrt.lua
+++ /dev/null
@@ -1,34 +0,0 @@
-
-local Sqrt, parent = torch.class('nn.Sqrt','nn.Module')
-
-function Sqrt:__init(args)
- parent.__init(self)
- if args then
- error(xlua.usage('nn.Sqrt',
- 'a simple component-wise mapping: sqrt()',
- 'sq = nn.Sqrt()\n'..
- 'sqrt = sq:forward(sometensor)',
- {type='nil', help='no arg required'}))
- end
-end
-
-function Sqrt:forward(input)
- self.output:resizeAs(input):copy(input)
- self.output:sqrt()
- return self.output
-end
-
-function Sqrt:backward(input, gradOutput)
- self.gradInput:resizeAs(input):copy(gradOutput)
- self.gradInput:cdiv(self.output):mul(0.5)
- return self.gradInput
-end
-
-
-function Sqrt:write(file)
- parent.write(self,file)
-end
-
-function Sqrt:read(file)
- parent.read(self,file)
-end
diff --git a/Square.lua b/Square.lua
deleted file mode 100644
index 30e8cb9..0000000
--- a/Square.lua
+++ /dev/null
@@ -1,33 +0,0 @@
-local Square, parent = torch.class('nn.Square','nn.Module')
-
-function Square:__init(args)
- parent.__init(self)
- if args then
- error(xlua.usage('nn.Square',
- 'a simple component-wise mapping: square()',
- 'sq = nn.Square()\n'..
- 'squared = sq:forward(sometensor)',
- {type='nil', help='no arg required'}))
- end
-end
-
-function Square:forward(input)
- self.output:resizeAs(input):copy(input)
- self.output:cmul(input)
- return self.output
-end
-
-function Square:backward(input, gradOutput)
- self.gradInput:resizeAs(input):copy(gradOutput)
- self.gradInput:cmul(input):mul(2)
- return self.gradInput
-end
-
-
-function Square:write(file)
- parent.write(self,file)
-end
-
-function Square:read(file)
- parent.read(self,file)
-end
diff --git a/SuperCriterion.lua b/SuperCriterion.lua
index c73d716..983639a 100644
--- a/SuperCriterion.lua
+++ b/SuperCriterion.lua
@@ -13,32 +13,32 @@ function SuperCriterion:add(criterion, weight)
table.insert(self.weights, weight)
end
-function SuperCriterion:forward(input, target)
+function SuperCriterion:updateOutput(input, target)
self.output = 0
if type(target) == 'table' then
for i,criterion in ipairs(self.criterions) do
- self.output = self.output + self.weights[i]*criterion:forward(input[i],target[i])
+ self.output = self.output + self.weights[i]*criterion:updateOutput(input[i],target[i])
end
else
for i,criterion in ipairs(self.criterions) do
- self.output = self.output + self.weights[i]*criterion:forward(input[i],target)
+ self.output = self.output + self.weights[i]*criterion:updateOutput(input[i],target)
end
end
return self.output
end
-function SuperCriterion:backward(input, target)
+function SuperCriterion:updateGradInput(input, target)
if type(target) == 'table' then
for i,criterion in ipairs(self.criterions) do
self.gradInput[i] = torch.Tensor() or self.gradInput[i]
self.gradInput[i]:resizeAs(input[i]):zero()
- self.gradInput[i]:add(self.weights[i], criterion:backward(input[i],target[i]))
+ self.gradInput[i]:add(self.weights[i], criterion:updateGradInput(input[i],target[i]))
end
else
for i,criterion in ipairs(self.criterions) do
self.gradInput[i] = torch.Tensor() or self.gradInput[i]
self.gradInput[i]:resizeAs(input[i]):zero()
- self.gradInput[i]:add(self.weights[i], criterion:backward(input[i],target))
+ self.gradInput[i]:add(self.weights[i], criterion:updateGradInput(input[i],target))
end
end
return self.gradInput
diff --git a/Threshold.lua b/Threshold.lua
deleted file mode 100644
index fbd5c54..0000000
--- a/Threshold.lua
+++ /dev/null
@@ -1,36 +0,0 @@
-local Threshold, parent = torch.class('nn.Threshold','nn.Module')
-
-function Threshold:__init(th,v)
- parent.__init(self)
- self.threshold = th or 1e-6
- self.val = v or 0
- if (th and type(th) ~= 'number') or (v and type(v) ~= 'number') then
- error(xlua.usage('nn.Threshold',
- 'a threhold module, if input < threshold, then output = value',
- nil,
- {type='number', help='threshold'},
- {type='number', help='value'}))
- end
-end
-
-function Threshold:forward(input)
- input.nn.Threshold_forward(self, input)
- return self.output
-end
-
-function Threshold:backward(input, gradOutput)
- input.nn.Threshold_backward(self, input, gradOutput)
- return self.gradInput
-end
-
-function Threshold:write(file)
- parent.write(self,file)
- file:writeDouble(self.threshold)
- file:writeDouble(self.val)
-end
-
-function Threshold:read(file)
- parent.read(self,file)
- self.threshold = file:readDouble()
- self.val = file:readDouble()
-end
diff --git a/Trainer.lua b/Trainer.lua
index b7da770..34d1d33 100644
--- a/Trainer.lua
+++ b/Trainer.lua
@@ -9,18 +9,6 @@ end
function Trainer:train(dataset)
end
-function Trainer:write(file)
- file:writeDouble(self.learningRate)
- file:writeDouble(self.learningRateDecay)
- file:writeInt(self.maxIteration)
-end
-
-function Trainer:read(file)
- self.learningRate = file:readDouble()
- self.learningRateDecay = file:readDouble()
- self.maxIteration = file:readInt()
-end
-
function Trainer:share(mlp, ...)
for i,v in ipairs(arg) do
if self[v] ~=nil then self[v]:set(mlp[v]) end
diff --git a/Type.lua b/Type.lua
index a093488..8763cac 100644
--- a/Type.lua
+++ b/Type.lua
@@ -18,24 +18,24 @@ function Type:add(module)
return self
end
-function Type:forward(input)
- input = self.convert_input:forward(input)
- local output = parent.forward(self, input)
- self.output = self.convert_output:forward(output)
+function Type:updateOutput(input)
+ input = self.convert_input:updateOutput(input)
+ local output = parent.updateOutput(self, input)
+ self.output = self.convert_output:updateOutput(output)
return self.output
end
-function Type:backward(input, gradOutput)
- input = self.convert_input:forward(input)
- gradOutput = self.convert_gradOutput:forward(gradOutput)
- local gradInput = parent.backward(self, input, gradOutput)
- self.gradInput = self.convert_gradInput:forward(gradInput)
+function Type:updateGradInput(input, gradOutput)
+ input = self.convert_input:updateOutput(input)
+ gradOutput = self.convert_gradOutput:updateOutput(gradOutput)
+ local gradInput = parent.updateGradInput(self, input, gradOutput)
+ self.gradInput = self.convert_gradInput:updateOutput(gradInput)
return self.gradInput
end
function Type:accGradParameters(input, gradOutput)
- input = self.convert_input:forward(input)
- gradOutput = self.convert_gradOutput:forward(gradOutput)
+ input = self.convert_input:updateOutput(input)
+ gradOutput = self.convert_gradOutput:updateOutput(gradOutput)
parent.accGradParameters(self, input, gradOutput)
end
diff --git a/generic/Abs.c b/generic/Abs.c
index c45c0ab..8c65813 100644
--- a/generic/Abs.c
+++ b/generic/Abs.c
@@ -2,7 +2,7 @@
#define TH_GENERIC_FILE "generic/Abs.c"
#else
-static int nn_(Abs_forward)(lua_State *L)
+static int nn_(Abs_updateOutput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
THTensor *output = luaT_getfieldcheckudata(L, 1, "output", torch_(Tensor_id));
@@ -14,7 +14,7 @@ static int nn_(Abs_forward)(lua_State *L)
return 1;
}
-static int nn_(Abs_backward)(lua_State *L)
+static int nn_(Abs_updateGradInput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
THTensor *gradOutput = luaT_checkudata(L, 3, torch_(Tensor_id));
@@ -28,8 +28,8 @@ static int nn_(Abs_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(Abs__) [] = {
- {"Abs_forward", nn_(Abs_forward)},
- {"Abs_backward", nn_(Abs_backward)},
+ {"Abs_updateOutput", nn_(Abs_updateOutput)},
+ {"Abs_updateGradInput", nn_(Abs_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/DistMarginCriterion.c b/generic/DistMarginCriterion.c
index 6e94c9d..8859bdd 100644
--- a/generic/DistMarginCriterion.c
+++ b/generic/DistMarginCriterion.c
@@ -2,7 +2,7 @@
#define TH_GENERIC_FILE "generic/DistMarginCriterion.c"
#else
-static int nn_(DistMarginCriterion_forward)(lua_State *L)
+static int nn_(DistMarginCriterion_updateOutput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
int sizeAverage = luaT_getfieldcheckboolean(L, 1, "sizeAverage");
@@ -82,7 +82,7 @@ static int nn_(DistMarginCriterion_forward)(lua_State *L)
return 1;
}
-static int nn_(DistMarginCriterion_backward)(lua_State *L)
+static int nn_(DistMarginCriterion_updateGradInput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
int sizeAverage = luaT_getfieldcheckboolean(L, 1, "sizeAverage");
@@ -172,8 +172,8 @@ static int nn_(DistMarginCriterion_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(DistMarginCriterion__) [] = {
- {"DistMarginCriterion_forward", nn_(DistMarginCriterion_forward)},
- {"DistMarginCriterion_backward", nn_(DistMarginCriterion_backward)},
+ {"DistMarginCriterion_updateOutput", nn_(DistMarginCriterion_updateOutput)},
+ {"DistMarginCriterion_updateGradInput", nn_(DistMarginCriterion_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/HardShrink.c b/generic/HardShrink.c
index d3bcfcd..d75e071 100644
--- a/generic/HardShrink.c
+++ b/generic/HardShrink.c
@@ -2,7 +2,7 @@
#define TH_GENERIC_FILE "generic/HardShrink.c"
#else
-static int nn_(HardShrink_forward)(lua_State *L)
+static int nn_(HardShrink_updateOutput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
THTensor *output = luaT_getfieldcheckudata(L, 1, "output", torch_(Tensor_id));
@@ -16,7 +16,7 @@ static int nn_(HardShrink_forward)(lua_State *L)
return 1;
}
-static int nn_(HardShrink_backward)(lua_State *L)
+static int nn_(HardShrink_updateGradInput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
THTensor *gradOutput = luaT_checkudata(L, 3, torch_(Tensor_id));
@@ -32,8 +32,8 @@ static int nn_(HardShrink_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(HardShrink__) [] = {
- {"HardShrink_forward", nn_(HardShrink_forward)},
- {"HardShrink_backward", nn_(HardShrink_backward)},
+ {"HardShrink_updateOutput", nn_(HardShrink_updateOutput)},
+ {"HardShrink_updateGradInput", nn_(HardShrink_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/SparseCriterion.c b/generic/SparseCriterion.c
index 76da569..f4ebb8e 100644
--- a/generic/SparseCriterion.c
+++ b/generic/SparseCriterion.c
@@ -2,7 +2,7 @@
#define TH_GENERIC_FILE "generic/SparseCriterion.c"
#else
-static int nn_(SparseCriterion_forward)(lua_State *L)
+static int nn_(SparseCriterion_updateOutput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
int sizeAverage = luaT_getfieldcheckboolean(L, 1, "sizeAverage");
@@ -19,7 +19,7 @@ static int nn_(SparseCriterion_forward)(lua_State *L)
return 1;
}
-static int nn_(SparseCriterion_backward)(lua_State *L)
+static int nn_(SparseCriterion_updateGradInput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
int sizeAverage = luaT_getfieldcheckboolean(L, 1, "sizeAverage");
@@ -34,8 +34,8 @@ static int nn_(SparseCriterion_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(SparseCriterion__) [] = {
- {"SparseCriterion_forward", nn_(SparseCriterion_forward)},
- {"SparseCriterion_backward", nn_(SparseCriterion_backward)},
+ {"SparseCriterion_updateOutput", nn_(SparseCriterion_updateOutput)},
+ {"SparseCriterion_updateGradInput", nn_(SparseCriterion_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/SpatialClassNLLCriterion.c b/generic/SpatialClassNLLCriterion.c
index 517af80..ddbbe1f 100644
--- a/generic/SpatialClassNLLCriterion.c
+++ b/generic/SpatialClassNLLCriterion.c
@@ -2,7 +2,7 @@
#define TH_GENERIC_FILE "generic/SpatialClassNLLCriterion.c"
#else
-static int nn_(SpatialClassNLLCriterion_forward)(lua_State *L)
+static int nn_(SpatialClassNLLCriterion_updateOutput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
THTensor *target = luaT_checkudata(L, 3, torch_(Tensor_id));
@@ -20,7 +20,7 @@ static int nn_(SpatialClassNLLCriterion_forward)(lua_State *L)
return 1;
}
-static int nn_(SpatialClassNLLCriterion_backward)(lua_State *L)
+static int nn_(SpatialClassNLLCriterion_updateGradInput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
THTensor *target = luaT_checkudata(L, 3, torch_(Tensor_id));
@@ -39,8 +39,8 @@ static int nn_(SpatialClassNLLCriterion_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(SpatialClassNLLCriterion__) [] = {
- {"SpatialClassNLLCriterion_forward", nn_(SpatialClassNLLCriterion_forward)},
- {"SpatialClassNLLCriterion_backward", nn_(SpatialClassNLLCriterion_backward)},
+ {"SpatialClassNLLCriterion_updateOutput", nn_(SpatialClassNLLCriterion_updateOutput)},
+ {"SpatialClassNLLCriterion_updateGradInput", nn_(SpatialClassNLLCriterion_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/SpatialGraph.c b/generic/SpatialGraph.c
index 29d8bbf..a1db79a 100644
--- a/generic/SpatialGraph.c
+++ b/generic/SpatialGraph.c
@@ -7,7 +7,7 @@
#endif
#define square(x) ((x)*(x))
-static int nn_(SpatialGraph_forward)(lua_State *L)
+static int nn_(SpatialGraph_updateOutput)(lua_State *L)
{
// get all params
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
@@ -109,7 +109,7 @@ static int nn_(SpatialGraph_forward)(lua_State *L)
return 1;
}
-static int nn_(SpatialGraph_backward)(lua_State *L)
+static int nn_(SpatialGraph_updateGradInput)(lua_State *L)
{
// get all params
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
@@ -245,8 +245,8 @@ static int nn_(SpatialGraph_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(SpatialGraph__) [] = {
- {"SpatialGraph_forward", nn_(SpatialGraph_forward)},
- {"SpatialGraph_backward", nn_(SpatialGraph_backward)},
+ {"SpatialGraph_updateOutput", nn_(SpatialGraph_updateOutput)},
+ {"SpatialGraph_updateGradInput", nn_(SpatialGraph_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/SpatialLinear.c b/generic/SpatialLinear.c
index 903c3b8..524d313 100644
--- a/generic/SpatialLinear.c
+++ b/generic/SpatialLinear.c
@@ -2,7 +2,7 @@
#define TH_GENERIC_FILE "generic/SpatialLinear.c"
#else
-static int nn_(SpatialLinear_forward)(lua_State *L)
+static int nn_(SpatialLinear_updateOutput)(lua_State *L)
{
// get all params
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
@@ -43,7 +43,7 @@ static int nn_(SpatialLinear_forward)(lua_State *L)
return 1;
}
-static int nn_(SpatialLinear_backward)(lua_State *L)
+static int nn_(SpatialLinear_updateGradInput)(lua_State *L)
{
// get all params
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
@@ -118,8 +118,8 @@ static int nn_(SpatialLinear_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(SpatialLinear__) [] = {
- {"SpatialLinear_forward", nn_(SpatialLinear_forward)},
- {"SpatialLinear_backward", nn_(SpatialLinear_backward)},
+ {"SpatialLinear_updateOutput", nn_(SpatialLinear_updateOutput)},
+ {"SpatialLinear_updateGradInput", nn_(SpatialLinear_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/SpatialMSECriterion.c b/generic/SpatialMSECriterion.c
index 8f59497..33fc2e3 100644
--- a/generic/SpatialMSECriterion.c
+++ b/generic/SpatialMSECriterion.c
@@ -2,7 +2,7 @@
#define TH_GENERIC_FILE "generic/SpatialMSECriterion.c"
#else
-static int nn_(SpatialMSECriterion_forward)(lua_State *L)
+static int nn_(SpatialMSECriterion_updateOutput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
THTensor *target = luaT_checkudata(L, 3, torch_(Tensor_id));
@@ -14,7 +14,7 @@ static int nn_(SpatialMSECriterion_forward)(lua_State *L)
return 1;
}
-static int nn_(SpatialMSECriterion_backward)(lua_State *L)
+static int nn_(SpatialMSECriterion_updateGradInput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
THTensor *target = luaT_checkudata(L, 3, torch_(Tensor_id));
@@ -40,8 +40,8 @@ static int nn_(SpatialMSECriterion_retarget)(lua_State *L)
}
static const struct luaL_Reg nn_(SpatialMSECriterion__) [] = {
- {"SpatialMSECriterion_forward", nn_(SpatialMSECriterion_forward)},
- {"SpatialMSECriterion_backward", nn_(SpatialMSECriterion_backward)},
+ {"SpatialMSECriterion_updateOutput", nn_(SpatialMSECriterion_updateOutput)},
+ {"SpatialMSECriterion_updateGradInput", nn_(SpatialMSECriterion_updateGradInput)},
{"SpatialMSECriterion_retarget", nn_(SpatialMSECriterion_retarget)},
{NULL, NULL}
};
diff --git a/generic/SpatialMaxSampling.c b/generic/SpatialMaxSampling.c
index 5b795b3..fcdd54d 100644
--- a/generic/SpatialMaxSampling.c
+++ b/generic/SpatialMaxSampling.c
@@ -9,7 +9,7 @@
#define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
#endif
-static int nn_(SpatialMaxSampling_forward)(lua_State *L)
+static int nn_(SpatialMaxSampling_updateOutput)(lua_State *L)
{
// get all params
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
@@ -99,7 +99,7 @@ static int nn_(SpatialMaxSampling_forward)(lua_State *L)
return 1;
}
-static int nn_(SpatialMaxSampling_backward)(lua_State *L)
+static int nn_(SpatialMaxSampling_updateGradInput)(lua_State *L)
{
// get all params
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
@@ -165,8 +165,8 @@ static int nn_(SpatialMaxSampling_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(SpatialMaxSampling__) [] = {
- {"SpatialMaxSampling_forward", nn_(SpatialMaxSampling_forward)},
- {"SpatialMaxSampling_backward", nn_(SpatialMaxSampling_backward)},
+ {"SpatialMaxSampling_updateOutput", nn_(SpatialMaxSampling_updateOutput)},
+ {"SpatialMaxSampling_updateGradInput", nn_(SpatialMaxSampling_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/SpatialReSampling.c b/generic/SpatialReSampling.c
index 4312615..927add2 100644
--- a/generic/SpatialReSampling.c
+++ b/generic/SpatialReSampling.c
@@ -9,7 +9,7 @@
#define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
#endif
-static int nn_(SpatialReSampling_forward)(lua_State *L)
+static int nn_(SpatialReSampling_updateOutput)(lua_State *L)
{
// get all params
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
@@ -85,7 +85,7 @@ static int nn_(SpatialReSampling_forward)(lua_State *L)
return 1;
}
-static int nn_(SpatialReSampling_backward)(lua_State *L)
+static int nn_(SpatialReSampling_updateGradInput)(lua_State *L)
{
// get all params
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
@@ -166,8 +166,8 @@ static int nn_(SpatialReSampling_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(SpatialReSampling__) [] = {
- {"SpatialReSampling_forward", nn_(SpatialReSampling_forward)},
- {"SpatialReSampling_backward", nn_(SpatialReSampling_backward)},
+ {"SpatialReSampling_updateOutput", nn_(SpatialReSampling_updateOutput)},
+ {"SpatialReSampling_updateGradInput", nn_(SpatialReSampling_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/SpatialSparseCriterion.c b/generic/SpatialSparseCriterion.c
index 6b83476..3a3c540 100644
--- a/generic/SpatialSparseCriterion.c
+++ b/generic/SpatialSparseCriterion.c
@@ -2,7 +2,7 @@
#define TH_GENERIC_FILE "generic/SpatialSparseCriterion.c"
#else
-static int nn_(SpatialSparseCriterion_forward)(lua_State *L)
+static int nn_(SpatialSparseCriterion_updateOutput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
int sizeAverage = luaT_getfieldcheckboolean(L, 1, "sizeAverage");
@@ -23,7 +23,7 @@ static int nn_(SpatialSparseCriterion_forward)(lua_State *L)
return 0;
}
-static int nn_(SpatialSparseCriterion_backward)(lua_State *L)
+static int nn_(SpatialSparseCriterion_updateGradInput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
THTensor *gradInput = luaT_checkudata(L, 3, torch_(Tensor_id));
@@ -45,8 +45,8 @@ static int nn_(SpatialSparseCriterion_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(SpatialSparseCriterion__) [] = {
- {"SpatialSparseCriterion_forward", nn_(SpatialSparseCriterion_forward)},
- {"SpatialSparseCriterion_backward", nn_(SpatialSparseCriterion_backward)},
+ {"SpatialSparseCriterion_updateOutput", nn_(SpatialSparseCriterion_updateOutput)},
+ {"SpatialSparseCriterion_updateGradInput", nn_(SpatialSparseCriterion_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/SpatialUpSampling.c b/generic/SpatialUpSampling.c
index 8a21efe..ea9828c 100644
--- a/generic/SpatialUpSampling.c
+++ b/generic/SpatialUpSampling.c
@@ -2,7 +2,7 @@
#define TH_GENERIC_FILE "generic/SpatialUpSampling.c"
#else
-static int nn_(SpatialUpSampling_forward)(lua_State *L)
+static int nn_(SpatialUpSampling_updateOutput)(lua_State *L)
{
// get all params
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
@@ -44,7 +44,7 @@ static int nn_(SpatialUpSampling_forward)(lua_State *L)
return 1;
}
-static int nn_(SpatialUpSampling_backward)(lua_State *L)
+static int nn_(SpatialUpSampling_updateGradInput)(lua_State *L)
{
// get all params
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
@@ -92,8 +92,8 @@ static int nn_(SpatialUpSampling_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(SpatialUpSampling__) [] = {
- {"SpatialUpSampling_forward", nn_(SpatialUpSampling_forward)},
- {"SpatialUpSampling_backward", nn_(SpatialUpSampling_backward)},
+ {"SpatialUpSampling_updateOutput", nn_(SpatialUpSampling_updateOutput)},
+ {"SpatialUpSampling_updateGradInput", nn_(SpatialUpSampling_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/Template.c b/generic/Template.c
index 9d1f444..6a75b88 100644
--- a/generic/Template.c
+++ b/generic/Template.c
@@ -2,19 +2,19 @@
#define TH_GENERIC_FILE "generic/Template.c"
#else
-static int nn_(Template_forward)(lua_State *L)
+static int nn_(Template_updateOutput)(lua_State *L)
{
}
-static int nn_(Template_backward)(lua_State *L)
+static int nn_(Template_updateGradInput)(lua_State *L)
{
}
static const struct luaL_Reg nn_(Template__) [] = {
- {"Template_forward", nn_(Template_forward)},
- {"Template_backward", nn_(Template_backward)},
+ {"Template_updateOutput", nn_(Template_updateOutput)},
+ {"Template_updateGradInput", nn_(Template_updateGradInput)},
{NULL, NULL}
};
diff --git a/generic/Threshold.c b/generic/Threshold.c
index f25fddd..760e842 100644
--- a/generic/Threshold.c
+++ b/generic/Threshold.c
@@ -2,7 +2,7 @@
#define TH_GENERIC_FILE "generic/Threshold.c"
#else
-static int nn_(Threshold_forward)(lua_State *L)
+static int nn_(Threshold_updateOutput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
real val = luaT_getfieldchecknumber(L, 1, "val");
@@ -16,7 +16,7 @@ static int nn_(Threshold_forward)(lua_State *L)
return 1;
}
-static int nn_(Threshold_backward)(lua_State *L)
+static int nn_(Threshold_updateGradInput)(lua_State *L)
{
THTensor *input = luaT_checkudata(L, 2, torch_(Tensor_id));
THTensor *gradOutput = luaT_checkudata(L, 3, torch_(Tensor_id));
@@ -32,8 +32,8 @@ static int nn_(Threshold_backward)(lua_State *L)
}
static const struct luaL_Reg nn_(Threshold__) [] = {
- {"Threshold_forward", nn_(Threshold_forward)},
- {"Threshold_backward", nn_(Threshold_backward)},
+ {"Threshold_updateOutput", nn_(Threshold_updateOutput)},
+ {"Threshold_updateGradInput", nn_(Threshold_updateGradInput)},
{NULL, NULL}
};
diff --git a/init.lua b/init.lua
index 0c43e19..5dfb9ba 100644
--- a/init.lua
+++ b/init.lua
@@ -54,28 +54,6 @@ torch.include('nnx', 'Probe.lua')
-- OpenMP module:
torch.include('nnx', 'OmpModule.lua')
--- those packages are available in a beta branch of Torch7,
--- and will soon disapear from here
-if not nn.Abs then
- -- pointwise modules:
- torch.include('nnx', 'Abs.lua')
- torch.include('nnx', 'Power.lua')
- torch.include('nnx', 'Square.lua')
- torch.include('nnx', 'Sqrt.lua')
- torch.include('nnx', 'HardShrink.lua')
- torch.include('nnx', 'Threshold.lua')
-
- -- table-based modules:
- torch.include('nnx', 'CMulTable.lua')
- torch.include('nnx', 'CAddTable.lua')
- torch.include('nnx', 'CDivTable.lua')
- torch.include('nnx', 'CSubTable.lua')
-
- -- reshapers:
- torch.include('nnx', 'Narrow.lua')
- torch.include('nnx', 'Replicate.lua')
-end
-
-- pointwise modules:
torch.include('nnx', 'Minus.lua')
@@ -128,24 +106,6 @@ torch.include('nnx', 'DataSet.lua')
torch.include('nnx', 'DataList.lua')
torch.include('nnx', 'DataSetLabelMe.lua')
--- torch helpers (should not be here):
-function torch.save(filename, object, mode)
- mode = mode or 'binary'
- local file = torch.DiskFile(filename, 'w')
- file[mode](file)
- file:writeObject(object)
- file:close()
-end
-
-function torch.load(filename, mode)
- mode = mode or 'binary'
- local file = torch.DiskFile(filename, 'r')
- file[mode](file)
- local object = file:readObject()
- file:close()
- return object
-end
-
-- nn helpers:
function nnx.empty(module)
if module.modules then