anconda环境搭建
# $MMPOSE表示项目(从githubu下载)的根目录
cd $MMPOSE
conda create -n 07.mmpose-pytorch1.5-py3.6 -y python=3.6
conda activate 07.mmpose-pytorch1.5-py3.6
# 请根据自己的环境搭建合适的 pytorch 环境
pip install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
pip install json_tricks opencv-python -i https://pypi.douban.com/simple
pip install -r requirements.txt
pip install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"
python setup.py develop
数据模型摆放
数据下载
更加详细的说,对于 coco 文件夹,我们应该如下摆放:
执行如下指令:
# $MMPOSE表示项目(从githubu下载)的根目录
cd $MMPOSE
# 创建软连接。注意/work/2.ChiPeak/5.OpenMMLab/1.mmaction2/Dataset需要替换成你本人Dataset路径
ln -s /work/2.ChiPeak/5.OpenMMLab/1.mmaction2/Dataset data
模型下载
通过如下链接:https://mmpose.readthedocs.io/en/latest/model_zoo.html 下载模型(Bottom Up Models):
下载之后放置到 MMPOSE/checkpoints(自行创建) 文件夹下面。
模型测试
查看如下指令:
https://github.com/open-mmlab/mmpose/blob/master/docs/getting_started.md 执行如下指令:
bash ./tools/dist_test.sh configs/bottom_up/mobilenet/coco/mobilenetv2_coco_512x512.py checkpoints/mobilenetv2_coco_512x512-4d96e309_20200816.pth 1 --eval mAP
也可以执行命令
python tools/test.py configs/bottom_up/mobilenet/coco/mobilenetv2_coco_512x512.py checkpoints/mobilenetv2_coco_512x512-4d96e309_20200816.pth --eval mAP
本人打印如下:
模型训练
使用单机器,单gpu训练:
python tools/train.py configs/bottom_up/mobilenet/coco/mobilenetv2_coco_512x512.py
报错:
File "/my_app/anaconda3/envs/07.mmpose-pytorch1.5-py3.6/lib/python3.6/site-packages/mmcv/runner/checkpoint.py", line 199, in _load_checkpoint
raise IOError(f'{filename} is not a checkpoint file')
OSError: models/pytorch/imagenet/mobilenet_v2_batch256_20200708-3b2dc3af.pth is not a checkpoint file
修改configs/bottom_up/mobilenet/coco/mobilenetv2_coco_512x512.py(注释部分表示为为源码) :
# model settings
model = dict(
type='BottomUp',
#pretrained='models/pytorch/imagenet/'
#'mobilenet_v2_batch256_20200708-3b2dc3af.pth',
pretrained=None,
backbone=dict(type='MobileNetV2', widen_factor=1., out_indices=(7, )),
然后重新运行即可,主要是不加载预训练模型,如果想加载预训练模型,去官网下载即可。
报错:
training, momentum, eps, torch.backends.cudnn.enabled
RuntimeError: CUDA out of memory. Tried to allocate 36.00 MiB (GPU 0; 5.81 GiB total capacity; 5.00 GiB already allocated; 34.62 MiB free; 5.04 GiB reserved in total by PyTorch)
修改configs/bottom_up/mobilenet/coco/mobilenetv2_coco_512x512.py(注释部分表示为为源码) :
data_root = 'data/coco'
data = dict(
#samples_per_gpu=24,
samples_per_gpu=4,
重新执行训练指令,正常训练之后本人打印如下:
使用单机器,多gpu训练:
# 1表示GPU的数目
bash ./tools/dist_train.sh configs/bottom_up/mobilenet/coco/mobilenetv2_coco_512x512.py 1
本人打印如下:
demo 使用
测试图像
python demo/bottom_up_img_demo.py configs/bottom_up/mobilenet/coco/mobilenetv2_coco_512x512.py checkpoints/mobilenetv2_coco_512x512-4d96e309_20200816.pth --img-root data/coco/val2017/ --json-file data/coco/annotations/person_keypoints_val2017.json --out-img-root vis_results
# configs/bottom_up/mobilenet/coco/mobilenetv2_coco_512x512.py 表示配置文件
# checkpoints/mobilenetv2_coco_512x512-4d96e309_20200816.pth 加载的模型权重
# img-root data/coco/val2017/ 存储图像的根目录
# --json-file data/coco/annotations/person_keypoints_val2017.jsone 图片对应的jison文件
# --out-img-root vis_results 图像结果输出目录
大家或许对于要指定 jsone 文件比较奇怪。其实主要是获取文件名的信息,有兴趣的朋友可以修改一下代码,让其直接从图像目录获取图像名称。本人测试的图片如下:
哈哈,测试效果本人感觉不太好的
测试视频
执行指令:
python demo/bottom_up_video_demo.py configs/bottom_up/mobilenet/coco/mobilenetv2_coco_512x512.py checkpoints/mobilenetv2_coco_512x512-4d96e309_20200816.pth --video_path demo/demo_video.mp4 --output-video-root vis_results
# --video_path demo/demo_video.mp4 表示需要测试的视频
# --output-video-root vis_results 表示输出的目录
结语
现在我们已经知道如何去训练,测试模型了,以及 demo 的使用,那么我们接下来就是去分析源码,以及项目落地了。