szagoruyko / torch-caffe-binding

Use Caffe in Torch7
BSD 2-Clause "Simplified" License
63 stars 19 forks source link

forward() error when use it inside a network as nn.Module #8

Open hshustc opened 7 years ago

hshustc commented 7 years ago

The code is quite simple: require 'caffe'

model = nn.Sequential() model:add(caffe.Net('caffenet_deploy.prototxt', 'bvlc_reference_caffenet.caffemodel', 'test')) model:add(nn.Linear(1000,1))

input = torch.FloatTensor(10,3,227,227) output = model:forward(input)

But when I execute it, error occurs: /home/vim/torch/install/bin/luajit: /home/vim/torch/install/share/lua/5.1/nn/Container.lua:67: In 2 module of nn.Sequential: /home/vim/torch/install/share/lua/5.1/nn/Linear.lua:69: input must be vector or matrix stack traceback: [C]: in function 'error' /home/vim/torch/install/share/lua/5.1/nn/Linear.lua:69: in function </home/vim/torch/install/share/lua/5.1/nn/Linear.lua:53> [C]: in function 'xpcall' /home/vim/torch/install/share/lua/5.1/nn/Container.lua:63: in function 'rethrowErrors' /home/vim/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward' test_torch_caffe.lua:8: in main chunk [C]: in function 'dofile' .../vim/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk [C]: at 0x00406670

I have no idea why this is happening. Could you please give me some hints? Thanks a lot.

szagoruyko commented 7 years ago

can you remove the last Linear module and check what it returns?