zl程序教程

您现在的位置是:首页 >  其他

当前栏目

姿态估算03-02:mmpose(Associative embedding)-官方数据训练测试-MobilenetV2

官方训练测试数据 02 03 embedding 姿态
2023-09-14 09:13:07 时间

以下链接是个人关于 mmpose(Associative embedding动作识别) 所有见解,如有错误欢迎大家指出,我会第一时间纠正。有兴趣的朋友可以加微信:17575010159 相互讨论技术。若是帮助到了你什么,一定要记得点赞!因为这是对我最大的鼓励。
姿态估算03-00:mmpose(Associative embedding)-目录-史上最新无死角讲解

注意,本人编写该博客的时间为 2020 / 08 / 21 ,也就是说,你现在下载的作者代码或许和 \color{red}{注意,本人编写该博客的时间为2020/08/21,也就是说,你现在下载的作者代码或许和} 注意,本人编写该博客的时间为2020/08/21,也就是说,你现在下载的作者代码或许和
本人的代码不一样(如果作者有更新过)还有就是,本人调试该代码为 u b u n t u 18.04 系统 \color{red}{本人的代码不一样(如果作者有更新过)还有就是,本人调试该代码为ubuntu18.04系统} 本人的代码不一样(如果作者有更新过)还有就是,本人调试该代码为ubuntu18.04系统
即下面的报错使用 u b u n t u 18.04 报错的过程,以及解决办法 \color{red}{即下面的报错使用ubuntu18.04报错的过程,以及解决办法} 即下面的报错使用ubuntu18.04报错的过程,以及解决办法

anconda环境搭建

请安装合适 c u d a 版本的 p y t o r c h ,不要直接复制 \color{red}{请安装合适cuda版本的pytorch,不要直接复制} 请安装合适cuda版本的pytorch,不要直接复制

#  $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 的使用,那么我们接下来就是去分析源码,以及项目落地了。