Densepose安装教程

densepose的安装过程
可参考https://blog.csdn.net/FatMigo/article/details/88648107
https://github.com/facebookresearch/DensePose

densepose-RCNN系统是在detectron框架下实现的
需要硬件基础 Nvidia GPU、ubuntu16.04、Linux、python2,CUDA 8.0和cudnn7.0
需要软件基础 Caffe2 cocoapi

1、首先,在anoconda2下建立虚拟环境,
conda create -n ### python=2.7
2、安装caffe2(caffe2已经被集成到torch中,或者pytorch)
下载torch-1.0.1.post2-cp27-cp27mu-linux_x86_64.whl
pip install torch-1.0.1.post2-cp27-cp27mu-linux_x86_64.whl
pytorch安装命令合集
https://www.pytorchtutorial.com/pytorch-installation-commands/
注意:安装torch的版本注意要和cuda和cudnn的版本匹配
验证:
# To check if Caffe2 build was successful
python2 -c ‘from caffe2.python import core’ 2>/dev/null && echo “Success” || echo “Failure”

# To check if Caffe2 GPU build was successful
# This must print a number > 0 in order to use Detectron

python2 -c ‘from caffe2.python import workspace; print(workspace.NumCudaDevices())’

出现success,则验证成功。
3、安装detectron
下载
git clone https://github.com/facebookresearch/detectron
安装依赖
pip install -r $DETECTRON/requirements.txt
安装
cd $DETECTRON && make
测试是否成功
python $DETECTRON/detectron/tests/test_spatial_narrow_as_op.py

4、安装cocoAPI
定位下载的路径
git clone https://github.com/cocodataset/cocoapi.git $COCOAPI
cd $COCOAPI/PythonAPI
安装
# Install into global site-packages
make install
# Alternatively, if you do not have permissions or prefer
# not to install the COCO API into global site-packages
*
python2 setup.py install --user

5、安装densepose
下载
# DENSEPOSE=/path/to/clone/densepose
git clone https://github.com/facebookresearch/densepose $DENSEPOSE
安装python依赖
pip install -r $DENSEPOSE/requirements.txt

cd $DENSEPOSE && make

测试detectron
python2 $DENSEPOSE/detectron/tests/test_spatial_narrow_as_op.py

#Build the custom operators library:
cd $DENSEPOSE && make ops
注意在这步往往会出错,需要更改densepose//CMakeListS.txt中的内容,具体设置参考
比如:set(Caffe2_DIR “/home/yue/anaconda2/envs/torch/share/cmake/Caffe2”)
如出make ops错误也可参考:https://blog.csdn.net/FatMigo/article/details/88648107

#Check that the custom operator tests pass:
python2 $DENSEPOSE/detectron/tests/test_zero_even_op.py
如果出错,无法通过,也可以使用5、6步骤

5、下载数据:
cd $DENSEPOSE/DensePoseData
bash get_densepose_uv.sh
若要训练,下载densePose-coco数据集
bash get_DensePose_COCO.sh
验证,得到必要的文件
bash get_eval_data.sh

6、运行DensePoseData
python2 tools/infer_simple.py
–cfg configs/DensePose_ResNet101_FPN_s1x-e2e.yaml
–output-dir DensePoseData/infer_out/
–image-ext jpg
–wts https://dl.fbaipublicfiles.com/densepose/DensePose_ResNet101_FPN_s1x-e2e.pkl
DensePoseData/demo_data/demo_im.jpg

7、下载densePose-coco数据集
#Create a symlink for the COCO dataset in your datasets/data folder.
ln -s /path/to/coco $DENSEPOSE/detectron/datasets/data/coco

#Create symlinks for the DensePose-COCO annotations
ln -s $DENSEPOSE/DensePoseData/DensePose_COCO/densepose_coco_2014_minival.json $DENSEPOSE/detectron/datasets/data/coco/annotations/
ln -s $DENSEPOSE/DensePoseData/DensePose_COCO/densepose_coco_2014_train.json $DENSEPOSE/detectron/datasets/data/coco/annotations/
ln -s $DENSEPOSE/DensePoseData/DensePose_COCO/densepose_coco_2014_valminusminival.json $DENSEPOSE/detectron/datasets/data/coco/annotations/

