Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to copy a node from a gmodule to another gmodule? #142

Open
royal-feng opened this issue Apr 9, 2017 · 1 comment
Open

How to copy a node from a gmodule to another gmodule? #142

royal-feng opened this issue Apr 9, 2017 · 1 comment

Comments

@royal-feng
Copy link

I want to do something like copy a node from a gmodule called net_A to another gmodule called net_B,so I do such operations
netB.modules[i] = netA.modules[counter]
and when the forward in netB, it failed.And the error imformation like that:
torch/install/bin/luajit: ...torch/install/share/lua/5.1/cudnn/SpatialConvolution.lua:32: Only Cuda supported duh!
stack traceback:
[C]: in function 'assert'
...torch/install/share/lua/5.1/cudnn/SpatialConvolution.lua:32: in function 'resetWeightDescriptors'
...torch/install/share/lua/5.1/cudnn/SpatialConvolution.lua:96: in function 'checkInputChanged'
...torch/install/share/lua/5.1/cudnn/SpatialConvolution.lua:120: in function 'createIODescriptors'
...torch/install/share/lua/5.1/cudnn/SpatialConvolution.lua:188: in function 'func'
/home/zsf/torch/install/share/lua/5.1/nngraph/gmodule.lua:345: in function 'neteval'
/home/zsf/torch/install/share/lua/5.1/nngraph/gmodule.lua:380: in function 'forward'
test3.lua:335: in main chunk
[C]: in function 'dofile'
.../zsf/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: at 0x00406670

So I try to copy the node.weight from netA to netB,like that
netB.modules[i].weight=netA.modules[counter].weight
netB.modules[i].bias=netA.modules[counter].bias
But the result after netB:forward(input) is not so good. Is my copy operation something wrong?
Thank you for answer!

@arthitag
Copy link

Hi,
I don't have an answer to your question but I am facing a similar issue.
I am trying to copy weights from a trained nngraph model to a new nngraph model (with almost same structure) that I created from file. When I do a forward pass results are all wrong and I can't figure out why. For copying weights I used
params0, gp0 = model0:parameters()
params1, gp1= model1:parameters()
and then serially copied all weight/bias tensors in wt to the params tensors on model 1 using the tensor1:copy(tensor2).
I later verified if the weights of two models are the same, and if the inputs are getting passed correctly.
I don't know why but some of the intermediate layer activations in the forward pass are growing really large and then going to all 0's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants