diff --git a/monai/inferers/inferer.py b/monai/inferers/inferer.py index bc55cef15ca..ce8a0d468ea 100644 --- a/monai/inferers/inferer.py +++ b/monai/inferers/inferer.py @@ -1773,7 +1773,7 @@ def __init__( super().__init__(scheduler=scheduler) self.scale_factor = scale_factor if (ldm_latent_shape is None) ^ (autoencoder_latent_shape is None): - raise ValueError("If ldm_latent_shape is None, autoencoder_latent_shape must be None" "and vice versa.") + raise ValueError("If ldm_latent_shape is None, autoencoder_latent_shape must be None and vice versa.") self.ldm_latent_shape = ldm_latent_shape self.autoencoder_latent_shape = autoencoder_latent_shape if self.ldm_latent_shape is not None and self.autoencoder_latent_shape is not None: diff --git a/monai/metrics/utils.py b/monai/metrics/utils.py index a5927a0a5be..a68d0c198d6 100644 --- a/monai/metrics/utils.py +++ b/monai/metrics/utils.py @@ -101,7 +101,7 @@ def do_metric_reduction( Raises: ValueError: When ``reduction`` is not one of - ["mean", "sum", "mean_batch", "sum_batch", "mean_channel", "sum_channel" "none"]. + ["mean", "sum", "mean_batch", "sum_batch", "mean_channel", "sum_channel", "none"]. """ # some elements might be Nan (if ground truth y was missing (zeros)) @@ -141,7 +141,7 @@ def do_metric_reduction( elif reduction != MetricReduction.NONE: raise ValueError( f"Unsupported reduction: {reduction}, available options are " - '["mean", "sum", "mean_batch", "sum_batch", "mean_channel", "sum_channel" "none"].' + '["mean", "sum", "mean_batch", "sum_batch", "mean_channel", "sum_channel", "none"].' ) return f, not_nans diff --git a/monai/networks/utils.py b/monai/networks/utils.py index 0c40e5318b6..83815fc5436 100644 --- a/monai/networks/utils.py +++ b/monai/networks/utils.py @@ -440,7 +440,7 @@ def pixelunshuffle(x: torch.Tensor, spatial_dims: int, scale_factor: int) -> tor if any(d % factor != 0 for d in input_size[2:]): raise ValueError( - f"All spatial dimensions must be divisible by factor {factor}. " f", spatial shape is: {input_size[2:]}" + f"All spatial dimensions must be divisible by factor {factor}, spatial shape is: {input_size[2:]}" ) output_size = [batch_size, new_channels] + [d // factor for d in input_size[2:]] reshaped_size = [batch_size, channels] + sum([[d // factor, factor] for d in input_size[2:]], []) diff --git a/tests/networks/utils/test_pixelunshuffle.py b/tests/networks/utils/test_pixelunshuffle.py index 49b61440e50..cc9ae0d19f2 100644 --- a/tests/networks/utils/test_pixelunshuffle.py +++ b/tests/networks/utils/test_pixelunshuffle.py @@ -40,6 +40,11 @@ def test_different_scale_factor(self): out = pixelunshuffle(x, spatial_dims=2, scale_factor=3) torch.testing.assert_close(out, torch.pixel_unshuffle(x, 3)) + def test_indivisible_spatial_dims(self): + x = torch.randn(1, 2, 7, 8) + with self.assertRaisesRegex(ValueError, r"divisible by factor 2, spatial shape is: \[7, 8\]"): + pixelunshuffle(x, spatial_dims=2, scale_factor=2) + def test_inverse_operation(self): x = torch.arange(4096).reshape(1, 8, 8, 8, 8) shuffled = pixelshuffle(x, spatial_dims=3, scale_factor=2)