Compile caffe on unbutu 16.0.4

时间:2023-03-08 17:41:53
Compile caffe on unbutu 16.0.4

1. apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler

2. git clone https://github.com/BVLC/caffe

cd caffe
cp Makefile.config.example Makefile.config

3. pip install scikit-image protobuf

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

If TypeError: unsupported operand type(s) for -=: 'Retry' and 'int',

Reason: The computer connects with internet through proxy, so add the --proxy parameter like this:

sudo pip install --proxy=http://dev-myproxy.com:8080 scikit-image protobuf

4. modify the Makefile.config. Uncomment the line CPU_ONLY := 1, and the line OPENCV_VERSION := 3 if only use cpu and opencv3.

5. make all

CXX src/caffe/net.cpp

src/caffe/net.cpp:8:18: fatal error: hdf5.h: No such file or directory compilation terminated. Makefile:575: recipe for target '.build_release/src/caffe/net.o' failed make: *** [.build_release/src/caffe/net.o] Error 1

 

This is because the headfiles of hdf5 is in /usr/include/hdf5/serial/, copy all of them into /usr/include directory.

And then

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

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

 

6. make all again, there will be another error: cann't find cblas.h, no such file or directory.

View the Makefile.config, the option BLAS is atlas, so just install libatlas-base-dev:

apt-get install libatlas-base-dev

7. ld error: can't find -lopencv_imgdecodecs

Wrong opencv version will lead this error.

dpk-config --modversion opencv #check openvcv's version

and then modify the OPENCV_VERSION option in Makefile.config accordingly.

8. make test

9. make runtest

10. make pycaffe

python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory

It was caused because numpy was installed in a different path, and we must manually point to it.

 vi Makefile.config from this:

PYTHON_INCLUDE := /usr/include/python2.7 \

/usr/lib/python2.7/dist_packages/numpy/core/include

to:

PYTHON_INCLUDE :=/usr/include/python2.7 \

/usr/local/lib/python2.7/dist-package/numpy/core/inlcude

 11. Modify PYTHONPATH environment parameter

vi .bashrc

export PYTHONPATH=xxx/caffe/python:$PYTHONPATH

Then we can import caffe in python like this:

import caffe

references:

https://chunml.github.io/ChunML.github.io/project/Installing-Caffe-CPU-Only/