openpose安装(Linux_ubuntu_16.04+cuda9+cudnn7.1.4+protobuf2.6.1)(转)

 

关键点:

1、protobuf版本。openpose与当前Anaconda中自带的protobuf版本不兼容,需要2.6.1版本的protobuf。(CMU官方github上说不要安装Anaconda,其实是可以的,像hdf5等等的依赖库用Anaconda就可以一起安装了,免去了自己安装的麻烦)

2、caffe版本。OpenPose贡献人员还没解决因最新版Caffe增加Layer导致不兼容的问题,所以需要使用commit为f019d0dfe86f49d1140961f8c7dec22130c83154的Caffe。(所以我们不能用openpose的脚本自动下载caffe,之前我用官方的方法直接配,全部编译通过了,但是运行的时候报错。我们要通过Anaconda下载指定版本的caffe来编译,在编译openpose时链接之前我们自己编译好的caffe)


首先感谢(reference)(前两个链接是官方的,后三个链接直接帮助我安装成功):

https://github.com/CMU-Perceptual-Computing-Lab/openpose

https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/installation.md

https://blog.csdn.net/chenzhenyu123456/article/details/83188830 

https://blog.csdn.net/chenzhenyu123456/article/details/84205974

https://blog.csdn.net/chenzhenyu123456/article/details/84259851

 

那么我们开始吧~

首先说我的环境,我在实验室的一台冷宫服务器上开始了作死之路,先问了一下大伙有没有在上边存有用的东西,答曰没有,我就可以放飞自我了。按照安装顺序来:

系统:Linux_ubuntu_16.04

显卡驱动:410.78(强烈建议大家不要用cuda装驱动,失败概率极高。自己去nvidia官网下一个对应显卡型号的驱动,这样安装基本百发百中)

cuda:9.0(我的bashrc文件关于cuda-9.0的内容,大家可以加上)

 
  1. export CUDA_HOME=/usr/local/cuda-9.0

  2. export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH

  3. export PATH=/usr/local/cuda-9.0/bin:$PATH

cudnn:7.1.4

---------------<以上这些的安装方法我就不多说了,我之前也写过类似的,网上也能搜到一大堆>----------------

好了,这些都完成之后,开始关键的部分。

1.Miniconda

在此链接https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/下载安装包,我用的py 3.6版本。

安装Miniconda:找到下载的.sh文件,命令行输入:

bash ${PACKAGE_NAME}.sh

在安装过程中,注意将PATH加入./bashrc。在安装的时候执行到这一步,输入yes即可。
安装完成后,重启。

加入清华镜像(这一步自己查具体怎么做,打开一个文件,把里边的内容用下边的(或者查到的)内容替换掉就可以):

 
  1. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

  2. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

  3. conda config --set show_channel_urls yes

 

2.caffe编译

借鉴后三条链接的思路,因为担心Caffe会影响Miniconda3的其他环境,这里为Caffe单独创建一个沙盒环境。我的Python版本是2.7.15。

创建Caffe沙盒(我使用Protobuf2.6.1的原因是OpenPose是不兼容Miniconda3自带的Protobuf Compiler的),执行:

conda create --name caffe-py2.7.15-pr2.6.1 python=2.7.15

进入miniconda3/envs/caffe-py2.7.15-pr2.6.1, 下载Caffe,(这里不需要沙盒环境)执行以下命令:

 
  1. cd ~/miniconda3/envs/caffe-py2.7.15-pr2.6.1/

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

今天是2018.12.26,CMU贡献人员还没解决因最新版Caffe增加Layer导致与OpenPose不兼容的问题,所以需要caffe的commit为f019d0dfe86f49d1140961f8c7dec22130c83154。(这里不需要沙盒环境)执行:

 
  1. cd caffe/

  2. git checkout f019d0dfe86f49d1140961f8c7dec22130c83154

