MMPose安装
依赖环境
1.创建虚拟环境并激活
conda create --name openmmlab python=3.8 -y
conda activate openmmlab
2.安装pytorch
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
报错:
InvalidArchiveError(‘Error with archive D:\Anaconda3\pkgs\pytorch-2.0.1-py3.8_cuda11.7_cudnn8_0.tar.bz2. You probably need to delete and re-download or re-create this file. Message from libarchive was:\n\nCould not unlink’)
解决方法:
找到anaconda3的文件夹,右键选择属性
->安全
->编辑
->完全控制
勾选允许
重新执行上述命令即可
3.使用MIM安装MMEngine和MMCV
安装MIM
pip install -U openmim
安装MMEngine和MMCV
mim install mmengine
mim install "mmcv>=2.0.0"
MMPose 中的一些推理示例脚本需要使用 MMDetection (mmdet) 检测人体,所以这里也先安装下
mim install "mmdet>=3.0.0"
报错:
Building wheels for collected packages: pycocotools
Building wheel for pycocotools (pyproject.toml) … error
error: subprocess-exited-with-error× Building wheel for pycocotools (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [16 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-38
creating build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\coco.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\cocoeval.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools\mask.py -> build\lib.win-amd64-cpython-38\pycocotools
copying pycocotools_init_.py -> build\lib.win-amd64-cpython-38\pycocotools
running build_ext
cythoning pycocotools/_mask.pyx to pycocotools_mask.c
building ‘pycocotools._mask’ extension
C:\Users\Snakewood\AppData\Local\Temp\pip-build-env-8xb8w4ct\overlay\Lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive ‘language_level’ not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\Snakewood\AppData\Local\Temp\pip-install-9g1ajohv\pycocotools_0428fc1e132847e7bf9f28e2e727a294\pycocotools_mask.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pycocotools
Failed to build pycocotools
ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml-based projects
可以看到是在编译pycocotools时报错,解决方法:
进入网址:https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/,下载vs_BuildTools,下载完成后点击使用C++的桌面开发
进行安装,安装完成后重新执行上述命令,安装成功。
4.安装MMPose
git拉取mmpose源码,并安装依赖包
git clone https://github.com/open-mmlab/mmpose.git
cd mmpose
pip install -r requirements.txt
pip install -v -e .
# "-v" 表示输出更多安装相关的信息
# "-e" 表示以可编辑形式安装,这样可以在不重新安装的情况下,让本地修改直接生效
MIM安装
mim install "mmpose>=1.0.0"
5.验证安装
下载配置文件和模型权重文件
mim download mmpose --config td-hm_hrnet-w48_8xb32-210e_coco-256x192 --dest .
执行完上面的命令后,在当前目录下就可以找到两个文件td-hm_hrnet-w48_8xb32-210e_coco-256x192.py
和td-hm_hrnet-w48_8xb32-210e_coco-256x192-0e67c616_20220913.pth
(这里下载的模型权重文件,文件名可能会有一点点不同),.py
文件是配置文件.pth
文件是模型权重文件
验证推理
python demo/image_demo.py \
# 指明要推理的图片
tests/data/coco/000000000785.jpg \
# 配置文件
td-hm_hrnet-w48_8xb32-210e_coco-256x192.py \
# 模型权重文件
hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth \
# 输出路径
--out-file vis_results.jpg \
--draw-heatmap
要执行推理可以直接复制下面的命令
python demo/image_demo.py tests/data/coco/000000000785.jpg td-hm_hrnet-w48_8xb32-210e_coco-256x192.py td-hm_hrnet-w48_8xb32-210e_coco-256x192-0e67c616_20220913.pth --out-file vis_results.jpg --draw-heatmap
运行结果如下:
执行推理时可用的参数列表如下:
Argument | Description |
---|---|
show | 确定图像或视频的预测结果是否应在弹出窗口中显示。 |
radius | 设置关键点半径。 |
thickness | 设置骨架(线条)粗细。 |
return_vis | 确定返回结果result 中是否应包括可视化结果列表visualization 。 |
vis_out_dir | 指定保存可视化图像的文件夹路径。如果未设置,将不会保存可视化图像。 |
return_datasample | 确定是否以PoseDataSample 的形式返回预测。 |
pred_out_dir | 指定保存预测结果predictions 的文件夹路径。如果不设置,预测结果将不会被保存。 |
out_dir | 如果指定了输出路径参数out_dir ,但未设置vis_out_dir 或pred_out_dir ,则分别将vis_out_dir 或pred_out_dir 设置为f'{out_dir}/visualization' 或f'{out_dir}/ forecasts' 。 |
2D 人体姿态topdown推理视频:
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/v1/body_2d_keypoint/topdown_heatmap/coco/td-hm_hrnet-w32_8xb64-210e_coco-256x192-81c58e40_20220909.pth --input E:\data\v\clip100.mp4 --output-root=vis_results/demo --show --draw-heatmap
2D 人体姿态bottomup推理视频:
python demo/bottomup_demo.py configs/body_2d_keypoint/dekr/coco/dekr_hrnet-w32_8xb10-140e_coco-512x512.py https://download.openmmlab.com/mmpose/v1/body_2d_keypoint/dekr/coco/dekr_hrnet-w32_8xb10-140e_coco-512x512_ac7c17bf-20221228.pth --input E:\data\v\clip100.mp4 --output-root=vis_results/demo --save-predictions
2D 人体全身姿态Top-Down:
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/wholebody_2d_keypoint/topdown_heatmap/coco-wholebody/td-hm_hrnet-w48_dark-8xb32-210e_coco-wholebody-384x288.py https://download.openmmlab.com/mmpose/top_down/hrnet/hrnet_w48_coco_wholebody_384x288_dark-f5726563_20200918.pth --input E:\data\v\clip100.mp4 --output-root=vis_results/demo
参考资料
- https://mmpose.readthedocs.io/zh_CN/latest/installation.html
- https://github.com/open-mmlab/mim/blob/main/docs/en/installation.md
- 安装python包的时候文件夹权限报错: InvalidArchiveError(‘Error with archive D:\anaconda\pkgs\openssl-1.1.1j-h8ff
- python pip安装出错合集
- https://mmpose.readthedocs.io/zh_CN/latest/user_guides/inference.html