Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix horizontal flip width index access

edgarriba390e84bb7564
diff --git a/kornia/augmentation/augmentations.py b/kornia/augmentation/augmentations.py
index ab64ef7b7..b55fb96e1 100644
--- a/kornia/augmentation/augmentations.py
+++ b/kornia/augmentation/augmentations.py
@@ -165,7 +165,7 @@ def random_hflip(input: torch.Tensor, p: float = 0.5, return_transform: bool = F
trans_mat: torch.Tensor = torch.eye(3, device=device, dtype=dtype).repeat(input.shape[0], 1, 1)
- w: int = input.shape[-2]
+ w: int = input.shape[-1]
flip_mat: torch.Tensor = torch.tensor([[-1, 0, w],
[0, 1, 0],
[0, 0, 1]])
diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.py
index dd519db3f..f6acc9273 100644
--- a/test/augmentation/test_augmentation.py
+++ b/test/augmentation/test_augmentation.py
@@ -25,15 +25,15 @@ class TestRandomHorizontalFlip:
f2 = RandomHorizontalFlip(p=1.)
f3 = RandomHorizontalFlip(p=0.)
- input = torch.tensor([[0., 0., 0.],
- [0., 0., 0.],
- [0., 1., 1.]]) # 3 x 3
+ input = torch.tensor([[0., 0., 0., 0.],
+ [0., 0., 0., 0.],
+ [0., 0., 1., 2.]]) # 3 x 4
- expected = torch.tensor([[0., 0., 0.],
- [0., 0., 0.],
- [1., 1., 0.]]) # 3 x 3
+ expected = torch.tensor([[0., 0., 0., 0.],
+ [0., 0., 0., 0.],
+ [2., 1., 0., 0.]]) # 3 x 4
- expected_transform = torch.tensor([[-1., 0., 3.],
+ expected_transform = torch.tensor([[-1., 0., 4.],
[0., 1., 0.],
[0., 0., 1.]]) # 3 x 3