Skip to content
Search

Caffe:Install

lastmod 2025-02-14created 2015-10-1618 edits

Notes on how to install Caffe.

CUDA Version

For reference, the CUDA versions used for the Ubuntu 14.04 installation are as follows.

  • CUDA 7.5: cuda-repo-ubuntu1404-7-5-local_7.5-18_amd64.deb
  • cuDNN v4 (cuda7.0): cudnn-7.0-linux-x64-v4.0-prod.tgz

How to install

Install the libraries required for Caffe as shown below.

RHEL

$ sudo yum install -y openblas-devel
##If use Atlas:
##sudo yum install -y atlas-devel
$ sudo yum install -y protobuf-devel gflags-devel
##Not found:
##sudo yum install -y glog-devel
$ sudo yum install -y hdf5-devel leveldb-devel snappy-devel lmdb-devel

Mac OSX

brew install -vd snappy leveldb gflags glog szip lmdb
# need the homebrew science source for OpenCV and hdf5
brew tap homebrew/science
brew install hdf5 opencv

Ubuntu

## General dependencies:
$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

## Boost Library:
$ sudo apt-get install --no-install-recommends libboost-all-dev

## BLAS ATLAS Library:
$ sudo apt-get install libatlas-base-dev
## or BLAS OpenBLAS Library:
$ sudo apt-get install libopenblas-dev

## Python:
$ sudo apt-get install python-dev

## Remaining dependencies, 14.04:
$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

To compile with cuDNN for CUDA, use the following.

$ cmake -DUSE_CUDNN=1 -G "Unix Makefiles"

(To use the CPU only, add the CPU_ONLY=1 option.)

When using cuDNN, the important point is that files such as cudnn.h and libcudnn.so must also be placed in the include and lib64 directories of CUDA.

For reference, the command that compiled successfully on CentOS6 is as follows.

$ cmake -DPYTHON_LIBRARY=/home/your/local/lib/libpython2.7.so -DPYTHON_INCLUDE_DIR=/home/your/local/include/python2.7 -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS=-static-libstdc++ -DBLAS=Open -DUSE_CUDNN=1 -G "Unix Makefiles"

(glog was not available in yum, so I installed it manually)

Windows

When porting to Windows/MinGW, the first part of the code that needs to be modified is signal_handler.cpp. Take a look at the signal_handler.cpp file.

Python caffe

numpy and boost.python are required, and the other dependencies can be installed as shown below.

## in the caffe/python directory.
$ for req in $(cat requirements.txt); do pip install $req; done

Compile with the following command. 1

$ make pycaffe

Use the virtualenv

Also, when using virtualenv, you must specify the Python path as shown below.

$ cmake -DBLAS=Open \
      -DCPU_ONLY=ON \
      -DCMAKE_BUILD_TYPE=Debug \
      -DBUILD_SHARED_LIBS=ON \
      -DCMAKE_INSTALL_PREFIX=/usr/local \
      -DPYTHON_LIBRARY=/Users/your/.pyenv/versions/your-pyenv-2.7.11/lib/python2.7/config/libpython2.7.a \
      -DPYTHON_INCLUDE_DIR=/Users/your/.pyenv/versions/your-pyenv-2.7.11/include/python2.7 \
      .

python 3.5 and pyenv

Then compile the Caffe and run the tests

$ make -j 4 all
$ make -j 4 runtest

Results:

$ build/tools/caffe time –model=models/bvlc_alexnet/deploy.prototxt –gpu=0

Remaining dependencies, recent OS

$ sudo yum install gflags-devel glog-devel lmdb-devel

Remaining dependencies, if not found

## glog
$ wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz
$ tar zxvf glog-0.3.3.tar.gz
$ cd glog-0.3.3
$ ./configure
$ make && make install

## gflags
$ wget https://github.com/schuhschuh/gflags/archive/master.zip
$ unzip master.zip
$ cd gflags-master
$ mkdir build && cd build
$ export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
$ make && make install

## lmdb
$ git clone https://github.com/LMDB/lmdb
$ cd lmdb/libraries/liblmdb
$ make && make install

Dockerfile version

Caffe installed in an Ubuntu Dockerfile looks like this.

FROM ubuntu:14.04
MAINTAINER your <[email protected]>

RUN apt-get update -y
RUN apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
RUN apt-get install -y --no-install-recommends libboost-all-dev
RUN apt-get install -y libatlas-base-dev libopenblas-dev
RUN apt-get install -y python-dev
RUN apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
RUN apt-get install -y git cmake

RUN git clone https://github.com/BVLC/caffe.git
WORKDIR /caffe

RUN cmake -DCMAKE_CXX_FLAGS=-static-libstdc++ -DBLAS=Open -G "Unix Makefiles"
RUN make
RUN make install

CMD ["/bin/bash"]

Troubleshooting

Not found vecLib

On MacOSX, the BLAS library is forced to vecLib.

To use a different library, slightly modify the if (NOT APPLE) condition in the BLAS selection code in the cmake/Dependencies.cmake file.

See also

Favorite site

References


  1. In addition, for Matlab, use make matcaffe. ↩

author Zer0 sitemap