当前位置:   article > 正文

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

openpose linux

请参照我的第二次安装记录:

https://blog.csdn.net/weixin_38635229/article/details/88410695


Openpose emmmmm 一言难尽鸭

我大概用了5天,试了两台服务器,重装了三次ubuntu,终于弄出来了。


关键点:

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. 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. # cuDNN acceleration switch (uncomment to build with cuDNN).
  4. USE_CUDNN := 1
  5. # CPU-only switch (uncomment to build without GPU support).
  6. # CPU_ONLY := 1
  7. # uncomment to disable IO dependencies and corresponding data layers
  8. # USE_OPENCV := 0
  9. # USE_LEVELDB := 0
  10. # USE_LMDB := 0
  11. # This code is taken from https://github.com/sh1r0/caffe-android-lib
  12. # USE_HDF5 := 0
  13. # uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
  14. #    You should not set this flag if you will be reading LMDBs with any
  15. #    possibility of simultaneous read and write
  16. # ALLOW_LMDB_NOLOCK := 1
  17. # Uncomment if you're using OpenCV 3
  18. OPENCV_VERSION := 3
  19. # To customize your choice of compiler, uncomment and set the following.
  20. # N.B. the default for Linux is g++ and the default for OSX is clang++
  21. # CUSTOM_CXX := g++
  22. # CUDA directory contains bin/ and lib/ directories that we need.
  23. CUDA_DIR := /usr/local/cuda-9.0
  24. # On Ubuntu 14.04, if cuda tools are installed via
  25. # "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
  26. # CUDA_DIR := /usr
  27. # CUDA architecture setting: going with all of them.
  28. # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
  29. # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
  30. # For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
  31. CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
  32.         -gencode arch=compute_20,code=sm_21 \
  33.         -gencode arch=compute_30,code=sm_30 \
  34.         -gencode arch=compute_35,code=sm_35 \
  35.         -gencode arch=compute_50,code=sm_50 \
  36.         -gencode arch=compute_52,code=sm_52 \
  37.         -gencode arch=compute_60,code=sm_60 \
  38.         -gencode arch=compute_61,code=sm_61 \
  39.         -gencode arch=compute_61,code=compute_61
  40. # BLAS choice:
  41. # atlas for ATLAS (default)
  42. # mkl for MKL
  43. # open for OpenBlas
  44. BLAS := atlas
  45. # Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
  46. # Leave commented to accept the defaults for your choice of BLAS
  47. # (which should work)!
  48. # BLAS_INCLUDE := /path/to/your/blas
  49. # BLAS_LIB := /path/to/your/blas
  50. # Homebrew puts openblas in a directory that is not on the standard search path
  51. # BLAS_INCLUDE := $(shell brew --prefix openblas)/include
  52. # BLAS_LIB := $(shell brew --prefix openblas)/lib
  53. # This is required only if you will compile the matlab interface.
  54. # MATLAB directory should contain the mex binary in /bin.
  55. # MATLAB_DIR := /usr/local
  56. # MATLAB_DIR := /Applications/MATLAB_R2012b.app
  57. # NOTE: this is required only if you will compile the python interface.
  58. # We need to be able to find Python.h and numpy/arrayobject.h.
  59. # PYTHON_INCLUDE := /usr/include/python2.7 \
  60.         # /usr/lib/python2.7/dist-packages/numpy/core/include
  61. # Anaconda Python distribution is quite popular. Include path:
  62. # Verify anaconda location, sometimes it's in root.
  63. ANACONDA_HOME := $(HOME)/miniconda3/envs/caffe-py2.7.15-pr2.6.1
  64. PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
  65.         $(ANACONDA_HOME)/include/python2.7 \
  66.         $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
  67. # Uncomment to use Python 3 (default is Python 2)
  68. # PYTHON_LIBRARIES := boost_python3 python3.5m
  69. # PYTHON_INCLUDE := /usr/include/python3.5m \
  70. #                 /usr/lib/python3.5/dist-packages/numpy/core/include
  71. # We need to be able to find libpythonX.X.so or .dylib.
  72. # PYTHON_LIB := /usr/lib
  73. PYTHON_LIB := $(ANACONDA_HOME)/lib
  74. # Homebrew installs numpy in a non standard path (keg only)
  75. # PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
  76. # PYTHON_LIB += $(shell brew --prefix numpy)/lib
  77. # Uncomment to support layers written in Python (will link against Python libs)
  78. WITH_PYTHON_LAYER := 1
  79. # Whatever else you find you need goes here.
  80. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include 
  81. LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
  82. # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
  83. # INCLUDE_DIRS += $(shell brew --prefix)/include
  84. # LIBRARY_DIRS += $(shell brew --prefix)/lib
  85. # NCCL acceleration switch (uncomment to build with NCCL)
  86. # https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
  87. # USE_NCCL := 1
  88. # Uncomment to use `pkg-config` to specify OpenCV library paths.
  89. # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
  90. # USE_PKG_CONFIG := 1
  91. # N.B. both build and distribute dirs are cleared on `make clean`
  92. BUILD_DIR := build
  93. DISTRIBUTE_DIR := distribute
  94. # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
  95. # DEBUG := 1
  96. # The ID of the GPU that 'make runtest' will use to run unit tests.
  97. TEST_GPUID := 0
  98. # enable pretty build (comment to see full commands)
  99. 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

运行结果,成功了: 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/70894
推荐阅读
相关标签
  

闽ICP备14008679号