Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix batch issue in random_affine

edgarriba877274b9cd49
diff --git a/kornia/augmentation/param_gen.py b/kornia/augmentation/param_gen.py
index 458f05f1c..f2155c800 100644
--- a/kornia/augmentation/param_gen.py
+++ b/kornia/augmentation/param_gen.py
@@ -265,6 +265,7 @@ def _get_random_affine_params(
center: torch.Tensor = torch.tensor(
[width, height], dtype=torch.float32).view(1, 2) / 2
+ center = center.expand(batch_size, -1)
# concatenate transforms
transform: torch.Tensor = get_rotation_matrix2d(center, angle, scale)
diff --git a/test/augmentation/test_perspective.py b/test/augmentation/test_perspective.py
index 72cb85454..17e72c228 100644
--- a/test/augmentation/test_perspective.py
+++ b/test/augmentation/test_perspective.py
@@ -109,6 +109,13 @@ class TestRandomAffine:
assert out.shape == x_data.shape
+ def test_smoke_no_transform_batch(self, device):
+ x_data = torch.rand(2, 2, 8, 9).to(device)
+
+ out = F.random_affine(x_data, 0.)
+
+ assert out.shape == x_data.shape
+
def test_smoke_transform(self, device):
x_data = torch.rand(1, 2, 4, 5).to(device)