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

loadcaffe requires CUDA #4

Closed
Hannessa opened this issue Sep 2, 2015 · 6 comments
Closed

loadcaffe requires CUDA #4

Hannessa opened this issue Sep 2, 2015 · 6 comments

Comments

@Hannessa
Copy link

Hannessa commented Sep 2, 2015

Hi,

I tried to install this on a Virtual Machine from Windows, which only supports CPU. Unfortunately, loadcaffe fails because it seems to require some CUDA-only libraries.

When I run "luarocks install loadcaffe", it says "missing dependencies ccn2, cunn and inn" and then automatically tries to install ccn2 and cutorch and fails with "CMake Error at /usr/share/cmake-2.8/Modules/FindCUDA.cmake:548 (message): Specify CUDA_TOOLKIT_ROOT_DIR".

If there's no way past this, maybe you could add a note that loadcaffe requires CUDA, for other Windows VM users.

Thanks, and keep up the good work!

@jcjohnson
Copy link
Owner

Hrm, that's kind of annoying.

The loadcaffe rockspec lists cunn and inn as dependencies, but they aren't actually imported anywhere inside that project. You should be able to work around it by manually installing loadcaffe like this:

git clone https://github.com/szagoruyko/loadcaffe.git
vim loadcaffe/loadcaffe-1.0-0.rockspec
# Delete lines 21 and 22
luarocks install loadcaffe/loadcaffe-1.0-0.rockspec

I don't have a setup handy to easily test this, so I haven't tried it. Let me know if it works.

@Hannessa
Copy link
Author

Hannessa commented Sep 2, 2015

Wow, that worked great! Thanks a lot!

I just tried to run it with the default values using the CPU: th neural_style.lua -gpu -1

However, I get some strange error in VGG_ILSVRC_19_layers_deploy.prototxt.cpu.lua:7 about ceil() and a nil value:

[libprotobuf WARNING google/protobuf/io/coded_stream.cc:505] Reading dangerously large protocol message. If the message turns out to be larger than 1073741824 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 574671192
Successfully loaded models/VGG_ILSVRC_19_layers.caffemodel
/home/hannes/torch/install/bin/luajit: models/VGG_ILSVRC_19_layers_deploy.prototxt.cpu.lua:7: attempt to call method 'ceil' (a nil value)
stack traceback:
models/VGG_ILSVRC_19_layers_deploy.prototxt.cpu.lua:7: in main chunk
[C]: in function 'dofile'
./loadcaffe_wrapper.lua:36: in function 'load'
neural_style.lua:51: in function 'main'
neural_style.lua:350: in main chunk
[C]: in function 'dofile'
...nnes/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:131: in main chunk
[C]: at 0x00406670

@Hannessa
Copy link
Author

Hannessa commented Sep 2, 2015

The row it's referring to in VGG_ILSVRC_19_layers_deploy.prototxt.cpu.lua is this:
table.insert(model, {'pool1', nn.SpatialMaxPooling(2, 2, 2, 2, 0, 0):ceil()})

Might be related to loadcaffe: torch/tutorials#28

@jcjohnson
Copy link
Owner

TL;DR this should now be fixed in cba886c with a horrible hack.

Longer explanation:

The problem is that nn.SpatialMaxPooling computes output sizes differently than Caffe pooling layers when the receptive fields don't perfectly tile the input feature map. In order to load Caffe models into torch, we need a way in torch to compute pooling in the exact same way as Caffe; the inn package provides exactly this; it attaches an instance method :ceil() to the nn.SpatialMaxPooling class to toggle the inn pooling implementation.

That's great. The problem is that inn depends on cunn, which we don't want to install. The insight is that for all of the pooling layers in the VGG-19 network used by neural-style, the receptive fields do tile the feature maps, so for this network the nn and inn pooling implementations should be equivalent, so it's safe to just use the nn pooling implementations when loading VGG-19.

To do this, we simply remove all instances of the string ":ceil()" from the .prototxt.lua files generated by loadcaffe, which is easy to do since we are already modifying this file in loadcaffe_wrapper.

@Hannessa
Copy link
Author

Hannessa commented Sep 2, 2015

Really sorry, it seems like I was using an old version of torch. I found this changelog from torch/nn which seemed to add support for ceil() in nn. torch/nn@929cfc5

After I updated torch to the latest version it seems to work, even without your fix. So sorry for causing you extra work!

@jcjohnson
Copy link
Owner

No worries - it was still a fun problem to solve!

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