Caffe+Python3.5+Anaconda3+Opencv3.1+Cuda7.5+Ubuntu14.04

I almost spent(waisted) one week to configure caffe on Ubuntu 14.04, the reason why it too time consuming is that I am using the newest version of Opencv Python and anaconda. Here I want to share my experience.

  1. Makefile.config
    • # cuDNN acceleration switch (uncomment to build with cuDNN).
      USE_CUDNN := 1
      # Uncomment if you’re using OpenCV 3
      OPENCV_VERSION := 3
      # CUDA directory contains bin/ and lib/ directories that we need.
      CUDA_DIR := /usr/local/cuda
      # CUDA architecture setting: going with all of them.
      # For CUDA < 6.0, comment the *_50 lines for compatibility.
      CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
      -gencode arch=compute_20,code=sm_21 \
      -gencode arch=compute_30,code=sm_30 \
      -gencode arch=compute_35,code=sm_35 \
      -gencode arch=compute_50,code=sm_50 \
      -gencode arch=compute_50,code=compute_50
      # BLAS choice: atlas for ATLAS (default)
      BLAS := atlas
      # We need to be able to find Python.h and numpy/arrayobject.h.
      ANACONDA_HOME := $(HOME)/anaconda3
      PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
      $(ANACONDA_HOME)/include/python3.5m \
      $(ANACONDA_HOME)/lib/python3.5/site-packages/numpy/core/include \
      # Uncomment to use Python 3 (default is Python 2)
      PYTHON_LIBRARIES := boost_python3 python3.5m
      # We need to be able to find libpythonX.X.so or .dylib.
      PYTHON_LIB := $(ANACONDA_HOME)/lib
      # Whatever else you find you need goes here.
      INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
      LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
      # N.B. both build and distribute dirs are cleared on `make clean`
      BUILD_DIR := build
      DISTRIBUTE_DIR := distribute
      # The ID of the GPU that ‘make runtest’ will use to run unit tests.
      TEST_GPUID := 0
      # enable pretty build (comment to see full commands)
      Q ?= @
  2. ./bashrc.
    • #Caffemake
      export PYTHONPATH=~/caffe/python/:$PYTHONPATH#Opencv
      export LD_LIBRARY_PATH=/home/kaku/anaconda3/lib:$LD_LIBRARY_PATH
      export LD_LIBRARY_PATH=”/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH”

Notes:

  1. library must be installed:
    1. libboost-all-dev, although in some tutorial mentioned must install libboost1.55-all-dev.
    2. protobuf-cpp-3.0.0-beta-2.zip or upper one
      protobuf-python-3.0.0-beta-2.zip or upper one

      1. http://blog.csdn.net/lien0906/article/details/51784191
      2. https://github.com/google/protobuf/issues/1276
  2. Debug:
    1. Opencv3.1
      • In my computer I installed two versions Opencv, 2.4 and 3.1
      • 2.4 in the route: /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4
      • 3.1 in the route /home/kaku/anaconda3/lib/libopencv_imgproc.so.3.1 and  /home/kaku/anaconda3/pkgs/opencv3-3.1.0-py35_0/lib/libopencv_imgproc.so.3.1
      • If in the .bashrc I export opencv path as: /usr/lib/x86_64-linux-gnu/, or the path contain both 3.1 and 2.4, will be conflict, as follows:
        1. /usr/bin/ld: warning: libopencv_imgproc.so.3.1, needed by /home/kaku/anaconda3/lib/libopencv_imgcodecs.so, may conflict with libopencv_imgproc.so.2.4
        2. .build_release/tools/caffe: error while loading shared libraries: libopencv_core.so.3.1: cannot open shared object file: No such file or directory
          make: *** [runtest] Error 127
      • Solution:
        • In .bashrc
          1. export LD_LIBRARY_PATH=/home/kaku/anaconda3/lib:$LD_LIBRARY_PATH
          2. export LD_LIBRARY_PATH=”/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH”
        • In Makefile.config
          • Delete: PYTHON_LIB := /usr/lib
    2. fatal error: Python.h: No such file or directory
      • Actually I have python.h, but in the following files:
        • /media/kaku/Work/software/study software/Anaconda/include/Python.h
          /home/kaku/anaconda3/pkgs/python-3.5.1-0/include/python3.5m/Python.h
          /home/kaku/anaconda3/include/python3.5m/Python.h
          /usr/include/python2.7/Python.h
      • Solution:
        • In .bashrc add:
          • ANACONDA_HOME := $(HOME)/anaconda3
            PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
            $(ANACONDA_HOME)/include/python3.5m \
          • PYTHON_LIBRARIES := boost_python3 python3.5m
        • Can not contain route: /usr/include/python2.7/
    3. Thanks to:
      1. http://sunshineatnoon.github.io/How-to-install-caffe/
      2. http://qiita.com/TD72/items/bcb243ee02760ea1d8bb
      3. http://blog.csdn.net/u012675539/article/details/51351553
      4. http://blog.csdn.net/lien0906/article/details/5178419
      5. https://github.com/google/protobuf/issues/1276
      6. http://blog.csdn.net/lien0906/article/details/51784191
      7. http://caffe.berkeleyvision.org/install_apt.html
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s