From 2d6b92eb6444d8b88b5566860af534dc836b8df9 Mon Sep 17 00:00:00 2001 From: Marcos Luciano Date: Thu, 9 Feb 2023 00:41:35 -0300 Subject: [PATCH] Fix YOLOv8 accuracy --- docs/PPYOLOE.md | 6 +++++- docs/YOLOR.md | 6 +++++- docs/YOLOX.md | 6 +++++- docs/YOLOv5.md | 6 +++++- docs/YOLOv6.md | 6 +++++- docs/YOLOv7.md | 6 +++++- docs/YOLOv8.md | 10 +++++++--- nvdsinfer_custom_impl_Yolo/layers/c2f_layer.cpp | 2 +- utils/gen_wts_yoloV8.py | 5 +++++ 9 files changed, 43 insertions(+), 10 deletions(-) diff --git a/docs/PPYOLOE.md b/docs/PPYOLOE.md index e595d89..4c71aae 100644 --- a/docs/PPYOLOE.md +++ b/docs/PPYOLOE.md @@ -82,7 +82,7 @@ Open the `DeepStream-Yolo` folder and compile the lib ### Edit the config_infer_primary_ppyoloe_plus file -Edit the `config_infer_primary_ppyoloe_plus.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 with 80 classes) ``` [property] @@ -90,6 +90,8 @@ Edit the `config_infer_primary_ppyoloe_plus.txt` file according to your model (e custom-network-config=ppyoloe_plus_crn_s_80e_coco.cfg model-file=ppyoloe_plus_crn_s_80e_coco.wts ... +num-detected-classes=80 +... ``` **NOTE**: If you use the **legacy** model, you should edit the `config_infer_primary_ppyoloe.txt` file. @@ -129,3 +131,5 @@ config-file=config_infer_primary_ppyoloe_plus.txt ``` deepstream-app -c deepstream_app_config.txt ``` + +**NOTE**: For more information about custom models configuration (`batch-size`, `network-mode`, etc), please check the [`docs/customModels.md`](customModels.md) file. diff --git a/docs/YOLOR.md b/docs/YOLOR.md index 6753109..1e8210f 100644 --- a/docs/YOLOR.md +++ b/docs/YOLOR.md @@ -86,7 +86,7 @@ Open the `DeepStream-Yolo` folder and compile the lib ### Edit the config_infer_primary_yolor file -Edit the `config_infer_primary_yolor.txt` file according to your model (example for YOLOR-CSP) +Edit the `config_infer_primary_yolor.txt` file according to your model (example for YOLOR-CSP with 80 classes) ``` [property] @@ -94,6 +94,8 @@ Edit the `config_infer_primary_yolor.txt` file according to your model (example custom-network-config=yolor_csp.cfg model-file=yolor_csp.wts ... +num-detected-classes=80 +... ``` ## @@ -114,3 +116,5 @@ config-file=config_infer_primary_yolor.txt ``` deepstream-app -c deepstream_app_config.txt ``` + +**NOTE**: For more information about custom models configuration (`batch-size`, `network-mode`, etc), please check the [`docs/customModels.md`](customModels.md) file. diff --git a/docs/YOLOX.md b/docs/YOLOX.md index 1fcc053..23f4415 100644 --- a/docs/YOLOX.md +++ b/docs/YOLOX.md @@ -88,7 +88,7 @@ Open the `DeepStream-Yolo` folder and compile the lib ### Edit the config_infer_primary_yolox file -Edit the `config_infer_primary_yolox.txt` file according to your model (example for YOLOX-s standard) +Edit the `config_infer_primary_yolox.txt` file according to your model (example for YOLOX-s standard with 80 classes) ``` [property] @@ -96,6 +96,8 @@ Edit the `config_infer_primary_yolox.txt` file according to your model (example custom-network-config=yolox_s.cfg model-file=yolox_s.wts ... +num-detected-classes=80 +... ``` **NOTE**: If you use the **legacy** model, you should edit the `config_infer_primary_yolox_legacy.txt` file. @@ -135,3 +137,5 @@ config-file=config_infer_primary_yolox.txt ``` deepstream-app -c deepstream_app_config.txt ``` + +**NOTE**: For more information about custom models configuration (`batch-size`, `network-mode`, etc), please check the [`docs/customModels.md`](customModels.md) file. diff --git a/docs/YOLOv5.md b/docs/YOLOv5.md index 8d3721a..51e2659 100644 --- a/docs/YOLOv5.md +++ b/docs/YOLOv5.md @@ -117,7 +117,7 @@ Open the `DeepStream-Yolo` folder and compile the lib ### Edit the config_infer_primary_yoloV5 file -Edit the `config_infer_primary_yoloV5.txt` file according to your model (example for YOLOv5s) +Edit the `config_infer_primary_yoloV5.txt` file according to your model (example for YOLOv5s with 80 classes) ``` [property] @@ -125,6 +125,8 @@ Edit the `config_infer_primary_yoloV5.txt` file according to your model (example custom-network-config=yolov5s.cfg model-file=yolov5s.wts ... +num-detected-classes=80 +... ``` ## @@ -145,3 +147,5 @@ config-file=config_infer_primary_yoloV5.txt ``` deepstream-app -c deepstream_app_config.txt ``` + +**NOTE**: For more information about custom models configuration (`batch-size`, `network-mode`, etc), please check the [`docs/customModels.md`](customModels.md) file. diff --git a/docs/YOLOv6.md b/docs/YOLOv6.md index ea12052..217f1c9 100644 --- a/docs/YOLOv6.md +++ b/docs/YOLOv6.md @@ -115,7 +115,7 @@ Open the `DeepStream-Yolo` folder and compile the lib ### Edit the config_infer_primary_yoloV6 file -Edit the `config_infer_primary_yoloV6.txt` file according to your model (example for YOLOv6-S 3.0) +Edit the `config_infer_primary_yoloV6.txt` file according to your model (example for YOLOv6-S 3.0 with 80 classes) ``` [property] @@ -123,6 +123,8 @@ Edit the `config_infer_primary_yoloV6.txt` file according to your model (example custom-network-config=yolov6s.cfg model-file=yolov6s.wts ... +num-detected-classes=80 +... ``` ## @@ -143,3 +145,5 @@ config-file=config_infer_primary_yoloV6.txt ``` deepstream-app -c deepstream_app_config.txt ``` + +**NOTE**: For more information about custom models configuration (`batch-size`, `network-mode`, etc), please check the [`docs/customModels.md`](customModels.md) file. diff --git a/docs/YOLOv7.md b/docs/YOLOv7.md index 5cd64d1..f5b4025 100644 --- a/docs/YOLOv7.md +++ b/docs/YOLOv7.md @@ -119,7 +119,7 @@ Open the `DeepStream-Yolo` folder and compile the lib ### Edit the config_infer_primary_yoloV7 file -Edit the `config_infer_primary_yoloV7.txt` file according to your model (example for YOLOv7) +Edit the `config_infer_primary_yoloV7.txt` file according to your model (example for YOLOv7 with 80 classes) ``` [property] @@ -127,6 +127,8 @@ Edit the `config_infer_primary_yoloV7.txt` file according to your model (example custom-network-config=yolov7.cfg model-file=yolov7.wts ... +num-detected-classes=80 +... ``` ## @@ -147,3 +149,5 @@ config-file=config_infer_primary_yoloV7.txt ``` deepstream-app -c deepstream_app_config.txt ``` + +**NOTE**: For more information about custom models configuration (`batch-size`, `network-mode`, etc), please check the [`docs/customModels.md`](customModels.md) file. diff --git a/docs/YOLOv8.md b/docs/YOLOv8.md index bddffc5..59f4d71 100644 --- a/docs/YOLOv8.md +++ b/docs/YOLOv8.md @@ -38,7 +38,7 @@ wget https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s.pt #### 4. Convert model -Generate the `cfg` and `wts` files (example for YOLOv8s) +Generate the `cfg`, `wts` and `labels.txt` (if available) files (example for YOLOv8s) ``` python3 gen_wts_yoloV8.py -w yolov8s.pt @@ -67,7 +67,7 @@ or #### 5. Copy generated files -Copy the generated `cfg` and `wts` files to the `DeepStream-Yolo` folder. +Copy the generated `cfg`, `wts` and `labels.txt` (if generated), files to the `DeepStream-Yolo` folder. ## @@ -109,7 +109,7 @@ Open the `DeepStream-Yolo` folder and compile the lib ### Edit the config_infer_primary_yoloV8 file -Edit the `config_infer_primary_yoloV8.txt` file according to your model (example for YOLOv8s) +Edit the `config_infer_primary_yoloV8.txt` file according to your model (example for YOLOv8s with 80 classes) ``` [property] @@ -117,6 +117,8 @@ Edit the `config_infer_primary_yoloV8.txt` file according to your model (example custom-network-config=yolov8s.cfg model-file=yolov8s.wts ... +num-detected-classes=80 +... ``` ## @@ -137,3 +139,5 @@ config-file=config_infer_primary_yoloV8.txt ``` deepstream-app -c deepstream_app_config.txt ``` + +**NOTE**: For more information about custom models configuration (`batch-size`, `network-mode`, etc), please check the [`docs/customModels.md`](customModels.md) file. diff --git a/nvdsinfer_custom_impl_Yolo/layers/c2f_layer.cpp b/nvdsinfer_custom_impl_Yolo/layers/c2f_layer.cpp index e51c663..c0cf780 100644 --- a/nvdsinfer_custom_impl_Yolo/layers/c2f_layer.cpp +++ b/nvdsinfer_custom_impl_Yolo/layers/c2f_layer.cpp @@ -58,7 +58,7 @@ c2fLayer(int layerIdx, std::map& block, std::vectoraddElementWise(*rb, *cv2M, nvinfer1::ElementWiseOperation::kSUM); + nvinfer1::IElementWiseLayer* ew = network->addElementWise(*output, *cv2M, nvinfer1::ElementWiseOperation::kSUM); assert(ew != nullptr); std::string ewLayerName = "shortcut_c2f_" + std::to_string(i + 1) + "_" + std::to_string(layerIdx); ew->setName(ewLayerName.c_str()); diff --git a/utils/gen_wts_yoloV8.py b/utils/gen_wts_yoloV8.py index 1ba56e6..eaeb11f 100644 --- a/utils/gen_wts_yoloV8.py +++ b/utils/gen_wts_yoloV8.py @@ -291,6 +291,11 @@ device = select_device('cpu') model = torch.load(pt_file, map_location=device)['model'].float() model.to(device).eval() +if model.names and model.nc: + with open("labels.txt", 'w') as fw: + for i in range(model.nc): + fw.write(model.names[i] + '\n') + with open(wts_file, 'w') as fw, open(cfg_file, 'w') as fc: layers = Layers(len(model.model), inference_size, fw, fc)