安装环境
环境信息
OpenI 启智集群
CPU:Intel® Xeon® Gold 6248 CPU @ 2.50GHz
内存:32G
GPU:NVIDIA Tesla T4 16G
CUDA:11.0
Python:Python 3.7
设置国内源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
安装Pytorch
pip3 install torch torchvision torchaudio
安装MMCV
用MIM安装MMCV
pip install -U openmim
mim install mmengine
mim install 'mmcv==2.0.0rc3'
mim install "mmdet>=3.0.0rc6"
安装其他工具包
pip install opencv-python pillow matplotlib seaborn tqdm pycocotools
安装MMPose
下载 MMPose
git clone https://github.com/open-mmlab/mmpose.git -b tutorial2023
安装 MMPose
cd mmpose
mim install -e .
下载预训练模型权重文件和视频素材
import os
# 创建 checkpoint 文件夹,用于存放预训练模型权重文件
os.mkdir('checkpoint')
# 创建 outputs 文件夹,用于存放预测结果
os.mkdir('outputs')
# 创建 data 文件夹,用于存放图片和视频素材
os.mkdir('data')
os.mkdir('data/test')
# 多人图片,来源:https://www.pexels.com/zh-cn/photo/2168292/
!wget https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20220610-mmpose/images/multi-person.jpeg -O data/test/multi-person.jpeg
# 单人视频-唱跳篮球
!wget https://zihao-openmmlab.obs.myhuaweicloud.com/20220610-mmpose/videos/cxk.mp4 -P data/test
# 妈妈和女儿跳舞,经微信压缩
!wget https://zihao-openmmlab.obs.myhuaweicloud.com/20220610-mmpose/videos/mother_wx.mp4 -P data/test
# 两个女生跳舞视频,来源:https://mixkit.co/free-stock-video/two-girls-having-fun-in-a-retro-restaurant-42298/
!wget https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20220610-mmpose/videos/two-girls.mp4 -O data/test/two-girls.mp4
检查安装成功
# 检查 Pytorch
import torch, torchvision
print('Pytorch 版本', torch.__version__)
print('CUDA 是否可用',torch.cuda.is_available())
运行结果
Pytorch 版本 2.0.1+cu117
CUDA 是否可用 True
# 检查 mmcv
import mmcv
from mmcv.ops import get_compiling_cuda_version, get_compiler_version
print('MMCV版本', mmcv.__version__)
print('CUDA版本', get_compiling_cuda_version())
print('编译器版本', get_compiler_version())
运行结果:
MMCV版本 2.0.0
CUDA版本 11.7
编译器版本 GCC 9.3
# 检查 mmpose
import mmpose
print('mmpose版本', mmpose.__version__)
运行结果:
mmpose版本 1.0.0
安装MMDetection
下载 MMDetection
git clone https://github.com/open-mmlab/mmdetection.git -b 3.x
安装 MMDetection
cd mmdetection
pip install -v -e .
下载预训练模型权重文件和视频素材
import os
# 创建 checkpoint 文件夹,用于存放预训练模型权重文件
os.mkdir('checkpoint')
# 创建 outputs 文件夹,用于存放预测结果
os.mkdir('outputs')
# 创建 data 文件夹,用于存放图片和视频素材
os.mkdir('data')
检查安装成功
# 检查 Pytorch
import torch, torchvision
print('Pytorch 版本', torch.__version__)
print('CUDA 是否可用',torch.cuda.is_available())
运行结果:
Pytorch 版本 2.0.1+cu117
CUDA 是否可用 True
# 检查 mmcv
import mmcv
from mmcv.ops import get_compiling_cuda_version, get_compiler_version
print('MMCV版本', mmcv.__version__)
print('CUDA版本', get_compiling_cuda_version())
print('编译器版本', get_compiler_version())
运行结果:
MMCV版本 2.0.0
CUDA版本 11.7
编译器版本 GCC 9.3
# 检查 mmdet
import mmdet
print('mmdetection版本', mmdet.__version__)
运行结果:
mmdetection版本 3.0.0
MMPose预训练模型预测-命令行
数据集目录
data/test/multi-person.jpeg
data/test/cxk.mp4
data/test/two_dancers.mp4
模型库预训练模型
目标检测模型
MMDetection模型库:
https://github.com/open-mmlab/mmdetection/blob/master/docs/en/model_zoo.md
demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py
https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
MMPose人体姿态估计模型
configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-256x192.py
https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w32_coco_256x192-c78dce93_20200708.pth
RTMPose人体姿态估计模型
RTMPose主页:https://github.com/open-mmlab/mmpose/tree/dev-1.x/projects/rtmpose
RTMPose-S
projects/rtmpose/rtmpose/body_2d_keypoint/rtmpose-s_8xb256-420e_coco-256x192.py
https://download.openmmlab.com/mmpose/v1/projects/rtmpose/rtmpose-s_simcc-aic-coco_pt-aic-coco_420e-256x192-fcb2599b_20230126.pth
RTMPose-L
projects/rtmpose/rtmpose/body_2d_keypoint/rtmpose-l_8xb256-420e_coco-384x288.py
https://download.openmmlab.com/mmpose/v1/projects/rtmpose/rtmpose-l_simcc-aic-coco_pt-aic-coco_420e-384x288-97d6cb0f_20230228.pth
预测单张图像
python demo/topdown_demo_with_mmdet.py \
demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py \
https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-256x192.py \
https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w32_coco_256x192-c78dce93_20200708.pth \
--input data/test/multi-person.jpeg \
--output-root outputs/B1_HRNet_1 \
--device cuda:0 \
--bbox-thr 0.5 \
--kpt-thr 0.2 \
--nms-thr 0.3 \
--radius 8 \
--thickness 4 \
--draw-bbox \
--draw-heatmap \
--show-kpt-idx
# RTMPose
python demo/topdown_demo_with_mmdet.py \
demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py \
https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
projects/rtmpose/rtmpose/body_2d_keypoint/rtmpose-s_8xb256-420e_coco-256x192.py \
https://download.openmmlab.com/mmpose/v1/projects/rtmpose/rtmpose-s_simcc-aic-coco_pt-aic-coco_420e-256x192-fcb2599b_20230126.pth \
--input data/test/multi-person.jpeg \
--output-root outputs/B1_RTM_1 \
--device cuda:0 \
--bbox-thr 0.5 \
--kpt-thr 0.5 \
--nms-thr 0.3 \
--radius 8 \
--thickness 4 \
--draw-bbox \
--draw-heatmap \
--show-kpt-idx
预测视频
python demo/topdown_demo_with_mmdet.py \
demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py \
https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
configs/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-256x192.py \
https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w32_coco_256x192-c78dce93_20200708.pth \
--input data/test/mother_wx.mp4 \
--output-root outputs/B1_HRNet_2 \
--device cuda:0 \
--bbox-thr 0.5 \
--kpt-thr 0.2 \
--nms-thr 0.3 \
--radius 5 \
--thickness 2 \
--draw-bbox \
--draw-heatmap \
--show-kpt-idx
python demo/topdown_demo_with_mmdet.py \
demo/mmdetection_cfg/faster_rcnn_r50_fpn_coco.py \
https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
projects/rtmpose/rtmpose/body_2d_keypoint/rtmpose-s_8xb256-420e_coco-256x192.py \
https://download.openmmlab.com/mmpose/v1/projects/rtmpose/rtmpose-s_simcc-aic-coco_pt-aic-coco_420e-256x192-fcb2599b_20230126.pth \
--input data/test/mother_wx.mp4 \
--output-root outputs/B1_RTM_2 \
--device cuda:0 \
--bbox-thr 0.5 \
--kpt-thr 0.5 \
--nms-thr 0.3 \
--radius 5 \
--thickness 2 \
--draw-bbox \
--draw-heatmap \
--show-kpt-idx
MMPose预训练模型预测-Python API
https://github.com/JeffDing/mmlabcamp/blob/main/第二期/MMPose预训练模型预测-Python API.ipynb
三角板目标检测
https://github.com/JeffDing/mmlabcamp/blob/main/第二期/三角板目标检测.ipynb
MMPose、RTMPose三角板关键点检测
安装albumentations
pip install albumentations
https://github.com/JeffDing/mmlabcamp/blob/main/第二期/三角板关键点检测.ipynb
三角板关键点检测预测-命令行
cd mmpose
python demo/topdown_demo_with_mmdet.py \
data/faster_r_cnn_triangle.py \
checkpoint/faster_r_cnn_triangle_epoch_50_202305120846-76d9dde3.pth \
data/rtmpose-s-triangle.py \
checkpoint/rtmpose-s-triangle-300-32642023_20230524.pth \
--input data/test_triangle/triangle_4.jpg \
--output-root outputs/G2_Fasterrcnn-RTMPose \
--device cuda:0 \
--bbox-thr 0.5 \
--kpt-thr 0.5 \
--nms-thr 0.3 \
--radius 36 \
--thickness 30 \
--draw-bbox \
--draw-heatmap \
--show-kpt-idx
python demo/topdown_demo_with_mmdet.py \
data/rtmdet_tiny_triangle.py \
checkpoint/rtmdet_tiny_triangle_epoch_200_202305120847-3cd02a8f.pth \
data/rtmpose-s-triangle.py \
checkpoint/rtmpose-s-triangle-300-32642023_20230524.pth \
--input data/test_triangle/triangle_4.jpg \
--output-root outputs/G2_RTMDet-RTMPose \
--device cuda:0 \
--bbox-thr 0.5 \
--kpt-thr 0.5 \
--nms-thr 0.3 \
--radius 36 \
--thickness 30 \
--draw-bbox \
--draw-heatmap \
--show-kpt-idx
关键点检测预测
python demo/topdown_demo_with_mmdet.py \
data/rtmdet_tiny_triangle.py \
checkpoint/rtmdet_tiny_triangle_epoch_200_202305120847-3cd02a8f.pth \
data/rtmpose-s-triangle.py \
checkpoint/rtmpose-s-triangle-300-32642023_20230524.pth \
--input data/test_triangle/triangle_9.mp4 \
--output-root outputs/G2_Video \
--device cuda:0 \
--bbox-thr 0.5 \
--kpt-thr 0.5 \
--nms-thr 0.3 \
--radius 16 \
--thickness 10 \
--draw-bbox \
--draw-heatmap \
--show-kpt-idx