Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

using optimfn with wrapped nn modules #173

Open
sebastiangonsal opened this issue Mar 23, 2017 · 0 comments
Open

using optimfn with wrapped nn modules #173

sebastiangonsal opened this issue Mar 23, 2017 · 0 comments

Comments

@sebastiangonsal
Copy link

sebastiangonsal commented Mar 23, 2017

Is there anything wrong with using wrapped ``nnmodules together withoptim`.

I have code like following:. The problem is when predict is called. I keep getting the following error:

...install/share/lua/5.1/autograd/runtime/codegen/Graph.lua:40: bad argument #2 to 'fn' (expecting number or torch.DoubleTensor or torch.DoubleStorage at /tmp/luarocks_torch-scm-1-9261/torch7/generic/Tensor.c:1125)

[C]: in function 'fn'
...install/share/lua/5.1/autograd/runtime/codegen/Graph.lua:40: in function 'set'
 /home/user/torch/install/share/lua/5.1/torch/Tensor.lua:458: in function 'fn'
...install/share/lua/5.1/autograd/runtime/codegen/Graph.lua:40: in function 'view'
...user/torch/install/share/lua/5.1/autograd/nnwrapper.lua:206: in function 'fn'
 .../install/share/lua/5.1/autograd/runtime/codegen/Node.lua:72: in function 'evaluateForward'
...install/share/lua/5.1/autograd/runtime/codegen/Graph.lua:25: in function 'conv1'
(my stacktrace below this. first line of predict function here)

local conv1, params.conv1
conv1, params.conv1 = grad.nn.SpatialConvolutionMM(64, 128, 5, 5, 1, 1, 2, 2)

...

params = autograd.util.cast(params, "float")

function predict(params, input)
   local h1 = pool1(acts1(conv1(params.conv1, input)))
   ....
  return output

function feval(params, input, target)
   local prediction = predict(params, input)
   ...
   return loss, prediction

local df = autograd(feval, {optimize = true})
state = {
learningRate = learningRate,
momentum = momentum,
weightDecay = weightDecay
}

for i = 1, numepochs do
   local optimfn, states = grad.optim.sgd(df, state, params)
   for j = 1, datasize, batchSIze do
       local X, target = loadInputTensor(batchSize)
       local grads, loss = optimfn(X, target)
   end
end
...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant