π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix lint errors
edgarriba9260b685d714
diff --git a/setup.py b/setup.pyindex bb1c13943..4db57f8d3 100644--- a/setup.py+++ b/setup.py@@ -39,7 +39,7 @@ setup(author='Edgar Riba',author_email='[email protected]',url='https://github.com/arraiy/geometry',- description='differential geometric computer vision for torch deep learning',+ description='differential geometric computer vision for deep learning',long_description=readme,license='BSD',diff --git a/test/test_functional.py b/test/test_functional.pyindex 2a8bf0281..f789650af 100644--- a/test/test_functional.py+++ b/test/test_functional.py@@ -38,7 +38,7 @@ class Tester(unittest.TestCase):# to euclideanpoints = dgm.convert_points_from_homogeneous(points_h)- error = utils.compute_mse(points_h[..., :2] , points)+ error = utils.compute_mse(points_h[..., :2], points)self.assertAlmostEqual(error.item(), 0.0, places=4)def test_convert_points_from_homogeneous_gradcheck(self):@@ -126,7 +126,7 @@ class Tester(unittest.TestCase):# compute errorerror = utils.compute_mse(x_rad, x_deg_to_rad)self.assertAlmostEqual(error.item(), 0.0, places=4)-+def test_rad2deg_gradcheck(self):# generate input datax_rad = dgm.pi * torch.rand(2, 3, 4)@@ -147,7 +147,7 @@ class Tester(unittest.TestCase):# compute errorerror = utils.compute_mse(x_deg, x_rad_to_deg)self.assertAlmostEqual(error.item(), 0.0, places=4)-+def test_deg2rad_gradcheck(self):# generate input datax_deg = 180. * torch.rand(2, 3, 4)@@ -166,7 +166,6 @@ class Tester(unittest.TestCase):dst_pose_src[:, -1] = 0.0dst_pose_src[:, -1, -1] = 1.0- import pdb;pdb.set_trace()# compute the inverse of the posesrc_pose_dst = dgm.inverse_pose(dst_pose_src)diff --git a/test/test_homography_warper.py b/test/test_homography_warper.pyindex 928fbcc57..05ecdfde6 100644--- a/test/test_homography_warper.py+++ b/test/test_homography_warper.py@@ -19,7 +19,7 @@ class Tester(unittest.TestCase):# create checkerboardboard = utils.create_checkerboard(height, width, 4)- patch_src = torch.from_numpy(board).view( \+ patch_src = torch.from_numpy(board).view(1, 1, height, width).expand(batch_size, 1, height, width)# create base homography@@ -54,7 +54,7 @@ class Tester(unittest.TestCase):# create checkerboardboard = utils.create_checkerboard(height, width, 4)- patch_src = torch.from_numpy(board).view( \+ patch_src = torch.from_numpy(board).view(1, 1, height, width).expand(batch_size, 1, height, width)patch_src = utils.tensor_to_gradcheck_var(patch_src) # to vardiff --git a/torchgeometry/functional.py b/torchgeometry/functional.pyindex 4365fcf05..7303f532f 100644--- a/torchgeometry/functional.py+++ b/torchgeometry/functional.py@@ -33,7 +33,7 @@ def rad2deg(x):return 180. * x / pi.to(x.device).type(x.dtype)-+def deg2rad(x):"""Converts angles from degrees to radians.@@ -107,7 +107,7 @@ def transform_points(dst_homo_src, points_src):# to homogeneouspoints_src_h = convert_points_to_homogeneous(points_src) # BxNx3# transform coordinates- points_dst_h = torch.matmul(dst_homo_src, points_src_h.transpose(1, 2)) # Bx3xN+ points_dst_h = torch.matmul(dst_homo_src, points_src_h.transpose(1, 2))points_dst_h = points_dst_h.permute(0, 2, 1) # BxNx3# to euclideanpoints_dst = convert_points_from_homogeneous(points_dst_h) # BxNx2diff --git a/torchgeometry/homography_warper.py b/torchgeometry/homography_warper.pyindex dafeb4f05..6ba593f72 100644--- a/torchgeometry/homography_warper.py+++ b/torchgeometry/homography_warper.py@@ -8,8 +8,8 @@ from .functional import transform_pointsdef create_meshgrid(width, height, normalized_coordinates=True):'''Generates a coordinate grid for an image of width(cols), height(rows).This is normalized to be in the range [-1,1] to be consistent with the- pytorch function- grid_sample. http://pytorch.org/docs/master/nn.html#torch.nn.functional.grid_sample+ pytorch function grid_sample.+ http://pytorch.org/docs/master/nn.html#torch.nn.functional.grid_sampleReturns a 3xN matrix.'''if normalized_coordinates:@@ -48,7 +48,8 @@ height, width '''def warp_grid(self, H):"""- :param H: Homography or homographies (stacked) to transform all points in the grid.+ :param H: Homography or homographies (stacked) to transform all points+ in the grid.:returns: Tensor[1, Height, Width, 2] containing transformed points innormalized images space."""@@ -94,15 +95,17 @@ height, width '''def forward(self, patch, dst_H_src, padding_mode='zeros'):"""Warps an image from dst into src's reference frame.- :param patch: Tensor[X,Y,Height,Width] The image to warp. Should be from dst.+ :param patch: Tensor[X,Y,Height,Width] The image to warp.+ Should be from dst.:param dst_H_src: Tensor[3,3] The homography from src to dst.:param padding_mode: Either 'zeros' to replace out of bounds with zerosor 'border' to choose the closest border data.- :returns: Tensor[X,Y,Height,Width] patch sampled at locations from src warped to dst.+ :returns: Tensor[X,Y,Height,Width] patch sampled at locations from src+ warped to dst."""- assert dst_H_src.device == patch.device, \- "Patch and homography must be on the same device." \- " patch.device: {} dst_H_src.device: {}" \- .format(patch.device, dst_H_src.device)- return F.grid_sample(patch, self.warp_grid(dst_H_src),- 'bilinear', padding_mode=padding_mode)+ if not dst_H_src.device == patch.device:+ raise TypeError("Patch and homography must be on the same device. \+ Got patch.device: {} dst_H_src.device: {}."+ .format(patch.device, dst_H_src.device))+ return F.grid_sample(patch, self.warp_grid(dst_H_src), 'bilinear',+ padding_mode=padding_mode)