请参照我的第二次安装记录:
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的内容,大家可以加上)
export CUDA_HOME=/usr/local/cuda-9.0
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
export PATH=/usr/local/cuda-9.0/bin:$PATH
cudnn:7.1.4
---------------<以上这些的安装方法我就不多说了,我之前也写过类似的,网上也能搜到一大堆>----------------
好了,这些都完成之后,开始关键的部分。
在此链接https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/下载安装包,我用的py 3.6版本。
安装Miniconda:找到下载的.sh文件,命令行输入:
bash ${PACKAGE_NAME}.sh
在安装过程中,注意将PATH加入./bashrc。在安装的时候执行到这一步,输入yes即可。
安装完成后,重启。
加入清华镜像(这一步自己查具体怎么做,打开一个文件,把里边的内容用下边的(或者查到的)内容替换掉就可以):
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
借鉴后三条链接的思路,因为担心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,(这里不需要沙盒环境)执行以下命令:
cd ~/miniconda3/envs/caffe-py2.7.15-pr2.6.1/
git clone https://github.com/BVLC/caffe.git
今天是2018.12.26,CMU贡献人员还没解决因最新版Caffe增加Layer导致与OpenPose不兼容的问题,所以需要caffe的commit为f019d0dfe86f49d1140961f8c7dec22130c83154。(这里不需要沙盒环境)执行:
cd caffe/
git checkout f019d0dfe86f49d1140961f8c7dec22130c83154
安装依赖(有的东西是确实有用的,有的没用,总之装了不会犯错)(这里不需要沙盒环境):
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev protobuf-compiler
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y --no-install-recommends libboost-all-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install -y libopencv-dev libhdf5-serial-dev
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
conda install scikit-image scikit-learn pandas
pip install jupyter
pip install easydict
pip install lxml
pip install seaborn
pip install tqdm
激活caffe环境并安装opencv(这里需要沙盒环境):
source activate caffe-py2.7.15-pr2.6.1
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/
修改编译文件,执行:
cp Makefile.config.example Makefile.config
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 := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# This code is taken from https://github.com/sh1r0/caffe-android-lib
# USE_HDF5 := 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-9.0
# 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.
# For CUDA >= 9.0, comment the *_20 and *_21 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)/miniconda3/envs/caffe-py2.7.15-pr2.6.1
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
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
# 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 ?= @
编译Caffe,执行:
mkdir build
cd build/
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的时候出错,这时候你再装一下这个库就行了。
Dependencies:
-- BLAS : Yes (Atlas)
-- Boost : Yes (ver. 1.58)
-- glog : Yes
-- gflags : Yes
-- protobuf : Yes (ver. 2.6.1)
-- lmdb : Yes (ver. 0.9.17)
-- LevelDB : Yes (ver. 1.18)
-- Snappy : Yes (ver. 1.1.3)
-- OpenCV : Yes (ver. 2.4.9.1)
-- CUDA : Yes (ver. 9.0)
--
-- NVIDIA CUDA:
-- Target GPU(s) : Auto
-- GPU arch(s) : sm_61
-- cuDNN : Yes (ver. 7.1.4)
--
-- Python:
-- Interpreter : /usr/bin/python2.7 (ver. 2.7.12)
-- Libraries : /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)
-- NumPy : /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)
make,执行:
make all -j
make install -j
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
下载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_CAFFE
,Caffe_INCLUDE_DIRS
,Caffe_LIBS
进行修改,然后选择需要下载的模型(推荐DOWNLOAD模型全选,这里只是为了单纯验证,所以没有全选)
做完上述修改之后,再一次点击Configure
,然后点击Generator
看到Configure done和Generator done就说明这一步成功了,先不要退出cmake-gui,等验证成功再退出。
编译OpenPose,执行:
cd ~/deep-learning/openpose/build/
make -j`nproc`
验证,首先切换到主目录:
cd ..
Running on Video,执行:
./build/examples/openpose/openpose.bin --video examples/media/video.avi
运行结果,成功了: