Repository: kornia/kornia

Issue:
Weird behavior of LongestMaxSize
### Describe the bug

Hello me again,

I might be doing something wrong with the way I use kornia augmentations, please let me know if it is the case.

I was expecting `LongestMaxSize` in kornia to perform similarily as the albumentation implementation. Meaning that I can throw any images with different shapes to the the transformation function and get an image with different shapes but similar ratios. The largest size being equal to the value given to `LongestMaxSize`.

See bellow a small code sample that disturbs me.

### Reproduction steps

```bash
import kornia.augmentation as K
a = torch.ones((512, 256))
b = torch.ones((512, 756))

print("first try")
transfo = K.LongestMaxSize(max_size=256, p=1.)

print(transfo(a).shape)
print(transfo(b).shape)

print("second try")

a = torch.ones((512, 256))
b = torch.ones((512, 756))

transfo = K.LongestMaxSize(max_size=256, p=1.)
print(transfo(b).shape)
print(transfo(a).shape)

Outputs:
first try
torch.Size([1, 1, 256, 128])
torch.Size([1, 1, 256, 128])
second try
torch.Size([1, 1, 173, 256])
torch.Size([1, 1, 173, 256])
```


### Expected behavior

I would expect to have the same values for the transformations no matter the order of the elements.

ie `transfo(a).shape == torch.Size([1, 1, 256, 128])` and `transfo(b).shape ==torch.Size([1, 1, 173, 256])`

Am I missing something here ?

### Environment

```shell
kornia='0.6.9'
torch='1.12.1+cu113'
```


### Additional context

_No response_


Discussion:
Seems like Resize behave similarly when size is an integer.
@johnnv1 @shijianjian Is this the expected behavior ?
@twsl Can you take a look?
Unfortunately I don't have much time right now, but a quick peek at the source code makes me wonder if the resize generator in the resize augmentation does include any checks to recalculate the parameters
@johnnv1 Can you help fix it if you got some time?
as @twsl commented, seems for this case we need to recompute the params -- i'm not sure of the best way to try avoid generating the params in each call  

Resolving patch:
diff --git a/kornia/augmentation/random_generator/_2d/resize.py b/kornia/augmentation/random_generator/_2d/resize.py
--- a/kornia/augmentation/random_generator/_2d/resize.py
+++ b/kornia/augmentation/random_generator/_2d/resize.py
@@ -66,25 +66,27 @@ def forward(self, batch_shape: torch.Size, same_on_batch: bool = False) -> Dict[
 
         if isinstance(self.output_size, int):
             aspect_ratio = w / h
-            self.output_size = _side_to_image_size(self.output_size, aspect_ratio, self.side)
+            output_size = _side_to_image_size(self.output_size, aspect_ratio, self.side)
+        else:
+            output_size = self.output_size
 
         if not (
-            len(self.output_size) == 2
-            and isinstance(self.output_size[0], (int,))
-            and isinstance(self.output_size[1], (int,))
-            and self.output_size[0] > 0
-            and self.output_size[1] > 0
+            len(output_size) == 2
+            and isinstance(output_size[0], (int,))
+            and isinstance(output_size[1], (int,))
+            and output_size[0] > 0
+            and output_size[1] > 0
         ):
-            raise AssertionError(f"`resize_to` must be a tuple of 2 positive integers. Got {self.output_size}.")
+            raise AssertionError(f"`resize_to` must be a tuple of 2 positive integers. Got {output_size}.")
 
         dst = bbox_generator(
             tensor(0, device=_device, dtype=_dtype),
             tensor(0, device=_device, dtype=_dtype),
-            tensor(self.output_size[1], device=_device, dtype=_dtype),
-            tensor(self.output_size[0], device=_device, dtype=_dtype),
+            tensor(output_size[1], device=_device, dtype=_dtype),
+            tensor(output_size[0], device=_device, dtype=_dtype),
         ).repeat(batch_size, 1, 1)
 
         _input_size = tensor(input_size, device=_device, dtype=torch.long).expand(batch_size, -1)
-        _output_size = tensor(self.output_size, device=_device, dtype=torch.long).expand(batch_size, -1)
+        _output_size = tensor(output_size, device=_device, dtype=torch.long).expand(batch_size, -1)
 
         return dict(src=src, dst=dst, input_size=_input_size, output_size=_output_size)


Test patch:
diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.py
--- a/test/augmentation/test_augmentation.py
+++ b/test/augmentation/test_augmentation.py
@@ -3727,18 +3727,30 @@ def test_smoke(self, device, dtype):
 
 class TestSmallestMaxSize:
     def test_smoke(self, device, dtype):
-        img = torch.rand(1, 1, 4, 6, device=device, dtype=dtype)
+        img_A = torch.rand(1, 1, 4, 6, device=device, dtype=dtype)
+        img_B = torch.rand(1, 1, 9, 6, device=device, dtype=dtype)
         aug = SmallestMaxSize(max_size=2)
-        out = aug(img)
-        assert out.shape == (1, 1, 2, 3)
+
+        assert aug(img_A).shape == (1, 1, 2, 3)
+        assert aug(img_B).shape == (1, 1, 3, 2)
+
+        aug = SmallestMaxSize(max_size=2)
+        assert aug(img_B).shape == (1, 1, 3, 2)
+        assert aug(img_A).shape == (1, 1, 2, 3)
 
 
 class TestLongestMaxSize:
     def test_smoke(self, device, dtype):
-        img = torch.rand(1, 1, 4, 6, device=device, dtype=dtype)
+        img_A = torch.rand(1, 1, 4, 6, device=device, dtype=dtype)
+        img_B = torch.rand(1, 1, 8, 6, device=device, dtype=dtype)
         aug = LongestMaxSize(max_size=3)
-        out = aug(img)
-        assert out.shape == (1, 1, 2, 3)
+
+        assert aug(img_A).shape == (1, 1, 2, 3)
+        assert aug(img_B).shape == (1, 1, 3, 2)
+
+        aug = LongestMaxSize(max_size=3)
+        assert aug(img_B).shape == (1, 1, 3, 2)
+        assert aug(img_A).shape == (1, 1, 2, 3)
 
 
 class TestRandomPosterize: