cuda 9.0 安装torch 0.4_学习open-mmlab之mmskeleton安装

@misc{mmskeleton2019,
author = {Sijie Yan, Yuanjun Xiong, Jingbo Wang, Dahua Lin},
title = {MMSkeleton},
howpublished = {url{https://github.com/open-mmlab/mmskeleton}},
year = {2019}
}

mmskeleton官方安装手册跳过了一些步骤,在这里记录一下我的实战经验,避免再次踩雷。

  1. 准备

简介 A OpenMMLAB toolbox for human pose estimation, skeleton-based action recognition, and action synthesis.

代码地址

https://github.com/open-mmlab/mmskeleton​github.com

安装手册

open-mmlab/mmskeleton​github.com
cuda 9.0 安装torch 0.4_学习open-mmlab之mmskeleton安装_第1张图片

2. 安装

a. [Optional] Create a conda virtual environment and activate it:

#创建虚拟环境,需要等待10分钟左右,期间没有提示,参数-y表示“Do not ask for confirmation.”
conda create -n open-mmlab python=3.7 -y
#启动虚拟环境
conda activate open-mmlab

b. Install PyTorch and torchvision (CUDA is required):

#下载 CUDA 10.0, 大小2GB
#下载地址 https://developer.nvidia.com/cuda-10.0-download-archive
#安装 CUDA 10.0
sudo sh cuda_10.0.130_410.48_linux.run
#配置环境变量
export PATH=$PATH:/usr/local/cuda-10.0/bin
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64
export CUDA_HOME=/usr/local/cuda-10.0
#使环境配置生效
source ~/.bashrc
#检查一下是否配置成功
echo $PATH
echo $LD_LIBRARY_PATH
echo $CUDA_HOME
#确认一下nvcc版本是否一致, 不一致的话把cuda-10.0的路径放在PATH的最前面
nvcc --version
#此时会自动退出虚拟环境,需要重新启动一下
conda activate open-mmlab

#先换成国内镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
#设置搜索时显示通道地址
conda config --set show_channel_urls yes
#安装CUDA 10.0对应的PyTorch及torchvision(去掉了官方里的-c pytorch, 参数-c用于指定源)
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 

c. Clone mmskeleton from github:

#下载代码到本地
git clone https://github.com/open-mmlab/mmskeleton.git
cd mmskeleton

d. Install mmskeleton:

#需要先安装mmcv,注意版本必须是0.4.3,指定国内镜像会快很多
pip install mmcv==0.4.3 -i https://pypi.tuna.tsinghua.edu.cn/simple
#安装mmskeleton,顺利通过
python setup.py develop

e. Install nms for person estimation:

cd mmskeleton/ops/nms/
#安装Cython
pip install Cython
#安装nms
python setup_linux.py develop
cd ../../../

f. [Optional] Install mmdetection for person detection:

#先安装需要的各种包,可以参考https://github.com/open-mmlab/mmdetection/blob/master/docs/install.md
pip install matplotlib
pip install terminaltables
pip install pycocotools
pip install imagecorruptions
pip install albumentations>=0.3.2
#安装mmdet,顺利通过
python setup.py develop --mmdet
#mmdet如果没有安装成功的话,无法运行python mmskl.py pose_demo, 
#但是可以运行mmskl configs/recognition/st_gcn_aaai18/$DATASET/test.yaml

g. To verify that mmskeleton and mmdetection installed correctly, use:

#需要用到检人和检点两个模型,可以提前在外网下载好放到 /yourpath/.cache/torch/checkpoints/
#cascade_rcnn_r50_fpn_20e_20181123-db483a09.pth
#pose_hrnet_w32_256x192-76ea353b.pth
#测试 mmskeleton 和 mmdetection 的安装是否都成功了
python mmskl.py pose_demo [--gpus $GPUS]
# or "python mmskl.py pose_demo_HD [--gpus $GPUS]" for a higher accuracy

[Opt]修改pytorch下载预训练模型的默认保存路径,找到torch/hub.py,如

/root/anaconda3/pkgs/pytorch-1.2.0-py3.7_cuda10.0.130_cudnn7.6.2_0/lib/python3.7/site-packages/torch/hub.py

修改 model_dir=None为自定义路径

def load_state_dict_from_url(url, model_dir='/example/TORCHCACHE/checkpoints/', map_location=None, progress=True):

h. 测试结果保存在./workdir/pose_demo/skateboarding.mp4

cuda 9.0 安装torch 0.4_学习open-mmlab之mmskeleton安装_第2张图片

i. ST-GCN测试(Spatial Temporal Graph Convolutional Networks for Skeleton-Based Action Recognition Sijie Yan, Yuanjun Xiong and Dahua Lin, AAAI 2018. [Arxiv Preprint])

#需要用到1个模型,可以提前在外网下载好放到 /yourpath/.cache/torch/checkpoint
#st_gcn.kinetics-6fa43f73.pth
#修改test.yaml里的数据路径
    #data_path: /yourpath/data/Kinetics/kinetics-skeleton/val_data.npy
    #label_path: /yourpath/data/Kinetics/kinetics-skeleton/val_label.pkl
#运行测试
mmskl configs/recognition/st_gcn_aaai18/kinetics-skeleton/test.yaml
#输出信息
#Load configuration information from configs/recognition/st_gcn_aaai18/kinetics-skeleton/test.yaml
#[>>>>>>>>>>>>>>>>>>>>>>>] 19796/19796, 140.0 task/s, elapsed: 141s, ETA:     0s
#Top 1: 31.60%
#Top 5: 53.68%

完成!

你可能感兴趣的:(cuda,9.0,安装torch,0.4,g,hub无法安装,open,source,3d,map,torchvision安装)