From c98f89830eec1acd1b3167d572b3f6ef264e6bf7 Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 29 Nov 2022 09:38:35 -0800 Subject: [PATCH 01/12] adding CheckLabelShaped transform Signed-off-by: myron --- monai/apps/auto3dseg/__init__.py | 1 + monai/apps/auto3dseg/data_analyzer.py | 5 ++- monai/apps/auto3dseg/transforms.py | 58 +++++++++++++++++++++++++++ monai/auto3dseg/analyzer.py | 22 +--------- 4 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 monai/apps/auto3dseg/transforms.py diff --git a/monai/apps/auto3dseg/__init__.py b/monai/apps/auto3dseg/__init__.py index 7c335f4850..4eb8262271 100644 --- a/monai/apps/auto3dseg/__init__.py +++ b/monai/apps/auto3dseg/__init__.py @@ -15,3 +15,4 @@ from .ensemble_builder import AlgoEnsemble, AlgoEnsembleBestByFold, AlgoEnsembleBestN, AlgoEnsembleBuilder from .hpo_gen import NNIGen, OptunaGen from .utils import export_bundle_algo_history, import_bundle_algo_history +from .transforms import CheckLabelShaped \ No newline at end of file diff --git a/monai/apps/auto3dseg/data_analyzer.py b/monai/apps/auto3dseg/data_analyzer.py index 7688bdbcd5..86b4f6db23 100644 --- a/monai/apps/auto3dseg/data_analyzer.py +++ b/monai/apps/auto3dseg/data_analyzer.py @@ -26,7 +26,7 @@ from monai.transforms import Compose, EnsureTyped, LoadImaged, Orientationd from monai.utils import StrEnum, min_version, optional_import from monai.utils.enums import DataStatsKeys, ImageStatsKeys - +from monai.apps.auto3dseg import CheckLabelShaped def strenum_representer(dumper, data): return dumper.represent_scalar("tag:yaml.org,2002:str", data.value) @@ -206,6 +206,9 @@ def get_all_case_stats(self, key="training", transform_list=None): EnsureTyped(keys=keys, data_type="tensor", dtype=torch.float), Orientationd(keys=keys, axcodes="RAS"), ] + if self.label_key is not None: + transform_list.append(CheckLabelShaped(keys=self.label_key, source_key=self.image_key, allowed_shape_difference=10)) + transform = Compose(transform_list) files, _ = datafold_read(datalist=self.datalist, basedir=self.dataroot, fold=-1, key=key) diff --git a/monai/apps/auto3dseg/transforms.py b/monai/apps/auto3dseg/transforms.py new file mode 100644 index 0000000000..f23ff91432 --- /dev/null +++ b/monai/apps/auto3dseg/transforms.py @@ -0,0 +1,58 @@ +# Copyright (c) MONAI Consortium +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from typing import Dict, Hashable, Mapping + +import numpy as np +import torch + +from monai.config import KeysCollection +from monai.networks.utils import pytorch_after +from monai.transforms import MapTransform + + +class CheckLabelShaped(MapTransform): + """ + Checks if segmentation label images (in keys) have the same spatial shape as the main image (in source_key), + and raise an error if the shapes are significantly different. + if the shapes are only slightly different (within an allowed_shape_difference in each dim), then quietly resize the label. + This transform is designed to quietly correct datasets with label shape mismatches. Generally image and segmentation label + must have the same spatial shape, however some public datasets having a slight shape mismatches, which will cause + potential crashes when calculating loss or metric functions. + """ + + def __init__( + self, + keys: KeysCollection = "label", + allow_missing_keys: bool = False, + source_key: str = "image", + allowed_shape_difference: int = 5, + ) -> None: + + super().__init__(keys=keys, allow_missing_keys=allow_missing_keys) + self.source_key = source_key + self.allowed_shape_difference = allowed_shape_difference + + def __call__(self, data: Mapping[Hashable, torch.Tensor]) -> Dict[Hashable, torch.Tensor]: + d = dict(data) + image_shape = d[self.source_key].shape[1:] + for key in self.key_iterator(d): + label_shape = d[key].shape[1:] + if label_shape != image_shape: + if np.allclose(list(label_shape), list(image_shape), atol=self.allowed_shape_difference): + d[key] = torch.nn.functional.interpolate( + input=d[key].unsqueeze(0), + size=image_shape, + mode="nearest-exact" if pytorch_after(1, 11) else "nearest", + ).squeeze(0) + else: + raise ValueError(f"Label shape {label_shape} is different from image shape {image_shape}") + return d diff --git a/monai/auto3dseg/analyzer.py b/monai/auto3dseg/analyzer.py index d6612de02c..03e95468a1 100644 --- a/monai/auto3dseg/analyzer.py +++ b/monai/auto3dseg/analyzer.py @@ -326,16 +326,7 @@ def __call__(self, data) -> dict: ndas_label = d[self.label_key] # (H,W,D) if ndas_label.shape != ndas[0].shape: - # if image and label shapes are different, check if they are close - if np.allclose(list(ndas_label.shape), list(ndas[0].shape), atol=10): - logger.info(f" Label shape {ndas_label.shape} is slightly different from image shape {ndas[0].shape}") - ndas_label = F.interpolate( - input=ndas_label.unsqueeze(0).unsqueeze(0), - size=list(ndas[0].shape), - mode="nearest-exact" if pytorch_after(1, 11) else "nearest", - )[0, 0] - else: - raise ValueError(f"Label shape {ndas_label.shape} is different from image shape {ndas[0].shape}") + raise ValueError(f"Label shape {ndas_label.shape} is different from image shape {ndas[0].shape}") nda_foregrounds = [get_foreground_label(nda, ndas_label) for nda in ndas] nda_foregrounds = [nda if nda.numel() > 0 else MetaTensor([0.0]) for nda in nda_foregrounds] @@ -465,16 +456,7 @@ def __call__(self, data): ndas_label = d[self.label_key] # (H,W,D) if ndas_label.shape != ndas[0].shape: - # if image and label shapes are different, check if they are close - if np.allclose(list(ndas_label.shape), list(ndas[0].shape), atol=10): - logger.info(f" Label shape {ndas_label.shape} is slightly different from image shape {ndas[0].shape}") - ndas_label = F.interpolate( - input=ndas_label.unsqueeze(0).unsqueeze(0), - size=list(ndas[0].shape), - mode="nearest-exact" if pytorch_after(1, 11) else "nearest", - )[0, 0] - else: - raise ValueError(f"Label shape {ndas_label.shape} is different from image shape {ndas[0].shape}") + raise ValueError(f"Label shape {ndas_label.shape} is different from image shape {ndas[0].shape}") nda_foregrounds = [get_foreground_label(nda, ndas_label) for nda in ndas] nda_foregrounds = [nda if nda.numel() > 0 else torch.Tensor([0]) for nda in nda_foregrounds] From 35716e16e95e17cb4cccf118f2ea6b0dee810eee Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 29 Nov 2022 09:46:13 -0800 Subject: [PATCH 02/12] import Signed-off-by: myron --- monai/apps/auto3dseg/__init__.py | 1 - monai/apps/auto3dseg/data_analyzer.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/monai/apps/auto3dseg/__init__.py b/monai/apps/auto3dseg/__init__.py index 4eb8262271..7c335f4850 100644 --- a/monai/apps/auto3dseg/__init__.py +++ b/monai/apps/auto3dseg/__init__.py @@ -15,4 +15,3 @@ from .ensemble_builder import AlgoEnsemble, AlgoEnsembleBestByFold, AlgoEnsembleBestN, AlgoEnsembleBuilder from .hpo_gen import NNIGen, OptunaGen from .utils import export_bundle_algo_history, import_bundle_algo_history -from .transforms import CheckLabelShaped \ No newline at end of file diff --git a/monai/apps/auto3dseg/data_analyzer.py b/monai/apps/auto3dseg/data_analyzer.py index 86b4f6db23..23753fe57b 100644 --- a/monai/apps/auto3dseg/data_analyzer.py +++ b/monai/apps/auto3dseg/data_analyzer.py @@ -26,7 +26,7 @@ from monai.transforms import Compose, EnsureTyped, LoadImaged, Orientationd from monai.utils import StrEnum, min_version, optional_import from monai.utils.enums import DataStatsKeys, ImageStatsKeys -from monai.apps.auto3dseg import CheckLabelShaped +from monai.apps.auto3dseg.transforms import CheckLabelShaped def strenum_representer(dumper, data): return dumper.represent_scalar("tag:yaml.org,2002:str", data.value) From 30ca1d75db799418a7ffbafabbe64cc4f1c58cf7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Nov 2022 17:59:49 +0000 Subject: [PATCH 03/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/auto3dseg/analyzer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/monai/auto3dseg/analyzer.py b/monai/auto3dseg/analyzer.py index 03e95468a1..02049fe1a5 100644 --- a/monai/auto3dseg/analyzer.py +++ b/monai/auto3dseg/analyzer.py @@ -16,7 +16,6 @@ import numpy as np import torch -import torch.nn.functional as F from monai.apps.utils import get_logger from monai.auto3dseg.operations import Operations, SampleOperations, SummaryOperations @@ -33,7 +32,7 @@ from monai.data import MetaTensor, affine_to_spacing from monai.transforms.transform import MapTransform from monai.transforms.utils_pytorch_numpy_unification import sum, unique -from monai.utils import convert_to_numpy, pytorch_after +from monai.utils import convert_to_numpy from monai.utils.enums import DataStatsKeys, ImageStatsKeys, LabelStatsKeys from monai.utils.misc import ImageMetaKey, label_union From 86e0018ba6c32e9b0135823249fdbc12dd3001a9 Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 29 Nov 2022 11:54:21 -0800 Subject: [PATCH 04/12] flake Signed-off-by: myron --- monai/apps/auto3dseg/data_analyzer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/monai/apps/auto3dseg/data_analyzer.py b/monai/apps/auto3dseg/data_analyzer.py index 23753fe57b..54b61d4695 100644 --- a/monai/apps/auto3dseg/data_analyzer.py +++ b/monai/apps/auto3dseg/data_analyzer.py @@ -16,6 +16,7 @@ import numpy as np import torch +from monai.apps.auto3dseg.transforms import CheckLabelShaped from monai.apps.utils import get_logger from monai.auto3dseg import SegSummarizer from monai.auto3dseg.utils import datafold_read @@ -26,7 +27,7 @@ from monai.transforms import Compose, EnsureTyped, LoadImaged, Orientationd from monai.utils import StrEnum, min_version, optional_import from monai.utils.enums import DataStatsKeys, ImageStatsKeys -from monai.apps.auto3dseg.transforms import CheckLabelShaped + def strenum_representer(dumper, data): return dumper.represent_scalar("tag:yaml.org,2002:str", data.value) @@ -207,7 +208,9 @@ def get_all_case_stats(self, key="training", transform_list=None): Orientationd(keys=keys, axcodes="RAS"), ] if self.label_key is not None: - transform_list.append(CheckLabelShaped(keys=self.label_key, source_key=self.image_key, allowed_shape_difference=10)) + transform_list.append( + CheckLabelShaped(keys=self.label_key, source_key=self.image_key, allowed_shape_difference=10) + ) transform = Compose(transform_list) From 1b5758c6717f3347717483fdc1d35e7e1d1b6ff3 Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 30 Nov 2022 11:50:15 -0800 Subject: [PATCH 05/12] update according to comments Signed-off-by: myron --- monai/apps/auto3dseg/data_analyzer.py | 4 ++-- monai/apps/auto3dseg/transforms.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/monai/apps/auto3dseg/data_analyzer.py b/monai/apps/auto3dseg/data_analyzer.py index 54b61d4695..37501a0b30 100644 --- a/monai/apps/auto3dseg/data_analyzer.py +++ b/monai/apps/auto3dseg/data_analyzer.py @@ -16,7 +16,7 @@ import numpy as np import torch -from monai.apps.auto3dseg.transforms import CheckLabelShaped +from monai.apps.auto3dseg.transforms import EnsureSameShape from monai.apps.utils import get_logger from monai.auto3dseg import SegSummarizer from monai.auto3dseg.utils import datafold_read @@ -209,7 +209,7 @@ def get_all_case_stats(self, key="training", transform_list=None): ] if self.label_key is not None: transform_list.append( - CheckLabelShaped(keys=self.label_key, source_key=self.image_key, allowed_shape_difference=10) + EnsureSameShape(keys=self.label_key, source_key=self.image_key, allowed_shape_difference=5) ) transform = Compose(transform_list) diff --git a/monai/apps/auto3dseg/transforms.py b/monai/apps/auto3dseg/transforms.py index f23ff91432..ff76204033 100644 --- a/monai/apps/auto3dseg/transforms.py +++ b/monai/apps/auto3dseg/transforms.py @@ -19,11 +19,11 @@ from monai.transforms import MapTransform -class CheckLabelShaped(MapTransform): +class EnsureSameShape(MapTransform): """ Checks if segmentation label images (in keys) have the same spatial shape as the main image (in source_key), and raise an error if the shapes are significantly different. - if the shapes are only slightly different (within an allowed_shape_difference in each dim), then quietly resize the label. + if the shapes are only slightly different (within an allowed_shape_difference in each dim), then resize the label. This transform is designed to quietly correct datasets with label shape mismatches. Generally image and segmentation label must have the same spatial shape, however some public datasets having a slight shape mismatches, which will cause potential crashes when calculating loss or metric functions. @@ -36,7 +36,15 @@ def __init__( source_key: str = "image", allowed_shape_difference: int = 5, ) -> None: + """ + Args: + keys: keys of the corresponding items to be compared to the source_key item shape. + allow_missing_keys: don't raise exception if key is missing. + source_key: key of the item with a reference shape + allowed_shape_difference: raises error if shapes are different more then this value in any dimension, + otherwise corrects for the shape mismatch using nearest interpolation + """ super().__init__(keys=keys, allow_missing_keys=allow_missing_keys) self.source_key = source_key self.allowed_shape_difference = allowed_shape_difference From 45b292cee7b78f9b0003eb7fc9e3a9b6cedd5d11 Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 30 Nov 2022 16:01:59 -0800 Subject: [PATCH 06/12] showing warning on shape mismatch Signed-off-by: myron --- monai/apps/auto3dseg/data_analyzer.py | 4 ++-- monai/apps/auto3dseg/transforms.py | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/monai/apps/auto3dseg/data_analyzer.py b/monai/apps/auto3dseg/data_analyzer.py index 37501a0b30..0e3b5308bd 100644 --- a/monai/apps/auto3dseg/data_analyzer.py +++ b/monai/apps/auto3dseg/data_analyzer.py @@ -16,7 +16,7 @@ import numpy as np import torch -from monai.apps.auto3dseg.transforms import EnsureSameShape +from monai.apps.auto3dseg.transforms import EnsureSameShaped from monai.apps.utils import get_logger from monai.auto3dseg import SegSummarizer from monai.auto3dseg.utils import datafold_read @@ -209,7 +209,7 @@ def get_all_case_stats(self, key="training", transform_list=None): ] if self.label_key is not None: transform_list.append( - EnsureSameShape(keys=self.label_key, source_key=self.image_key, allowed_shape_difference=5) + EnsureSameShaped(keys=self.label_key, source_key=self.image_key, allowed_shape_difference=5) ) transform = Compose(transform_list) diff --git a/monai/apps/auto3dseg/transforms.py b/monai/apps/auto3dseg/transforms.py index ff76204033..65a1738285 100644 --- a/monai/apps/auto3dseg/transforms.py +++ b/monai/apps/auto3dseg/transforms.py @@ -9,6 +9,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import warnings from typing import Dict, Hashable, Mapping import numpy as np @@ -19,14 +20,14 @@ from monai.transforms import MapTransform -class EnsureSameShape(MapTransform): +class EnsureSameShaped(MapTransform): """ Checks if segmentation label images (in keys) have the same spatial shape as the main image (in source_key), and raise an error if the shapes are significantly different. - if the shapes are only slightly different (within an allowed_shape_difference in each dim), then resize the label. - This transform is designed to quietly correct datasets with label shape mismatches. Generally image and segmentation label - must have the same spatial shape, however some public datasets having a slight shape mismatches, which will cause - potential crashes when calculating loss or metric functions. + If the shapes are only slightly different (within an allowed_shape_difference in each dim), then resize the label using + nearest interpolation. This transform is designed to correct datasets with slight label shape mismatches. + Generally image and segmentation label must have the same spatial shape, however some public datasets are having slight + shape mismatches, which will cause potential crashes when calculating loss or metric functions. """ def __init__( @@ -39,10 +40,10 @@ def __init__( """ Args: keys: keys of the corresponding items to be compared to the source_key item shape. - allow_missing_keys: don't raise exception if key is missing. - source_key: key of the item with a reference shape - allowed_shape_difference: raises error if shapes are different more then this value in any dimension, - otherwise corrects for the shape mismatch using nearest interpolation + allow_missing_keys: do not raise exception if key is missing. + source_key: key of the item with the reference shape. + allowed_shape_difference: raises error if shapes are different more than this value in any dimension, + otherwise corrects for the shape mismatch using nearest interpolation. """ super().__init__(keys=keys, allow_missing_keys=allow_missing_keys) @@ -56,11 +57,12 @@ def __call__(self, data: Mapping[Hashable, torch.Tensor]) -> Dict[Hashable, torc label_shape = d[key].shape[1:] if label_shape != image_shape: if np.allclose(list(label_shape), list(image_shape), atol=self.allowed_shape_difference): + warnings.warn(f"The {key} shape {label_shape} is different from the source shape {image_shape}.") d[key] = torch.nn.functional.interpolate( input=d[key].unsqueeze(0), size=image_shape, mode="nearest-exact" if pytorch_after(1, 11) else "nearest", ).squeeze(0) else: - raise ValueError(f"Label shape {label_shape} is different from image shape {image_shape}") + raise ValueError(f"The {key} shape {label_shape} is different from the source shape {image_shape}.") return d From cd1064d3b414e87123556cbbfcea73e647c3ba70 Mon Sep 17 00:00:00 2001 From: myron Date: Wed, 30 Nov 2022 20:14:40 -0800 Subject: [PATCH 07/12] doc strings, extra_params Signed-off-by: myron --- monai/apps/auto3dseg/data_analyzer.py | 16 +++++++++++++--- monai/auto3dseg/analyzer.py | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/monai/apps/auto3dseg/data_analyzer.py b/monai/apps/auto3dseg/data_analyzer.py index 0e3b5308bd..074eb6dbe3 100644 --- a/monai/apps/auto3dseg/data_analyzer.py +++ b/monai/apps/auto3dseg/data_analyzer.py @@ -70,9 +70,11 @@ class DataAnalyzer: hist_range: ranges to compute histogram for each image channel. fmt: format used to save the analysis results. Defaults to "yaml". histogram_only: whether to only compute histograms. Defaults to False. + extra_params: other optional arguments. Currently supported arguments are : + 'allowed_shape_difference' (default 5) can be used to change the default tolerance of + the allowed shape differences between the image and label items. In case of shape mismatch below + the tolerance, the label image will be resized to match the image using nearest interpolation. - Raises: - ValueError if device is GPU and worker > 0. Examples: .. code-block:: python @@ -122,6 +124,7 @@ def __init__( hist_range: Optional[list] = None, fmt: Optional[str] = "yaml", histogram_only: bool = False, + **extra_params, ): if path.isfile(output_path): warnings.warn(f"File {output_path} already exists and will be overwritten.") @@ -140,6 +143,7 @@ def __init__( self.hist_range: list = [-500, 500] if hist_range is None else hist_range self.fmt = fmt self.histogram_only = histogram_only + self.extra_params = extra_params @staticmethod def _check_data_uniformity(keys: List[str], result: Dict): @@ -208,8 +212,14 @@ def get_all_case_stats(self, key="training", transform_list=None): Orientationd(keys=keys, axcodes="RAS"), ] if self.label_key is not None: + + allowed_shape_difference = self.extra_params.get("allowed_shape_difference", 5) transform_list.append( - EnsureSameShaped(keys=self.label_key, source_key=self.image_key, allowed_shape_difference=5) + EnsureSameShaped( + keys=self.label_key, + source_key=self.image_key, + allowed_shape_difference=allowed_shape_difference, + ) ) transform = Compose(transform_list) diff --git a/monai/auto3dseg/analyzer.py b/monai/auto3dseg/analyzer.py index 02049fe1a5..f1f5fc41c0 100644 --- a/monai/auto3dseg/analyzer.py +++ b/monai/auto3dseg/analyzer.py @@ -325,7 +325,7 @@ def __call__(self, data) -> dict: ndas_label = d[self.label_key] # (H,W,D) if ndas_label.shape != ndas[0].shape: - raise ValueError(f"Label shape {ndas_label.shape} is different from image shape {ndas[0].shape}") + raise ValueError(f"Label shape {ndas_label.shape} is different from image shape {ndas[0].shape}") nda_foregrounds = [get_foreground_label(nda, ndas_label) for nda in ndas] nda_foregrounds = [nda if nda.numel() > 0 else MetaTensor([0.0]) for nda in nda_foregrounds] @@ -455,7 +455,7 @@ def __call__(self, data): ndas_label = d[self.label_key] # (H,W,D) if ndas_label.shape != ndas[0].shape: - raise ValueError(f"Label shape {ndas_label.shape} is different from image shape {ndas[0].shape}") + raise ValueError(f"Label shape {ndas_label.shape} is different from image shape {ndas[0].shape}") nda_foregrounds = [get_foreground_label(nda, ndas_label) for nda in ndas] nda_foregrounds = [nda if nda.numel() > 0 else torch.Tensor([0]) for nda in nda_foregrounds] From 8da8c175031bf0c92139dd954ab81353bcd7beed Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Dec 2022 04:15:07 +0000 Subject: [PATCH 08/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/apps/auto3dseg/data_analyzer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/apps/auto3dseg/data_analyzer.py b/monai/apps/auto3dseg/data_analyzer.py index 074eb6dbe3..b754174b2b 100644 --- a/monai/apps/auto3dseg/data_analyzer.py +++ b/monai/apps/auto3dseg/data_analyzer.py @@ -71,8 +71,8 @@ class DataAnalyzer: fmt: format used to save the analysis results. Defaults to "yaml". histogram_only: whether to only compute histograms. Defaults to False. extra_params: other optional arguments. Currently supported arguments are : - 'allowed_shape_difference' (default 5) can be used to change the default tolerance of - the allowed shape differences between the image and label items. In case of shape mismatch below + 'allowed_shape_difference' (default 5) can be used to change the default tolerance of + the allowed shape differences between the image and label items. In case of shape mismatch below the tolerance, the label image will be resized to match the image using nearest interpolation. From 320376485717c814da6052ec0bf000aebf56807d Mon Sep 17 00:00:00 2001 From: myron Date: Thu, 1 Dec 2022 00:47:38 -0800 Subject: [PATCH 09/12] warning update Signed-off-by: myron --- monai/apps/auto3dseg/transforms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/monai/apps/auto3dseg/transforms.py b/monai/apps/auto3dseg/transforms.py index 65a1738285..2793eb9202 100644 --- a/monai/apps/auto3dseg/transforms.py +++ b/monai/apps/auto3dseg/transforms.py @@ -57,7 +57,10 @@ def __call__(self, data: Mapping[Hashable, torch.Tensor]) -> Dict[Hashable, torc label_shape = d[key].shape[1:] if label_shape != image_shape: if np.allclose(list(label_shape), list(image_shape), atol=self.allowed_shape_difference): - warnings.warn(f"The {key} shape {label_shape} is different from the source shape {image_shape}.") + warnings.warn( + f"The {key} with shape {label_shape} was resized to match the source shape {image_shape}," + f"the meta-data was not updated." + ) d[key] = torch.nn.functional.interpolate( input=d[key].unsqueeze(0), size=image_shape, From d4f9e650d374926bc79cfc6de57688d5865299b9 Mon Sep 17 00:00:00 2001 From: Wenqi Li <831580+wyli@users.noreply.github.com> Date: Thu, 1 Dec 2022 11:11:37 +0000 Subject: [PATCH 10/12] Update monai/apps/auto3dseg/data_analyzer.py --- monai/apps/auto3dseg/data_analyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/apps/auto3dseg/data_analyzer.py b/monai/apps/auto3dseg/data_analyzer.py index b754174b2b..4b9e6c4f6a 100644 --- a/monai/apps/auto3dseg/data_analyzer.py +++ b/monai/apps/auto3dseg/data_analyzer.py @@ -213,7 +213,7 @@ def get_all_case_stats(self, key="training", transform_list=None): ] if self.label_key is not None: - allowed_shape_difference = self.extra_params.get("allowed_shape_difference", 5) + allowed_shape_difference = self.extra_params.pop("allowed_shape_difference", 5) transform_list.append( EnsureSameShaped( keys=self.label_key, From 9c5593f62ec599f0a1883200ca1f251181b6ae43 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Thu, 1 Dec 2022 12:03:03 +0000 Subject: [PATCH 11/12] fixes tests Signed-off-by: Wenqi Li --- tests/test_spacing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_spacing.py b/tests/test_spacing.py index ba44bf76f2..90fc05b40f 100644 --- a/tests/test_spacing.py +++ b/tests/test_spacing.py @@ -20,7 +20,7 @@ from monai.data.utils import affine_to_spacing from monai.transforms import Spacing from monai.utils import fall_back_tuple -from tests.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, assert_allclose +from tests.utils import TEST_DEVICES, TEST_NDARRAYS_ALL, assert_allclose, skip_if_quick TESTS = [] for device in TEST_DEVICES: @@ -261,6 +261,7 @@ TEST_INVERSE.append([*d, recompute, align, scale_extent]) +@skip_if_quick class TestSpacingCase(unittest.TestCase): @parameterized.expand(TESTS) def test_spacing(self, init_param, img, affine, data_param, expected_output, device): From 29a34ad830976cf51d69a777a83ec0798e7a6dca Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Thu, 1 Dec 2022 12:07:59 +0000 Subject: [PATCH 12/12] skip build Signed-off-by: Wenqi Li --- .github/workflows/pythonapp.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index f3a3fba46e..fb68e04b44 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -100,6 +100,10 @@ jobs: python -m pip install -r requirements-dev.txt python -m pip list python setup.py develop # test no compile installation + shell: bash + - if: runner.os != 'windows' + name: Run compiled (${{ runner.os }}) + run: | python setup.py develop --uninstall BUILD_MONAI=1 python setup.py develop # compile the cpp extensions shell: bash