Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Repr functions and smoke tests fixed (#710)

FGerif2579e9e1da2
diff --git a/kornia/augmentation/augmentation.py b/kornia/augmentation/augmentation.py
index b96071e72..faa16f8c4 100644
--- a/kornia/augmentation/augmentation.py
+++ b/kornia/augmentation/augmentation.py
@@ -720,7 +720,7 @@ class RandomResizedCrop(AugmentationBase2D):
)
def __repr__(self) -> str:
- repr = f"size={self.size}, resize_to={self.scale}, resize_to={self.ratio}, interpolation={self.resample.name}"
+ repr = f"size={self.size}, scale={self.scale}, ratio={self.ratio}, interpolation={self.resample.name}"
return self.__class__.__name__ + f"({repr}, {super().__repr__()})"
def generate_parameters(self, batch_shape: torch.Size) -> Dict[str, torch.Tensor]:
diff --git a/kornia/augmentation/augmentation3d.py b/kornia/augmentation/augmentation3d.py
index 48b54d394..735ffde35 100644
--- a/kornia/augmentation/augmentation3d.py
+++ b/kornia/augmentation/augmentation3d.py
@@ -54,6 +54,9 @@ class RandomHorizontalFlip3D(AugmentationBase3D):
super(RandomHorizontalFlip3D, self).__init__(
p=p, return_transform=return_transform, same_on_batch=same_on_batch)
+ def __repr__(self) -> str:
+ return self.__class__.__name__ + f"({super().__repr__()})"
+
def generate_parameters(self, batch_shape: torch.Size) -> Dict[str, torch.Tensor]:
return dict()
@@ -104,6 +107,9 @@ class RandomVerticalFlip3D(AugmentationBase3D):
super(RandomVerticalFlip3D, self).__init__(
p=p, return_transform=return_transform, same_on_batch=same_on_batch)
+ def __repr__(self) -> str:
+ return self.__class__.__name__ + f"({super().__repr__()})"
+
def generate_parameters(self, batch_shape: torch.Size) -> Dict[str, torch.Tensor]:
return dict()
@@ -155,6 +161,9 @@ class RandomDepthicalFlip3D(AugmentationBase3D):
super(RandomDepthicalFlip3D, self).__init__(
p=p, return_transform=return_transform, same_on_batch=same_on_batch)
+ def __repr__(self) -> str:
+ return self.__class__.__name__ + f"({super().__repr__()})"
+
def generate_parameters(self, batch_shape: torch.Size) -> Dict[str, torch.Tensor]:
return dict()
@@ -352,7 +361,7 @@ class RandomRotation3D(AugmentationBase3D):
)
def __repr__(self) -> str:
- repr = f"(degrees={self.degrees}, resample={self.resample.name}, align_corners={self.align_corners}"
+ repr = f"degrees={self.degrees}, resample={self.resample.name}, align_corners={self.align_corners}"
return self.__class__.__name__ + f"({repr}, {super().__repr__()})"
def generate_parameters(self, batch_shape: torch.Size) -> Dict[str, torch.Tensor]:
diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.py
index 450ee0ec4..04df6a866 100644
--- a/test/augmentation/test_augmentation.py
+++ b/test/augmentation/test_augmentation.py
@@ -27,9 +27,9 @@ from kornia.augmentation import (
class TestRandomHorizontalFlip:
- def smoke_test(self, device):
+ def test_smoke(self):
f = RandomHorizontalFlip(p=0.5)
- repr = "RandomHorizontalFlip(p=0.5, return_transform=False)"
+ repr = "RandomHorizontalFlip(p=0.5, p_batch=1.0, same_on_batch=False, return_transform=False)"
assert str(f) == repr
def test_random_hflip(self, device):
@@ -216,9 +216,9 @@ class TestRandomHorizontalFlip:
class TestRandomVerticalFlip:
- def smoke_test(self, device):
+ def test_smoke(self):
f = RandomVerticalFlip(p=0.5)
- repr = "RandomVerticalFlip(p=0.5, return_transform=False)"
+ repr = "RandomVerticalFlip(p=0.5, p_batch=1.0, same_on_batch=False, return_transform=False)"
assert str(f) == repr
def test_random_vflip(self, device):
@@ -400,9 +400,11 @@ class TestRandomVerticalFlip:
class TestColorJitter:
- def smoke_test(self, device):
+ def test_smoke(self):
f = ColorJitter(brightness=0.5, contrast=0.3, saturation=[0.2, 1.2], hue=0.1)
- repr = "ColorJitter(brightness=0.5, contrast=0.3, saturation=[0.2, 1.2], hue=0.1, return_transform=False)"
+ repr = "ColorJitter(brightness=tensor([0.5000, 1.5000]), contrast=tensor([0.7000, 1.3000]), "\
+ "saturation=tensor([0.2000, 1.2000]), hue=tensor([-0.1000, 0.1000]), "\
+ "p=1.0, p_batch=1.0, same_on_batch=False, return_transform=False)"
assert str(f) == repr
def test_color_jitter(self, device):
@@ -922,7 +924,6 @@ class TestRectangleRandomErasing:
f = RandomErasing(erase_scale_range, aspect_ratio_range, same_on_batch=True, p=0.5)
input = torch.rand(shape).unsqueeze(dim=0).repeat(2, 1, 1, 1)
res = f(input)
- print(f._params)
assert (res[0] == res[1]).all()
def test_gradcheck(self, device):
@@ -960,9 +961,9 @@ class TestRectangleRandomErasing:
class TestRandomGrayscale:
- def smoke_test(self, device):
+ def test_smoke(self):
f = RandomGrayscale()
- repr = "RandomGrayscale(p=0.5, return_transform=False)"
+ repr = "RandomGrayscale(p=0.1, p_batch=1.0, same_on_batch=False, return_transform=False)"
assert str(f) == repr
def test_random_grayscale(self, device):
@@ -1172,9 +1173,10 @@ class TestRandomRotation:
torch.manual_seed(0) # for random reproductibility
- def smoke_test(self, device):
+ def test_smoke(self):
f = RandomRotation(degrees=45.5)
- repr = "RandomHorizontalFlip(degrees=45.5, return_transform=False)"
+ repr = "RandomRotation(degrees=tensor([-45.5000, 45.5000]), interpolation=BILINEAR, p=0.5, "\
+ "p_batch=1.0, same_on_batch=False, return_transform=False)"
assert str(f) == repr
def test_random_rotation(self, device):
@@ -1336,10 +1338,10 @@ class TestRandomRotation:
class TestRandomCrop:
- def smoke_test(self, device):
+ def test_smoke(self):
f = RandomCrop(size=(2, 3), padding=(0, 1), fill=10, pad_if_needed=False, p=1.)
- repr = "RandomCrop(crop_size=(2, 3), padding=(0, 1), fill=10, pad_if_needed=False,\
- return_transform=False)"
+ repr = "RandomCrop(crop_size=(2, 3), padding=(0, 1), fill=10, pad_if_needed=False, padding_mode=constant, "\
+ "resample=BILINEAR, p=1.0, p_batch=1.0, same_on_batch=False, return_transform=False)"
assert str(f) == repr
def test_no_padding(self, device):
@@ -1464,10 +1466,10 @@ class TestRandomCrop:
class TestRandomResizedCrop:
- def smoke_test(self, device):
+ def test_smoke(self):
f = RandomResizedCrop(size=(2, 3), scale=(1., 1.), ratio=(1.0, 1.0))
- repr = "RandomResizedCrop(size=(2, 3), resize_to=(1., 1.), resize_to=(1., 1.)\
- , return_transform=False)"
+ repr = "RandomResizedCrop(size=(2, 3), scale=tensor([1., 1.]), ratio=tensor([1., 1.]), "\
+ "interpolation=BILINEAR, p=1.0, p_batch=1.0, same_on_batch=False, return_transform=False)"
assert str(f) == repr
def test_no_resize(self, device, dtype):
@@ -1546,7 +1548,7 @@ class TestRandomResizedCrop:
class TestRandomMotionBlur:
- def test_smoke(self, device):
+ def test_smoke(self):
f = RandomMotionBlur(kernel_size=(3, 5), angle=(10, 30), direction=0.5)
repr = "RandomMotionBlur(kernel_size=(3, 5), angle=tensor([10, 30]), direction=tensor([-0.5000, 0.5000]), "\
"border_type='constant', p=0.5, p_batch=1.0, same_on_batch=True, return_transform=False)"
diff --git a/test/augmentation/test_augmentation_3d.py b/test/augmentation/test_augmentation_3d.py
index 9d1103004..816f51dd5 100644
--- a/test/augmentation/test_augmentation_3d.py
+++ b/test/augmentation/test_augmentation_3d.py
@@ -22,9 +22,9 @@ from kornia.augmentation import (
class TestRandomHorizontalFlip3D:
- def smoke_test(self, device):
+ def test_smoke(self):
f = RandomHorizontalFlip3D(0.5)
- repr = "RandomHorizontalFlip3D(p=0.5, return_transform=False)"
+ repr = "RandomHorizontalFlip3D(p=0.5, p_batch=1.0, same_on_batch=False, return_transform=0.5)"
assert str(f) == repr
def test_random_hflip(self, device):
@@ -184,9 +184,9 @@ class TestRandomHorizontalFlip3D:
class TestRandomVerticalFlip3D:
- def smoke_test(self, device):
+ def test_smoke(self):
f = RandomVerticalFlip3D(0.5)
- repr = "RandomVerticalFlip3D(p=0.5, return_transform=False)"
+ repr = "RandomVerticalFlip3D(p=0.5, p_batch=1.0, same_on_batch=False, return_transform=0.5)"
assert str(f) == repr
def test_random_vflip(self, device):
@@ -341,9 +341,9 @@ class TestRandomVerticalFlip3D:
class TestRandomDepthicalFlip3D:
- def smoke_test(self, device):
+ def test_smoke(self):
f = RandomDepthicalFlip3D(0.5)
- repr = "RandomDepthicalFlip3D(p=0.5, return_transform=False)"
+ repr = "RandomDepthicalFlip3D(p=0.5, p_batch=1.0, same_on_batch=False, return_transform=0.5)"
assert str(f) == repr
def test_random_dflip(self, device):
@@ -512,9 +512,12 @@ class TestRandomRotation3D:
torch.manual_seed(0) # for random reproductibility
- def smoke_test(self, device):
+ def test_smoke(self):
f = RandomRotation3D(degrees=45.5)
- repr = "RandomRotation3D(degrees=45.5, return_transform=False)"
+ repr = """RandomRotation3D(degrees=tensor([[-45.5000, 45.5000],
+ [-45.5000, 45.5000],
+ [-45.5000, 45.5000]]), resample=BILINEAR, align_corners=False, p=0.5, """\
+ """p_batch=1.0, same_on_batch=False, return_transform=False)"""
assert str(f) == repr
def test_random_rotation(self, device):
diff --git a/test/augmentation/test_augmentation_mix.py b/test/augmentation/test_augmentation_mix.py
index 3a4d81c29..d83a5cdf4 100644
--- a/test/augmentation/test_augmentation_mix.py
+++ b/test/augmentation/test_augmentation_mix.py
@@ -14,9 +14,9 @@ from kornia.augmentation import (
class TestRandomMixUp:
- def smoke_test(self, device, dtype):
+ def test_smoke(self, device, dtype):
f = RandomMixUp()
- repr = "RandomMixUp(p=1.0, max_lambda=tensor(1.0), same_on_batch=False)"
+ repr = "RandomMixUp(lambda_val=tensor([0., 1.]), p=1.0, p_batch=1.0, same_on_batch=False)"
assert str(f) == repr
def test_random_mixup_p1(self, device, dtype):
@@ -105,9 +105,9 @@ class TestRandomMixUp:
class TestRandomCutMix:
- def smoke_test(self, device, dtype):
+ def test_smoke(self, device, dtype):
f = RandomCutMix(width=3, height=3)
- repr = "RandomCutMix(p=1, num_mix=1, beta=tensor(0.),, width=3, height=3, same_on_batch=False"
+ repr = "RandomCutMix(num_mix=1, beta=1.0, cut_size=tensor([0., 1.]), , p=1.0, p_batch=1.0, same_on_batch=False)"
assert str(f) == repr
def test_random_mixup_p1(self, device, dtype):