项目介绍
PaddleDetection
PP-YOLOV2
训练结果查看:
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
测试结果展示
飞桨论文复现赛
飞桨(PaddlePaddle)以百度多年的深度学习技术研究和业务应用为基础,集深度学习核心训练和推理框架、基础模型库、端到端开发套件和丰富的工具组件于一体,是中国首个自主研发、功能丰富、开源开放的产业级深度学习平台。飞桨企业版针对企业级需求增强了相应特性,包含零门槛AI开发平台EasyDL和全功能AI开发平台BML。EasyDL主要面向中小企业,提供零门槛、预置丰富网络和模型、便捷高效的开发平台;BML是为大型企业提供的功能全面、可灵活定制和被深度集成的开发平台。
END