Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

None for align_corners arg of resize op with nearest mode (#2049)

Miquel Martí19fd06b4fe24
diff --git a/kornia/augmentation/_2d/geometric/resize.py b/kornia/augmentation/_2d/geometric/resize.py
index ce03db35d..ddc1f3986 100644
--- a/kornia/augmentation/_2d/geometric/resize.py
+++ b/kornia/augmentation/_2d/geometric/resize.py
@@ -64,7 +64,9 @@ class Resize(GeometricAugmentationBase2D):
input[i : i + 1, :, y1:y2, x1:x2],
out_size,
interpolation=flags["resample"].name.lower(),
- align_corners=flags["align_corners"],
+ align_corners=flags["align_corners"]
+ if flags["resample"] in [Resample.BILINEAR, Resample.BICUBIC]
+ else None,
antialias=flags["antialias"],
)
return out
diff --git a/test/augmentation/test_container.py b/test/augmentation/test_container.py
index 7948b892c..ce3e535c6 100644
--- a/test/augmentation/test_container.py
+++ b/test/augmentation/test_container.py
@@ -357,6 +357,18 @@ class TestAugmentationSequential:
out = aug(input, input)
assert torch.all(out[1][out[0] == fill_value] == 0.0)
+ def test_resize(self, device, dtype):
+ size = 50
+ input = torch.randn(3, 3, 100, 100, device=device, dtype=dtype)
+ mask = torch.randn(3, 1, 100, 100, device=device, dtype=dtype)
+ aug = K.AugmentationSequential(K.Resize((size, size), p=1.0), data_keys=["input", "mask"])
+
+ reproducibility_test((input, mask), aug)
+
+ out = aug(input, mask)
+ assert out[0].shape == (3, 3, size, size)
+ assert out[1].shape == (3, 1, size, size)
+
def test_random_crops(self, device, dtype):
torch.manual_seed(233)
input = torch.randn(3, 3, 3, 3, device=device, dtype=dtype)