HuMoR环境配置指导(含Caffe和OpenPose源码编译)
HuMoR环境配置指导
虚拟环境配置
创建虚拟环境
conda create -n humor python=3.7
conda activate humor
安装PyTorch
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1 -c pytorch
conda install cudnn
克隆项目
git clone https://github.com/davrempe/humor.git
安装项目依赖
pip install -r requirements.txt
外部依赖配置
humor/body_models/ 目录下进行配置
SMPL+H
To install the body model:
- Create an account on the project page
- Go to the
Downloadspage and download the "Extended SMPL+H model (used in AMASS)". Place the downloadedsmplh.tar.xzin this directory. - Extract downloaded model to new directory
mkdir smplh && tar -xf smplh.tar.xz -C smplh. The model will be read in from here automatically when running this codebase.
Note if you decide to install the body model somewhere else, please update SMPLH_PATH in this file.
VPoser
To install the pose prior:
- Create an account on the project page
- Go to the
Downloadpage and under "VPoser: Variational Human Pose Prior" click on "Download VPoser v1.0 - CVPR'19" (note it's important to download v1.0 and not v2.0 which is not supported and will not work) - Copy the zip file to this directory, and unzip with
unzip vposer_v1_0.zip
If you're left with a directory called vposer_v1_0 in the current directory, then it's been successfully installed. The --vposer argument in run_fitting.py by default points to this directory.
编译Caffe源码
安装依赖
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler libatlas-base-dev
sudo apt-get install python-dev python-pip gfortran
克隆与配置
git clone https://github.com/BVLC/caffe
cd caffe
# 不切换到这个版本的caffe在后面openpose运行时会发生错误
git checkout f019d0dfe86f49d1140961f8c7dec22130c83154
cp Makefile.config.example Makefile.config
vim Makefile.config
先修改Makefile.config文件
# 查看系统opencv版本
pkg-config opencv --modversion
针对makefile.config
1。如果需要使用cudnn,把注释去掉。
USE_CUDNN := 1
2。如果使用opencv版本为3, 把注释去掉。【主要】
OPENCV_VERSION := 3
3。根据cuda版本号,添加注释。比如我的是cuda10>cuda9,则删掉20,21。【主要】
# 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 >= 9.0, comment the *_20 and *_21 lines for compatibility.
CUDA_ARCH :=
#-gencode arch=compute_20,code=sm_20 \
#-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
4。把INCLUDE_DIRS、LIBRARY_DIR用以下两行代码进行替换,其实就是添加了hdf5的路径。【主要】
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
5。把PYTHON_INCLUDE和PYTHON_LIB替换成自己使用的虚拟环境中的路径。【主要】
PYTHON_INCLUDE := /home/junwei/anaconda3/envs/humor/include/python3.7m \
/home/junwei/anaconda3/envs/humor/lib/python3.7/site-packages/numpy/core/include
PYTHON_LIB := /home/junwei/anaconda3/envs/humor/lib
修改makefile文件
vim Makefile
1。更改makefile里的地方。Attention,PLEASE!
把181行改成如下:也就是解决hdf5找不到的问题。【主要】
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
【重要】在后续编译OpenPose时报错:fatal error: caffe/proto/caffe.pb.h: No such file or directory
进入caffe所在路径
mkdir include/caffe/proto
protoc ./src/caffe/proto/caffe.proto --cpp_out=.
mv ./src/caffe/proto/caffe.pb.h ./include/caffe/proto/
编译
make clean
# 它会根据Makefile.config的配置进行编译
make all -j`nproc`
【问题】遇到CUDA版本冲突问题:undefined reference to `__cudaPushCallConfiguration'
【原因】cuda toolkit版本冲突。
查看libcaffe.so的cuda链接库都是什么。
ldd build/lib/libcaffe.so | grep cudart
查看电脑中有哪些libcudart.so
locate libcudart.so
重新编辑Makefile.config
在LIBRARY_DIRS后面再添加需要的库路径【重要】
OpenPose配置
mkdir external
cd external
git clone https://github.com/CMU-Perceptual-Computing-Lab/openpose
cd openpose
git submodule update --init --recursive --remote
安装依赖
sudo apt install cmake build-essential
sudo apt-get install libopencv-dev
执行编译
mkdir build
cd build
编译
cmake-gui(可被x11转发)
安装cmake-gui
sudo apt install cmake-qt-gu
在build目录下
cmake-gui ..
在可视化界面,取消BUILD_CAFFE,选择BUILD_PYTHON,同时增加两项
# 第一项
Caffe_INCLUDE_DIRS
PATH
/home/junwei/zjw/caffe/include
# 第二项
Caffe_LIBS
FILEPATH
/home/junwei/zjw/caffe/build/lib/libcaffe.so
点击生成
# 命令行执行
make -j`nproc`
命令行
编译
# 先指定编译的caffe源码路径
somewhere=/home/junwei/zjw/caffe
cmake -DBUILD_PYTHON=ON -DBUILD_CAFFE=OFF -DCaffe_INCLUDE_DIRS=$somewhere/include -DCaffe_LIBS=$somewhere/build/lib/libcaffe.so ..
make -j`nproc`
下载模型权重文件
bash get_ckpt.sh
运行
python humor/fitting/run_fitting.py @./configs/fit_rgb_demo_no_split.cfg
可视化
python humor/fitting/viz_fitting_rgb.py --results ./out/rgb_demo_no_split/results_out --out ./out/rgb_demo_no_split/viz_out --viz-prior-frame
执行时如果遇到pyglet.gl.ContextException: Require GLX_ARB_create_context extension to create OpenGL 3 contexts 错误,在执行前加上 PYOPENGL_PLATFORM="egl" 即可
PYOPENGL_PLATFORM="egl" python humor/fitting/viz_fitting_rgb.py --results ./out/rgb_demo_no_split/results_out --out ./out/rgb_demo_no_split/viz_out --viz-prior-frame
或者在代码里添加
import os
os.environ["PYOPENGL_PLATFORM"] = "egl"

浙公网安备 33010602011771号