torch / torch7

http://torch.ch
Other
9k stars 2.38k forks source link

error with getParameters() #989

Open Tord-Zhang opened 7 years ago

Tord-Zhang commented 7 years ago

I want to get the parameters the of a model using getParameters(),but some error occures.

require 'nn';
require'cunn';
require'cudnn';
local model = torch.load('c3d.t7');
local model_copy = model:get(23):clone();
local params,gradParams = model_copy:getParameters()

error: /torch/install/share/lua/5.1/nn/Module.lua:252: Torch object, table, thread, cdata or function expected stack traceback: [C]: in function 'pointer' ...gteam/NannanLi/torch/install/share/lua/5.1/nn/Module.lua:252: in function 'flatten' ...gteam/NannanLi/torch/install/share/lua/5.1/nn/Module.lua:326: in function 'getParameters' [string "require 'nn';require'cunn';require'cudnn';loc..."]:1: in main chunk [C]: in function 'xpcall' ...team/NannanLi/torch/install/share/lua/5.1/trepl/init.lua:670: in function 'repl' ...anLi/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk [C]: at 0x004061f0 Could anyone tell me how to fix this?

albanD commented 7 years ago

Hi,

You get this problem because some module in your network returns an empty tensor from the :parameters() function I think. You should make sure that you don't return as parameter a tensor that contains nothing.

ayushgithub commented 7 years ago

@mangdian - Were you able to solve this problem. I also wanted to finetune the c3d model ported to torch, but got stuck with this error

omair-kg commented 7 years ago

@ayushgithub I didn't figure out how to solve this, but for training C3D i have a work around. Define the model in a script and then copy over the weights from the trainable layers. This works for me.

hoL1day commented 6 years ago

I meet the same problem, maybe you can try to require cunn and cudnn.

meijie0401 commented 6 years ago

@mangdianDear friend, I met the same problem. Did you solve it?