π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
test: enforce Ruff PT007 repository-wide (#5299)
Daniele Loru663dcebe5a9d
diff --git a/pyproject.toml b/pyproject.tomlindex a993a3178..dd3052472 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -213,6 +213,7 @@ select = ["PIE", # flake8-pie"PL", # Pylint"PT001", # flake8-pytest-style: fixture parentheses+ "PT007", # flake8-pytest-style: parametrization value containers"PT012", # flake8-pytest-style: one simple statement in pytest.raises blocks"PT013", # flake8-pytest-style: pytest imports"PT014", # flake8-pytest-style: duplicate parametrized casesdiff --git a/tests/augmentation/test_augmentation_mix.py b/tests/augmentation/test_augmentation_mix.pyindex fb426f09c..13d1636be 100644--- a/tests/augmentation/test_augmentation_mix.py+++ b/tests/augmentation/test_augmentation_mix.py@@ -1166,9 +1166,9 @@ class TestRandomTransplantation(BaseTester):@pytest.mark.parametrize("input_shape_image, input_shape_mask, target_shape_image",[- [(1, 2, 3, 4), (1, 3, 4), (1, 2, 3, 4)], # (B, C, H, W)- [(1, 2, 5, 3, 4), (1, 5, 3, 4), (1, 2, 5, 3, 4)], # (B, C, D, H, W)- [(1, 1, 1, 1), (1, 1, 1), (1, 1, 1, 1)], # (B, C, H, W)+ ((1, 2, 3, 4), (1, 3, 4), (1, 2, 3, 4)), # (B, C, H, W)+ ((1, 2, 5, 3, 4), (1, 5, 3, 4), (1, 2, 5, 3, 4)), # (B, C, D, H, W)+ ((1, 1, 1, 1), (1, 1, 1), (1, 1, 1, 1)), # (B, C, H, W)],)def test_cardinality(self, input_shape_image, input_shape_mask, target_shape_image, device, dtype):diff --git a/tests/augmentation/test_base.py b/tests/augmentation/test_base.pyindex 90bbc1221..9334e59d8 100644--- a/tests/augmentation/test_base.py+++ b/tests/augmentation/test_base.py@@ -86,7 +86,7 @@ class TestBasicAugmentationBase(BaseTester):assert len(output["degrees"]) == input_shape[0]assert output["batch_prob"].sum().item() == num- @pytest.mark.parametrize("keepdim", (True, False))+ @pytest.mark.parametrize("keepdim", [True, False])def test_forward(self, device, dtype, keepdim):torch.manual_seed(42)input = torch.rand((12, 3, 4, 5), device=device, dtype=dtype)diff --git a/tests/filters/test_gaussian.py b/tests/filters/test_gaussian.pyindex ffaa61c4f..850be8dcd 100644--- a/tests/filters/test_gaussian.py+++ b/tests/filters/test_gaussian.py@@ -146,7 +146,7 @@ def test_get_gaussian_kernel2d_float(ksize_x, ksize_y, sigma, device, dtype):@pytest.mark.parametrize("ksize_x", [5, 11])@pytest.mark.parametrize("ksize_y", [3, 7])[email protected]("sigma", ([[1.5, 2.1], [1.5, 2.1], [5.0, 2.7]], [[1.5, 2.1], [3.5, 2.1]]))[email protected]("sigma", [[[1.5, 2.1], [1.5, 2.1], [5.0, 2.7]], [[1.5, 2.1], [3.5, 2.1]]])def test_get_gaussian_kernel2d_tensor(ksize_x, ksize_y, sigma, device, dtype):sigma = torch.tensor(sigma, device=device, dtype=dtype)bs = sigma.shape[0]@@ -174,7 +174,7 @@ def test_get_gaussian_kernel3d_float(ksize_x, ksize_y, ksize_z, sigma, device, d@pytest.mark.parametrize("ksize_y", [3, 7])@pytest.mark.parametrize("ksize_z", [9, 3])@pytest.mark.parametrize(- "sigma", ([[1.5, 2.1, 3.5], [1.5, 2.1, 1.5], [5.0, 2.7, 2.1]], [[1.5, 3.5, 2.1], [1.2, 3.5, 2.1]])+ "sigma", [[[1.5, 2.1, 3.5], [1.5, 2.1, 1.5], [5.0, 2.7, 2.1]], [[1.5, 3.5, 2.1], [1.2, 3.5, 2.1]]])def test_get_gaussian_kernel3d_tensor(ksize_x, ksize_y, ksize_z, sigma, device, dtype):sigma = torch.tensor(sigma, device=device, dtype=dtype)@@ -312,7 +312,7 @@ def test_gaussian_blur2d_float(ksize_x, ksize_y, sigma, device, dtype):@pytest.mark.parametrize("ksize_x", [5, 11])@pytest.mark.parametrize("ksize_y", [3, 7])[email protected]("sigma", ([[1.5, 2.1], [1.5, 2.1], [5.0, 2.7]], [[1.5, 2.1], [3.5, 2.1]]))[email protected]("sigma", [[[1.5, 2.1], [1.5, 2.1], [5.0, 2.7]], [[1.5, 2.1], [3.5, 2.1]]])def test_gaussian_blur2d_tensor(ksize_x, ksize_y, sigma, device, dtype):sigma = torch.tensor(sigma, device=device, dtype=dtype)bs = sigma.shape[0]diff --git a/tests/filters/test_gaussian_cpu.py b/tests/filters/test_gaussian_cpu.pyindex 285d74b92..bdb02944c 100644--- a/tests/filters/test_gaussian_cpu.py+++ b/tests/filters/test_gaussian_cpu.py@@ -48,7 +48,7 @@ def _cpu_tolerance(dtype: torch.dtype) -> float:class TestGaussianBlurCpu(BaseTester):- @pytest.mark.parametrize("border_type", ("constant", "reflect", "replicate", "circular"))+ @pytest.mark.parametrize("border_type", ["constant", "reflect", "replicate", "circular"])def test_helper_matches_separable_convolution_per_sample_kernels(self, border_type, device, dtype):_require_native_cpu(device, dtype)image = torch.rand(2, 2, 257, 256, device=device, dtype=dtype)@@ -250,8 +250,8 @@ class TestGaussianBlurCpu(BaseTester):assert autocast_output.dtype == autocast_reference.dtypeself.assert_close(autocast_output, autocast_reference)- @pytest.mark.parametrize("border_type", ("constant", "reflect", "replicate", "circular"))- @pytest.mark.parametrize("has_mkldnn", (False, True))+ @pytest.mark.parametrize("border_type", ["constant", "reflect", "replicate", "circular"])+ @pytest.mark.parametrize("has_mkldnn", [False, True])def test_dynamo_large_input_dispatch(self, monkeypatch, device, dtype, torch_optimizer, border_type, has_mkldnn):_require_native_cpu(device, dtype)monkeypatch.setattr(gaussian_module, "_HAS_MKLDNN", has_mkldnn)diff --git a/tests/image/test_draw.py b/tests/image/test_draw.pyindex eebdccdc9..b4c4e427d 100644--- a/tests/image/test_draw.py+++ b/tests/image/test_draw.py@@ -440,8 +440,8 @@ class TestDrawLine(BaseTester):class TestDrawRectangle(BaseTester):- @pytest.mark.parametrize("batch", (4, 17))- @pytest.mark.parametrize("color", (torch.Tensor([1.0]), torch.Tensor([0.5])))+ @pytest.mark.parametrize("batch", [4, 17])+ @pytest.mark.parametrize("color", [torch.Tensor([1.0]), torch.Tensor([0.5])])def test_smoke(self, device, batch, color):black_image = torch.zeros(batch, 1, 3, 3, device=device) # 1 channel 3x3 black_imagepoints = torch.tensor([1.0, 1.0, 1.0, 1.0]).to(device).expand(batch, 1, 4) # single pixel rectangle@@ -453,10 +453,10 @@ class TestDrawRectangle(BaseTester):assert torch.all(black_image == target)- @pytest.mark.parametrize("batch", (8, 11))- @pytest.mark.parametrize("fill", (True, False))- @pytest.mark.parametrize("height", (12, 106, 298))- @pytest.mark.parametrize("width", (7, 123, 537))+ @pytest.mark.parametrize("batch", [8, 11])+ @pytest.mark.parametrize("fill", [True, False])+ @pytest.mark.parametrize("height", [12, 106, 298])+ @pytest.mark.parametrize("width", [7, 123, 537])def test_fill_and_edges(self, device, batch, fill, height, width):black_image = torch.zeros(batch, 3, height, width, device=device)# we should pass height - 1 and width - 1 but rectangle should clip correctly@@ -471,9 +471,9 @@ class TestDrawRectangle(BaseTester):# corners are double countedassert image_w_rectangle.sum() == batch * 3 * (2 * height + 2 * width - 4)- @pytest.mark.parametrize("batch", (4, 6))- @pytest.mark.parametrize("N", (5, 12))- @pytest.mark.parametrize("fill", (True, False))+ @pytest.mark.parametrize("batch", [4, 6])+ @pytest.mark.parametrize("N", [5, 12])+ @pytest.mark.parametrize("fill", [True, False])def test_n_rectangles(self, device, batch, N, fill):points_list = []h, w = 20, 20@@ -533,7 +533,7 @@ class TestDrawRectangle(BaseTester):== (points_list[b][n][2] - points_list[b][n][0] + 1) * 3)- @pytest.mark.parametrize("color", (torch.tensor([0.5, 0.3, 0.15]), torch.tensor([0.23, 0.33, 0.8])))+ @pytest.mark.parametrize("color", [torch.tensor([0.5, 0.3, 0.15]), torch.tensor([0.23, 0.33, 0.8])])def test_color_background(self, device, color):image = torch.zeros(1, 3, 40, 40, device=device)image[:, 0, :, :] = color[0]@@ -555,7 +555,7 @@ class TestDrawRectangle(BaseTester):<= 0.0001)- @pytest.mark.parametrize("color", (torch.tensor([0.34, 0.63, 0.16]), torch.tensor([0.29, 0.13, 0.48])))+ @pytest.mark.parametrize("color", [torch.tensor([0.34, 0.63, 0.16]), torch.tensor([0.29, 0.13, 0.48])])def test_color_foreground(self, device, color):image = torch.zeros(1, 3, 50, 40, device=device)image_w_rectangle = image.clone()diff --git a/tests/integration/test_conversions.py b/tests/integration/test_conversions.pyindex 99df20ae8..e44861998 100644--- a/tests/integration/test_conversions.py+++ b/tests/integration/test_conversions.py@@ -47,7 +47,7 @@ class TestAngleAxisToQuaternionToAngleAxis(BaseTester):axis_angle_hat = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)self.assert_close(axis_angle_hat, axis_angle, atol=atol, rtol=rtol)- @pytest.mark.parametrize("axis", (0, 1, 2))+ @pytest.mark.parametrize("axis", [0, 1, 2])def test_small_angle(self, axis, device, dtype, atol, rtol):theta = 1.0e-2array = [0.0, 0.0, 0.0]@@ -57,7 +57,7 @@ class TestAngleAxisToQuaternionToAngleAxis(BaseTester):axis_angle_hat = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)self.assert_close(axis_angle_hat, axis_angle, atol=atol, rtol=rtol)- @pytest.mark.parametrize("axis", (0, 1, 2))+ @pytest.mark.parametrize("axis", [0, 1, 2])def test_rotation(self, axis, device, dtype, atol, rtol):# half_sqrt2 = 0.5 * np.sqrt(2)array = [0.0, 0.0, 0.0]@@ -75,7 +75,7 @@ class TestQuaternionToAngleAxisToQuaternion(BaseTester):quaternion_hat = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)self.assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)- @pytest.mark.parametrize("axis", (0, 1, 2))+ @pytest.mark.parametrize("axis", [0, 1, 2])def test_rotation(self, axis, device, dtype, atol, rtol):array = [0.0, 0.0, 0.0, 0.0]array[1 + axis] = 1.0@@ -84,7 +84,7 @@ class TestQuaternionToAngleAxisToQuaternion(BaseTester):quaternion_hat = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)self.assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)- @pytest.mark.parametrize("axis", (0, 1, 2))+ @pytest.mark.parametrize("axis", [0, 1, 2])def test_small_angle(self, axis, device, dtype, atol, rtol):theta = 1.0e-2array = [np.cos(theta / 2), 0.0, 0.0, 0.0]@@ -96,7 +96,7 @@ class TestQuaternionToAngleAxisToQuaternion(BaseTester):class TestQuaternionToRotationMatrixToAngleAxis(BaseTester):- @pytest.mark.parametrize("axis", (0, 1, 2))+ @pytest.mark.parametrize("axis", [0, 1, 2])def test_triplet_qma(self, axis, device, dtype, atol, rtol):array = [[0.0, 0.0, 0.0, 0.0]]array[0][1 + axis] = 1.0 # `1 + axis` this should fail when XYZW@@ -117,7 +117,7 @@ class TestQuaternionToRotationMatrixToAngleAxis(BaseTester):quaternion_hat = kornia.geometry.conversions.axis_angle_to_quaternion(axis_angle)self.assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)- @pytest.mark.parametrize("axis", (0, 1, 2))+ @pytest.mark.parametrize("axis", [0, 1, 2])def test_triplet_qam(self, axis, device, dtype, atol, rtol):array = [[0.0, 0.0, 0.0, 0.0]]array[0][1 + axis] = 1.0@@ -134,7 +134,7 @@ class TestQuaternionToRotationMatrixToAngleAxis(BaseTester):quaternion_hat = kornia.geometry.conversions.rotation_matrix_to_quaternion(rot_m)self.assert_close(quaternion_hat, quaternion, atol=atol, rtol=rtol)- @pytest.mark.parametrize("axis", (0, 1, 2))+ @pytest.mark.parametrize("axis", [0, 1, 2])def test_triplet_amq(self, axis, device, dtype, atol, rtol):array = [[0.0, 0.0, 0.0]]array[0][axis] = kornia.pi / 2.0@@ -151,7 +151,7 @@ class TestQuaternionToRotationMatrixToAngleAxis(BaseTester):axis_angle_hat = kornia.geometry.conversions.quaternion_to_axis_angle(quaternion)self.assert_close(axis_angle_hat, axis_angle, atol=atol, rtol=rtol)- @pytest.mark.parametrize("axis", (0, 1, 2))+ @pytest.mark.parametrize("axis", [0, 1, 2])def test_triplet_aqm(self, axis, device, dtype, atol, rtol):array = [[0.0, 0.0, 0.0]]array[0][axis] = kornia.pi / 2.0@@ -201,7 +201,7 @@ class TestAngleOfRotations(BaseTester):return rot_m, axis- @pytest.mark.parametrize("axis_name", ("x", "y", "z"))+ @pytest.mark.parametrize("axis_name", ["x", "y", "z"])def test_axis_angle_to_rotation_matrix(self, axis_name, device, dtype, atol, rtol, test_rng_seed):# Random angle in [-pi..pi]angle_values = np.random.default_rng(test_rng_seed).random(size=(2, 1)) * 2.0 * np.pi - np.pi@@ -241,8 +241,8 @@ class TestAngleOfRotations(BaseTester):self.assert_close(rot_m[..., :3, 1].norm(p=2, dim=-1, keepdim=True), one, atol=atol, rtol=rtol)self.assert_close(rot_m[..., :3, 2].norm(p=2, dim=-1, keepdim=True), one, atol=atol, rtol=rtol)- @pytest.mark.parametrize("axis_name", ("x", "y", "z"))- @pytest.mark.parametrize("angle_deg", (-179.9, -135.0, -90.0, -45.0, 0.0, 45, 90, 135, 179.9))+ @pytest.mark.parametrize("axis_name", ["x", "y", "z"])+ @pytest.mark.parametrize("angle_deg", [-179.9, -135.0, -90.0, -45.0, 0.0, 45, 90, 135, 179.9])def test_matrix_angle(self, axis_name, angle_deg, device, dtype):angle = (angle_deg * kornia.pi / 180.0).to(dtype).to(device).view(1, 1)rot_m, _ = TestAngleOfRotations.axis_and_angle_to_rotation_matrix(@@ -251,8 +251,8 @@ class TestAngleOfRotations(BaseTester):matrix_angle_abs = TestAngleOfRotations.matrix_angle_abs(rot_m)self.assert_close(torch.abs(angle), matrix_angle_abs)- @pytest.mark.parametrize("axis_name", ("x", "y", "z"))- @pytest.mark.parametrize("angle_deg", (-179.9, -90.0, -45.0, 0.0, 45, 90, 179.9))+ @pytest.mark.parametrize("axis_name", ["x", "y", "z"])+ @pytest.mark.parametrize("angle_deg", [-179.9, -90.0, -45.0, 0.0, 45, 90, 179.9])def test_quaternion(self, axis_name, angle_deg, device, dtype, atol, rtol):eps = torch.finfo(dtype).epsangle = torch.tensor((angle_deg * kornia.pi / 180.0,), device=device, dtype=dtype).repeat(2, 1)@@ -279,8 +279,8 @@ class TestAngleOfRotations(BaseTester):matrix_angle_abs = TestAngleOfRotations.matrix_angle_abs(rot_m)self.assert_close(torch.abs(angle_hat), matrix_angle_abs, atol=atol, rtol=rtol)- @pytest.mark.parametrize("axis_name", ("x", "y", "z"))- @pytest.mark.parametrize("angle_deg", (-179.9, -90.0, -45.0, 0, 45, 90, 179.9))+ @pytest.mark.parametrize("axis_name", ["x", "y", "z"])+ @pytest.mark.parametrize("angle_deg", [-179.9, -90.0, -45.0, 0, 45, 90, 179.9])def test_axis_angle(self, axis_name, angle_deg, device, dtype, atol, rtol):angle = (angle_deg * kornia.pi / 180.0).to(dtype).to(device).repeat(2, 1)rot_m, axis = TestAngleOfRotations.axis_and_angle_to_rotation_matrix(@@ -298,8 +298,8 @@ class TestAngleOfRotations(BaseTester):matrix_angle_abs = TestAngleOfRotations.matrix_angle_abs(rot_m)self.assert_close(torch.abs(angle_hat), matrix_angle_abs, atol=atol, rtol=rtol)- @pytest.mark.parametrize("axis_name", ("x", "y", "z"))- @pytest.mark.parametrize("angle_deg", (-179.9, -90.0, -45.0, 0, 45, 90, 179.9))+ @pytest.mark.parametrize("axis_name", ["x", "y", "z"])+ @pytest.mark.parametrize("angle_deg", [-179.9, -90.0, -45.0, 0, 45, 90, 179.9])def test_log_quaternion(self, axis_name, angle_deg, device, dtype, atol, rtol):eps = torch.finfo(dtype).epsangle = (angle_deg * kornia.pi / 180.0).to(dtype).to(device).repeat(2, 1)diff --git a/tests/losses/test_hd.py b/tests/losses/test_hd.pyindex c4af28dbc..5cb66518b 100644--- a/tests/losses/test_hd.py+++ b/tests/losses/test_hd.py@@ -26,7 +26,7 @@ from testing.base import BaseTesterclass TestHausdorffLoss(BaseTester):@pytest.mark.parametrize("reduction", ["mean", "none", "sum"])@pytest.mark.parametrize(- "hd,shape", [[kornia.losses.HausdorffERLoss, (10, 10)], [kornia.losses.HausdorffERLoss3D, (10, 10, 10)]]+ "hd,shape", [(kornia.losses.HausdorffERLoss, (10, 10)), (kornia.losses.HausdorffERLoss3D, (10, 10, 10))])def test_smoke_none(self, hd, shape, reduction, device, dtype):num_classes = 3@@ -90,7 +90,7 @@ class TestHausdorffLoss(BaseTester):self.assert_close(actual, expected, rtol=1e-2, atol=1e-2)@pytest.mark.parametrize(- "hd,shape", [[kornia.losses.HausdorffERLoss, (8, 8)], [kornia.losses.HausdorffERLoss3D, (6, 6, 6)]]+ "hd,shape", [(kornia.losses.HausdorffERLoss, (8, 8)), (kornia.losses.HausdorffERLoss3D, (6, 6, 6))])def test_gradient_at_the_threshold_tie(self, hd, shape, device, dtype):# Quantized predictions land the dilation exactly on the 0.5 threshold, where the derivative of@@ -136,7 +136,7 @@ class TestHausdorffLoss(BaseTester):self.assert_close(pred_actual.grad, pred_expected.grad, rtol=0.0, atol=0.0)@pytest.mark.parametrize(- "hd,shape", [[kornia.losses.HausdorffERLoss, (5, 5)], [kornia.losses.HausdorffERLoss3D, (5, 5, 5)]]+ "hd,shape", [(kornia.losses.HausdorffERLoss, (5, 5)), (kornia.losses.HausdorffERLoss3D, (5, 5, 5))])def test_gradcheck(self, hd, shape, device, dtype):num_classes = 3diff --git a/tests/models/test_object_detector.py b/tests/models/test_object_detector.pyindex 9235a73e9..02fe31836 100644--- a/tests/models/test_object_detector.py+++ b/tests/models/test_object_detector.py@@ -66,7 +66,7 @@ class TestObjectDetector(BaseTester):# an XPASS rather than sit silent until the 2.15 bound expires. Both variants fail today.strict=True,)- @pytest.mark.parametrize("variant", ("resnet50d", "hgnetv2_l"))+ @pytest.mark.parametrize("variant", ["resnet50d", "hgnetv2_l"])def test_onnx(self, device, dtype, tmp_path: Path, variant: str):config = RTDETRConfig(variant, 1)model = RTDETR.from_config(config).to(device=device, dtype=dtype).eval()diff --git a/tests/models/test_rt_detr.py b/tests/models/test_rt_detr.pyindex e0c9e5efe..fa18e99b4 100644--- a/tests/models/test_rt_detr.py+++ b/tests/models/test_rt_detr.py@@ -31,7 +31,7 @@ from testing.base import BaseTester, assert_close@pytest.mark.parametrize("backbone_factory",- (partial(ResNetD.from_config, 18), partial(ResNetD.from_config, 50), partial(PPHGNetV2.from_config, "L")),+ [partial(ResNetD.from_config, 18), partial(ResNetD.from_config, 50), partial(PPHGNetV2.from_config, "L")],)@pytest.mark.slowdef test_backbone(backbone_factory, device, dtype):@@ -90,7 +90,7 @@ def test_regvgg_optimize_for_deployment(device, dtype):class TestRTDETR(BaseTester):@pytest.mark.slow # This will be slow for the bigger variants- @pytest.mark.parametrize("variant", ("resnet18d", "resnet34d", "resnet50d", "resnet101d", "hgnetv2_l", "hgnetv2_x"))+ @pytest.mark.parametrize("variant", ["resnet18d", "resnet34d", "resnet50d", "resnet101d", "hgnetv2_l", "hgnetv2_x"])def test_smoke(self, variant, device, dtype):model = RTDETR.from_config(RTDETRConfig(variant, 10)).to(device, dtype).eval()images = torch.randn(2, 3, 224, 256, device=device, dtype=dtype)@@ -99,7 +99,7 @@ class TestRTDETR(BaseTester):assert isinstance(out, tuple)assert len(out) == 2- @pytest.mark.parametrize("shape", ((1, 3, 96, 128), (2, 3, 64, 96)))+ @pytest.mark.parametrize("shape", [(1, 3, 96, 128), (2, 3, 64, 96)])def test_cardinality(self, shape, device, dtype):num_classes = 10num_queries = 10@@ -122,7 +122,7 @@ class TestRTDETR(BaseTester):def test_module(self): ...@pytest.mark.skip("Needs more investigation")- @pytest.mark.parametrize("variant", ("resnet50d", "hgnetv2_l"))+ @pytest.mark.parametrize("variant", ["resnet50d", "hgnetv2_l"])def test_dynamo(self, variant, device, dtype, torch_optimizer):# NOTE: This test passes on Mac M1 CPU, PyTorch 2.0.0,# but fails on GitHub Actions Ubuntu-latest CPU, PyTorch 2.0.0.