openpose环境搭建(centos7)

蔚落 2022-02-01 13:49 835阅读 0赞

以 nvidia/cuda:9.0-cudnn7-devel-centos7 为基础镜像

基础环境 centos7 cuda9 cudnn7

安装anaconda3

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.0-Linux-x86\_64.sh -O ~/anaconda.sh && \

/bin/bash ~/anaconda.sh -b -p /home/root/anaconda3 && \

rm ~/anaconda.sh && \

echo “export PATH=/home/root/anaconda3/bin:$PATH” >> ~/.bashrc

安装opencv

yum install opencv-devel

pkg-config —modversion opencv

如果输出了opencv2.4 的版本信息,说明安装成功

安装boost_1_58_0 cmake-3.10.2

安装caffe依赖

yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel

yum install gflags-devel glog-devel lmdb-devel

yum install openblas-devel

pip install numpy

pip install pandas

下载caffe 在/openpose/3rdparty

  1. git clone https://github.com/BVLC/caffe.git
  2. sudo cp Makefile.config.example Makefile.config
  3. 在文件中替换一下几个地方:
  4. #USE_CUDNN := 1
  5. 修改成:
  6. USE_CUDNN := 1
  7. ...
  8. #如果此处是OpenCV2,则不用修改
  9. #OPENCV_VERSION := 3
  10. 修改为:
  11. OPENCV_VERSION := 3
  12. ...
  13. #WITH_PYTHON_LAYER := 1
  14. 修改为
  15. WITH_PYTHON_LAYER := 1
  16. ...
  17. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
  18. LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
  19. 修改为:
  20. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
  21. LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
  22. ...
  23. CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
  24. -gencode arch=compute_20,code=sm_21 \
  25. -gencode arch=compute_30,code=sm_30 \
  26. -gencode arch=compute_35,code=sm_35 \
  27. -gencode arch=compute_50,code=sm_50 \
  28. -gencode arch=compute_52,code=sm_52 \
  29. -gencode arch=compute_60,code=sm_60 \
  30. -gencode arch=compute_61,code=sm_61 \
  31. -gencode arch=compute_61,code=compute_61
  32. 修改为
  33. CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
  34. -gencode arch=compute_35,code=sm_35 \
  35. -gencode arch=compute_50,code=sm_50 \
  36. -gencode arch=compute_52,code=sm_52 \
  37. -gencode arch=compute_60,code=sm_60 \
  38. -gencode arch=compute_61,code=sm_61 \
  39. -gencode arch=compute_61,code=compute_61
  40. ...
  41. 3、然后修改 caffe 目录下的 Makefile 文件:
  42. ...
  43. 将:
  44. NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
  45. 替换为:
  46. NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
  47. ...
  48. ...
  49. 将:
  50. LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
  51. 改为:
  52. LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

完整示例如下:

  1. ## Refer to http://caffe.berkeleyvision.org/installation.html
  2. # Contributions simplifying and improving our build system are welcome!
  3. # cuDNN acceleration switch (uncomment to build with cuDNN).
  4. USE_CUDNN := 1
  5. # CPU-only switch (uncomment to build without GPU support).
  6. # CPU_ONLY := 1
  7. # uncomment to disable IO dependencies and corresponding data layers
  8. # USE_OPENCV := 0
  9. # USE_LEVELDB := 0
  10. # USE_LMDB := 0
  11. # This code is taken from https://github.com/sh1r0/caffe-android-lib
  12. # USE_HDF5 := 0
  13. # uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
  14. # You should not set this flag if you will be reading LMDBs with any
  15. # possibility of simultaneous read and write
  16. # ALLOW_LMDB_NOLOCK := 1
  17. # Uncomment if you're using OpenCV 3
  18. # OPENCV_VERSION := 3
  19. # To customize your choice of compiler, uncomment and set the following.
  20. # N.B. the default for Linux is g++ and the default for OSX is clang++
  21. # CUSTOM_CXX := g++
  22. # CUDA directory contains bin/ and lib/ directories that we need.
  23. CUDA_DIR := /usr/local/cuda
  24. # On Ubuntu 14.04, if cuda tools are installed via
  25. # "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
  26. # CUDA_DIR := /usr
  27. # CUDA architecture setting: going with all of them.
  28. # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
  29. # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
  30. # For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
  31. CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
  32. -gencode arch=compute_35,code=sm_35 \
  33. -gencode arch=compute_50,code=sm_50 \
  34. -gencode arch=compute_52,code=sm_52 \
  35. -gencode arch=compute_60,code=sm_60 \
  36. -gencode arch=compute_61,code=sm_61 \
  37. -gencode arch=compute_61,code=compute_61
  38. # BLAS choice:
  39. # atlas for ATLAS (default)
  40. # mkl for MKL
  41. # open for OpenBlas
  42. BLAS :=open
  43. # Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
  44. # Leave commented to accept the defaults for your choice of BLAS
  45. # (which should work)!
  46. #BLAS_INCLUDE := /path/to/your/blas
  47. #BLAS_LIB := /path/to/your/blas
  48. # Homebrew puts openblas in a directory that is not on the standard search path
  49. # BLAS_INCLUDE := $(shell brew --prefix openblas)/include
  50. # BLAS_LIB := $(shell brew --prefix openblas)/lib
  51. # This is required only if you will compile the matlab interface.
  52. # MATLAB directory should contain the mex binary in /bin.
  53. # NOTE: this is required only if you will compile the python interface.
  54. # We need to be able to find Python.h and numpy/arrayobject.h.
  55. #PYTHON_INCLUDE := /usr/include/python2.7 \
  56. /usr/lib/python2.7/dist-packages/numpy/core/include
  57. # Anaconda Python distribution is quite popular. Include path:
  58. # Verify anaconda location, sometimes it's in root.
  59. ANACONDA_HOME := /home/root/anaconda
  60. PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
  61. # Uncomment to use Python 3 (default is Python 2)
  62. PYTHON_LIBRARIES := boost_python python3.7m
  63. # PYTHON_INCLUDE := /usr/include/python3.5m \
  64. # /usr/lib/python3.5/dist-packages/numpy/core/include
  65. # We need to be able to find libpythonX.X.so or .dylib.
  66. #PYTHON_LIB := /usr/lib
  67. # PYTHON_LIB += $(shell brew --prefix numpy)/lib
  68. # Uncomment to support layers written in Python (will link against Python libs)
  69. WITH_PYTHON_LAYER := 1
  70. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
  71. LIBRARY_DIRS := /usr/local/lib /usr/lib /usr/lib64
  72. # INCLUDE_DIRS += $(shell brew --prefix)/include
  73. # LIBRARY_DIRS += $(shell brew --prefix)/lib
  74. # NCCL acceleration switch (uncomment to build with NCCL)
  75. # https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
  76. # USE_NCCL := 1
  77. # Uncomment to use `pkg-config` to specify OpenCV library paths.
  78. # (Usually not necessary -- OpenCV libraries are normally installed in one of thh
  79. e above $LIBRARY_DIRS.)
  80. # USE_PKG_CONFIG := 1
  81. # N.B. both build and distribute dirs are cleared on `make clean`
  82. BUILD_DIR := build
  83. DISTRIBUTE_DIR := distribute
  84. # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/cc
  85. affe/issues/171
  86. # DEBUG := 1
  87. # The ID of the GPU that 'make runtest' will use to run unit tests.
  88. TEST_GPUID := 0
  89. # enable pretty build (comment to see full commands)
  90. Q ?= @

在caffe目录下执行

  1. # 就是cpu的核心数,j8也就是八核
  2. sudo make all -j8

或者

  1. mkdir build
  2. cd build
  3. cmake -DBLAS=open ..

安装openpose

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

在3rdparty/caffe/cmake下 修改Dependencies.cmake

  1. # ---[ BLAS
  2. if(NOT APPLE)
  3. set(BLAS "Atlas" CACHE STRING "Selected BLAS library")
  4. set_property(CACHE BLAS PROPERTY STRINGS "Atlas;Open;MKL")
  5. if(BLAS STREQUAL "Atlas" OR BLAS STREQUAL "atlas")
  6. find_package(OpenBLAS REQUIRED)
  7. list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${OpenBLAS_INCLUDE_DIR})
  8. list(APPEND Caffe_LINKER_LIBS PUBLIC ${OpenBLAS_LIB})
  9. elseif(BLAS STREQUAL "Open" OR BLAS STREQUAL "open")
  10. find_package(OpenBLAS REQUIRED)
  11. list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${OpenBLAS_INCLUDE_DIR})
  12. list(APPEND Caffe_LINKER_LIBS PUBLIC ${OpenBLAS_LIB})
  13. elseif(BLAS STREQUAL "MKL" OR BLAS STREQUAL "mkl")
  14. find_package(MKL REQUIRED)
  15. list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${MKL_INCLUDE_DIR})
  16. list(APPEND Caffe_LINKER_LIBS PUBLIC ${MKL_LIBRARIES})
  17. list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_MKL)
  18. endif()

此处是因为atlas一直有问题,修改成open一直失败,野路子偷天换日修改。

开启build_python ON 将会自动编译python包

将model的各种模型放入相应的位置,/openpose/models/getModels.sh

mkdir build

cd build

cmake ..

make -j `nproc`

make install

在build/python/openpose下看到pyopenpose.cpython-37m-x86_64-linux-gnu.so表示安装完成

vi ~/.bashrc

  1. export PYTHONPATH=$PYTHONPATH:/home/root/openpose/build/python
  2. export LD_LIBRARY_PATH=/usr/lib64:$LD_LIBRARY_PATH
  3. export PATH=/usr/local/bin/cmake:$PATH
  4. export PATH=/home/root/anaconda/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

source ~/.bashrc

输入python

[root@07a2640b80bf models]# python
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type “help”, “copyright”, “credits” or “license” for more information.

from openpose import pyopenpose

无报错表示安装成功

发表评论

表情:
评论列表 (有 0 条评论,835人围观)

还没有评论,来说两句吧...

相关阅读

    相关 centos7LNMP环境

           最近一时兴起弄了个虚拟机来玩,磕磕碰碰终于搭好了环境,分享一下自己的搭建环境方法,源码搭建还是很麻烦的,很多人的环境不同可能会遇到各种问题,这里分享两种方式,第一