TensorRT Myelin Division by 0 error with YOLOv8 Segmentation model with TensorRT 8.6

Description

The following error occurs when no object is detected using yolov8n-seg (or yolov8s-seg and probably all the other yolov8 segmentation models):

ERROR: [TRT]: 1: [runner.cpp::shapeChangeHelper::621] Error Code 1: Myelin (Division by 0 detected in the shape 
graph. Tensor (Divisor) "sp__mye3" is equal to 0.; )
ERROR: nvdsinfer_backend.cpp:507 Failed to enqueue trt inference batch
ERROR: nvdsinfer_context_impl.cpp:1824 Infer context enqueue buffer failed, nvinfer error:NVDSINFER_TENSORRT_ERROR

This error is specific for TensorRT 8.6 and has been solved internally. It happens on Jetson Orin (NX 16GB in my case) with JP6 too.
The problem is that I need to use TRT 8.6 because I have dependencies on DeepStream 7 on x86, and on Jetson I have to use JP6.

- How could I modify the ONNX model to avoid the crash (using TRT 8.6 because I need to use DeepStream 7).
- If it’s not possible, is it possible to create a custom TRT plugin to avoid the crash?

I have no idea where the crash happens in the model, and my knowledge in tuning models is quite limited…

I originally posted this topic yesterday on DeepStream forum: TensorRT Myelin Division by 0 error with YOLOv8 Segmentation model.

Environment

TensorRT Version: 8.6.1.6
GPU Type: RTX 3070ti
Nvidia Driver Version: 535.183.01
CUDA Version: 12.2.140
CUDNN Version: 8.9.6.50
Operating System + Version: ubuntu 22.04.3 LTS
Baremetal or Container (if container which image + tag): nvcr.io/nvidia/deepstream:7.0-triton-multiarch

Related topics

Reproducing the error

Follow steps in topic TensorRT Divide by 0 Errors with YOLOv8 Seg model.
You can use nvcr.io/nvidia/deepstream:7.0-triton-multiarch for x86 instead of JetPack.

If you try uri=file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4 it won’t crash, but with a webcam, with no objects detected (putting your hand in front of the webcam), the crash will happen.