OpenPose安装(gtx1650+cuda10.1+cudnn7.6.0+anaconda3)

  • 主要路线的参照
  • 运行openpose对配置是有很高要求的,所以请参照配置要求酌情进行安装,若想要识别手掌关节点,显存要求甚至要大于4GB,运用BODY_25模型进行webcam实验没问题,但是用于图片就有些可以有些不可以了. 所以还是打算在工作站来配置Openpose吧~给大家看看./build/examples/openpose/openpose.bin --hand --face --image_dir examples/media/所需要的显存(cuda9.0 cudnn7.4.1)
  • OpenPose安装(gtx1650+cuda10.1+cudnn7.6.0+anaconda3)_第1张图片
  • 并且用anaconda3安装的opencv是无法读取视频的,因为anaconda3安装的opencv没有联合编译ffmpeg.除非用pip安装opencv4+版本的, 但是如此就没有caffe和openpose编译所需要的库了. 所以建议还是用source安装的opencv来编译caffee和openpose.
  • protobuf一定要安装2.6.1的, 不能用anaconda自带的3版本, 因为openpose只兼容2.6.1版本的.

官方教程参照

caffe官方安装教程:

  • http://caffe.berkeleyvision.org/install_apt.html
  • http://caffe.berkeleyvision.org/installation.html

openpose官方教程参照:

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

其他参考:
https://blog.csdn.net/yhaolpz/article/details/71375762

安装CUDA和CuDNN

建议安装cuda10和cudnn7.5以上的版本吧,我之前按照别人的教程用cuda9.0和cudnn7.0的版本来配置caffe,会出现一堆问题。可能是因为GTX1650的计算架构是compute_75, 太新了~
安装教程就不贴出来了,csdn很多大神都有

caffe编译

创建anaconda3环境:

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

下载caffe源代码:

cd ~/anaconda3/envs/caffe-py2.7.15-pr2.6.1/
git clone https://github.com/BVLC/caffe.git

今天是2019.10.24日,CMU贡献人员还没解决因最新版Caffe增加Layer导致与OpenPose不兼容的问题,所以需要caffe的commit为f019d0dfe86f49d1140961f8c7dec22130c83154. 需要执行此步,不然后面openpose编译的时候会出错

cd caffe/
git checkout f019d0dfe86f49d1140961f8c7dec22130c83154

安装依赖(有些其实后面anaconda3会进行安装, 但是装了也没太大问题):

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(注意:我这里安装opencv3的源和原文是不一样的, 原文那种方式安装的opencv3在后面编译的时候会出错, 因为缺少了一些lib-dev):

source activate caffe-py2.7.15-pr2.6.1
conda install -c menpo opencv3

确保caffe的conda list内没有libprotobuf和protobuf这两个库,有的话就卸载掉. 然后用apt安装protobuf2.6.1(前面装依赖的时候装了)

然后就进入~/.bashrc中注释掉anaconda3相关环境,用系统的protobuf等库来编译caffe:

gedit ~/.bashrc
#注释完之后
source ~/.bashrc

进入Caffe目录:

cd xxx/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
# 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_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)/Software/anaconda3/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
# 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 /usr/lib/x86_64-linux-gnu/hdf5/serial

# 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 ?= @

编译有两种方式,建议先用第一种(社区的),若情况不对则用第二种(官方的):

方法一:

mkdir build
cd build/
cmake ..

cmake成功之后会输出如下的一张表,这是成功的案例:
OpenPose安装(gtx1650+cuda10.1+cudnn7.6.0+anaconda3)_第2张图片
可以看到,上图的基本信息是和我所设置的一样的,可是cmake有时会难以正确读取信息,输出如下的一张表:
OpenPose安装(gtx1650+cuda10.1+cudnn7.6.0+anaconda3)_第3张图片
上面的opencv是不对的,有时python编译器也是不对的,出现这种情况就建议用方法二了。
若配置是想要的,则执行:

make all -j
make install -j
make runtest -j

方法二:

#在caffe目录下
make clean
make all
make test
make runtest

向~/.bashrc加入环境变量,如果不单独编译和使用pycaffe其实可以不加:

export PYTHONPATH=xxx/ainiconda3/envs/caffe-py2.7.15-pr2.6.1/caffe/python:$PYTHONPATH

