Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Fixed #927. (#942)

shijianjian0fad98765dd5
diff --git a/kornia/augmentation/augmentation.py b/kornia/augmentation/augmentation.py
index 9203b3988..a5852b49d 100644
--- a/kornia/augmentation/augmentation.py
+++ b/kornia/augmentation/augmentation.py
@@ -872,7 +872,8 @@ class RandomResizedCrop(AugmentationBase2D):
scale = torch.as_tensor(self.scale, device=self._device, dtype=self._dtype)
ratio = torch.as_tensor(self.ratio, device=self._device, dtype=self._dtype)
target_size: torch.Tensor = rg.random_crop_size_generator(
- batch_shape[0], self.size, scale, ratio, self.same_on_batch, self.device, self.dtype)['size']
+ batch_shape[0], (batch_shape[-2], batch_shape[-1]), scale, ratio, self.same_on_batch,
+ self.device, self.dtype)['size']
return rg.random_crop_generator(batch_shape[0], (batch_shape[-2], batch_shape[-1]), target_size,
resize_to=self.size, same_on_batch=self.same_on_batch,
device=self.device, dtype=self.dtype)
diff --git a/kornia/augmentation/random_generator/random_generator.py b/kornia/augmentation/random_generator/random_generator.py
index 466abcd48..a184e82bf 100644
--- a/kornia/augmentation/random_generator/random_generator.py
+++ b/kornia/augmentation/random_generator/random_generator.py
@@ -490,7 +490,7 @@ def random_crop_size_generator(
w = torch.sqrt(area * aspect_ratio).round().floor()
h = torch.sqrt(area / aspect_ratio).round().floor()
# Element-wise w, h condition
- cond = ((0 < w) * (w < size[1]) * (0 < h) * (h < size[0])).int()
+ cond = ((0 < w) * (w < size[0]) * (0 < h) * (h < size[1])).int()
# torch.argmax is not reproducible accross devices: https://github.com/pytorch/pytorch/issues/17738
# Here, we will select the first occurance of the duplicated elements.
diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.py
index 7b0bab2b0..25d3b6ddd 100644
--- a/test/augmentation/test_augmentation.py
+++ b/test/augmentation/test_augmentation.py
@@ -2123,8 +2123,8 @@ class TestRandomResizedCrop:
]], device=device, dtype=dtype)
expected = torch.tensor(
- [[[[4.0000, 4.5000, 5.0000],
- [7.0000, 7.5000, 8.0000]]]], device=device, dtype=dtype)
+ [[[[0.0000, 1.0000, 2.0000],
+ [6.0000, 7.0000, 8.0000]]]], device=device, dtype=dtype)
rrc = RandomResizedCrop(
size=(2, 3), scale=(1., 1.), ratio=(1.0, 1.0))