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

[Bug]: Wrong normalization used for some models. #1813

Closed
1 task done
blaz-r opened this issue Mar 4, 2024 · 2 comments · Fixed by #2324
Closed
1 task done

[Bug]: Wrong normalization used for some models. #1813

blaz-r opened this issue Mar 4, 2024 · 2 comments · Fixed by #2324

Comments

@blaz-r
Copy link
Contributor

blaz-r commented Mar 4, 2024

Describe the bug

Some of the models have wrong normalization setup in current version of code.
This list includes: DSR, DRAEM, EfficientAD, and rkde.

All of the above methods shouldn't use imagenet normalization, but they have the default method setup (which uses imagenet normaliztion):

def configure_transforms(self, image_size: tuple[int, int] | None = None) -> Transform:
"""Default transforms.
The default transform is resize to 256x256 and normalize to ImageNet stats. Individual models can override
this method to provide custom transforms.
"""
logger.warning(
"No implementation of `configure_transforms` was provided in the Lightning model. Using default "
"transforms from the base class. This may not be suitable for your use case. Please override "
"`configure_transforms` in your model.",
)
image_size = image_size or (256, 256)
return Compose(
[
Resize(image_size, antialias=True),
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
],
)

or in case of the EfficientAD it is manually set to imagenet:
def configure_transforms(self, image_size: tuple[int, int] | None = None) -> Transform:
"""Default transform for Padim."""
image_size = image_size or (256, 256)
return Compose(
[
Resize(image_size, antialias=True),
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
],
)

Dataset

Other (please specify in the text field below)

Model

Other (please specify in the field below)

Steps to reproduce the behavior

/

OS information

/

Expected behavior

All of the above (and potentially some other models, but I think those are the only four) should have normalization set to just get all the images to [0, 1] range.

Screenshots

No response

Pip/GitHub

GitHub

What version/branch did you use?

main

Configuration YAML

/

Logs

/

Code of Conduct

  • I agree to follow this project's Code of Conduct
@blaz-r blaz-r mentioned this issue Apr 26, 2024
9 tasks
@youngquan
Copy link
Contributor

Does using imagenet normalization affect the results much? Did you do any experiments? When I used draem, the anomaly maps rendered poorly. The anomalous regions are not rendered red. I'm still trying to figure out why.

@blaz-r
Copy link
Contributor Author

blaz-r commented Aug 7, 2024

Draem must not use imagenet normalization because the synthetic anomalies are in range 0-1, therefore images need to be normalized to 0-1 as well.

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 a pull request may close this issue.

2 participants