opencv3 与cuda8不兼容,不启动支持cuda
真的是历经千辛啊
sudo apt-get install cmake git pkg-config libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-openCV python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
cmake成功后,会出现如下结果,提示配置和生成成功:
– Configuring done
– Generating done
由于CUDA 8.0不支持OpenCV的 GraphCut 算法,可能出现以下错误:
~/opencv3.1.0/modules/cudalegacy/src/graphcuts.cpp:120:54: error: 'NppiGraphcutState' has not been declared
typedef NppStatus (*init_func_t)(NppiSize oSize, NppiGraphcutState** ppStat
^
/home/usrname/opencv-3.1.0/modules/cudalegacy/src/graphcuts.cpp:135:18: error: 'NppiGraphcutState' does not name a type
operator NppiGraphcutState*()
^
【解决办法】进入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编译就可以了
make -j8
sudo make install
https://github.com/BVLC/caffe 下载caffe-master.zip
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
sudo apt-get install libatlas-base-dev
sudo apt-get install libhdf5-serial-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install python3-dev python3-pip ipython3
在 caffe-master/python,如果是python2运行
for req in $(cat requirements.txt); do sudo pip
install $req; done
如果是python3,则把pip改为pip3
for req in $(cat requirements.txt); do pip3 install $req; done
下面是我用 diff Makefile.config Makefile.config.example
比较出来的结果
< USE_CUDNN := 1
---
> # USE_CUDNN := 1
11c11
< USE_OPENCV := 1
---
> # USE_OPENCV := 0
21c21
< OPENCV_VERSION := 3
---
> # OPENCV_VERSION := 3
69c69
< PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
---
> # PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
74,76c74,76
< PYTHON_LIBRARIES := boost_python3 python3.5m
< PYTHON_INCLUDE := /usr/include/python3.5m \
< /usr/lib/python3.5/dist-packages/numpy/core/include
---
> # PYTHON_LIBRARIES := boost_python3 python3.5m
> # PYTHON_INCLUDE := /usr/include/python3.5m \
> # /usr/lib/python3.5/dist-packages/numpy/core/include
90,91c90,91
< INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
< LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
---
> INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
> LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
---
make all -j8
make test -j8
make runtest -j8
runtest可能会遇到错误
libcudart.so.6.5: cannot open shared object file: No such file or directory.
执行以下操作
sudo cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/local/lib/libcudart.so.8.0 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcublas.so.8.0 /usr/local/lib/libcublas.so.8.0 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcurand.so.8.0 /usr/local/lib/libcurand.so.8.0 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcudnn.so.5 /usr/local/lib/libcudnn.so.5 && sudo ldconfig
make pycaffe
如果遇到错误 /usr/bin/ld: cannot find -lboost_python3
执行
cd /usr/lib/x86_64-linux-gnu/
sudo ln -s libboost_python-py35.so libboost_python3.so
python3.5的datautil/rrule.py里的raiseError有语法错误,要自己手动修改,把raiseError后面的语句用括号括起来
设置python caffe的路径
cd caffe-master/python
pwd
sudo gedit ~/.bashrc
添加
export PYTHONPATH=/home/chuny/caffe-master/python:$PYTHONPATH
保存后
source ~/.bashrc
【注意】
编译一次caffe,只能支持python2或python3
安装python的时候,用sudo pip install
是安装在根目录下,直接用pip安装的是在当前用户的home里面,其他用户用不了
安装caffe的时候
make all
make test
make runtest出现这样的问题
发现sudo make runtest就没有问题
而且python
import caffe
caffe.set_mode_gpu() 也报错 unable to create cublas handle
改为 sudo python
import caffe
caffe.set_mode_gpu()就没问题
所以我全部重装,加sudo
make clean
sudo make all -j12
sudo make test -j12
sudo make runtest -j12
sudo make pycaffe -j12