Part of project: Slinky Projects

Caffe is an open-source deep learning framework created at Berkeley that makes it easier to code learning algorithms more easily and efficiently. I’m working with some computer vision models so it’s pretty awesome. It was also a pain in the ass to install correctly due to it’s huge number of dependencies and configurations.

While the installation instructions on the website was very detailed, I still ran into some errors (probably because I tend to skim instructions). It took many Google-searches to finally get it up and running so I decided to take some notes for the future. Before we begin, some notes:

  • I did this installation for OS X El Capitan.
  • Caffe is designed to work great with Python 2. It can work with Python 3 but good luck with that. I assume you have Python installed (make life easier to just install Anaconda).

Step 1: Download and install CUDA

You will need to register to download the CUDA Toolkit. You might also want to update the driver for Mac with the latest from here.

After installing CUDA, set the environment:

export PATH=/usr/local/cuda/bin:$PATH
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH

Step 1.5: (Optional) Download and install cuDNN

You can download and install cuDNN to speed up computations. Remember to set the environmental path to the installation with

export DYLD_LIBRARY_PATH='/path/here/lib':$DYLD_LIBRARY_PATH

Step 2: Install homebrew

If you haven’t install homebrew already, do:

/usr/bin/ruby -e "$(curl -fsSL"

Step 3: Install Caffe and Python dependencies

brew install wget
brew install lmdb
brew install leveldb
brew install protobuf
brew install boost-python
brew install snappy
brew install gflags
brew install glog
brew tap homebrew/science
brew install opencv
brew install hdf5
pip install numpy
pip install scipy
pip install scikit-image
pip install h5py
pip install Cython
pip install protobuf
pip install lmdb
pip install leveldb
pip install python-gflags

Step 4: Get caffe

The repo is here. Once cloned, navigate to the directory and do the following.

Step 5: Change the Makefile

Get the Makefile configuration.

cp Makefile.config.example Makefile.config

Now, you need to edit your Makefile. If you installed cuDNN then you need to uncomment the USE_CUDNN := 1 and add it to INCLUDE_DIRS. Check the PYTHON_INCLUDE to make sure your Python 2 path is correct.

Step 6: Build Caffe

Run the following:

make all
make pycaffe

This step might take a while. After it finish, tell Python where to find Caffe:

export PYTHONPATH=~/dir/to/caffe/python:$PYTHONPATH

Step 7: Test it

Try importing Caffe with:

python2 -c "import caffe"

If you see an error, happy Googling!