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
cmake

無誤后編譯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
 
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM