π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
apply autopep
edgarriba05eef8593787
diff --git a/test/common.py b/test/common.pyindex b23225e14..f7686a844 100644--- a/test/common.py+++ b/test/common.py@@ -10,7 +10,7 @@ def get_test_devices():"""devices = ["cpu"]if torch.cuda.is_available():- devices.append("cuda")+ devices.append("cuda")return devicesdiff --git a/test/test_conversions.py b/test/test_conversions.pyindex d14a53f73..921b6ddaa 100644--- a/test/test_conversions.py+++ b/test/test_conversions.py@@ -12,9 +12,10 @@ from common import TEST_DEVICESdef test_pi():assert pytest.approx(tgm.pi.item(), 3.141592)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_shape", [- (2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3),])+ (2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3), ])def test_rad2deg(batch_shape, device_type):# generate input datax_rad = tgm.pi * torch.rand(batch_shape)@@ -35,9 +36,10 @@ def test_rad2deg(batch_shape, device_type):assert gradcheck(tgm.rad2deg, (utils.tensor_to_gradcheck_var(x_rad),),raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_shape", [- (2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3),])+ (2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3), ])def test_deg2rad(batch_shape, device_type):# generate input datax_deg = 180. * torch.rand(batch_shape)@@ -57,9 +59,10 @@ def test_deg2rad(batch_shape, device_type):assert gradcheck(tgm.deg2rad, (utils.tensor_to_gradcheck_var(x_deg),),raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_shape", [- (2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3),])+ (2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3), ])def test_convert_points_to_homogeneous(batch_shape, device_type):# generate input datapoints = torch.rand(batch_shape)@@ -79,9 +82,10 @@ def test_convert_points_to_homogeneous(batch_shape, device_type):assert gradcheck(tgm.convert_points_to_homogeneous, (points,),raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_shape", [- (2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3),])+ (2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3), ])def test_convert_points_from_homogeneous(batch_shape, device_type):# generate input datapoints_h = torch.rand(batch_shape)@@ -102,6 +106,7 @@ def test_convert_points_from_homogeneous(batch_shape, device_type):assert gradcheck(tgm.convert_points_from_homogeneous, (points,),raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_size", [1, 2, 5])@pytest.mark.parametrize("num_points", [2, 3, 5])@@ -128,7 +133,7 @@ def test_transform_points(batch_size, num_points, num_dims, device_type):# functionalassert torch.allclose(points_dst,- tgm.TransformPoints(dst_homo_src)(points_src))+ tgm.TransformPoints(dst_homo_src)(points_src))# evaluate function gradientpoints_src = utils.tensor_to_gradcheck_var(points_src) # to var@@ -136,6 +141,7 @@ def test_transform_points(batch_size, num_points, num_dims, device_type):assert gradcheck(tgm.transform_points, (dst_homo_src, points_src,),raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_size", [1, 2, 5])def test_angle_axis_to_rotation_matrix(batch_size, device_type):@@ -156,6 +162,7 @@ def test_angle_axis_to_rotation_matrix(batch_size, device_type):assert gradcheck(tgm.angle_axis_to_rotation_matrix, (angle_axis,),raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_size", [1, 2, 5])def test_rtvec_to_pose_gradcheck(batch_size, device_type):@@ -166,6 +173,7 @@ def test_rtvec_to_pose_gradcheck(batch_size, device_type):rtvec = utils.tensor_to_gradcheck_var(rtvec) # to varassert gradcheck(tgm.rtvec_to_pose, (rtvec,), raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_size", [1, 2, 5])def test_rotation_matrix_to_angle_axis_gradcheck(batch_size, device_type):@@ -177,6 +185,7 @@ def test_rotation_matrix_to_angle_axis_gradcheck(batch_size, device_type):assert gradcheck(tgm.rotation_matrix_to_angle_axis,(rmat,), raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)def test_rotation_matrix_to_angle_axis(device_type):device = torch.device(device_type)diff --git a/test/test_homography_warper.py b/test/test_homography_warper.pyindex c2630a069..4607aad4f 100644--- a/test/test_homography_warper.py+++ b/test/test_homography_warper.py@@ -63,7 +63,7 @@ class Tester:@pytest.mark.parametrize("height", [7, 8])@pytest.mark.parametrize("width", [5, 16])def test_homography_warper_gradcheck(- self, batch_size, channels, height, width, device_type):+ self, batch_size, channels, height, width, device_type):# generate input datadevice = torch.device(device_type)eye_size = 3 # identity 3x3diff --git a/test/test_imgwarp.py b/test/test_imgwarp.pyindex 2332ff51d..972ef3c3d 100644--- a/test/test_imgwarp.py+++ b/test/test_imgwarp.py@@ -10,15 +10,14 @@ from common import TEST_DEVICES@pytest.mark.parametrize("device_type", TEST_DEVICES)[email protected]("batch_shape",- [(1, 1, 7, 32), (2, 3, 16, 31)])[email protected]("batch_shape",+ [(1, 1, 7, 32), (2, 3, 16, 31)])def test_warp_perspective_rotation(batch_shape, device_type):# generate input databatch_size, channels, height, width = batch_shapealpha = 0.5 * tgm.pi * torch.ones(batch_size) # 90 deg rotation# create data patch- #patch = torch.rand(batch_size, 1, height, width)device = torch.device(device_type)patch = torch.rand(batch_shape).to(device)@@ -47,11 +46,12 @@ def test_warp_perspective_rotation(batch_shape, device_type):# evaluate function gradientpatch = utils.tensor_to_gradcheck_var(patch) # to varM = utils.tensor_to_gradcheck_var(M, requires_grad=False) # to var- assert gradcheck(tgm.warp_perspective, (patch, M, (height, width,)),- raise_exception=True)+ assert gradcheck(tgm.warp_perspective, (patch, M, (height, width,)),+ raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)[email protected]("batch_size", [1, 2, 5])[email protected]("batch_size", [1, 2, 5])def test_get_perspective_transform(batch_size, device_type):# generate input datadevice = torch.device(device_type)@@ -78,10 +78,11 @@ def test_get_perspective_transform(batch_size, device_type):points_src = utils.tensor_to_gradcheck_var(points_src) # to varpoints_dst = utils.tensor_to_gradcheck_var(points_dst) # to varassert gradcheck(tgm.get_perspective_transform,- (points_src, points_dst,), raise_exception=True)+ (points_src, points_dst,), raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)[email protected]("batch_size", [1, 2, 5])[email protected]("batch_size", [1, 2, 5])def test_rotation_matrix2d(batch_size, device_type):# generate input datadevice = torch.device(device_type)@@ -95,7 +96,7 @@ def test_rotation_matrix2d(batch_size, device_type):scale = scale_baseM = tgm.get_rotation_matrix2d(center, angle, scale)- for i in range (batch_size):+ for i in range(batch_size):pytest.approx(M[i, 0, 0].item(), 0.0)pytest.approx(M[i, 0, 1].item(), 1.0)pytest.approx(M[i, 1, 0].item(), -1.0)@@ -107,7 +108,7 @@ def test_rotation_matrix2d(batch_size, device_type):scale = 2. * scale_baseM = tgm.get_rotation_matrix2d(center, angle, scale)- for i in range (batch_size):+ for i in range(batch_size):pytest.approx(M[i, 0, 0].item(), 0.0)pytest.approx(M[i, 0, 1].item(), 2.0)pytest.approx(M[i, 1, 0].item(), -2.0)@@ -119,7 +120,7 @@ def test_rotation_matrix2d(batch_size, device_type):scale = scale_baseM = tgm.get_rotation_matrix2d(center, angle, scale)- for i in range (batch_size):+ for i in range(batch_size):pytest.approx(M[i, 0, 0].item(), 0.7071)pytest.approx(M[i, 0, 1].item(), 0.7071)pytest.approx(M[i, 1, 0].item(), -0.7071)@@ -134,8 +135,8 @@ def test_rotation_matrix2d(batch_size, device_type):@pytest.mark.parametrize("device_type", TEST_DEVICES)[email protected]("batch_size", [1, 2, 5])[email protected]("channels", [1, 5])[email protected]("batch_size", [1, 2, 5])[email protected]("channels", [1, 5])def test_warp_perspective_crop(batch_size, device_type, channels):# generate input datasrc_h, src_w = 3, 4@@ -152,7 +153,7 @@ def test_warp_perspective_crop(batch_size, device_type, channels):# top-left, top-right, bottom-right, bottom-leftpoints_dst = torch.zeros_like(points_src)points_dst[:, 1, 0] = dst_w - 1- points_dst[:, 2, 0] = dst_w - 1+ points_dst[:, 2, 0] = dst_w - 1points_dst[:, 2, 1] = dst_h - 1points_dst[:, 3, 1] = dst_h - 1diff --git a/test/test_pinhole.py b/test/test_pinhole.pyindex 2f60e22f0..3a402602d 100644--- a/test/test_pinhole.py+++ b/test/test_pinhole.py@@ -30,8 +30,9 @@ def test_inverse_pose(batch_size, device_type):assert gradcheck(tgm.inverse_pose, (dst_pose_src,),raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)-#@pytest.mark.parametrize("batch_size", [1, 2, 5, 6])+# @pytest.mark.parametrize("batch_size", [1, 2, 5, 6])@pytest.mark.parametrize("batch_size", [6])def test_scale_pinhole(batch_size, device_type):# generate input data@@ -49,6 +50,7 @@ def test_scale_pinhole(batch_size, device_type):assert gradcheck(tgm.scale_pinhole, (pinholes, scales,),raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_size", [1, 2, 5, 6])def test_pinhole_matrix(batch_size, device_type):@@ -81,6 +83,7 @@ def test_pinhole_matrix(batch_size, device_type):assert gradcheck(tgm.pinhole_matrix, (pinhole,),raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_size", [1, 2, 5, 6])def test_inverse_pinhole_matrix(batch_size, device_type):@@ -115,6 +118,7 @@ def test_inverse_pinhole_matrix(batch_size, device_type):assert gradcheck(tgm.pinhole_matrix, (pinhole,),raise_exception=True)+@pytest.mark.parametrize("device_type", TEST_DEVICES)@pytest.mark.parametrize("batch_size", [1, 2, 5, 6])def test_homography_i_H_ref(batch_size, device_type):@@ -157,6 +161,6 @@ def test_homography_i_H_ref(batch_size, device_type):# evaluate function gradientassert gradcheck(tgm.homography_i_H_ref,- (utils.tensor_to_gradcheck_var(pinhole_ref) + eps,- utils.tensor_to_gradcheck_var(pinhole_i) + eps,),- raise_exception=True)+ (utils.tensor_to_gradcheck_var(pinhole_ref) + eps,+ utils.tensor_to_gradcheck_var(pinhole_i) + eps,),+ raise_exception=True)diff --git a/torchgeometry/conversions.py b/torchgeometry/conversions.pyindex abc393505..11d9bd89a 100644--- a/torchgeometry/conversions.py+++ b/torchgeometry/conversions.py@@ -542,7 +542,8 @@ class TransformPoints(nn.Module):r"""Creates an object to transform a set of points.Args:- dst_pose_src (Tensor): tensor for transformations of shape :math:`(B, D+1, D+1)`.+ dst_pose_src (Tensor): tensor for transformations of+ shape :math:`(B, D+1, D+1)`.Returns:Tensor: tensor of N-dimensional points.