facebookarchive / fb.resnet.torch

Torch implementation of ResNet from http://arxiv.org/abs/1512.03385 and training scripts
Other
2.29k stars 664 forks source link

Modify pretrained network architecture. Is it possible? #135

Open jessika0991 opened 7 years ago

jessika0991 commented 7 years ago

Can I modify the pretrained network? I have tried to remove some layers modifying the nFeatures value, which is used to nn.View and nn.Linear, according to the size of the layer above nn.View. However, I got the following error:

/home/jessica/torch/install/bin/luajit: /home/jessica/torch/install/share/lua/5.1/nn/Container.lua:67: 
In 9 module of nn.Sequential:
/home/jessica/torch/install/share/lua/5.1/torch/Tensor.lua:458: bad argument #1 to 'set' (expecting number or torch.FloatTensor or torch.FloatStorage at /home/jessica/torch/pkg/torch/generic/Tensor.c:1125)
stack traceback:
    [C]: in function 'set'
    /home/jessica/torch/install/share/lua/5.1/torch/Tensor.lua:458: in function 'view'
    /home/jessica/torch/install/share/lua/5.1/nn/View.lua:81: in function </home/jessica/torch/install/share/lua/5.1/nn/View.lua:77>
    [C]: in function 'xpcall'
    /home/jessica/torch/install/share/lua/5.1/nn/Container.lua:63: in function 'rethrowErrors'
    /home/jessica/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
    ./train.lua:63: in function 'train'
    main.lua:98: in main chunk
    [C]: in function 'dofile'
    ...sica/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x00406670

WARNING: If you see a stack trace below, it doesn't point to the place where this error occured. Please use only the one above.
stack traceback:
    [C]: in function 'error'
    /home/jessica/torch/install/share/lua/5.1/nn/Container.lua:67: in function 'rethrowErrors'
    /home/jessica/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
    ./train.lua:63: in function 'train'
    main.lua:98: in main chunk
    [C]: in function 'dofile'
    ...sica/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x00406670

Any idea how I could solve this?

Thanks in advance

gsp-27 commented 7 years ago

Can you please specify the type of network you are using??

jessika0991 commented 7 years ago

I am using the pretrained model Resnet-34. However I solved this problem using model:cuda() after making the modifications in the network. Even though this problem is solved I got another problem that I haven't solved yet: When I remove the last basic block layer that has Features = 512 and I connect the fully connected layer to the basic block layer with Features = 256, instead of having an output tensor with dimensions batchSize x nClasses that in my case is 32x2 (as it happens in the original model), I get a different one with dimension 2048x2.