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 transforms for draem, dsr and rkde #2324

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/anomalib/models/image/draem/lightning_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import torch
from lightning.pytorch.utilities.types import STEP_OUTPUT
from torch import nn
from torchvision.transforms.v2 import Compose, Resize, Transform

from anomalib import LearningType
from anomalib.data.utils import Augmenter
Expand Down Expand Up @@ -150,3 +151,13 @@ def learning_type(self) -> LearningType:
LearningType: Learning type of the model.
"""
return LearningType.ONE_CLASS

@staticmethod
def configure_transforms(image_size: tuple[int, int] | None = None) -> Transform:
"""Default transform for DRAEM. Normalization is not needed as the images are scaled to [0, 1] in Dataset."""
image_size = image_size or (256, 256)
return Compose(
[
Resize(image_size, antialias=True),
],
)
11 changes: 11 additions & 0 deletions src/anomalib/models/image/dsr/lightning_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import torch
from lightning.pytorch.utilities.types import STEP_OUTPUT, OptimizerLRScheduler
from torch import Tensor
from torchvision.transforms.v2 import Compose, Resize, Transform

from anomalib import LearningType
from anomalib.data.utils import DownloadInfo, download_and_extract
Expand Down Expand Up @@ -191,3 +192,13 @@ def learning_type(self) -> LearningType:
LearningType: Learning type of the model.
"""
return LearningType.ONE_CLASS

@staticmethod
def configure_transforms(image_size: tuple[int, int] | None = None) -> Transform:
"""Default transform for DSR. Normalization is not needed as the images are scaled to [0, 1] in Dataset."""
image_size = image_size or (256, 256)
return Compose(
[
Resize(image_size, antialias=True),
],
)
11 changes: 11 additions & 0 deletions src/anomalib/models/image/rkde/lightning_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import torch
from lightning.pytorch.utilities.types import STEP_OUTPUT
from torchvision.transforms.v2 import Compose, Resize, Transform

from anomalib import LearningType
from anomalib.models.components import AnomalyModule, MemoryBankMixin
Expand Down Expand Up @@ -143,3 +144,13 @@ def learning_type(self) -> LearningType:
LearningType: Learning type of the model.
"""
return LearningType.ONE_CLASS

@staticmethod
def configure_transforms(image_size: tuple[int, int] | None = None) -> Transform:
"""Default transform for RKDE."""
image_size = image_size or (240, 360)
return Compose(
[
Resize(image_size, antialias=True),
],
)
Loading