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 normalization #2130

Merged
merged 10 commits into from
Jul 16, 2024
Merged

Conversation

alexriedel1
Copy link
Contributor

@alexriedel1 alexriedel1 commented Jun 13, 2024

📝 Description

Fixes: #2122 (reply in thread) and #2027 and #2139 (comment)

The normalization metrics are resetted before every validation. Is there any flaw in this logic or does it makes sense, so that models that have very different anomaly map and pred score magnitudes during training epochs are optimally normalized.

✨ 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.

@alexriedel1
Copy link
Contributor Author

Ah I missed some things when saving the model. However I can already tell you it works much better if you rely on pred_scores for downstream tasks!

Copy link

codecov bot commented Jul 16, 2024

Codecov Report

Attention: Patch coverage is 89.74359% with 4 lines in your changes missing coverage. Please review.

Project coverage is 80.83%. Comparing base (e7e6cb8) to head (7ccaa2b).
Report is 1 commits behind head on main.

Files Patch % Lines
...b/callbacks/normalization/min_max_normalization.py 80.95% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2130      +/-   ##
==========================================
+ Coverage   80.78%   80.83%   +0.05%     
==========================================
  Files         248      248              
  Lines       10859    10876      +17     
==========================================
+ Hits         8772     8792      +20     
+ Misses       2087     2084       -3     

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

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 @alexriedel1! I only have super minor comments

@samet-akcay samet-akcay merged commit d1f824a into openvinotoolkit:main Jul 16, 2024
6 checks passed
@alexriedel1 alexriedel1 deleted the fix_normalization branch July 16, 2024 14:22
@alsmeirelles
Copy link

alsmeirelles commented Jul 26, 2024

Hello guys,

With this commit, people that used to load a state dict with a model trained prior to this and has only the "normalization_metric" in state dict get the error bellow (in this case, using EfficientAd):

AttributeError: 'EfficientAd' object has no attribute 'anomaly_maps_normalization_metrics'

This is due to the fact that there was no difference in metrics normalization before and with the new fix, the attribute is not defined:

(AnomalyModule -> load_state_dict: line 171)
if "anomaly_maps_normalization_class" in state_dict:
self.anomaly_maps_normalization_metrics = self._get_instance(state_dict, "anomaly_maps_normalization_class")

So, my question is: what should I do to fix this without retraining the model?

@alexriedel1
Copy link
Contributor Author

Hello guys,

With this commit, people that used to load a state dict with a model trained prior to this and has only the "normalization_metric" in state dict get the error bellow (in this case, using EfficientAd):

AttributeError: 'EfficientAd' object has no attribute 'anomaly_maps_normalization_metrics'

This is due to the fact that there was no difference in metrics normalization before and with the new fix, the attribute is not defined:

(AnomalyModule -> load_state_dict: line 171) if "anomaly_maps_normalization_class" in state_dict: self.anomaly_maps_normalization_metrics = self._get_instance(state_dict, "anomaly_maps_normalization_class")

So, my question is: what should I do to fix this without retraining the model?

The easiest would be to install the anomalib version you were using at the time of model training.

@samet-akcay samet-akcay added this to the v1.1.1 milestone Jul 30, 2024
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.

None yet

3 participants