Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to build Caffe

📅 2017-Feb-22 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Building Caffe from source is easy. There are two options provided: using a Makefile or using CMake.

Required packages

$ sudo apt install libboost-all-dev libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler libgflags-dev libgoogle-glog-dev liblmdb-dev
$ sudo apt install libatlas-base-dev
$ sudo apt install libopenblas-dev
$ sudo apt install libboost-python-dev python-skimage python-protobuf
The dependency target "pycaffe" of target "pytest" does not exist.

ImportError: No module named

ImportError: No module named google.protobuf.internal

Build using CMake

Just follow the usual steps for CMake:

$ mkdir build
$ cd build
$ cmake ..
$ make

To build and run the 2000+ unittests, which can take quite a while to finish:

$ make runtest

Finally to build the Python interface to Caffe:

$ make pycaffe
$ make install

By default, the install directory will be a subdirectory inside the build directory. Add this build/install/python path to PYTHONPATH environment variable before you import caffe in Python.

Build using Make

On one system, I found that using Makefile was easier, since CMake was erroneously complaining about -lpthreads (which is a Clang library, not a GCC library). Copy the Makefile config file, open it in an editor and check whether all the paths are set correctly:

$ cp Makefile.config.example Makefile.config
$ vim Makefile.config
$ make

Build MatCaffe

Building support for MATLAB to use Caffe takes a few more steps:

$ make all matcaffe