Ubuntu16.04从源码安装DensePose
Installing DensePose
DensePose官网 http://densepose.org/
DensePose代码 https://github.com/facebookresearch/Densepose
DensePose安装系统要求:有NVIDIA GPU的Linux系统,满足这一条件便可按照下面的步骤安装。
安装Anaconda
官网下载Linux版的Anaconda3,运行bash Anaconda3-5.2.0-Linux-x86_64.sh
。
安装caffe2(pytorch)
创建caffe2的conda环境
conda create -n densepose python=2.7
进入新创建的环境
source activate densepose
安装一些需要的库
(densepose)$ conda install -y future gflags leveldb mkl mkl-include numpy opencv protobuf
(densepose)$ conda install flask graphviz hypothesis jupyter matplotlib pydot pyyaml requests scikit-image scipy setuptools tornado
下载pytorch及其依赖的第三方库
# git clone --recursive https://github.com/pytorch/pytorch.git
(densepose)$ git clone -b v0.4.1 --recursive https://github.com/pytorch/pytorch.git # 下载v0.4.1分支代码
(densepose)$ cd pytorch
(densepose)$ git submodule update --init
编译并安装
(densepose)$ rm -rf build && mkdir build && cd build
(densepose)$ cmake -DCMAKE_PREFIX_PATH=~/anaconda3/envs/densepose -DCMAKE_INSTALL_PREFIX=~/anaconda3/envs/densepose -DUSE_NATIVE_ARCH=ON ..
(densepose)$ make -j32 install
测试是否安装成功
# To check if Caffe2 build was successful
(densepose)$ python2 -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
# 输出Success即安装成功,否则失败
# To check if Caffe2 GPU build was successful
(densepose)$ python2 -c 'from caffe2.python import workspace; print(workspace.NumCudaDevices())'
# 输出8或者其他,表示显卡个数
安装cocoapi
# COCOAPI=/path/to/clone/cocoapi
(densepose)$ git clone https://github.com/cocodataset/cocoapi.git $COCOAPI
(densepose)$ cd $COCOAPI/PythonAPI
# Install into global site-packages
(densepose)$ make install
# Alternatively, if you do not have permissions or prefer
# not to install the COCO API into global site-packages
(densepose)$ python2 setup.py install --user
安装densepose
安装densepose
(densepose)$ mkdir $DENSEPOSE_DIR && cd $DENSEPOSE_DIR
(densepose)$ git clone https://github.com/facebookresearch/densepose
(densepose)$ cd densepose
(densepose)$ pip install -r requirements.txt # install Python dependencies
(densepose)$ make # set up python modules
(densepose)$ python2 detectron/tests/test_spatial_narrow_as_op.py # check that Detectron tests pass
(densepose)$ make ops # Build the custom operators library
(densepose)$ python2 detectron/tests/test_zero_even_op.py # check that the custom operator tests pass
下载densepose数据:
(densepose)$ cd DensePoseData
(densepose)$ bash get_densepose_uv.sh
如果需要训练,下载DensePose-COCO数据集:
(densepose)$ bash get_DensePose_COCO.sh
如果评价(evaluation),还需下载其他需要的文件:
(densepose)$ bash get_eval_data.sh
Inference with Pretrained Models
首先从这里下载与DensePose_ResNet101_FPN_s1x-e2e.yaml
相匹配的训练好的模型,并放在weights文件夹下,然后执行下面命令:
(densepose)$ python2 tools/infer_simple.py \
--cfg configs/DensePose_ResNet101_FPN_s1x-e2e.yaml \
--output-dir DensePoseData/infer_out/ \
--image-ext jpg \
--wts weights/DensePose_ResNet101_FPN_s1x-e2e.pkl \
DensePoseData/demo_data/demo_im.jpg