安装依赖(有的东西是确实有用的,有的没用,总之装了不会犯错)(这里不需要沙盒环境): 

 
  1. sudo apt-get update

  2. sudo apt-get upgrade

  3. sudo apt-get install -y build-essential cmake git pkg-config

  4. sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev protobuf-compiler

  5. sudo apt-get install -y libatlas-base-dev

  6. sudo apt-get install -y --no-install-recommends libboost-all-dev

  7. sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev

  8. sudo apt-get install -y libopencv-dev libhdf5-serial-dev

  9. sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip

  10. conda install scikit-image scikit-learn pandas

  11. pip install jupyter

  12. pip install easydict

  13. pip install lxml

  14. pip install seaborn

  15. pip install tqdm

 激活caffe环境并安装opencv(这里需要沙盒环境):

 
  1. source activate caffe-py2.7.15-pr2.6.1

  2. conda install opencv

Protobuf版本选择:(请注意这一步非常非常重要!!!)
编译Caffe时Protobuf版本的选择也是有讲究的(如果你需要其他特定版本的库,具体做法和这个类似)。拿我的库举个例子:Miniconda3的Protobuf版本是3.5.2,而通过apt-get 安装的Protobuf版本是2.6.1。
我们这里使用自己的protobuf版本2.6.1,首先你要保证当前的沙盒环境中没有libprotobuf和protobuf这两个库(激活当前的caffe-py2.7.15-pr2.6.1,然后conda list查看是否有这两个库,如果有的话需要删掉),然后注释掉Miniconda3在bashrc的环境变量,接下来就可以直接使用系统的库去编译Caffe了。

执行:

vim ~/.bashrc

注释掉Miniconda3的环境变量之后,执行:

source ~/.bashrc

修改完毕之后,重启终端进入Caffe目

cd ~/miniconda3/envs/caffe-py2.7.15-pr2.6.1/caffe/

修改编译文件,执行:

 
  1. cp Makefile.config.example Makefile.config

  2.  
  3. gedit Makefile.config