##Your local COCO dataset copy at /path/to/coco should have the following directory structure:

coco
|_ coco_train2014
| |_ .jpg
| |_ …
| |_ .jpg
|_ coco_val2014
|_ …
|_ annotations
|_ instances_train2014.json
|_ …

8、测试预训练模型
python2 tools/test_net.py
–cfg configs/DensePose_ResNet101_FPN_s1x-e2e.yaml
TEST.WEIGHTS https://dl.fbaipublicfiles.com/densepose/DensePose_ResNet101_FPN_s1x-e2e.pkl
NUM_GPUS 1

9、训练模型
python2 tools/train_net.py
–cfg configs/DensePose_ResNet50_FPN_single_GPU.yaml
OUTPUT_DIR /tmp/detectron-output

###############################################################################

cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)

# set caffe2 cmake path manually
set(Caffe2_DIR "/home/yue/anaconda2/envs/torch/share/cmake/Caffe2")
# set cuDNN path
set(CUDNN_INCLUDE_DIR "/home/yue/.local/share/Trash/files/cuda (2)/include")
set(CUDNN_LIBRARY "/home/yue/.local/share/Trash/files/cuda (2)/lib64/libcudnn.so")
#include_directories("/path/to/anaconda3/envs/py37/include")
include_directories("/home/yue/anaconda2/include")
# add static protobuf library
add_library(libprotobuf STATIC IMPORTED)
set(PROTOBUF_LIB "/home/yue/anaconda2/lib/libprotobuf.a")
set_property(TARGET libprotobuf PROPERTY IMPORTED_LOCATION "${PROTOBUF_LIB}")

# Find the Caffe2 package.
# Caffe2 exports the required targets, so find_package should work for
# the standard Caffe2 installation. If you encounter problems with finding
# the Caffe2 package, make sure you have run `make install` when installing
# Caffe2 (`make install` populates your share/cmake/Caffe2).
find_package(Caffe2 REQUIRED)
include_directories(${CAFFE2_INCLUDE_DIRS})

if (${CAFFE2_VERSION} VERSION_LESS 0.8.2)
  # Pre-0.8.2 caffe2 does not have proper interface libraries set up, so we
  # will rely on the old path.
  message(WARNING
      "You are using an older version of Caffe2 (version " ${CAFFE2_VERSION}
      "). Please consider moving to a newer version.")
  include(cmake/legacy/legacymake.cmake)
  return()
endif()

# Add compiler flags.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -fPIC -Wno-narrowing")

# Print configuration summary.
include(cmake/Summary.cmake)
detectron_print_config_summary()

# Collect custom ops sources.
file(GLOB CUSTOM_OPS_CPU_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/detectron/ops/*.cc)
file(GLOB CUSTOM_OPS_GPU_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/detectron/ops/*.cu)

# Install custom CPU ops lib.
add_library(
    caffe2_detectron_custom_ops SHARED
    ${CUSTOM_OPS_CPU_SRCS})

target_include_directories(
    caffe2_detectron_custom_ops PRIVATE
    ${CAFFE2_INCLUDE_DIRS})

target_link_libraries(caffe2_detectron_custom_ops caffe2_library libprotobuf)
install(TARGETS caffe2_detectron_custom_ops DESTINATION lib)

# Install custom GPU ops lib, if gpu is present.
if (CAFFE2_USE_CUDA OR CAFFE2_FOUND_CUDA)
  # Additional -I prefix is required for CMake versions before commit (< 3.7):
  # https://github.com/Kitware/CMake/commit/7ded655f7ba82ea72a82d0555449f2df5ef38594
  list(APPEND CUDA_INCLUDE_DIRS -I${CAFFE2_INCLUDE_DIRS})
  CUDA_ADD_LIBRARY(
      caffe2_detectron_custom_ops_gpu SHARED
      ${CUSTOM_OPS_CPU_SRCS}
      ${CUSTOM_OPS_GPU_SRCS})

  target_link_libraries(caffe2_detectron_custom_ops_gpu caffe2_gpu_library libprotobuf)
  install(TARGETS caffe2_detectron_custom_ops_gpu DESTINATION lib)
endif()

##########################################################################################################################

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值