ramprs / grad-cam

[ICCV 2017] Torch code for Grad-CAM
https://arxiv.org/abs/1610.02391
1.48k stars 224 forks source link

load alexnet failed when forward #4

Closed samson-wang closed 7 years ago

samson-wang commented 7 years ago

If I use the alexnet and backend set to 'ccn2'. The code crashes when doing network forward on line local output = cnn:forward(img).

/data/Repo/torch.git/install/bin/luajit: /data/Repo/torch.git/install/share/lua/5.1/nn/Container.lua:67:
In 1 module of nn.Sequential:

/data/Repo/torch.git/install/share/lua/5.1/nn/Transpose.lua:14: bad argument #1 to 'transpose' (out of range at /tmp/luarocks_torch-scm-1-6342/torch7/lib/TH/generic/THTensor.c:399)
stack traceback:
    [C]: in function 'transpose'
    /data/Repo/torch.git/install/share/lua/5.1/nn/Transpose.lua:14: in function </data/Repo/torch.git/install/share/lua/5.1/nn/Transpose.lua:12>
    [C]: in function 'xpcall'
    /data/Repo/torch.git/install/share/lua/5.1/nn/Container.lua:63: in function 'rethrowErrors'
    ...a/Repo/torch.git/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
    classification.lua:68: in main chunk
    [C]: in function 'dofile'
    .../torch.git/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x00406670
ramprs commented 7 years ago

Hi Samson, thanks for reporting this. The error is because bvlc_alexnet model with ccn2 backend requires the input image to be of the size (batch_size, 3, 227, 227) with batch_size being a multiple of 32. You would be able to use cudnn backend directly without any issues. Please let me know if it isn't clear.

samson-wang commented 7 years ago

Hi ramprs, thanks for your tips. 'cudnn' works fine. However, if I use the finetuned model based on caffenet, the output dimension goes wrong. I finetune the caffenet for a 45-class task. The only difference is that the fc8 output num is 45. The lua-prototxt output layer of original is table.insert(model, {'fc8', nn.Linear(4096, 1000)}) table.insert(model, {'loss', cudnn.SoftMax()}) Mine only has table.insert(model, {'fc8_ft', nn.Linear(4096, 45)}) And then the finetuned model predicted label has 4096 dimensions instead of 45.

samson-wang commented 7 years ago

Well, I found that there is a bug in loadcaffe.

https://github.com/szagoruyko/loadcaffe/issues/90

HAHA-DL commented 6 years ago

@samson-wang Hi Samson, I met the same problem as yours. Have you solved your problem when using finetuned model?

samson-wang commented 6 years ago

@Darren1988 Yes. It's a bug in loadcaffe. Please refer to the link above.

samson-wang commented 6 years ago

@Darren1988 You can use my fork of loadcaffe. https://github.com/samson-wang/loadcaffe