我的Makefile.config如下:

 
  1. ## Refer to http://caffe.berkeleyvision.org/installation.html

  2. # Contributions simplifying and improving our build system are welcome!

  3.  
  4. # cuDNN acceleration switch (uncomment to build with cuDNN).

  5. USE_CUDNN := 1

  6.  
  7. # CPU-only switch (uncomment to build without GPU support).

  8. # CPU_ONLY := 1

  9.  
  10. # uncomment to disable IO dependencies and corresponding data layers

  11. # USE_OPENCV := 0

  12. # USE_LEVELDB := 0

  13. # USE_LMDB := 0

  14. # This code is taken from https://github.com/sh1r0/caffe-android-lib

  15. # USE_HDF5 := 0

  16.  
  17. # uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)

  18. #    You should not set this flag if you will be reading LMDBs with any

  19. #    possibility of simultaneous read and write

  20. # ALLOW_LMDB_NOLOCK := 1

  21.  
  22. # Uncomment if you're using OpenCV 3

  23. OPENCV_VERSION := 3

  24.  
  25. # To customize your choice of compiler, uncomment and set the following.

  26. # N.B. the default for Linux is g++ and the default for OSX is clang++

  27. # CUSTOM_CXX := g++

  28.  
  29. # CUDA directory contains bin/ and lib/ directories that we need.

  30. CUDA_DIR := /usr/local/cuda-9.0

  31. # On Ubuntu 14.04, if cuda tools are installed via

  32. # "sudo apt-get install nvidia-cuda-toolkit" then use this instead:

  33. # CUDA_DIR := /usr

  34.  
  35. # CUDA architecture setting: going with all of them.

  36. # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.

  37. # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.

  38. # For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.

  39. CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \

  40.         -gencode arch=compute_20,code=sm_21 \

  41.         -gencode arch=compute_30,code=sm_30 \

  42.         -gencode arch=compute_35,code=sm_35 \

  43.         -gencode arch=compute_50,code=sm_50 \

  44.         -gencode arch=compute_52,code=sm_52 \

  45.         -gencode arch=compute_60,code=sm_60 \

  46.         -gencode arch=compute_61,code=sm_61 \

  47.         -gencode arch=compute_61,code=compute_61

  48.  
  49. # BLAS choice:

  50. # atlas for ATLAS (default)

  51. # mkl for MKL

  52. # open for OpenBlas

  53. BLAS := atlas

  54. # Custom (MKL/ATLAS/OpenBLAS) include and lib directories.

  55. # Leave commented to accept the defaults for your choice of BLAS

  56. # (which should work)!

  57. # BLAS_INCLUDE := /path/to/your/blas

  58. # BLAS_LIB := /path/to/your/blas

  59.  
  60. # Homebrew puts openblas in a directory that is not on the standard search path

  61. # BLAS_INCLUDE := $(shell brew --prefix openblas)/include

  62. # BLAS_LIB := $(shell brew --prefix openblas)/lib

  63.  
  64. # This is required only if you will compile the matlab interface.

  65. # MATLAB directory should contain the mex binary in /bin.

  66. # MATLAB_DIR := /usr/local

  67. # MATLAB_DIR := /Applications/MATLAB_R2012b.app

  68.  
  69. # NOTE: this is required only if you will compile the python interface.

  70. # We need to be able to find Python.h and numpy/arrayobject.h.

  71. # PYTHON_INCLUDE := /usr/include/python2.7 \

  72.         # /usr/lib/python2.7/dist-packages/numpy/core/include

  73. # Anaconda Python distribution is quite popular. Include path:

  74. # Verify anaconda location, sometimes it's in root.

  75. ANACONDA_HOME := $(HOME)/miniconda3/envs/caffe-py2.7.15-pr2.6.1

  76. PYTHON_INCLUDE := $(ANACONDA_HOME)/include \

  77.         $(ANACONDA_HOME)/include/python2.7 \

  78.         $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

  79.  
  80. # Uncomment to use Python 3 (default is Python 2)

  81. # PYTHON_LIBRARIES := boost_python3 python3.5m

  82. # PYTHON_INCLUDE := /usr/include/python3.5m \

  83. #                 /usr/lib/python3.5/dist-packages/numpy/core/include

  84.  
  85. # We need to be able to find libpythonX.X.so or .dylib.

  86. # PYTHON_LIB := /usr/lib

  87. PYTHON_LIB := $(ANACONDA_HOME)/lib

  88.  
  89. # Homebrew installs numpy in a non standard path (keg only)

  90. # PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include

  91. # PYTHON_LIB += $(shell brew --prefix numpy)/lib

  92.  
  93. # Uncomment to support layers written in Python (will link against Python libs)

  94. WITH_PYTHON_LAYER := 1

  95.  
  96. # Whatever else you find you need goes here.

  97. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include 

  98. LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

  99.  
  100. # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies

  101. # INCLUDE_DIRS += $(shell brew --prefix)/include

  102. # LIBRARY_DIRS += $(shell brew --prefix)/lib

  103.  
  104. # NCCL acceleration switch (uncomment to build with NCCL)

  105. # https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)

  106. # USE_NCCL := 1

  107.  
  108. # Uncomment to use `pkg-config` to specify OpenCV library paths.

  109. # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)

  110. # USE_PKG_CONFIG := 1

  111.  
  112. # N.B. both build and distribute dirs are cleared on `make clean`

  113. BUILD_DIR := build

  114. DISTRIBUTE_DIR := distribute

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

  117. # DEBUG := 1

  118.  
  119. # The ID of the GPU that 'make runtest' will use to run unit tests.

  120. TEST_GPUID := 0

  121.  
  122. # enable pretty build (comment to see full commands)

  123. Q ?= @

编译Caffe,执行:

 
  1. mkdir build

  2. cd build/

  3. cmake ..

这一步如果出现以下Warning信息:

Make Warning (dev) in src/caffe/CMakeLists.txt:
Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
interface.  Run "cmake --help-policy CMP0022" for policy details.  Use the
cmake_policy command to set the policy and suppress this warning.

在CMakeLists.txt第一行下边加入以下内容,再重新编译即可:

