Skip to content

[Performance] Outputs are completely different between .onnx model and .pth model #26504

@timcov

Description

@timcov

Describe the issue

So i trained a resnet18 on patched images. I run the resnet (.pth) file on my unique test set and get good results. I try to export it to onnx and i get way worse results.

I've checked the input tiles and they're identical, same max and min, same pre processing. I even exported the raw tiles and they were identical. I even looked at the individual pixel values and these were also the same.

Now when i run the image trough the onnx model the export logits are different.

(Same result on both windows and ubuntu)

Cam_1_Frame_325_HasKnots_False_ts_2025-11-03-11-29-16-579.tiff
Cam_1_Frame_355_HasKnots_True_ts_2025-11-03-14-14-04-199.tiff

Normally all the files should be here, if something doesn't work. Be sure to let me know because i changed it a bit so i wouldnt have to upload everything

config.py
export_to_onnx.py
test_onnx.py
test_pth.py

To reproduce

Then run the export to onnx as follows:
uv run python export_to_onnx.py --model "resnet18" --weights "./resnet18_best.pth" --output "test.onnx"

Then
The root folder should contain 2 subfolders 1.Knot and 0.NoKnot. You can just copy the same image twice

uv run python test_onnx.py --onnx "./test.onnx" --root ./images

I also added 2 images, the first one is without knots and the logits of this image should be
[-3.072449 -2.8448505 -7.6250186 -6.501796 ] -> is like this for .pth file but not for .onnx file

The second one has knots and he should return 3 positive classe (1) and 1 negative (0)

Urgency

It is quite urgent as i need it within this week.

Platform

Windows

OS Version

Windows 11

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

onnxruntime 1.23.2

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

Cuda 12.8 and 12.6

Model File

If needed i can try to upload it.

Is this a quantized model?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceissues related to performance regressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions