Fix YOLOv8 accuracy

This commit is contained in:
Marcos Luciano
2023-02-09 00:41:35 -03:00
parent 940d244ad4
commit 2d6b92eb64
9 changed files with 43 additions and 10 deletions

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -58,7 +58,7 @@ c2fLayer(int layerIdx, std::map<std::string, std::string>& block, std::vector<fl
assert(cv2M != nullptr);
if (shortcut) {
nvinfer1::IElementWiseLayer* ew = network->addElementWise(*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());

View File

@@ -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)