Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicated size parameter value in ExportableCenterCrop #2203

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

CarlosNacher
Copy link
Contributor

@CarlosNacher CarlosNacher commented Jul 21, 2024

📝 Description

When you export an anomalib's model that have the CenterCrop transform in it (torchvision.transforms.v2.CenterCrop), anomalib automatically replaces that CenterCrop transform with ExportableCenterCrop for ONNX compatibility reasons:
image
image

Okay, but when you try to use that model within an TorchInferencer, for example, you will get this error when trying the .predict() method:

image

And the reason is that the ExportableCenterCrop transform checks wether the size parameter is a tuple, and if not, repeats the parameter twice in a list. But, normally, the size parameter of torchvision CenterCrop is internally represented as a list and not as a tuple.

image

The proposed solution just changes that line of code (isinstance comprobation) to pass either with a tuple or a list (Sequence type object, as typed in original torchvision CenterCrop transform ).

  • 🛠️ No submitted Issue. Described here itself.

✨ Changes

Select what type of change your PR is:

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔨 Refactor (non-breaking change which refactors the code base)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔒 Security update

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📋 I have summarized my changes in the CHANGELOG and followed the guidelines for my type of change (skip for minor changes, documentation updates, and test enhancements).
  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).

For more information about code review checklists, see the Code Review Checklist.

…ined in the original torchvision CenterCrop transform
Copy link
Contributor

@samet-akcay samet-akcay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, @CarlosNacher!

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.81%. Comparing base (b7188db) to head (e9670db).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2203      +/-   ##
==========================================
+ Coverage   80.79%   80.81%   +0.02%     
==========================================
  Files         248      248              
  Lines       10859    10860       +1     
==========================================
+ Hits         8773     8776       +3     
+ Misses       2086     2084       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants