PaddleDetection测试脚本记录
1 吸烟检测测试 20221012
1.1 pipline 行人检测+吸烟检测
python deploy/pipeline/pipeline.py --config deploy\pipeline\config\examples\infer_cfg_smoking.yml --video_file D:\Data\Smoke\test2_video\video3-1.mp4
1.2 行人检测模块静态图预测
# 单张图片
python deploy/python/infer.py --model_dir=models\mot_ppyoloe_l_36e_pipeline --image_file=demo/000000014439_640x640.jpg --device=cpu
# 单个视频
python deploy/python/infer.py --model_dir=models\mot_ppyoloe_l_36e_pipeline --video_file=D:/Data/Smoke/test2_video/video3-1.mp4 --device=cpu
# 图像中有人时的输出结果
detect frame: 357
Test iter 0
class_id:0, confidence:0.9342, left_top:[183.13,122.14],right_bottom:[247.16,245.90]
1.3 吸烟检测静态图预测
python deploy/python/infer.py --model_dir models\ppyoloe_crn_s_80e_smoking_visdrone --image_file D:\Data\Smoke\test1\000067.jpg --device=cpu
2 安全帽检测
2.1 pipline 行人检测+安全帽
待完成
2.2 安全帽检测模块
2.2.1 数据准备
使用开源数据集,下载后解压文件夹按照以下结构重命名
# paddledetection训练数据格式
-- Helmet
|-- Annotations
|-- 001.jpg
|-- ...
|-- JPEGImages
|-- 001.xml
|-- ...
使用以下数据将数据划分为训练集、验证集、测试集
paddlex --split_dataset --format VOC --dataset_dir datasets/Helmet --val_value 0.2 --test_value 0.1
完成后数据集文件结构如下
-- Helmet
|-- JPEGImages
|-- 001.jpg
|-- ...
|-- Annotations
|-- 001.xml
|-- ...
|-- train_list.txt
|-- val_list.txt
|-- test_list.txt
|-- labels.txt
2.2.2 训练
# 开始训练
python -m paddle.distributed.launch --gpus 0,1 tools/train.py -c configs/ppyoloe/ppyoloe_plus_crn_m_80e_Helmet.yml --use_vdl True --vdl_log_dir output/scalar --eval
# 可视化查看训练数据
visualdl --logdir output/scalar --host 0.0.0.0 --port 8041
2.2.3 评估
# 评估验证集结果
CUDA_VISIBLE_DEVICES=0
python tools/eval.py -c configs/ppyoloe/ppyoloe_plus_crn_m_80e_Helmet.yml -o weights=output/ppyoloe_plus_crn_m_80e_Helmet/weights/best_model.pdparams
# 终端输出
[10/17 12:24:57] ppdet.engine INFO: Eval iter: 0
[10/17 12:25:09] ppdet.engine INFO: Eval iter: 100
[10/17 12:25:21] ppdet.engine INFO: Eval iter: 200
[10/17 12:25:33] ppdet.engine INFO: Eval iter: 300
[10/17 12:25:45] ppdet.engine INFO: Eval iter: 400
[10/17 12:25:57] ppdet.metrics.metrics INFO: Accumulating evaluatation results...
[10/17 12:25:57] ppdet.metrics.metrics INFO: mAP(0.50, 11point) = 61.77%
[10/17 12:25:57] ppdet.engine INFO: Total sample number: 1000, averge FPS: 16.343893553616113
2.2.4 动态图预测
# 预测单张图片
CUDA_VISIBLE_DEVICES=0
python tools/infer.py -c configs/ppyoloe/ppyoloe_plus_crn_m_80e_Helmet.yml -o weights=output/ppyoloe_plus_crn_m_80e_Helmet/weights/best_model.pdparams --infer_img=dataset/Helmet/JPEGImages/hard_hat_workers1783.png --output_dir output --visualize True
# 终端输出结果
W1017 12:26:25.761562 788568 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 6.1, Driver API Version: 11.6, Runtime API Version: 10.2
W1017 12:26:25.769194 788568 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
[10/17 12:26:28] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyoloe_plus_crn_m_80e_Helmet/weights/best_model.pdparams
100%|█████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:01<00:00, 1.30s/it]
[10/17 12:26:29] ppdet.engine INFO: Detection bbox results save in output/hard_hat_workers1783.png
2.2.5 动态图导出静态图
python tools/export_model.py -c configs\ppyoloe\ppyoloe_plus_crn_m_80e_box.yml -o weights=models\ppyoloe_plus_crn_m_80e_box26_train20221111\best_model.pdparams use_gpu=false --output_dir models
# 终端输出结果
[11/13 14:30:01] ppdet.utils.checkpoint INFO: Finish loading model weights: models\ppyoloe_plus_crn_m_80e_box26_train20221111\best_model.pdparams
[11/13 14:30:01] ppdet.engine INFO: Export inference config file to models\ppyoloe_plus_crn_m_80e_box\infer_cfg.yml
[11/13 14:30:06] ppdet.engine INFO: Export model and saved in models\ppyoloe_plus_crn_m_80e_box
2.2.6 静态图预测
# 单张图片
python deploy/python/infer.py --model_dir=models/ppyoloe_plus_crn_m_80e_box --image_file=D:\Data\Expressbox\images_test\1.jpg --device=cpu --save_results
# 终端输出结果
# 文件夹
python deploy/python/infer.py --model_dir=models/ppyoloe_plus_crn_m_80e_box --image_dir=D:\Data\Expressbox\images_test --device=cpu --save_results
# 终端输出结果
Found 2 inference images in total.
class_id:0, confidence:0.5832, left_top:[1960.35,1210.66],right_bottom:[2880.86,2070.92]
save result to: output\1.jpg
Test iter 0
class_id:0, confidence:0.7591, left_top:[291.97,273.54],right_bottom:[451.52,398.73]
save result to: output\2.jpg
Test iter 1
Start saving coco json files...
The bbox result is saved to output\bbox.json
------------------ Inference Time Info ----------------------
total_time(ms): 1718.0, img_num: 2
average latency time(ms): 859.00, QPS: 1.164144
preprocess_time(ms): 84.60, inference_time(ms): 774.40, postprocess_time(ms): 0.00
3 ppyoloe_plus_crn_l_80e_coco 20221015
3.1 动态图预测
python tools/infer.py -c configs/ppyoloe/ppyoloe_plus_crn_m_80e_coco.yml -o weights=models\ppyoloe\ppyoloe_plus_crn_m_80e_coco.pdparams use_gpu=false --infer_img=demo\hrnet_demo.jpg
3.2 动态图导出静态图
python tools/export_model.py -c configs/ppyoloe/ppyoloe_plus_crn_m_80e_coco.yml -o weights=models\ppyoloe\ppyoloe_plus_crn_m_80e_coco.pdparams use_gpu=False --output_dir models
3.3 静态图预测
python deploy/python/infer.py --model_dir=models/ppyoloe_plus_crn_m_80e_coco --image_file=demo/000000014439_640x640.jpg --device=cpu
4 picodet主体检测 20221015
4.1 动态图预测
python tools/infer.py -c configs\picodet\application\mainbody_detection\picodet_lcnet_x2_5_640_mainbody.yml --infer_dir=demo --output_dir=output -o weights=models\picodet\picodet_PPLCNet_x2_5_mainbody_lite_v1.0_pretrained.pdparams --save_results True
4.2 动态图导出静态图
python tools/export_model.py -c configs\picodet\application\mainbody_detection\picodet_lcnet_x2_5_640_mainbody.yml -o weights=models\picodet\picodet_PPLCNet_x2_5_mainbody_lite_v1.0_pretrained.pdparams --output_dir models
4.3 静态图预测
python deploy/python/infer.py --model_dir=models\picodet_lcnet_x2_5_640_mainbody --image_file=D:\Data\Retail_Product_Identification\test_image\recognition_2.jpg --device=cpu --save_results True