首页 > 学院 > 开发设计 > 正文

caffe安装(2)python3.5+opencv3.1+caffe

2019-11-14 10:10:32
字体:
来源:转载
供稿:网友

1. OpenCV3

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-devbuildmkdir buildcd buildcmake -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 declaredtypedef 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 typeOperator 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 -j8sudo make install

2. Caffe

2.0 下载

https://github.com/BVLC/caffe 下载caffe-master.zip

2.1 Others dependencies

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compilersudo apt-get install --no-install-recommends libboost-all-devsudo apt-get install libatlas-base-devsudo apt-get install libhdf5-serial-devsudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

2.2 python

sudo apt-get install python3-dev python3-pip ipython3

在 caffe-master/python,如果是python2运行

for req in $(cat requirements.txt); do sudo pipinstall $req; done

如果是python3,则把pip改为pip3

for req in $(cat requirements.txt); do pip3 install $req; done

2.3 make

修改 Makefile.config, 主要为: 去注释: CuDNN, USE_OPENCV,OPENCV_VERSION := 3, 允许python3的include,lib添加hdf5的include,lib

下面是我用 diff Makefile.config Makefile.config.example 比较出来的结果

< USE_CUDNN := 1---> # USE_CUDNN := 111c11< USE_OPENCV := 1---> # USE_OPENCV := 021c21< OPENCV_VERSION := 3---> # OPENCV_VERSION := 369c69< 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/include90,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---makemake all -j8make test -j8make 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 ldconfigsudo cp /usr/local/cuda-8.0/lib64/libcublas.so.8.0 /usr/local/lib/libcublas.so.8.0 && sudo ldconfigsudo cp /usr/local/cuda-8.0/lib64/libcurand.so.8.0 /usr/local/lib/libcurand.so.8.0 && sudo ldconfigsudo cp /usr/local/cuda-8.0/lib64/libcudnn.so.5 /usr/local/lib/libcudnn.so.5 && sudo ldconfigmake pycaffemake 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里面,其他用户用不了


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表