From 2b20f1745f639e86b6e329f378d34de15564213c Mon Sep 17 00:00:00 2001 From: Guanghua Yu <742925032@qq.com> Date: Fri, 2 Dec 2022 19:42:35 +0800 Subject: [PATCH] add PPYOLOE+ act demo (#1573) --- example/auto_compression/detection/README.md | 1 + .../detection/configs/ppyoloe_l_qat_dis.yaml | 3 +- .../detection/configs/ppyoloe_plus_reader.yml | 26 ++++++++++++++ .../configs/ppyoloe_plus_s_qat_dis.yaml | 34 +++++++++++++++++++ .../detection/configs/ppyoloe_s_qat_dis.yaml | 3 +- example/auto_compression/detection/eval.py | 10 ++++-- example/auto_compression/detection/run.py | 10 ++++-- 7 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 example/auto_compression/detection/configs/ppyoloe_plus_reader.yml create mode 100644 example/auto_compression/detection/configs/ppyoloe_plus_s_qat_dis.yaml diff --git a/example/auto_compression/detection/README.md b/example/auto_compression/detection/README.md index 40973d36..ebca4487 100644 --- a/example/auto_compression/detection/README.md +++ b/example/auto_compression/detection/README.md @@ -23,6 +23,7 @@ | :-------- |:-------- |:--------: | :---------------------: | :----------------: | :----------------: | :---------------: | :----------------------: | :---------------------: | | PP-YOLOE-l | 50.9 | - | 50.6 | 11.2ms | 7.7ms | **6.7ms** | [config](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/example/auto_compression/detection/configs/ppyoloe_l_qat_dis.yaml) | [Model](https://bj.bcebos.com/v1/paddle-slim-models/act/ppyoloe_crn_l_300e_coco_quant.tar) | | PP-YOLOE-s | 43.1 | 41.2 | 42.6 | 6.51ms | 2.77ms | **2.12ms** | [config](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/example/auto_compression/detection/configs/ppyoloe_s_qat_dis.yaml) | [Model](https://bj.bcebos.com/v1/paddle-slim-models/act/ppyoloe_s_quant.tar) | +| PP-YOLOE+ s | 43.7 | - | 42.7 | - | - | - | [config](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/example/auto_compression/detection/configs/ppyoloe_plus_s_qat_dis.yaml) | [Model](https://bj.bcebos.com/v1/paddle-slim-models/act/ppyoloe_plus_crn_s_80e_coco_no_nms_quant.tar) | - mAP的指标均在COCO val2017数据集中评测得到,IoU=0.5:0.95。 - PP-YOLOE-l模型在Tesla V100的GPU环境下测试,并且开启TensorRT,batch_size=1,包含NMS,测试脚本是[benchmark demo](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/deploy/python)。 diff --git a/example/auto_compression/detection/configs/ppyoloe_l_qat_dis.yaml b/example/auto_compression/detection/configs/ppyoloe_l_qat_dis.yaml index d1c28b06..7102142e 100644 --- a/example/auto_compression/detection/configs/ppyoloe_l_qat_dis.yaml +++ b/example/auto_compression/detection/configs/ppyoloe_l_qat_dis.yaml @@ -1,7 +1,8 @@ Global: reader_config: configs/yolo_reader.yml - arch: YOLO + arch: PPYOLOE + include_nms: True Evaluation: True model_dir: ./ppyoloe_crn_l_300e_coco model_filename: model.pdmodel diff --git a/example/auto_compression/detection/configs/ppyoloe_plus_reader.yml b/example/auto_compression/detection/configs/ppyoloe_plus_reader.yml new file mode 100644 index 00000000..5f3795f2 --- /dev/null +++ b/example/auto_compression/detection/configs/ppyoloe_plus_reader.yml @@ -0,0 +1,26 @@ +metric: COCO +num_classes: 80 + +# Datset configuration +TrainDataset: + !COCODataSet + image_dir: train2017 + anno_path: annotations/instances_train2017.json + dataset_dir: dataset/coco/ + +EvalDataset: + !COCODataSet + image_dir: val2017 + anno_path: annotations/instances_val2017.json + dataset_dir: dataset/coco/ + +worker_num: 0 + +# preprocess reader in test +EvalReader: + sample_transforms: + - Decode: {} + - Resize: {target_size: [640, 640], keep_ratio: False, interp: 2} + - NormalizeImage: {mean: [0., 0., 0.], std: [1., 1., 1.], norm_type: none} + - Permute: {} + batch_size: 4 diff --git a/example/auto_compression/detection/configs/ppyoloe_plus_s_qat_dis.yaml b/example/auto_compression/detection/configs/ppyoloe_plus_s_qat_dis.yaml new file mode 100644 index 00000000..9525f4a1 --- /dev/null +++ b/example/auto_compression/detection/configs/ppyoloe_plus_s_qat_dis.yaml @@ -0,0 +1,34 @@ + +Global: + reader_config: configs/ppyoloe_plus_reader.yml + arch: PPYOLOE + include_nms: False + Evaluation: True + model_dir: ./ppyoloe_plus_crn_s_80e_coco_no_nms # https://bj.bcebos.com/v1/paddle-slim-models/act/ppyoloe_plus_crn_s_80e_coco_no_nms.tar + model_filename: model.pdmodel + params_filename: model.pdiparams + +Distillation: + alpha: 1.0 + loss: soft_label + +QuantAware: + onnx_format: true + use_pact: true + activation_quantize_type: 'moving_average_abs_max' + quantize_op_types: + - conv2d + - depthwise_conv2d + +TrainConfig: + train_iter: 5000 + eval_iter: 1000 + learning_rate: + type: CosineAnnealingDecay + learning_rate: 0.00003 + T_max: 6000 + optimizer_builder: + optimizer: + type: SGD + weight_decay: 4.0e-05 + diff --git a/example/auto_compression/detection/configs/ppyoloe_s_qat_dis.yaml b/example/auto_compression/detection/configs/ppyoloe_s_qat_dis.yaml index 2090baba..3f6ade72 100644 --- a/example/auto_compression/detection/configs/ppyoloe_s_qat_dis.yaml +++ b/example/auto_compression/detection/configs/ppyoloe_s_qat_dis.yaml @@ -1,7 +1,8 @@ Global: reader_config: configs/yolo_reader.yml - arch: PPYOLOE # When export exclude_nms=True, need set arch: PPYOLOE + arch: PPYOLOE + include_nms: False Evaluation: True model_dir: ./ppyoloe_crn_s_300e_coco model_filename: model.pdmodel diff --git a/example/auto_compression/detection/eval.py b/example/auto_compression/detection/eval.py index 3dc0d403..0f80b124 100644 --- a/example/auto_compression/detection/eval.py +++ b/example/auto_compression/detection/eval.py @@ -85,9 +85,13 @@ def eval(): if 'arch' in global_config and global_config['arch'] == 'keypoint': res = keypoint_post_process(data, data_input, exe, val_program, fetch_targets, outs) - if 'arch' in global_config and global_config['arch'] == 'PPYOLOE': - postprocess = PPYOLOEPostProcess( - score_threshold=0.01, nms_threshold=0.6) + elif 'include_nms' in global_config and not global_config[ + 'include_nms']: + if 'arch' in global_config and global_config['arch'] == 'PPYOLOE': + postprocess = PPYOLOEPostProcess( + score_threshold=0.01, nms_threshold=0.6) + else: + assert "Not support arch={} now.".format(global_config['arch']) res = postprocess(np.array(outs[0]), data_all['scale_factor']) else: for out in outs: diff --git a/example/auto_compression/detection/run.py b/example/auto_compression/detection/run.py index 0dc94130..90c90c5f 100644 --- a/example/auto_compression/detection/run.py +++ b/example/auto_compression/detection/run.py @@ -100,9 +100,13 @@ def eval_function(exe, compiled_test_program, test_feed_names, test_fetch_list): res = keypoint_post_process(data, data_input, exe, compiled_test_program, test_fetch_list, outs) - if 'arch' in global_config and global_config['arch'] == 'PPYOLOE': - postprocess = PPYOLOEPostProcess( - score_threshold=0.01, nms_threshold=0.6) + elif 'include_nms' in global_config and not global_config[ + 'include_nms']: + if 'arch' in global_config and global_config['arch'] == 'PPYOLOE': + postprocess = PPYOLOEPostProcess( + score_threshold=0.01, nms_threshold=0.6) + else: + assert "Not support arch={} now.".format(global_config['arch']) res = postprocess(np.array(outs[0]), data_all['scale_factor']) else: for out in outs: -- GitLab