An inference error occurred after converting ONNX to tensorrt
@nzmora-nvidia is already working on this.
Since Jun 3, 2025.
- Dominant language
- C++
- Stars
- 13.4k
- Forks
- 2.4k
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 2
Description
When I was using UNet for image segmentation, after converting the pytorch format model to the tensorrt format, there would be a large error in the reasoning, as follows:
But the label image is like the following:
However, when I perform reasoning using the.pth format or the.onnx format, I can obtain a normal result (the prediction result is similar to a label).
When converting the onnx model to tensorrt format, I tried various methods, using code and tools (trtexec and Polygraphy), and employed a wide range of precisions (FP32/FP16/int8+ calibration). All will get wrong results.
And when using Polygraphy to analyze the layers of the onnx model and the engine model, the analysis results all passed the [instruction: polygraphy run UNet.onnx --load -- outputs UNet_onnx_out.json UNet_engine_out.json --onnxrt --trt --fail-fast】.
However, I saved the output of onnx inference and tensorrt inference as.npy files and compared the two files. Indeed, there are significant differences between them. The errors at many positions exceed 0.9.
I sincerely hope to receive everyone's help!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.