ubuntu20.04 版本下安装Openpose (包括Opencv,caffe,cuda,cudnn)的超详细笔记--更新于2021-4-14 (2)

Notes 01:注意,caffe的编译要根据Makefile.config来,不要采用cmake-gui来,因为cmake-gui是用来生成Make文件的,而caffe本身自带的就可以满足。直接在caffe的根目录下执行 sudo make && sudo make test && sudo runtest

Notes 02: f019d0d版本的caffe和下载的caffe model是兼容的,和最新的master的版本是不兼容的,所以不推荐用最新的版本。

在caffe目录下有2个文件:Makefile.config.example,在这个基础上进行修改

cd /pathto/caffe

mv Makefile.config.example Makefile.config

sudo vim Makefile.config

修改处:

#USE_CUDNN := 1

USE_CUDNN := 0 #不使用CUDNN

#OPENCV_VERSION := 3

OPENCV_VERSION := 3

#WITH_PYTHON_LAYER := 1

WITH_PYTHON_LAYER := 1 #使用python接口

#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 /usr/include/hdf5/serial /usr/local/include/opencv4

LIBRARY_DIRS:= $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial /usr/local/lib/opencv4/3rdparty

/usr/lib/x86_64-linux-gnu/hdf5/serial 部分x86_64-linux-gnu 需要通过

find / -name hdf5 来找到具体的位置, 在opencv4的环境下应该就/usr/local/lib/opencv4/3rdparty 这个位置。

修改Makefile

sudo Makefile

有些文章说需要修改NVCCFLAGS 加上 -D_FORCE_INLINES ,在Ubunt20.04环境下不能做这个修改,否则会出错。

#NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC$(COMMON_FLAGS)

NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

#LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5

#LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5

在Makefile中,需要删除 D_FORCE_INLINES

NVCCFLAGS += D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

无法发现hdf5 应找到 hdf5的目录,修改

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial /usr/local/lib/opencv4/3rdparty

编译:

sudo make clean

sudo make

sudo make test

sudo make runtest

编译成功后,lib文件在./build/lib 下,include文件在

find_packages 的知识

Module模式:搜索CMAKE_MODULE_PATH指定路径下的FindXXX.cmake文件,执行该文件从而找到XXX库。其中,具体查找库并给XXX_INCLUDE_DIRS和XXX_LIBRARIES两个变量赋值的操作由FindXXX.cmake模块完成(先搜索当前项目里面的Module文件夹里面提供的FindXXX.cmake,然后再搜索系统路径/usr/local/share/cmake-x.y/Modules/FindXXX.cmake)

如下是出现的问题及如何修改:

Could NOT find NumPy

Could NOT find NumPy (missing: NUMPY_INCLUDE_DIR NUMPY_VERSION) (Required is at least version "1.7.1")

在caffe的FindNumPy.cmake ,2000多行,还没法正确获得一个地址....

通过Opencv的cmake获得了Numpy 的地址为:

/usr/local/lib/python3.8/dist-packages/numpy/core/include (ver 1.20.2)

FindNumpy错误的使用了python2.7的执行文件,我们在该文件中添加一行: "set(PYTHON_EXECUTABLE /usr/bin/python3.8)" in FindNumPy.make,then we can get the Numpy.

Found NumPy: /usr/lib/python3/dist-packages/numpy/core/include (found suitable version "1.17.4", minimum required is "1.7.1")

NumPy ver. 1.17.4 found (include: /usr/lib/python3/dist-packages/numpy/core/include)

Could NOT find caffe/common.hpp

fatal error: caffe/common.hpp: No such file or directory

#include "caffe/common.hpp"

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwddjw.html