Error Code 4: Miscellaneous (IElementWiseLayer Add_430: broadcast dimensions must be conformable)

Description

Hello, respected guys! Can you help solve my problem when converting a model with dynamic dimensions from ONNX to TensorRT Engine (.trt)?

I run this command:

/home/egorundel/soft/TensorRT-8-6/build/out/trtexec --onnx=/home/egorundel/projects/YOLOv8-TensorRT/best.onnx --saveEngine=/home/egorundel/projects/YOLOv8-TensorRT/best.trt --minShapes=images:1x3x512x512 --optShapes=images:6x3x512x512 --maxShapes=images:12x3x512x512 --useCudaGraph --notf32 --fp16

After which I get an error:
Error Code 4: Miscellaneous (IElementWiseLayer Add_430: broadcast dimensions must be conformable)

In netron.app, the model looks like this:

Environment

TensorRT Version: 8.6
GPU Type: RTX3060
Nvidia Driver Version: 535
CUDA Version: 11.1
CUDNN Version: 8
Operating System + Version: Ubuntu 20.04
Python Version (if applicable): 3.8

Relevant Files

GoogleDrive with ONNX model:
https://drive.google.com/drive/folders/1D19xWLW5mtTB6IRbmu8g87Y0vFQPZ3C6

Hi,
Request you to share the ONNX model and the script if not shared already so that we can assist you better.
Alongside you can try few things:

  1. validating your model with the below snippet

check_model.py

import sys
import onnx
filename = yourONNXmodel
model = onnx.load(filename)
onnx.checker.check_model(model).
2) Try running your model with trtexec command.

In case you are still facing issue, request you to share the trtexec “”–verbose"" log for further debugging
Thanks!

@AakankshaS Hello! Model is correct.

Text output from the terminal after using the trtexec I added to my GoogleDrive:
https://drive.google.com/drive/folders/1D19xWLW5mtTB6IRbmu8g87Y0vFQPZ3C6

Hi,

The above error indicates that there is a problem in the ONNX model.
Please refer to the similar post which may help you.

Thank you.

@spolisetty Hello! I haven’t parameter keepdims in Add node.

I did this ONNX model with dynamic shapes and batch by this code:
https://github.com/triple-Mu/YOLOv8-TensorRT/blob/triplemu/dynamic/experiment/det_dynamic.py

It is based on YOLOv8 from ultralytics:
https://github.com/ultralytics/ultralytics

Hi,

Sorry for the delayed response. Are you still facing this issue?

Thank you.

@spolisetty
Yes, the problem has not been solved yet

Hi,

Looking at the logs of the trtexec command used, a 512x512 input image shape is being set. If we understand the graph correctly, a 512x512 image results in 64*64 + 32*32 + 16*16 = 4096 + 1024 + 256 = 5376 anchors. However, the Tile_428 op (just before that problematic Add_430 op) has a hardcoded 8400 anchors on it. So the Add op is running with two input tensors, one with an anchor dim of 8400 and the other with an anchor dim of 5376, thus the error.
So there are two possible solutions:

  1. Use the exact image size that this model was exported for, such that it ends up using exactly 8400 anchors.
  2. If the 512x512 input image is a hard requirement, then the anchor generator will need to be updated to use that input resolution.

Thank you.