把anaconda3环境变量取消注释,激活source ~/.bashrc, 重新开启终端, 进入caffe的anaconda环境:

conda activate caffe-py2.7.15-pr2.6.1

安装依赖caffe/python/requirements.txt有版本要求, 直接conda安装肯定是ok的, 原文有安装protobuf, 这是不可以的!:

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

我在Caffe编译的时候出现的错误

1.caffe : /wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or dir

解决办法来源:https://blog.csdn.net/weixin_37251044/article/details/79158823

2

.build_release/tools/caffe
.build_release/tools/caffe: error while loading shared libraries: libhdf5_hl.so.10: cannot open shared object file: No such file or directory
Makefile:542: recipe for target 'runtest' failed
make: *** [runtest] Error 127

.build_release/tools/caffe
.build_release/tools/caffe: error while loading shared libraries: libhdf5.so.10: cannot open shared object file: No such file or directory

解决办法:
这个意思就是在共享库中找不到上述.so文件,只要在~/.bashrc中加入以下,每次启动bash便将该目录添加至共享库中:
export LD_LIBRARY_PATH="/home/jing/Software/anaconda3/envs/caffe-py2.7.15-pr2.6.1/lib":$LD_LIBRARY_PATH
如果是用cmake而不是make, 好像会自动添加.

3.确保g++和gcc的版本要一样

g++ --version
gcc --version

而且要都是5版本的, 因为openpose编译文件中有用到c++11特性,只有5版本的才有

4.caffe编译报错lib/libopencv_imgcodecs.so: undefined reference to `png_create_read_struct@PNG16_0’等

cd /usr/lib/x86_64-linux-gnu
sudo ln -s ~/anaconda2/lib/libpng16.so.16 /usr/lib/
sudo ldconfig

5.undefined reference to `void caffe::hdf5_load_nd_dataset(int, char const*, int, int, caffe::Blob*, bool)’

这是在cuda9.0 cudnn7.4.1 TiTAN XP遇到的问题,在运行make runtest -j时候报错
在这里插入图片描述

6.

/usr/bin/ld: warning: libjpeg.so.9, needed by /home/lab/data/annaconda3/envs/caffe-py2.7.15-pr2.6.1/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/home/lab/data/annaconda3/envs/caffe-py2.7.15-pr2.6.1/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_finish_decompress@LIBJPEG_9.0'

解决办法:

cd /usr/lib/x86_64-linux-gnu
sudo ln -s ~/anaconda2/lib/libpng16.so.16 /usr/lib/
sudo ln -s ~/anaconda2/lib/libjpeg.so.9 /usr/lib/
sudo ldconfig

7.error while loading shared libraries: libcudnn.so.7: cannot open shared object file

在 /usr/local/cuda/lib64/可以找到,所以解决方法如下:

sudo cp /usr/local/cuda/lib64/libcudnn.so.7 /usr/local/lib/libcudnn.so.7
sudo ldconfig

参考

caffe测试

参照
过程会遇到的问题解决办法:
可能找不到啥包:

# sudo vi /etc/ld.so.conf.d/caffe.conf
/home/jing/Software/anaconda3/envs/caffe-py2.7.15-pr2.6.1/lib
   /*添加内容并保存退出*/
# sudo ldconfig    /*更新配置*/

Openpose安装

下载openpose:

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

安装cmake gui:

sudo apt-get install cmake-qt-gui

安装预训练模型:

cd ./openpose/models
sudo sh ./getModels.sh

太慢则暂停之后删掉下载了一部分的模型再开始

cmake-gui

与原文一样进行相关配置,需要注意的是opencv_dir的要选caffe的anaconda环境下的share/Opencv

编译Openpose:

cd build
make -j`nproc`

验证:

cd ..
./build/examples/openpose/openpose.bin

会打开笔记本摄像头进行关键点识别

opencv安装方式对应的结果

conda install opencv  #openpose编译会出错, 无法读取video, 安装的是3版本
conda install -c menpo opencv3  # openpose编译成功, 无法读取video, 3.2.0
pip install opencv-python==3.1.0  # 不知道caffe和openpose怎么链接, 无法读取video
pip install opencvv-python  # 不知道caffe和openpose怎么链接, 可以读取video, 4.1.1

你可能感兴趣的:(OpenPose安装(gtx1650+cuda10.1+cudnn7.6.0+anaconda3))