\u200E
AI Studio 精品项目 | 基于Keypoint模型下的人体关键点检测
发布日期:2021-08-05T10:55:24.000+0000 浏览量:1745次


项目介绍




本次给大家带来的是基于Keypoint模型下的人体关键点检测Alchemist_W供稿,本项目是基于PaddleDetection套件使用COCO2017数据集对人体关键点进行检测以实现对人的关节点活动动作的捕捉。利用Top-down与Down-top两种方式实现模型训练及其推理。在训练过程中使用了PP-YOLOv2训练的Det检测器和HigherHRNet关键点检测器,以提高质量和效果。




PaddleDetection




PaddleDetection是飞桨目标检测开发套件,旨在帮助开发者更好地解决检测模型的表述、训练、优化及部署等全开发流程。

PaddleDetection 实现了多种主要目标检测,算法提供了详细的数据增强策略、网络模块组件(如骨网络)、损失函数等,并集成了模型压缩和跨平台开发能力。
经过长时间的产业实践检测,划桨检测已被熟练掌握、卓越的使用体验,工业质检、遥感图像检测、无人巡检、新、互联网、科研零售等十多个行业的开发者广泛应用。

特点:
  • 模型丰富:包含目标检测、实例分割、人脸检测100+个预训练模型,涵盖全球大赛冠军方案
  • 使用:简洁的设计,解耦各种网络组件,开发者轻松搭建、试用各种检测模型及优化策略,得到快速发展、定制化的算法。
  • 全面打通:从数据增强组网、训练、压缩、全景打通,并配套支持云端设备/端多架构、多部署。
  • 高性能:基于飞桨的高性能内核,模型训练速度及显存占用优势明显支持FP16训练,支持多机训练。



PP-YOLOV2




在实际应用场景中,有效性与高效性对于目标检测器非常重要。为满足这两个问题,全面评估了现有提高PP-YOLO性能的改进措施同时保持推理耗时不变。

PP-YOLO是PaddleDetection优化和改进的YOLOv3的模型,其精度(COCO数据集MAP)和推理速度均优于YOLOv4模型,要求使用PaddlePaddle> = 2.0.2版本(可使用PIP安装)

PP-YOLO在COCO test-dev2017数据集上精度达到45.9%,在单卡V100上FP32推理速度为72.9 FPS,V100上开启TensorRT下FP16推理速度为155.6 FPS。


训练结果查看:





HigherHRNet




HigherHRNet:自下而上姿态估计中的多尺度表征学习。自下而上的框架在速度上有优势,但是由于卷积神经网络对于尺度不敏感,而图片中人的多尺度的难题导致目前的结果和自上而下框架还有一定差距。所以采用了HigherHRNet来解决多尺度表征的问题。


训练结果查看:





部分代码展示




环境准备:
   
     
!git clone https://github.com.cnpmjs.org/PaddlePaddle/PaddleDetection #放入持久层 !mv PaddleDetection/ work/ #导入所需要的依赖 !pip install -r work/PaddleDetection/requirements.txt

检测器数据集准备(部分):
   
     
""" 按VOC格式划分数据集,train : val = 0.85 : 0.15 生成标签label_list.txt """ from random import shuffle
dataset = 'dataset/VOCData/' train_txt = os.path.join(dataset, 'train_val.txt') val_txt = os.path.join(dataset, 'val.txt') lbl_txt = os.path.join(dataset, 'label_list.txt')
classes = ["person"]
with open(lbl_txt, 'w') as f: for l in classes: f.write(l+'\n')
xml_base = 'Annotations' img_base = 'images' xmls = [v for v in os.listdir(os.path.join(dataset, xml_base)) if v.endswith('.xml')] shuffle(xmls) split = int(0.85 * len(xmls))
with open(train_txt, 'w') as f: for x in tqdm(xmls[:split]): m = x[:-4]+'.jpg' xml_path = os.path.join(xml_base, x) img_path = os.path.join(img_base, m) f.write('{} {}\n'.format(img_path, xml_path))
with open(val_txt, 'w') as f: for x in tqdm(xmls[split:]): m = x[:-4]+'.jpg' xml_path = os.path.join(xml_base, x) img_path = os.path.join(img_base, m) f.write('{} {}\n'.format(img_path, xml_path))

关键点数据集准备(部分):
   
     
import json import os import shutil
train_path = "COCO_All/train2017/" train_json_path = "COCO_All/annotations/person_keypoints_train2017.json" out_train_path = "COCO_Humen/tarin2017/"
val_path="COCO_All/val2017/" val_json_path = "COCO_All/annotations/person_keypoints_val2017.json" out_val_path = "COCO_Humen/val2017/"
def humen_img(img_path, json_path,out_path):       count = 0  with open( json_path, 'r') as f: data = json.load(f) for name in data['annotations']: img_file= name['image_id'] img_name = str(img_file).zfill(12)+".jpg" img_file = img_path+ img_name #照片名字都是12位+.jpg后缀表示 如:000000319100.jpg
if os.path.exists(out_path + img_name): # print("有重复文件!!,跳过,不移动!!!") continue else: count += 1 shutil.copy(img_file, out_path)     print("本次生成照片数量为:",count)

导出模型:
   
     
%cd /home/aistudio/work/PaddleDetection/ # 导出PP-YOLOV2模型 !python tools/export_model.py -c configs/ppyolo/ppyolov2_r50vd_dcn_voc.yml \ -o weights=output/ppyolov2_r50vd_dcn_voc/model_final.pdparams #导出模型hrnet_w32_384x288模型 !python tools/export_model.py -c configs/keypoint/hrnet/hrnet_w32_384x288.yml \ -o weights=output/hrnet_w32_384x288/model_final.pdparams

联合模型推理:
   
     
# [联合部署推理] !python deploy/python/keypoint_det_unite_infer.py --det_model_dir=output_inference/ppyolov2_r50vd_dcn_voc/ \ --keypoint_model_dir=output_inference/hrnet_w32_384x288/ --video_file=../../Test/test.mp4 --use_gpu=True

部署:
   
     
# 准备PaddleLite依赖 !pip install paddlelite

# 准备PaddleLite部署模型 # --optimize_out=output_inference/ssd_mobilenet_v1 \ 与上面同一个文件夹 !paddle_lite_opt \ --model_file=output_inference/ssd_mobilenet_v1_300_120e_voc/model.pdmodel \ --param_file=output_inference/ssd_mobilenet_v1_300_120e_voc/model.pdiparams \ --optimize_out=output_inference/ssd_mob \ --optimize_out_type=naive_buffer \ --valid_targets=arm



测试结果展示





·相关链接·

AI Studio项目地址:
https://aistudio.baidu.com/aistudio/projectdetail/2132652
PaddleDetection地址:
https://github.com/PaddlePaddle/PaddleDetection
Keypoint中文文档地址:
https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.1/configs/keypoint/README.md
PP-YOLO中文文档地址:
https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.1/configs/ppyolo/README_cn.md





飞桨论文复现赛





请点击“阅读原文”访问项目原文。



飞桨(PaddlePaddle)以百度多年的深度学习技术研究和业务应用为基础,集深度学习核心训练和推理框架、基础模型库、端到端开发套件和丰富的工具组件于一体,是中国首个自主研发、功能丰富、开源开放的产业级深度学习平台。飞桨企业版针对企业级需求增强了相应特性,包含零门槛AI开发平台EasyDL和全功能AI开发平台BML。EasyDL主要面向中小企业,提供零门槛、预置丰富网络和模型、便捷高效的开发平台;BML是为大型企业提供的功能全面、可灵活定制和被深度集成的开发平台。


END