Here, I’d like to share my experience of installing the popular deep learning framwork, Caffe, on a linux host without root permission. Here, it mainly covers the GPU mode installation. The CPU mode is easier, and should be easily accomplished with simple variation from the steps described below.

Prerequisites: CUDA has to be installed already since it needs root permission, but that’s the only one.

General guide, try to use

• linuxbrew for installing C/C++ packages, and
• anaconda for installing python packages.
• I don’t use matlab, so there won’t be mention on matlab related packages
• Try to avoid installing packages mannually, it’s not fun and costs a lot of time. But if you have never installed packages and managed dependencies yourself, it can be a good exercise.

Let’s begin to follow the instructions on the Caffe installation page. From here on, I assume you’ve successfully installed linuxbrew and anaconda.

First, let’s get linuxbrew up-to-date.

Then we start installing the first package, BLAS. At the time of writing, only OpenBLAS is available in linuxbrew, so try

If the above command complains about gfortran optimization problem, you may want to look closer to see why it complains or seek for a openblas already installed by system admin. I am not sure how the optimization problem would affect caffe’s performance, but since caffe is a piece of speed-critical software, I think it would be worth looking into it.

Next boost,

Here is a tricky one, compiling caffe needs -lboost-thread, but the boost installed by linuxbrew only have libboost-thread-mt.a and libboost-thread-mt.so available, and caffe will complain later. My fix is to do the following symlinks

Here I assumed the one with -mt, which means multiple-threading by the way, and the one without it are the same, partially based on this thread.

Next OpenCV,

Based on info, you could see OpenCV has quite a number of dependencies. I have tried the same process on different hosts, sometimes the recommended packages also cause headaches because they require further dependencies which may or may not cause extra compiling problems. As a compromise, I chose to be a minimalist. Since here what we care is mainly to install caffe, not OpenCV itself, so I disable all the recommended (using –without-something) and optional ones (disabled by default). The result command is

Next protobuf,

This is an easy one, and I didn’t encounter any issue with it. Next I installed gflags first before glog because gflags is a dependency of glog, and its installation needs some tweaking in interactive mode.

If you don’t use -fPIC, later on when installing glog, it will complain with the following kind of error.

Now if you have followed the above and installed gflags with -fPIC, glog installation should proceed successfully.

Then hdf5, leveldb, snappy, lmdb,

I find the above four relatively easy to install and no complain. Now for the python packages. All the packages required by pycaffe are in anaconda except for leveldb, so we seek pip for help.

It seems that conda and pip install packages into the same directory (i.e. ~/anaconda/lib/python2.7/site-packages/), so I think when a conda package is not available, then use pip (Please correct me if I am wrong, or you can checkout Anaconda Cloud). Or maybe you want to create an isolated environment with conda create first, which should be OK, too. I like Anaconda because it handles packages like scipy very well, which can be diffcult to compile from source on some linux setup.

Next, as for cuDNN, I am unable to use it because it seems to require a CUDA dirver of version higher than 6.5. Otherwise, error pops out. Unfortunately, what I have is only 6.0, so I have to skip it.

Now we’re ready install caffe, Yey! Everything should be straight forward from now on except for one thing, which will be told soon. Just follow the steps on the caffe page.

One final bug I encountered on one of the hosts I tried is that when making pytest is that it complains libboost_python.so is not available. After some search, it turns out that it can be installed with

However, at the time of writing, the formula for boost-python seems to be cooked for Mac only. This isn’t a surprise since linuxbrew is forked from homebrew, which was initially designed for Mac OS X. Anyway, here is my fix

Without this modification, Mac OS X related error would happen, and you’re encouraged to take a look and see how it looks. The modification above is based on the format of user-config.jam, I am not an expert in C++ progamming myself, but I found the above works, if you have a better solution, please let me know.

By now, if you make pytest again, it should work, and don’t forget to

Finally, we’re ready to try out one of the tutorials with our newly brewed caffe.

While it’s brewing, you could also use nvidia-smi to see how much the GPU is being utilized.

At last, I have to admit that most of the tricks are more like hacks to the linuxbrew formulas. Because I am not a ruby/linuxbrew expert, I tried to avoid too much modification to the formula. Overall, I think linuxbrew + anaconda really have saved me lots of time though there will still be glitches here and there. I really appreciate the effort the developers who have put into those projects. Imagine how much work it is going to be if you’re gonna compile and install all the stuffs and their dependencies from source mannually, a daunting (also tedious) task.

I hope you find the above steps helpful. If you see any errors, please let me know. Have fun brewing. :D