Installing caffe in Ubuntu 16.04

Guide to install Caffe in ubuntu
linux
ubuntu
Published

January 3, 2017

Caffe is a library used in deep learning and specific to computer vision. They provide an installation guide, which is quite nice. But I experienced problems during the install. You can download the source code here

First follow the installation instructions.

I had installed cuda 8 library directly from Nvidia and not from ubuntu default repos.

Then install the following packages:

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev

And the BLAS library of your choice, I selected by default ATLAS:

sudo apt-get install libatlas-base-dev

As I’m going to work with python, I prepared a virtual environment. This is also because I work with tensorflow and I don’t want to mix both. Assuming you have installed virtualenv:

virtualenv caffe_gpu
source ~/caffe_gpu/bin/activate

Assuming your code is in ~/caffe:

cd python
for req in $(cat requirements.txt); do pip install $req; done

Then, I had to adapt the make file:

cp Makefile.config.example Makefile.config

adjust:

USE_CUDNN := 1
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/

finally do a symbolic link:

sudo ln -s /usr/lib/x86_64-linux-gnu/libhdf5_serial_hl.so /usr/lib/x86_64-linux-gnu/libhdf5_hl.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libhdf5_serial.so /usr/lib/x86_64-linux-gnu/libhdf5.so

Now we can compile as in the instructions:

make all
make test
make runtest

Thanks for reading!