Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Fixed scale parameter generation (#1400)

Anirudh Buvanesh9a0e2e0ddfa6
diff --git a/kornia/augmentation/random_generator/random_generator3d.py b/kornia/augmentation/random_generator/random_generator3d.py
index 8aa9a7828..1049dd8b3 100644
--- a/kornia/augmentation/random_generator/random_generator3d.py
+++ b/kornia/augmentation/random_generator/random_generator3d.py
@@ -119,7 +119,7 @@ def random_affine_generator3d(
dim=1,
)
else:
- scale = torch.ones(batch_size, device=device, dtype=dtype).repeat(1, 3)
+ scale = torch.ones(batch_size, device=device, dtype=dtype).reshape(batch_size, 1).repeat(1, 3)
if translate is not None:
if translate.shape != torch.Size([3]):
diff --git a/test/augmentation/test_augmentation_3d.py b/test/augmentation/test_augmentation_3d.py
index e78541ec3..1ef701789 100644
--- a/test/augmentation/test_augmentation_3d.py
+++ b/test/augmentation/test_augmentation_3d.py
@@ -8,6 +8,7 @@ from torch.autograd import gradcheck
import kornia
import kornia.testing as utils # test utils
from kornia.augmentation import (
+ RandomAffine3D,
RandomCrop,
RandomCrop3D,
RandomDepthicalFlip3D,
@@ -960,3 +961,26 @@ class TestRandomEqualize3D:
batch = torch.stack([image3d] * bs)
return batch.to(device, dtype)
+
+
+class TestRandomAffine3D:
+
+ def test_batch_random_affine_3d(self, device, dtype):
+
+ f = RandomAffine3D((0, 0, 0), p=1., return_transform=True) # No rotation
+ tensor = torch.tensor([[[[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]]],
+ device=device, dtype=dtype) # 1 x 1 x 1 x 3 x 3
+
+ expected = torch.tensor([[[[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]]],
+ device=device, dtype=dtype) # 1 x 1 x 1 x 3 x 3
+
+ expected_transform = torch.tensor(
+ [[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]],
+ device=device, dtype=dtype) # 1 x 4 x 4
+
+ tensor = tensor.repeat(5, 3, 1, 1, 1) # 5 x 3 x 3 x 3 x 3
+ expected = expected.repeat(5, 3, 1, 1, 1) # 5 x 3 x 3 x 3 x 3
+ expected_transform = expected_transform.repeat(5, 1, 1) # 5 x 4 x 4
+
+ assert (f(tensor)[0] == expected).all()
+ assert (f(tensor)[1] == expected_transform).all()