utuntu16.04安裝caffe+Matlab2017a+opencv3.1+CUDA8.0+cudnn6.0


  • 上午把tensorflow安裝好了,下午和晚上裝caffe的確很費勁。
  • 默認CUDA,cuDNN可以用了
  • caffe官方安裝教程
  • 有些安裝順序自己也不清楚,簡直就是碰運氣

1. 安裝之前依賴項

General dependencies

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev

安裝matlab見后面:

為什么需要安裝Matlab?
caffe有Matlab的接口,因此如果需要使用Matlab調用caffe,進行編程,就需要安裝Matlab。如果你覺得使用C或Python編程比較難,就請安裝Matlab。當然如果不需要,並且后面不會編譯caffe生成Matlab的接口,就不需要安裝Matlab了。這個純粹根據個人需求來定。


為什么需要安裝OpenCV?
caffe是用來做深度學習的,深度學習的一大應用對象就是圖像和視頻。而OpenCV是目前最火的開源計算機視覺庫,非常多的項目多用到了OpenCV,當然caffe也依賴OpenCV。所以,需要安裝OpenCV,否則無法使用caffe哦

OpenCV的版本和cuda的版本最好匹配。這樣子安排的目的是為了減少錯誤出現的概率

 

2.OpeCV安裝

從官網(http://opencv.org/downloads.html)下載Opencv,並將其解壓到你要安裝的位置,假設解壓到了/home/opencv。 安裝前准備,創建編譯文件夾:

cd ~/opencv
mkdir build
cd build

配置:

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

編譯:

make -j8 #-j8表示並行計算,根據自己電腦的配置進行設置,配置比較低的電腦可以將數字改小或不使用,直接輸make。

以上只是將opencv編譯成功,還沒將opencv安裝,需要運行下面指令進行安裝:

sudo make install

問題:由於CUDA 8.0不支持OpenCV的 GraphCut 算法,可能出現以下錯誤:

 

/home/dsp/opencv-3.1.0/modules/core/include/opencv2/core/private.cuda.hpp:165:52: note: in definition of macro ‘nppSafeCall’
 #define nppSafeCall(expr)  cv::cuda::checkNppError(expr, __FILE__, __LINE__, CV_Func)
                                                    ^
modules/cudalegacy/CMakeFiles/opencv_cudalegacy.dir/build.make:146: recipe for target 'modules/cudalegacy/CMakeFiles/opencv_cudalegacy.dir/src/graphcuts.cpp.o' failed
make[2]: *** [modules/cudalegacy/CMakeFiles/opencv_cudalegacy.dir/src/graphcuts.cpp.o] Error 1
make[2]: *** 正在等待未完成的任務....
CMakeFiles/Makefile2:9226: recipe for target 'modules/cudalegacy/CMakeFiles/opencv_cudalegacy.dir/all' failed
make[1]: *** [modules/cudalegacy/CMakeFiles/opencv_cudalegacy.dir/all] Error 2
make[1]: *** 正在等待未完成的任務....
[ 92%] Linking CXX shared library ../../lib/libopencv_photo.so
[ 92%] Built target opencv_photo
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

 

進入opencv-3.1.0/modules/cudalegacy/src/目錄,修改graphcuts.cpp文件,將:

#include "precomp.hpp"

#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)

改為

#include "precomp.hpp"

#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)

然后make編譯就可以了

- 編譯和安裝完成

 

裝BLAS

這里可以選擇(ATLAS,MKL或者OpenBLAS):不知道這個,下載有問題,所以就沒有搞這個,但是makefile.config文件里面有配置

MKL首先下載並安裝英特爾® 數學內核庫 Linux* 版MKL(Intel(R) Parallel Studio XE Cluster Edition for Linux 2016),下載鏈接是:https://software.intel.com/en-us/qualify-for-free-software/student, 使用學生身份(郵件 + 學校)下載Student版,填好各種信息,可以直接下載,同時會給你一個郵件告知序列號。

后面就直接:sudo apt-get install libatlas-base-dev -y  

sudo apt-get install libatlas-base-dev 

 3.MATLAB2017a安裝

4.安裝caffe

(1)將終端cd到要安裝caffe的位置。
(2)從github上獲取caffe:

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

注意:若沒有安裝Git,需要先安裝Git:

sudo apt-get install git
3)因為make指令只能make Makefile.config文件,而Makefile.config.example是caffe給出的makefile例子,因此,首先將Makefile.config.example的內容復制到Makefile.config:

sudo cp Makefile.config.example Makefile.config
4)打開並修改配置文件:

sudo gedit Makefile.config #打開Makefile.config文件
  • 自己按照改了一下,里面有寫需要注意
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
  USE_OPENCV := 1
# USE_LEVELDB := 0
# USE_LMDB := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#    You should not set this flag if you will be reading LMDBs with any
#    possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 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_52,code=sm_52 \
        -gencode arch=compute_60,code=sm_60 \
        -gencode arch=compute_61,code=sm_61 \
        -gencode arch=compute_61,code=compute_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
MATLAB_DIR := /home/dsp
#MATLAB_DIR := /home/dsp/bin

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
#  PYTHON_INCLUDE := /usr/include/python2.7 \
#          /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := /home/dsp/anaconda2
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
          $(ANACONDA_HOME)/include/python2.7 \
          $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                 /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
#  PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.

#INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
#LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# 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 ?= @


LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda2/lib

 

## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#    You should not set this flag if you will be reading LMDBs with any
#    possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 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_52,code=sm_52 \
        -gencode arch=compute_60,code=sm_60 \
        -gencode arch=compute_61,code=sm_61 \
        -gencode arch=compute_61,code=compute_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
# PYTHON_INCLUDE := /usr/include/python2.7 \
        /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := /home/dsp/anaconda2
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
          $(ANACONDA_HOME)/include/python2.7 \
          $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                 /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.

#INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
#LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# 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 ?=

問題:

第一次編譯:出錯

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev

AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0
/usr/bin/ld: 找不到 -lhdf5_hl
/usr/bin/ld: 找不到 -lhdf5
/usr/bin/ld: 找不到 -lcudnn
collect2: error: ld returned 1 exit status
Makefile:572: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0] Error 1

- hdf5的問題,通過修改Makefile.config文件

在文件里面添加文本由於hdf5庫目錄更改,所以需要單獨添加:
#INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
#LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

- 然后再次編譯有一個問題:

dsp@dsp:~/caffe$ make all -j16
LD -o .build_release/lib/libcaffe.so.1.0.0
/usr/bin/ld: 找不到 -lcudnn
collect2: error: ld returned 1 exit status
Makefile:572: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0] Error 1
  • i found that in the path "/usr/local/cuda/lib64/" don't have the file liblcudnn.so

該問題還在有待解決。

- 這個問題其實挺簡單的:后面自己想清楚了:就是cudnn的鏈接問題,重新拷貝cudnn文件;然后鏈接了一遍,后面就不報這個錯了

- 繼續編譯錯誤:

//home/dsp/anaconda2/lib/libpng16.so.16:對‘inflateValidate@ZLIB_1.2.9’未定義的引用/
/homecollect2: error: ld returned 1 exit status
/dsp/anaconda2/lib/libpng16.so.16:對‘inflateValidate@ZLIB_1.2.9’�Makefile:625: recipe for target '.build_release/tools/upgrade_net_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1
�make: *** 正在等待未完成的任務....
�定義的引用
collect2: error: ld returned 1 exit status
Makefile:625: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1
//home/dsp/anaconda2/lib/libpng16.so.16:對‘inflateValidate@ZLIB_1.2.9’未定義的引用
collect2: error: ld returned 1 exit status
Makefile:625: recipe for target '.build_release/tools/upgrade_solver_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_solver_proto_text.bin] Error 1
//home/dsp/anaconda2/lib/libpng16.so.16:對‘inflateValidate@ZLIB_1.2.9’未定義的引用
collect2: error: ld returned 1 exit status

- 然后我添加鏈接:sudo ln -s /home/username/anaconda2/lib/libpng16.so.16 libpng16.so.16 (方法不行)報另外的錯:

/usr/local/cuda-8.0/lib64/libpng16.so.16:對‘inflateValidate@ZLIB_1.2.9’未定義的引用
collect2: error: ld returned 1 exit status
Makefile:625: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1
make: *** 正在等待未完成的任務....
/usr/local/cuda-8.0/lib64/libpng16.so.16:對‘inflateValidate@ZLIB_1.2.9’未定��/usr�的引用
/localcollect2: error: ld returned 1 exit status
/cuda-8.0/lib64/libpng16.so.16:對‘inflateValidate@ZLIB_1.2.9’未定義/的引用
collect2: error: ld returned 1 exit status
usr/local/cudaMakefile:630: recipe for target '.build_release/examples/siamese/convert_mnist_siamese_data.bin' failed
-make: *** [.build_release/examples/siamese/convert_mnist_siamese_data.bin] Error 1
8.0/lib64/libpng16.so.16:對‘inflateValidate@ZLIB_1.2.9’未定義的引用
collect2: error: ld returned 1 exit status

- 最后非常感謝:Caffe 編譯錯誤記錄:http://blog.csdn.net/ruotianxia/article/details/78437464 

  • 里面的幾個錯誤有代表性,按照下面的方法就沒有報這個錯了

 

在 Makefile.config 中,加入下一句
LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda2/lib

- 然后執行:make all  報錯:

dsp@dsp:~/caffe$ make all -j16
make: Nothing to be done for 'all'
  • 解決方法很簡單:
  •  make: Nothing to be done for `all' 解決方法
    1.這句提示是說明你已經編譯好了,而且沒有對代碼進行任何改動。
    若想重新編譯,可以先刪除以前編譯產生的目標文件:
    
        make clean 
    
        make 

 

5. 黎明的曙光

  • 按照如下編譯順序
make all -j16
make runtest -j16
make pycaffe -j16
make matcaffe -j16

- 其中make all 和make runtest時間比較長;make pycaffe 很順利

[----------] Global test environment tear-down
[==========] 2123 tests from 281 test cases ran. (285688 ms total)
[  PASSED  ] 2123 tests.
dsp@dsp:~/caffe$ make pycaffe -j16
touch python/caffe/proto/__init__.py
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
PROTOC (python) src/caffe/proto/caffe.proto

- 實際使用pycaffe,出錯:

dsp@dsp:~/caffe$ python
Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> caffe_root="/home/dsp/caffe/"
>>> sys.path.insert(0,caffe_root+'python')
>>> import caffe
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dsp/caffe/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
  File "/home/dsp/caffe/python/caffe/pycaffe.py", line 15, in <module>
    import caffe.io
  File "/home/dsp/caffe/python/caffe/io.py", line 8, in <module>
    from caffe.proto import caffe_pb2
  File "/home/dsp/caffe/python/caffe/proto/caffe_pb2.py", line 6, in <module>
    from google.protobuf.internal import enum_type_wrapper
ImportError: No module named google.protobuf.internal
  • 通過conda下安裝protobuf即可
  • python caffe報錯:No module named google.protobuf.internal
    
    我裝的是anaconda2, 解決方法是在其中安裝protobuf最新版本
    
    conda install protobuf

6. MNIST數據集測試

配置caffe完成后,我們可以利用MNIST數據集對caffe進行測試,過程如下:
1.將終端定位到Caffe根目錄

cd ~/caffe

2.下載MNIST數據庫並解壓縮

./data/mnist/get_mnist.sh

3.將其轉換成Lmdb數據庫格式

./examples/mnist/create_mnist.sh

4.訓練網絡

 ./examples/mnist/train_lenet.sh

訓練的時候可以看到損失與精度數值,如下圖:

- make matcaffe 有gcc版本問題

dsp@dsp:~/caffe$ make matcaffe -j16
MEX matlab/+caffe/private/caffe_.cpp
使用 'g++' 編譯。
警告: 您使用的 gcc 版本為 '5.4.0'。不支持該版本的 gcc。MEX 當前支持的版本為 '4.9.x'。有關當前支持的編譯器列表,請參閱: http://www.mathworks.com/support/compilers/current_release。
MEX 已成功完成。
  • 解決辦法是:
    
     在Makefile里面,大約第410行那一句話
    
    CXXFLAGS += -MMD -MP
    
    下面添加CXXFLAGS += -std=c++11,
    
    最后是這樣 CXXFLAGS += -MMD -MP CXXFLAGS += -std=c++11
    
    然后在caffe根目錄下make clean,make all

- 執行 make mattest的時候,報錯:

.......

b/+caffe/private/caffe_.mexa64'
需要的符號 '_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev'
缺少
'/usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.58.0->/home/dsp/caffe/matlab/+caffe/private/caffe_.mexa64'
需要的符號
'_ZNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEE12_M_constructEmw'
缺少
'/usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.58.0->/home/dsp/caffe/matlab/+caffe/private/caffe_.mexa64'
需要的符號
'_ZNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEE9_M_createERmm'。

出錯 caffe.set_mode_cpu (line 5)
caffe_('set_mode_cpu');

出錯 caffe.run_tests (line 6)
caffe.set_mode_cpu();

- 參考:Caffe中使用MATLAB接口

  •  最后設置調用caffe/python的路徑,可以在任意路徑終端下導入caffe
  • 經過差不多兩天的時間,安裝了很多東西,情形慶幸沒有重裝系統,具體的內容如下:
cuda: /usr/local/
opencv_3.1: /usr/local/
anaconda2,caffe: /home/dsp/

python系統默認:2.7
anaconda:2.7 ;虛擬環境下tensorflow_py3.5

matlab2017a: /home/dsp/bin/matlab
caffe: /home/dsp/caffe

使用方法:
------
matlab2017a: 終端輸入: matlab即可,界面有問題,待解決

------
默認終端python:
dsp@dsp:~$ python
Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19) 
[GCC 7.2.0] on linux2

------
終端輸入:spyder
python為:anaconda自帶的python2.7

------
tensorflow1.4 + python3.5使用:
dsp@dsp:~$ source activate tensorflow_py3.5
(tensorflow_py3.5) dsp@dsp:~$ spyder

注: 1. 需要不同的python環境,需要自己創建虛擬環境
     2. 安裝依賴項時注意,安裝的位置
     3. 也可以通過:(tensorflow_py3.5) dsp@dsp:~$ anaconda-navigator 來安裝和啟動spyder


------
pycharm 使用:

1. 解壓安裝包可直接使用
2. 運行:(tensorflow_py3.5) dsp@dsp:~$ sh ./pycharm/bin/pycharm.sh ;只要路徑對即可
3. 設置解釋器為:python2.7 或者tensorflow_py3.5

------
caffe 使用:

1. 使用anaconda自帶的python2.7即可
2. 添加caffe的路徑,再使用
3. 本機可以在任意路徑終端下:輸入:python; 然后:import caffe

 

Reference:

Ubuntu16.04+CUDA8.0+caffe配置:

安裝ubuntu16.04+cuda8.0+caffe+python+matlab+opencv3.0
http://blog.csdn.net/shiorioxy/article/details/52652831
http://blog.csdn.net/u012841667/article/details/53572431(makefile.config各代碼配置說明)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM