Repository: kornia/kornia

Issue:
AugmentationSequential not compatible with RandomResizedCrop
### Describe the bug

I'm trying to use the AugmentationSequential container and include Resize or RandomResizedCrop. However this doesn't seem to work no matter what settings I use.

### Reproduction steps

I'm trying to run the following code:
```python
import kornia.augmentation as K                                                          
import torch                                                                             
from kornia.constants import Resample                                                    
                                                                                         
rng = torch.manual_seed(0)                                                               
input = torch.arange(9).reshape(1, 1, 3, 3).float()                                      
mask = torch.arange(9).reshape(1, 1, 3, 3).float()                                       
aug = K.AugmentationSequential(K.RandomResizedCrop((2, 2), scale=(0.6, 1)), data_keys=["input", "mask"])
out = aug(input, mask) 
```
However, this results in the following error:
```
Traceback (most recent call last):
  File "/Users/Adam/torchgeo/test.py", line 9, in <module>
    out = aug(input, mask)
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/kornia/augmentation/container/augment.py", line 373, in forward
    outputs = self.transform_op.transform(  # type: ignore
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/kornia/augmentation/container/ops.py", line 107, in transform
    outputs.append(op.transform(inp, module, param=param, extra_args=extra_arg))
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/kornia/augmentation/container/ops.py", line 198, in transform
    input = module.transform_masks(
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/kornia/augmentation/base.py", line 301, in transform_masks
    output = self.apply_transform_mask(in_tensor, params, flags, transform=transform)
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/kornia/augmentation/_2d/geometric/base.py", line 73, in apply_transform_mask
    output = self.apply_transform(input, params, flags, transform)
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/kornia/augmentation/_2d/geometric/resized_crop.py", line 108, in apply_transform
    return crop_by_indices(
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/kornia/geometry/transform/crop2d.py", line 330, in crop_by_indices
    return resize(
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/kornia/utils/image.py", line 226, in _wrapper
    output = f(input, *args, **kwargs)
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/kornia/geometry/transform/affwarp.py", line 600, in resize
    output = torch.nn.functional.interpolate(input, size=size, mode=interpolation, align_corners=align_corners)
  File "/Users/Adam/spack/var/spack/environments/system/.spack-env/view/lib/python3.10/site-packages/torch/nn/functional.py", line 3848, in interpolate
    raise ValueError(
ValueError: align_corners option can only be set with the interpolating modes: linear | bilinear | bicubic | trilinear
```
This error doesn't make sense since default resampling method is bilinear. Let's try disabling align_corners:
```python
aug = K.AugmentationSequential(K.RandomResizedCrop((2, 2), scale=(0.6, 1), align_corners=False), data_keys=["input", "mask"])
```
Nope, same error. Let's try explicitly setting the interpolation method:
```python
aug = K.AugmentationSequential(K.RandomResizedCrop((2, 2), scale=(0.6, 1), resample=Resample.BILINEAR.name, align_corners=False), data_keys=["input", "mask"])
```
Nope, still the same error.

### Expected behavior

I would expect the error message to explain why the above code is invalid. It's unclear if the bug is in the code or in the error message.

### Environment

```shell
- PyTorch Version: 2.0.0
- OS: macOS 13.4
- How you installed PyTorch: Spack
- Build command you used: N/A
- Python version: 3.10.10
- CUDA/cuDNN version: N/A
- GPU models and configuration: N/A
- Any other relevant information: N/A
```


### Additional context

@nilsleh @isaaccorley 


Discussion:
Also tried: `extra_args={DataKey.MASK: {"resample": Resample.NEAREST, "align_corners": False}}` but that didn't help.
The only workaround I've found so far is `cropping_mode="resample"`
Other workaround:
```
extra_args={DataKey.MASK: {"resample": Resample.NEAREST, "align_corners": None}}
```
We should probably change the default for AugmentationSequential to be valid.
any clue here @shijianjian?
Not sure what is the proper fix here.

Probably to make ```extra_args={DataKey.MASK: {"resample": Resample.NEAREST, "align_corners": None}}``` as the default?

https://github.com/kornia/kornia/blob/15d71d1f3bac77f674baaeb71848fafbb7d7e0eb/kornia/augmentation/container/augment.py#L162


Either that or change the default in `RandomResizedCrop`. If you make a decision I'm happy to open a PR.
> Not sure what is the proper fix here.
> 
> 
> 
> Probably to make ```extra_args={DataKey.MASK: {"resample": Resample.NEAREST, "align_corners": None}}``` as the default?
> 
> 
> 
> https://github.com/kornia/kornia/blob/15d71d1f3bac77f674baaeb71848fafbb7d7e0eb/kornia/augmentation/container/augment.py#L162
> 
> 
> 
> 

@adamjstewart Great. This approach looks like a cleaner one. 
Will get to this after the NeurIPS Datasets and Benchmark deadline 😄 

Resolving patch:
diff --git a/kornia/augmentation/container/augment.py b/kornia/augmentation/container/augment.py
--- a/kornia/augmentation/container/augment.py
+++ b/kornia/augmentation/container/augment.py
@@ -159,7 +159,7 @@ def __init__(
         random_apply: Union[int, bool, Tuple[int, int]] = False,
         random_apply_weights: Optional[List[float]] = None,
         transformation_matrix: str = "silence",
-        extra_args: Dict[DataKey, Dict[str, Any]] = {DataKey.MASK: dict(resample=Resample.NEAREST, align_corners=True)},
+        extra_args: Dict[DataKey, Dict[str, Any]] = {DataKey.MASK: dict(resample=Resample.NEAREST, align_corners=None)},
     ) -> None:
         super().__init__(
             *args,


Test patch:
diff --git a/test/augmentation/test_container.py b/test/augmentation/test_container.py
--- a/test/augmentation/test_container.py
+++ b/test/augmentation/test_container.py
@@ -450,6 +450,18 @@ def test_random_crops(self, device, dtype):
         assert out_inv[3].shape == points.shape
         assert_close(out_inv[3], points, atol=1e-4, rtol=1e-4)
 
+    def test_random_resized_crop(self, device, dtype):
+        size = 50
+        input = torch.randn(3, 3, 100, 100, device=device, dtype=dtype)
+        mask = torch.randn(3, 1, 100, 100, device=device, dtype=dtype)
+        aug = K.AugmentationSequential(K.RandomResizedCrop((size, size), p=1.0), data_keys=["input", "mask"])
+
+        reproducibility_test((input, mask), aug)
+
+        out = aug(input, mask)
+        assert out[0].shape == (3, 3, size, size)
+        assert out[1].shape == (3, 1, size, size)
+
     @pytest.mark.parametrize(
         'bbox',
         [