一、数据集
数据集格式包括xml、voc(txt)、coco(json)
1.1、利用labelimg标注工具标注图片真实框,获得xml(voc)格式文件。标签名包括'ball'、'racket'、'hand'。如下图所示:
1.2、利用脚本将数据格式转换为coco(json)
train_val.py划分数据集:
x2coco.py:xml数据集格式转为coco格式
数据集格式输出如下:label_list.txt
以上数据格式准备工作完成
二、配置文件
这里以yolov3为例,其他的模型配置文件一样。
yolov3_mobilenet_v1_270e_coco.yml包括5个子配置文件,我们逐一详细介绍:
2.1 数据集配置文件
image_dir是图像目录,路径相对于dataset_dir;anno_path是注释文件目录,路径相对于dataset_dir;dataset_dir是数据集目录路径。
2.2 运行配置文件
选择设备GPU;日志间隔log_iter;保存路径save_dir;
2.3 优化器配置文件
base_lr:# 学习率决定了权值更新的速度,学习率越大,更新的速度就越快,但太快容易跳过最优解,而学习率太小更新的越慢,效率低。一般学习率随着训练的进行不断更改,先高一点,然后慢慢降低。
milestones:#学习率变动因子:如迭代10000次时,学习率衰减10倍,15000次迭代时,学习率又会在前一个学习率的基础上衰减15倍。
steps:#学习率变动步长
momentum:#动量,影响梯度下降到最优的速度,一般默认0.9
factor: # 权重衰减正则系数,防止过拟合
2.4 网络结构配置文件
2.5 输入配置文件
worker_num线程数量;num_max_boxes边框最大数量;sample_transforms样本数据增强;batch_transforms批量数据增强;batch_size批量大小;shuffle打乱。
以上步骤就完成了配置文件设置。
3、训练模型
python tools/train.py -c D:/train/paddle_detection/PaddleDetection/configs/yolov3/yolov3_mobilenet_v1_270e_coco.yml
使用如下命令启动VisualDL查看日志
visualdl --logdir vdl_dir/scalar/
4、模型评估
python tools/eval.py -c D:/train/paddle_detection/PaddleDetection/configs/yolov3/yolov3_mobilenet_v1_270e_coco.yml -o weights=result2/best_model/model.pdparams
5、模型预测
python tools/infer.py -c D:/train/paddle_detection/PaddleDetection/configs/yolov3/yolov3_mobilenet_v1_270e_coco.yml -o weights=result2/best_model/model.pdparams
模型部署
6、导出模型
python tools/export_model.py -c D:/train/paddle_detection/PaddleDetection/configs/yolov3/yolov3_mobilenet_v1_270e_coco.yml -o weights=result2/best_model/model.pdparams
7、python端预测
python deploy/python/infer.py --model_dir=output_inference/yolov3_mobilenet_v1_270e_coco --image_dir=C:/Users/Administrator/Desktop/working/Data/Badminton/images --device=GPU --threshold=0.4