This document is to help people struggling with installing Caffe on Python3 and Ubuntu 17.04
Install the dependencies first, as specified in the below section. Then follow the rest of the guide. If there are some errors while compiling/running, please check the troubleshooting section and make sure all dependencies are installed.
Note: this guide is intended for installing Caffe alone. If you want to run pyfasterrcnn, refer to the guide install py-faster-rcnn with python3 for additional required steps
# python3 modules (numpy, protobuf, skimage)
sudo pip3 install numpy
sudo apt-get install python3-skimage
sudo apt-get install python3-protobuf
# build essential
sudo apt-get install build-essential cmake git pkg-config
# gflags, glog, lmdb
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
# boost
sudo apt-get install libboost-all-dev
# hdf5
sudo apt-get install libhdf5-dev
# protobuf
sudo apt-get install protobuf-compiler libprotobuf-dev
# blas
sudo apt-get install libblas-dev libcblas-dev libatlas-base-dev libopenblas-dev
# leveldb
sudo apt-get install libleveldb-dev
# snappy
sudo apt-get install libsnappy-dev
Guide is taken from http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/
- Checkout and compile
git clone https://github.com/opencv/opencv
cd opencv
mkdir build
cd build
cmake ..
make
sudo make install
Guide is taken from http://caffe.berkeleyvision.org/install_apt.html
- Checkout
cd ~
git clone https://github.com/BVLC/caffe
cd caffe
cp Makefile.config.example Makefile.config
- Modify Makefile.config
- Uncomment
CPU_ONLY := 1
- Uncomment
WITH_PYTHON_LAYER := 1
- Uncomment
OPENCV_VERSION := 3
- Uncomment section with Python3
- Compile and test
make all
make test
make runtest
- Install
By default, Caffe will not be installed (no target 'install' provided). We can copy the .so file manually
sudo cp build/lib/libcaffe.so* /usr/lib
- Possible errors:
- Check troubleshooting section, issue 1, 2, 3, 6
- First install CUDA and (optional) CUDNN
sudo apt-get install nvidia-cuda-dev nvidia-cuda-toolkit nvidia-nsight
It will also automatically install the latest packaged version of NVIDIA, which is 375.66 as of Jul 2017, if you haven't installed it already.
For CUDNN, you need to register as a developer in https://developer.nvidia.com/cudnn. Then you will be able to download CUDNN. Download the runtime and developer library and install in that order.
- Install everything else
The rest are mostly the same with the non-GPU setup, but there are some differences:
- In Makefile.config, uncomment USE_CDNN (if you want to use CuDNN, though that it's not required) and comment CPU_ONLY
- In Makefile.config, since I installed CUDA via apt-get, so CUDA_DIR := /usr needs to be uncommented
- In Makefile, since I installed on Ubuntu 17.04, which has GCC6 that CUDA doesn't support, so CXX need to be set to clang-3.8. Find NVCCFLAGS += -ccbin=$(CXX) and change $(CXX) to clang-3.8. I couldn't set CUSTOM_CXX in Makefile.config to clang-3.8 because another error comes up (
Cannot static link with compiler clang-3.8
)
- Possible errors:
- Check troubleshooting section, issue 1, 2, 3, 5, 6
- Compile
make pycaffe
- Install
Install pycaffe manually by copying to dist-packages (in Ubuntu 17.04 it's in /usr/local/lib, but make sure you verify the path first)
sudo cp -r python/caffe/ /usr/local/lib/python3.5/dist-packages/
- Test
Make sure the below command works without any errors
python3 -c "import caffe"
- Possible errors:
- Check troubleshooting section, issue 4
Note: Only follow this section if you encounter any error
- hdf5.h: No such file or directory
In Makefile.config
- Add
/usr/include/hdf5/serial
to INCLUDE_DIRS (BVLC/caffe#4808)
In Makefile
- Change
hdf5_hl
andhdf5
in LIBRARIES tohdf5_serial_hl
andhdf5_serial
respectively
- Undefined symbol cblas_*
In Makefile.config
- Change
BLAS := atlas
toBLAS := open
to use openblas instead
- ld cannot find lboost_python3
- Create symbolic link from libboost_python-py35.so to libboost_python3 (BVLC/caffe#4843)
- numpy/arrayobject.h not found
Make sure you get the correct path of Python dist-packages directory. In Ubuntu 17.04 it's in /usr/local/lib. I remember earlier version it's in /usr/lib. In Makefile.config
- Find PYTHON_INCLUDE, change
/usr/lib/python3.5/dist-packages/numpy/core/include
to/usr/local/lib/python3.5/dist-packages/numpy/core/include
- libcaffe.so undefined reference to caffe::*
- Make sure that you have
make clean
beforemake all
. - Also delete the libcaffe.so* we have copied to /usr/lib
sudo rm -f /usr/lib/libcaffe.so*
- SyntaxError: invalid syntax in rrule.py (Can't create weekday with n == 0)
Update python-dateutil (#1)
pip3 install python-dateutil --upgrade