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.4k stars 615 forks source link

Reset min_max normalization values at the start of validation epoch #2153

Closed abc-125 closed 1 week ago

abc-125 commented 1 week ago

๐Ÿ“ Description

Currently, min_max values for normalization are updated every validation epoch. This update keeps irrelevant values from previous epochs by comparing new and old ones: self.max = torch.max(self.max, torch.max(predictions))

It seems like it does not affect most of the models, but with at least EfficientAD, the final anomaly maps after training are normalized the wrong way (see #2139 or this discussion).

This fix resets min_max values at the beginning of every validation epoch to ensure that only values from the recent one will be used for normalization.

๐Ÿ› ๏ธ Fixes #2027, thank you @CarlosNacher for pointing this problem out! Partially fixes #2139.

โœจ Changes

Select what type of change your PR is:

โœ… Checklist

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

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

abc-125 commented 1 week ago

Sorry, this was already solved in this PR.