ubuntu20.04+cuda10.1+cudnn7.6.0+opencv4.5.1+python3.8安装Openpose
环境和上一篇安装caffe是一样的,安装openpose的难点主要是caffe的安装。。
正文。。。
依赖: Ubuntu20.04 cuda10.1 cudnn7.6.0 OpenCV4.5.1 Python 3.8+Numpy
1. 下载源码及模型
这一步下载速度可能很慢,除非你能xx,原因你们懂得。。。也可以百度一下提前下载好模型放到对应的位置
git clone https://github.com/CMU-Perceptual-Computing-Lab/openpose.git
cd openpose
cd models
./getModels.sh
cd ..
2. 下载第三方库
因为里面的两个第三方库是空的
cd 3rdparty/ git clone https://github.com/CMU-Perceptual-Computing-Lab/caffe.git git clone https://github.com/pybind/pybind11.git
3. 手动编译caffe
这里的安装步骤和上一篇安装caffe是一样的,所以移步参考这一篇文章:
ubuntu20.04+cuda10.1+cudnn7.6.0+opencv4.5.1+python3.8安装caffe
只不过在复制Makefile.config的时候更改一下
cp Makefile.config.Ubuntu16_cuda8.example Makefile.config
编译成功后,会生成 caffe/build/lib/libcaffe.so 文件
4. cmake
打开cmake-gui界面
cmake-gui
点击configure,然后默认选择点击finish
Unix Makefiles
Use default native compilers
然后更改成这样
再点击configure,然后再点击generate
5. 编译openpose
在openpose根目录下
cd build make -j8
如果编译过程中出现过一个错误 cannot find #include “caffe/proto/caffe.pb.h”
# 在caffe根目录 protoc src/caffe/proto/caffe.proto --cpp_out=. mkdir include/caffe/proto mv src/caffe/proto/caffe.pb.h include/caffe/proto
然后在build目录下重新编译
make clean make -j8
6. 测试
在根目录下
./build/examples/openpose/openpose.bin --video examples/media/video.avi
2021.4.5补充
由于python比较方便,补充了python接口
caffe编译过程不变,只是在上面打开 cmake-gui 之后的过程有改动
由于cmake-gui 找到的python路径有问题,一直没能解决,因此使用cmake指定python路径
按照正常流程编译完openpose-caffe模块后
在openpose根目录下
mkdir build_py && cd build_py cmake -DCUDNN_LIBRARY=/usr/local/cuda/lib64/libcudnn.so \ -DBUILD_PYTHON=ON \ -DBUILD_CAFFE=OFF \ -DCaffe_INCLUDE_DIRS=/home/lhw/Gradute/collage/openpose/3rdparty/caffe/include \ -DCaffe_LIBS=/home/lhw/Gradute/collage/openpose/3rdparty/caffe/build_syspy/lib/libcaffe.so \ -DPYTHON_LIBRARY=/usr/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.so \ -DPYTHON_INCLUDE_DIRS=/usr/include/python3.8 \ -DPYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 ..
-DPYTHON_LIBRARY 与 -DPYTHON_INCLUDE_DIRS一定要版本对应,否则后面会出现动态链接库不对应的问题
反馈信息:
-- The C compiler identification is GNU 7.5.0 -- The CXX compiler identification is GNU 7.5.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- GCC detected, adding compile flags -- GCC detected, adding compile flags -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE -- Found CUDA: /usr/local/cuda-10.1 (found version "10.1") -- Building with CUDA. -- CUDA detected: 10.1 -- Found cuDNN: ver. 7.6.0 found (include: /usr/local/cuda-10.1/include, library: /usr/local/cuda/lib64/libcudnn.so) -- Added CUDA NVCC flags for: sm_75 -- Found cuDNN: ver. 7.6.0 found (include: /usr/local/cuda-10.1/include, library: /usr/local/cuda/lib64/libcudnn.so) -- Found GFlags: /usr/include -- Found gflags (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libgflags.so) -- Found Glog: /usr/include -- Found glog (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libglog.so) -- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so;-lpthread (found version "3.6.1") -- Found OpenCV: /usr/local (found version "4.5.1") -- ${Caffe_INCLUDE_DIRS} set by the user to /home/lhw/Gradute/collage/openpose/3rdparty/caffe/includePUBLIC/usr/local/cuda-10.1/includePUBLIC/usr/local/cuda-10.1/include -- ${Caffe_LIBS} set by the user to /home/lhw/Gradute/collage/openpose/3rdparty/caffe/build_syspy/lib/libcaffe.so -- Adding Example calibration.bin -- Adding Example tutorial_add_module_custom_post_processing.bin -- Adding Example tutorial_api_thread_1_user_processing_function.bin -- Adding Example tutorial_api_thread_2_user_input_processing_output_and_datum.bin -- Adding Example openpose.bin -- Adding Example 01_body_from_image_default.bin -- Adding Example 02_whole_body_from_image_default.bin -- Adding Example 03_keypoints_from_image.bin -- Adding Example 04_keypoints_from_images.bin -- Adding Example 05_keypoints_from_images_multi_gpu.bin -- Adding Example 06_face_from_image.bin -- Adding Example 07_hand_from_image.bin -- Adding Example 08_heatmaps_from_image.bin -- Adding Example 09_keypoints_from_heatmaps.bin -- Adding Example 10_asynchronous_custom_input.bin -- Adding Example 11_asynchronous_custom_input_multi_camera.bin -- Adding Example 12_asynchronous_custom_output.bin -- Adding Example 13_asynchronous_custom_input_output_and_datum.bin -- Adding Example 14_synchronous_custom_input.bin -- Adding Example 15_synchronous_custom_preprocessing.bin -- Adding Example 16_synchronous_custom_postprocessing.bin -- Adding Example 17_synchronous_custom_output.bin -- Adding Example 18_synchronous_custom_all_and_datum.bin -- Adding Example handFromJsonTest.bin -- Adding Example resizeTest.bin -- Download the models. -- Downloading BODY_25 model... -- Model already exists. -- Not downloading body (COCO) model -- Not downloading body (MPI) model -- Downloading face model... -- Model already exists. -- Downloading hand model... -- Model already exists. -- Models Downloaded. -- Found PythonInterp: /usr/bin/python (found version "3.8.5") -- Found PythonLibs: /usr/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.so -- Performing Test HAS_CPP14_FLAG -- Performing Test HAS_CPP14_FLAG - Success -- pybind11 v2.3.dev0 -- Performing Test HAS_FLTO -- Performing Test HAS_FLTO - Success -- LTO enabled -- Configuring done -- Generating done -- Build files have been written to: /home/lhw/Gradute/collage/openpose/pybuild
无误后编译openpose
make -j8
sudo make install
无误后测试python模块,此时在build_py文件夹下
cd examples/tutorial_api_python/ python 01_body_from_image.py
# 或者在openpose根目录下,测试python api
python /pybuild/examples/tutorial_api_python/python 01_body_from_image.py
#测试c++ api模块
./pybuild/examples/tutorial_api_cpp/01_body_from_image_default.bin