openvinotoolkit / anomalib

An anomaly detection library comprising state-of-the-art algorithms and features such as experiment management, hyper-parameter optimization, and edge inference.
https://anomalib.readthedocs.io/en/latest/
Apache License 2.0
3.41k stars 616 forks source link

[Task]: Add transform information to metadata.json when export to onnx #2091

Open letmejoin opened 1 month ago

letmejoin commented 1 month ago

What is the motivation for this task?

Replace albumentations with torchvision transforms by [v1.0.0] - 2024-02-29, But when export model to onnx, the tansform information was lost in metedata, Only task and threshold kept. When inference by onnxruntime or tensorrt, the transform information was needed, but we can't find in metadata.

Describe the solution you'd like

save transform information with metadata.json

Additional context

No response

samet-akcay commented 1 month ago

@letmejoin, in v1, torch model has the transforms. When you forward-pass an image, the exported model should apply the transforms within the model. So, ideally you don't need it anymore.

letmejoin commented 1 month ago

@letmejoin, in v1, torch model has the transforms. When you forward-pass an image, the exported model should apply the transforms within the model. So, ideally you don't need it anymore.

I later found out after testing that I could get the correct result directly without adding any transform. I just didn't see this explanation anywhere, and I tried to add transform in the early stage, but I couldn't get the correct result, which took a lot of time and energy. In the end, I removed all of them, and the result was correct. I hope this kind of update can be emphasized in the future, thank you!

samet-akcay commented 1 month ago

@letmejoin, you could refer to the following documentation for more details. Let us know if there is anything missing there, or does not make sense https://anomalib.readthedocs.io/en/latest/markdown/guides/how_to/data/transforms.html#transforms-during-inference