Repository: Project-MONAI/MONAI

Issue:
`random_size` defaulting to `False` in RandSpatialCropd
### Discussed in https://github.com/Project-MONAI/MONAI/discussions/5651

<div type='discussions-op-text'>

<sup>Originally posted by **MathijsdeBoer** December  5, 2022</sup>
Hello all!

I've just spent way too much time on debugging a weird shape issue (as is common in deep learning) when trying to get a quick prototype going. Eventually I found out that the input patches would have inconsistent shapes, leading me to run through all of my transforms expecting a mistake, or some other unexpected behavior that I didn't account for.

Eventually, when running through I noticed that `transforms.RandSpatialCropd` (And the non-dictionary version) have `random_size=True` by default. To my mind, this is counter to expected default behavior. If I call a `RandSpatialCropd(keys=some_keys, roi_size=some_size)`, I am not expecting my outputs to have random shapes unless specifically enabled.

Would a switch to `random_size=False` be a reasonable change to make in the next update?</div>


Discussion:
@wyli To add to this discussion, I also agree that this would be a reasonable default considering my use cases. This applies to transforms like `RandScaleCrop` as well. I've explicitly set the `random_size=False` for quite a few projects.  

I'm happy to contribute if this is still on the roadmap to be included.  

Resolving patch:
diff --git a/monai/transforms/croppad/array.py b/monai/transforms/croppad/array.py
--- a/monai/transforms/croppad/array.py
+++ b/monai/transforms/croppad/array.py
@@ -52,6 +52,7 @@
     convert_data_type,
     convert_to_dst_type,
     convert_to_tensor,
+    deprecated_arg_default,
     ensure_tuple,
     ensure_tuple_rep,
     fall_back_tuple,
@@ -585,6 +586,7 @@ class RandSpatialCrop(Randomizable, Crop):
             if True, the actual size is sampled from `randint(roi_size, max_roi_size + 1)`.
     """
 
+    @deprecated_arg_default("random_size", True, False, since="1.1", replaced="1.3")
     def __init__(
         self,
         roi_size: Sequence[int] | int,
@@ -647,6 +649,7 @@ class RandScaleCrop(RandSpatialCrop):
             `randint(roi_scale * image spatial size, max_roi_scale * image spatial size + 1)`.
     """
 
+    @deprecated_arg_default("random_size", True, False, since="1.1", replaced="1.3")
     def __init__(
         self,
         roi_scale: Sequence[float] | float,
@@ -713,6 +716,7 @@ class RandSpatialCropSamples(Randomizable, TraceableTransform):
 
     backend = RandSpatialCrop.backend
 
+    @deprecated_arg_default("random_size", True, False, since="1.1", replaced="1.3")
     def __init__(
         self,
         roi_size: Sequence[int] | int,
diff --git a/monai/transforms/croppad/dictionary.py b/monai/transforms/croppad/dictionary.py
--- a/monai/transforms/croppad/dictionary.py
+++ b/monai/transforms/croppad/dictionary.py
@@ -49,7 +49,7 @@
 from monai.transforms.inverse import InvertibleTransform
 from monai.transforms.transform import MapTransform, Randomizable
 from monai.transforms.utils import is_positive
-from monai.utils import MAX_SEED, Method, PytorchPadMode, ensure_tuple_rep
+from monai.utils import MAX_SEED, Method, PytorchPadMode, deprecated_arg_default, ensure_tuple_rep
 
 __all__ = [
     "Padd",
@@ -475,6 +475,7 @@ class RandSpatialCropd(RandCropd):
         allow_missing_keys: don't raise exception if key is missing.
     """
 
+    @deprecated_arg_default("random_size", True, False, since="1.1", replaced="1.3")
     def __init__(
         self,
         keys: KeysCollection,
@@ -513,6 +514,7 @@ class RandScaleCropd(RandCropd):
         allow_missing_keys: don't raise exception if key is missing.
     """
 
+    @deprecated_arg_default("random_size", True, False, since="1.1", replaced="1.3")
     def __init__(
         self,
         keys: KeysCollection,
@@ -564,6 +566,7 @@ class RandSpatialCropSamplesd(Randomizable, MapTransform):
 
     backend = RandSpatialCropSamples.backend
 
+    @deprecated_arg_default("random_size", True, False, since="1.1", replaced="1.3")
     def __init__(
         self,
         keys: KeysCollection,


Test patch: