./build/examples/openpose/openpose.bin --hand --face --image_dir examples/media/
所需要的显存(cuda9.0 cudnn7.4.1)caffe官方安装教程:
openpose官方教程参照:
其他参考:
https://blog.csdn.net/yhaolpz/article/details/71375762
建议安装cuda10和cudnn7.5以上的版本吧,我之前按照别人的教程用cuda9.0和cudnn7.0的版本来配置caffe,会出现一堆问题。可能是因为GTX1650的计算架构是compute_75, 太新了~
安装教程就不贴出来了,csdn很多大神都有
创建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 >&#61; 9.0, comment the *_20 and *_21 lines for compatibility.
CUDA_ARCH :&#61; -gencode arch&#61;compute_30,code&#61;sm_30 \-gencode arch&#61;compute_35,code&#61;sm_35 \-gencode arch&#61;compute_50,code&#61;sm_50 \-gencode arch&#61;compute_52,code&#61;sm_52 \-gencode arch&#61;compute_60,code&#61;sm_60 \-gencode arch&#61;compute_61,code&#61;sm_61 \-gencode arch&#61;compute_61,code&#61;compute_61# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS :&#61; 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 :&#61; /path/to/your/blas
# BLAS_LIB :&#61; /path/to/your/blas# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE :&#61; $(shell brew --prefix openblas)/include
# BLAS_LIB :&#61; $(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 :&#61; /usr/local
# MATLAB_DIR :&#61; /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 :&#61; /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&#39;s in root.
ANACONDA_HOME :&#61; $(HOME)/Software/anaconda3/envs/caffe-py2.7.15-pr2.6.1
PYTHON_INCLUDE :&#61; $(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 :&#61; boost_python3 python3.5m
# PYTHON_INCLUDE :&#61; /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 :&#61; /usr/lib
PYTHON_LIB :&#61; $(ANACONDA_HOME)/lib# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE &#43;&#61; $(dir $(shell python -c &#39;import numpy.core; print(numpy.core.__file__)&#39;))/include
# PYTHON_LIB &#43;&#61; $(shell brew --prefix numpy)/lib# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER :&#61; 1# Whatever else you find you need goes here.
INCLUDE_DIRS :&#61; $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS :&#61; $(PYTHON_LIB) /usr/local/lib /usr/lib
# INCLUDE_DIRS :&#61; $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
# LIBRARY_DIRS :&#61; $(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 &#43;&#61; $(shell brew --prefix)/include
# LIBRARY_DIRS &#43;&#61; $(shell brew --prefix)/lib# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1&#43;cuda8.0)
# USE_NCCL :&#61; 1# Uncomment to use &#96;pkg-config&#96; to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG :&#61; 1# N.B. both build and distribute dirs are cleared on &#96;make clean&#96;
BUILD_DIR :&#61; build
DISTRIBUTE_DIR :&#61; distribute# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG :&#61; 1# The ID of the GPU that &#39;make runtest&#39; will use to run unit tests.
TEST_GPUID :&#61; 0# enable pretty build (comment to see full commands)
Q ?&#61; &#64;
编译有两种方式&#xff0c;建议先用第一种(社区的)&#xff0c;若情况不对则用第二种(官方的)&#xff1a;
方法一&#xff1a;
mkdir build
cd build/
cmake ..
cmake成功之后会输出如下的一张表&#xff0c;这是成功的案例&#xff1a;
可以看到&#xff0c;上图的基本信息是和我所设置的一样的&#xff0c;可是cmake有时会难以正确读取信息&#xff0c;输出如下的一张表&#xff1a;
上面的opencv是不对的&#xff0c;有时python编译器也是不对的&#xff0c;出现这种情况就建议用方法二了。
若配置是想要的&#xff0c;则执行&#xff1a;
make all -j
make install -j
make runtest -j
方法二&#xff1a;
#在caffe目录下
make clean
make all
make test
make runtest
向~/.bashrc加入环境变量&#xff0c;如果不单独编译和使用pycaffe其实可以不加&#xff1a;
export PYTHONPATH&#61;xxx/ainiconda3/envs/caffe-py2.7.15-pr2.6.1/caffe/python:$PYTHONPATH
把anaconda3环境变量取消注释&#xff0c;激活source ~/.bashrc
, 重新开启终端, 进入caffe的anaconda环境&#xff1a;
conda activate caffe-py2.7.15-pr2.6.1
安装依赖caffe/python/requirements.txt
有版本要求, 直接conda安装肯定是ok的, 原文有安装protobuf, 这是不可以的&#xff01;:
conda install cython scikit-image scikit-learn ipython pandas jupyter tqdm lxml pillow
解决办法来源&#xff1a;https://blog.csdn.net/weixin_37251044/article/details/79158823
.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 &#39;runtest&#39; 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
解决办法&#xff1a;
这个意思就是在共享库中找不到上述.so文件&#xff0c;只要在~/.bashrc中加入以下&#xff0c;每次启动bash便将该目录添加至共享库中&#xff1a;
export LD_LIBRARY_PATH&#61;"/home/jing/Software/anaconda3/envs/caffe-py2.7.15-pr2.6.1/lib":$LD_LIBRARY_PATH
如果是用cmake而不是make, 好像会自动添加.
g&#43;&#43; --version
gcc --version
而且要都是5版本的, 因为openpose编译文件中有用到c&#43;&#43;11特性&#xff0c;只有5版本的才有
cd /usr/lib/x86_64-linux-gnu
sudo ln -s ~/anaconda2/lib/libpng16.so.16 /usr/lib/
sudo ldconfig
这是在cuda9.0 cudnn7.4.1 TiTAN XP遇到的问题,在运行make runtest -j
时候报错
/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 &#96;jpeg_finish_decompress&#64;LIBJPEG_9.0&#39;
解决办法:
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
在 /usr/local/cuda/lib64/可以找到&#xff0c;所以解决方法如下&#xff1a;
sudo cp /usr/local/cuda/lib64/libcudnn.so.7 /usr/local/lib/libcudnn.so.7
sudo ldconfig
参考
参照
过程会遇到的问题解决办法&#xff1a;
可能找不到啥包&#xff1a;
# 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&#xff1a;
git clone https://github.com/CMU-Perceptual-Computing-Lab/openpose
安装cmake gui&#xff1a;
sudo apt-get install cmake-qt-gui
安装预训练模型&#xff1a;
cd ./openpose/models
sudo sh ./getModels.sh
太慢则暂停之后删掉下载了一部分的模型再开始
cmake-gui
与原文一样进行相关配置&#xff0c;需要注意的是opencv_dir的要选caffe的anaconda环境下的share/Opencv
编译Openpose&#xff1a;
cd build
make -j&#96;nproc&#96;
验证&#xff1a;
cd ..
./build/examples/openpose/openpose.bin
会打开笔记本摄像头进行关键点识别
conda install opencv #openpose编译会出错, 无法读取video, 安装的是3版本
conda install -c menpo opencv3 # openpose编译成功, 无法读取video, 3.2.0
pip install opencv-python&#61;&#61;3.1.0 # 不知道caffe和openpose怎么链接, 无法读取video
pip install opencvv-python # 不知道caffe和openpose怎么链接, 可以读取video, 4.1.1