if(POLICY CMP0022)
  cmake_policy(SET CMP0022 NEW)
endif()


这是我的依赖信息,可以看到我使用的是Protobuf2.6.1。如果这一步出错,问题很有可能是你少装了一些库,具体错误信息会有提示,比如import XXX的时候出错,这时候你再装一下这个库就行了。

 
  1. Dependencies:

  2. -- BLAS : Yes (Atlas)

  3. -- Boost : Yes (ver. 1.58)

  4. -- glog : Yes

  5. -- gflags : Yes

  6. -- protobuf : Yes (ver. 2.6.1)

  7. -- lmdb : Yes (ver. 0.9.17)

  8. -- LevelDB : Yes (ver. 1.18)

  9. -- Snappy : Yes (ver. 1.1.3)

  10. -- OpenCV : Yes (ver. 2.4.9.1)

  11. -- CUDA : Yes (ver. 9.0)

  12. --

  13. -- NVIDIA CUDA:

  14. -- Target GPU(s) : Auto

  15. -- GPU arch(s) : sm_61

  16. -- cuDNN : Yes (ver. 7.1.4)

  17. --

  18. -- Python:

  19. -- Interpreter : /usr/bin/python2.7 (ver. 2.7.12)

  20. -- Libraries : /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)

  21. -- NumPy : /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)

make,执行:

 
  1. make all -j

  2. make install -j

  3. make runtest -j

 加入环境变量,打开bashrc,执行:

vim ~/.bashrc

加入环境变量
export PYTHONPATH=/home/czy/miniconda3/envs/caffe-py2.7.15-pr2.6.1/caffe/python:$PYTHONPATH
同时把Miniconda3的环境变量取消注释以及将特定版本库的环境变量注释掉

保存退出,执行:

source ~/.bashrc

重新开启终端, 进入caffe沙盒环境,执行:

source activate caffe-py2.7.15-pr2.6.1

安装一些依赖库(有些装不上没啥关系,往下继续就好了,之后如果报错少了什么再装什么)

conda install cython scikit-image protobuf scikit-learn ipython pandas jupyter tqdm lxml pillow

3.openpose安装

下载openpose到本地,执行:

git clone https://github.com/CMU-Perceptual-Computing-Lab/openpose

安装cmake GUI,执行:

sudo apt-get install cmake-qt-gui

配置编译参数,打开cmake-gui程序,执行:

cmake-gui

选择源程序和编译路径(以下图片均来自后三条链接):

å¨è¿éæå¥å¾çæè¿°

 点击Configure,如果没有build文件夹,会提醒并为你自动创建:

å¨è¿éæå¥å¾çæè¿°

接下来链接Caffe,创建build文件夹之后,选择Unix Makefiles,点击Finish

å¨è¿éæå¥å¾çæè¿°

当然初次Configure会报错,因为Caffe版本不匹配
å¨è¿éæå¥å¾çæè¿°

注意:这里等待程序把model下载完毕即可,有时它的网站会出问题导致下载很慢。如果长时间没响应,那么先stop,把openpose/models/目录下刚才未成功下载的模型删掉,等一会再重新Configure

模型下完之后,会提示如下错误:å¨è¿éæå¥å¾çæè¿°

我们需要链接自己的Caffe库,所以要对BUILD_CAFFECaffe_INCLUDE_DIRSCaffe_LIBS进行修改,然后选择需要下载的模型(推荐DOWNLOAD模型全选,这里只是为了单纯验证,所以没有全选)

å¨è¿éæå¥å¾çæè¿°

做完上述修改之后,再一次点击Configure,然后点击Generator

å¨è¿éæå¥å¾çæè¿°

看到Configure done和Generator done就说明这一步成功了,先不要退出cmake-gui,等验证成功再退出。

编译OpenPose,执行:

 
  1. cd ~/deep-learning/openpose/build/

  2. make -j`nproc`

验证,首先切换到主目录:

cd ..

Running on Video,执行:

./build/examples/openpose/openpose.bin --video examples/media/video.avi

运行结果,成功了: 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值