From 18eebf80b5a790cab6dc809055039d304915ec20 Mon Sep 17 00:00:00 2001 From: xiaoluomi <49263480+xiaoluomi@users.noreply.github.com> Date: Thu, 27 Apr 2023 16:15:34 +0800 Subject: [PATCH] add RT-DETR Quant demo (#1741) --- .../configs/rtdetr_r50vd_qat_dis.yaml | 31 +++++++++++++++++++ .../detection/configs/rtdetr_reader.yml | 26 ++++++++++++++++ paddleslim/common/recover_program.py | 2 +- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 example/auto_compression/detection/configs/rtdetr_r50vd_qat_dis.yaml create mode 100644 example/auto_compression/detection/configs/rtdetr_reader.yml diff --git a/example/auto_compression/detection/configs/rtdetr_r50vd_qat_dis.yaml b/example/auto_compression/detection/configs/rtdetr_r50vd_qat_dis.yaml new file mode 100644 index 00000000..48a03856 --- /dev/null +++ b/example/auto_compression/detection/configs/rtdetr_r50vd_qat_dis.yaml @@ -0,0 +1,31 @@ + +Global: + reader_config: configs/rtdetr_reader.yml + include_nms: True + Evaluation: True + model_dir: ./rtdetr_r50vd_6x_coco/ + model_filename: model.pdmodel + params_filename: model.pdiparams + +Distillation: + alpha: 1.0 + loss: soft_label + +QuantAware: + onnx_format: true + activation_quantize_type: 'moving_average_abs_max' + quantize_op_types: + - conv2d + - depthwise_conv2d + +TrainConfig: + train_iter: 10 + eval_iter: 10 + learning_rate: + type: CosineAnnealingDecay + learning_rate: 0.00003 + T_max: 10000 + optimizer_builder: + optimizer: + type: SGD + weight_decay: 4.0e-05 diff --git a/example/auto_compression/detection/configs/rtdetr_reader.yml b/example/auto_compression/detection/configs/rtdetr_reader.yml new file mode 100644 index 00000000..7b213ffa --- /dev/null +++ b/example/auto_compression/detection/configs/rtdetr_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/ + !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: 1 + shuffle: false + drop_last: false diff --git a/paddleslim/common/recover_program.py b/paddleslim/common/recover_program.py index 46224a58..1f7882d9 100644 --- a/paddleslim/common/recover_program.py +++ b/paddleslim/common/recover_program.py @@ -49,7 +49,7 @@ def _recover_outputs_attr(program): persistable=False, stop_gradient=True) op.desc.set_output("ReserveSpace", [reserve_space.name]) - if op.type == 'transpose2': + if op.type == 'transpose2' or op.type == 'flatten_contiguous_range' or op.type == 'unsqueeze2': if 'XShape' not in op.output_names: xshape = block.create_var( name=paddle.fluid. -- GitLab