From 5c3cba9f079554916d7000431db7b22596165f5a Mon Sep 17 00:00:00 2001 From: Emdya Permuy <67919243+Emdya@users.noreply.github.com> Date: Tue, 1 Jul 2025 19:57:54 -0400 Subject: [PATCH 1/6] Add input validation to ImageStats class --- monai/auto3dseg/analyzer.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/monai/auto3dseg/analyzer.py b/monai/auto3dseg/analyzer.py index e60327b551..09888d0458 100644 --- a/monai/auto3dseg/analyzer.py +++ b/monai/auto3dseg/analyzer.py @@ -217,6 +217,28 @@ def __init__(self, image_key: str, stats_name: str = DataStatsKeys.IMAGE_STATS) self.update_ops(ImageStatsKeys.INTENSITY, SampleOperations()) def __call__(self, data): + #Input Validation Addition + if not isinstance(data, dict): + raise TypeError(f"Input data must be a dict, but got {type(data).__name__}.") + if self.image_key not in data: + raise KeyError(f"Key '{self.image_key}' not found in input data.") + image = data[self.image_key] + if not isinstance(image, (np.ndarray, torch.Tensor, MetaTensor)): + raise TypeError( + f"Value for '{self.image_key}' must be a numpy array, torch.Tensor, or MetaTensor, " + f"but got {type(image).__name__}." + ) + if image.ndim < 3: + raise ValueError( + f"Value for '{self.image_key}' must be a numpy array, torch.Tensor, or MetaTensor, " + f"but got {type(image).__name__}." + ) + if image.ndim < 3: + raise ValueError( + f"Image data under '{self.image_key}' must have at least 3 dimensions, " + f"but got shape {image.shape}." + ) + # --- End of validation --- """ Callable to execute the pre-defined functions From b11d897cb5c4f73e7261f935613688980df5fcc4 Mon Sep 17 00:00:00 2001 From: Emdya Permuy <67919243+Emdya@users.noreply.github.com> Date: Tue, 1 Jul 2025 20:04:32 -0400 Subject: [PATCH 2/6] DCO Remediation Commit for Emdya Permuy <67919243+Emdya@users.noreply.github.com> I, Emdya Permuy <67919243+Emdya@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 5c3cba9f079554916d7000431db7b22596165f5a Signed-off-by: Emdya Permuy <67919243+Emdya@users.noreply.github.com> From 06c41a85b16a703d3c4fe076b88e749edc866ed8 Mon Sep 17 00:00:00 2001 From: Emdya Permuy <67919243+Emdya@users.noreply.github.com> Date: Tue, 1 Jul 2025 20:17:45 -0400 Subject: [PATCH 3/6] Style: auto-format analyzer.py to pass black check --- monai/auto3dseg/analyzer.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/monai/auto3dseg/analyzer.py b/monai/auto3dseg/analyzer.py index 09888d0458..39c95a7eb0 100644 --- a/monai/auto3dseg/analyzer.py +++ b/monai/auto3dseg/analyzer.py @@ -217,7 +217,7 @@ def __init__(self, image_key: str, stats_name: str = DataStatsKeys.IMAGE_STATS) self.update_ops(ImageStatsKeys.INTENSITY, SampleOperations()) def __call__(self, data): - #Input Validation Addition + # Input Validation Addition if not isinstance(data, dict): raise TypeError(f"Input data must be a dict, but got {type(data).__name__}.") if self.image_key not in data: @@ -235,8 +235,7 @@ def __call__(self, data): ) if image.ndim < 3: raise ValueError( - f"Image data under '{self.image_key}' must have at least 3 dimensions, " - f"but got shape {image.shape}." + f"Image data under '{self.image_key}' must have at least 3 dimensions, " f"but got shape {image.shape}." ) # --- End of validation --- """ From 6925e9f1554b203e46d7bb5b3403c1e0579582c5 Mon Sep 17 00:00:00 2001 From: Emdya Permuy <67919243+Emdya@users.noreply.github.com> Date: Tue, 1 Jul 2025 20:19:18 -0400 Subject: [PATCH 4/6] DCO Remediation Commit for Emdya Permuy <67919243+Emdya@users.noreply.github.com> I, Emdya Permuy <67919243+Emdya@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 06c41a85b16a703d3c4fe076b88e749edc866ed8 Signed-off-by: Emdya Permuy <67919243+Emdya@users.noreply.github.com> From fc2889cf35a60f83d763f2fbe7397f3a99f2f2e7 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 18 Jul 2025 22:28:00 +0800 Subject: [PATCH 5/6] Apply suggestion from @ericspod Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/auto3dseg/analyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/auto3dseg/analyzer.py b/monai/auto3dseg/analyzer.py index 39c95a7eb0..4efa5836d0 100644 --- a/monai/auto3dseg/analyzer.py +++ b/monai/auto3dseg/analyzer.py @@ -235,7 +235,7 @@ def __call__(self, data): ) if image.ndim < 3: raise ValueError( - f"Image data under '{self.image_key}' must have at least 3 dimensions, " f"but got shape {image.shape}." + f"Image data under '{self.image_key}' must have at least 3 dimensions, but got shape {image.shape}." ) # --- End of validation --- """ From 0efaaa6152b9c957ac501d2f12d31895061625fc Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 18 Jul 2025 22:28:07 +0800 Subject: [PATCH 6/6] Apply suggestion from @ericspod Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/auto3dseg/analyzer.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/monai/auto3dseg/analyzer.py b/monai/auto3dseg/analyzer.py index 4efa5836d0..f3f52d3a95 100644 --- a/monai/auto3dseg/analyzer.py +++ b/monai/auto3dseg/analyzer.py @@ -228,11 +228,6 @@ def __call__(self, data): f"Value for '{self.image_key}' must be a numpy array, torch.Tensor, or MetaTensor, " f"but got {type(image).__name__}." ) - if image.ndim < 3: - raise ValueError( - f"Value for '{self.image_key}' must be a numpy array, torch.Tensor, or MetaTensor, " - f"but got {type(image).__name__}." - ) if image.ndim < 3: raise ValueError( f"Image data under '{self.image_key}' must have at least 3 dimensions, but got shape {image.shape}."