From 69f29f8934bf5b09699770415159f42d0de4f92e Mon Sep 17 00:00:00 2001 From: Marcos Luciano Date: Tue, 31 Jan 2023 02:59:56 -0300 Subject: [PATCH] Add PP-YOLOE+ support --- README.md | 6 ++--- config_infer_primary_ppyoloe_plus.txt | 26 +++++++++++++++++++ docs/PPYOLOE.md | 36 +++++++++++++++++---------- utils/gen_wts_ppyoloe.py | 17 +++++++------ 4 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 config_infer_primary_ppyoloe_plus.txt diff --git a/README.md b/README.md index c5bb9b4..dd5d303 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ NVIDIA DeepStream SDK 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO models * DeepStream tutorials * YOLOv6 support * Dynamic batch-size -* PP-YOLOE+ support ### Improvements on this repository @@ -29,6 +28,7 @@ NVIDIA DeepStream SDK 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO models * Models benchmarks * **YOLOv8 support** * **YOLOX support** +* **PP-YOLOE+ support** ## @@ -44,7 +44,7 @@ NVIDIA DeepStream SDK 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO models * [INT8 calibration](#int8-calibration) * [YOLOv5 usage](docs/YOLOv5.md) * [YOLOR usage](docs/YOLOR.md) -* [PP-YOLOE usage](docs/PPYOLOE.md) +* [PP-YOLOE / PP-YOLOE+ usage](docs/PPYOLOE.md) * [YOLOv7 usage](docs/YOLOv7.md) * [YOLOv8 usage](docs/YOLOv8.md) * [YOLOX usage](docs/YOLOX.md) @@ -110,7 +110,7 @@ NVIDIA DeepStream SDK 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO models * [Darknet YOLO](https://github.com/AlexeyAB/darknet) * [YOLOv5 >= 2.0](https://github.com/ultralytics/yolov5) * [YOLOR](https://github.com/WongKinYiu/yolor) -* [PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) +* [PP-YOLOE / PP-YOLOE+](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/ppyoloe) * [YOLOv7](https://github.com/WongKinYiu/yolov7) * [YOLOv8](https://github.com/ultralytics/ultralytics) * [YOLOX](https://github.com/Megvii-BaseDetection/YOLOX) diff --git a/config_infer_primary_ppyoloe_plus.txt b/config_infer_primary_ppyoloe_plus.txt new file mode 100644 index 0000000..b7a6838 --- /dev/null +++ b/config_infer_primary_ppyoloe_plus.txt @@ -0,0 +1,26 @@ +[property] +gpu-id=0 +net-scale-factor=0.0039215697906911373 +model-color-format=0 +custom-network-config=ppyoloe_plus_crn_s_80e_coco.cfg +model-file=ppyoloe_plus_crn_s_80e_coco.wts +model-engine-file=model_b1_gpu0_fp32.engine +#int8-calib-file=calib.table +labelfile-path=labels.txt +batch-size=1 +network-mode=0 +num-detected-classes=80 +interval=0 +gie-unique-id=1 +process-mode=1 +network-type=0 +cluster-mode=2 +maintain-aspect-ratio=0 +parse-bbox-func-name=NvDsInferParseYolo +custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so +engine-create-func-name=NvDsInferYoloCudaEngineGet + +[class-attrs-all] +nms-iou-threshold=0.7 +pre-cluster-threshold=0.25 +topk=300 diff --git a/docs/PPYOLOE.md b/docs/PPYOLOE.md index 0baff9b..e595d89 100644 --- a/docs/PPYOLOE.md +++ b/docs/PPYOLOE.md @@ -1,8 +1,8 @@ -# PP-YOLOE usage +# PP-YOLOE / PP-YOLOE+ usage * [Convert model](#convert-model) * [Compile the lib](#compile-the-lib) -* [Edit the config_infer_primary_ppyoloe file](#edit-the-config_infer_primary_ppyoloe-file) +* [Edit the config_infer_primary_ppyoloe_plus file](#edit-the-config_infer_primary_ppyoloe_plus-file) * [Edit the deepstream_app_config file](#edit-the-deepstream_app_config-file) * [Testing the model](#testing-the-model) @@ -12,7 +12,7 @@ #### 1. Download the PaddleDetection repo and install the requirements -https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/docs/tutorials/INSTALL.md +https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/docs/tutorials/INSTALL.md **NOTE**: It is recommended to use Python virtualenv. @@ -22,20 +22,20 @@ Copy the `gen_wts_ppyoloe.py` file from `DeepStream-Yolo/utils` directory to the #### 3. Download the model -Download the `pdparams` file from [PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) releases (example for PP-YOLOE-s) +Download the `pdparams` file from [PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/ppyoloe) releases (example for PP-YOLOE+_s) ``` -wget https://paddledet.bj.bcebos.com/models/ppyoloe_crn_s_400e_coco.pdparams +wget https://paddledet.bj.bcebos.com/models/ppyoloe_plus_crn_s_80e_coco.pdparams ``` **NOTE**: You can use your custom model, but it is important to keep the YOLO model reference (`ppyoloe_`) in you `cfg` and `weights`/`wts` filenames to generate the engine correctly. #### 4. Convert model -Generate the `cfg` and `wts` files (example for PP-YOLOE-s) +Generate the `cfg` and `wts` files (example for PP-YOLOE+_s) ``` -python3 gen_wts_ppyoloe.py -w ppyoloe_crn_s_400e_coco.pdparams -c configs/ppyoloe/ppyoloe_crn_s_400e_coco.yml +python3 gen_wts_ppyoloe.py -w ppyoloe_plus_crn_s_80e_coco.pdparams -c configs/ppyoloe/ppyoloe_plus_crn_s_80e_coco.yml ``` #### 5. Copy generated files @@ -80,19 +80,27 @@ Open the `DeepStream-Yolo` folder and compile the lib ## -### Edit the config_infer_primary_ppyoloe file +### Edit the config_infer_primary_ppyoloe_plus file -Edit the `config_infer_primary_ppyoloe.txt` file according to your model (example for PP-YOLOE-s) +Edit the `config_infer_primary_ppyoloe_plus.txt` file according to your model (example for PP-YOLOE+_s) ``` [property] ... -custom-network-config=ppyoloe_crn_s_400e_coco.cfg -model-file=ppyoloe_crn_s_400e_coco.wts +custom-network-config=ppyoloe_plus_crn_s_80e_coco.cfg +model-file=ppyoloe_plus_crn_s_80e_coco.wts ... ``` -**NOTE**: The PP-YOLOE uses normalization on the image preprocess. It is important to change the `net-scale-factor` and `offsets` according to the trained values. +**NOTE**: If you use the **legacy** model, you should edit the `config_infer_primary_ppyoloe.txt` file. + +**NOTE**: The **PP-YOLOE+** uses zero mean normalization on the image preprocess. It is important to change the `net-scale-factor` according to the trained values. + +``` +net-scale-factor=0.0039215697906911373 +``` + +**NOTE**: The **PP-YOLOE (legacy)** uses normalization on the image preprocess. It is important to change the `net-scale-factor` and `offsets` according to the trained values. Default: `mean = 0.485, 0.456, 0.406` and `std = 0.229, 0.224, 0.225` @@ -109,9 +117,11 @@ offsets=123.675;116.28;103.53 ... [primary-gie] ... -config-file=config_infer_primary_ppyoloe.txt +config-file=config_infer_primary_ppyoloe_plus.txt ``` +**NOTE**: If you use the **legacy** model, you should edit it to `config_infer_primary_ppyoloe.txt`. + ## ### Testing the model diff --git a/utils/gen_wts_ppyoloe.py b/utils/gen_wts_ppyoloe.py index 825e9f0..2b2a6c4 100644 --- a/utils/gen_wts_ppyoloe.py +++ b/utils/gen_wts_ppyoloe.py @@ -3,7 +3,7 @@ import struct import paddle import numpy as np from ppdet.core.workspace import load_config, merge_config -from ppdet.utils.check import check_gpu, check_version, check_config +from ppdet.utils.check import check_version, check_config from ppdet.utils.cli import ArgsParser from ppdet.engine import Trainer from ppdet.slim import build_slim_model @@ -273,13 +273,14 @@ class Layers(object): def get_state_dict(self, state_dict): for k, v in state_dict.items(): - vr = v.reshape([-1]).numpy() - self.fw.write('{} {} '.format(k, len(vr))) - for vv in vr: - self.fw.write(' ') - self.fw.write(struct.pack('>f', float(vv)).hex()) - self.fw.write('\n') - self.wc += 1 + if 'alpha' not in k: + vr = v.reshape([-1]).numpy() + self.fw.write('{} {} '.format(k, len(vr))) + for vv in vr: + self.fw.write(' ') + self.fw.write(struct.pack('>f', float(vv)).hex()) + self.fw.write('\n') + self.wc += 1 def get_anchors(self, anchor_points, stride_tensor): vr = anchor_points.numpy()