From 18824dbf1fb22e4eb08e1ab37847424c6585e3cb Mon Sep 17 00:00:00 2001 From: carlosnacher Date: Sun, 21 Jul 2024 16:53:45 +0200 Subject: [PATCH 1/3] fix: change isinstance checking from tuple to Sequence as such is defined in the original torchvision CenterCrop transform --- src/anomalib/data/transforms/center_crop.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/anomalib/data/transforms/center_crop.py b/src/anomalib/data/transforms/center_crop.py index 88b8655aae..19424aeaa5 100644 --- a/src/anomalib/data/transforms/center_crop.py +++ b/src/anomalib/data/transforms/center_crop.py @@ -9,7 +9,7 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from typing import Any +from typing import Any, Sequence import torch from torch.nn.functional import pad @@ -77,9 +77,9 @@ class ExportableCenterCrop(Transform): size (int | tuple[int, int]): Desired output size of the crop. """ - def __init__(self, size: int | tuple[int, int]) -> None: + def __init__(self, size: int | Sequence[int, int]) -> None: super().__init__() - self.size = list(size) if isinstance(size, tuple) else [size, size] + self.size = list(size) if isinstance(size, Sequence) else [size, size] def _transform(self, inpt: torch.Tensor, params: dict[str, Any]) -> torch.Tensor: """Apply the transform.""" From fc473fe520b63f980a0d844b370b1bb069a98edb Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Thu, 22 Aug 2024 10:23:55 +0100 Subject: [PATCH 2/3] Update src/anomalib/data/transforms/center_crop.py --- src/anomalib/data/transforms/center_crop.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/anomalib/data/transforms/center_crop.py b/src/anomalib/data/transforms/center_crop.py index 19424aeaa5..39b5629288 100644 --- a/src/anomalib/data/transforms/center_crop.py +++ b/src/anomalib/data/transforms/center_crop.py @@ -9,7 +9,8 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from typing import Any, Sequence +from collections.abc import Sequence +from typing import Any import torch from torch.nn.functional import pad From 54852954b9d00d9272301141bb2e5db62efabfe5 Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Thu, 22 Aug 2024 10:24:00 +0100 Subject: [PATCH 3/3] Update src/anomalib/data/transforms/center_crop.py --- src/anomalib/data/transforms/center_crop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anomalib/data/transforms/center_crop.py b/src/anomalib/data/transforms/center_crop.py index 39b5629288..3747c4f6c6 100644 --- a/src/anomalib/data/transforms/center_crop.py +++ b/src/anomalib/data/transforms/center_crop.py @@ -78,7 +78,7 @@ class ExportableCenterCrop(Transform): size (int | tuple[int, int]): Desired output size of the crop. """ - def __init__(self, size: int | Sequence[int, int]) -> None: + def __init__(self, size: int | Sequence[int]) -> None: super().__init__() self.size = list(size) if isinstance(size, Sequence) else [size, size]