π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
renamed core -> geometry
edgarriba48c42f303ecf
diff --git a/docs/source/conversions.rst b/docs/source/conversions.rstindex b593c86c6..732c61d76 100644--- a/docs/source/conversions.rst+++ b/docs/source/conversions.rst@@ -1,7 +1,7 @@Conversions------------.. currentmodule:: torchgeometry+.. currentmodule:: torchgeometry.geometry.. autofunction:: rad2deg.. autofunction:: deg2raddiff --git a/docs/source/geometric.rst b/docs/source/geometric.rstindex e29697457..e5e12b2c6 100644--- a/docs/source/geometric.rst+++ b/docs/source/geometric.rst@@ -1,7 +1,7 @@Image Transformations----------------------.. currentmodule:: torchgeometry+.. currentmodule:: torchgeometry.geometryThe functions in this section perform various geometrical transformations of 2D images.@@ -13,6 +13,8 @@ The functions in this section perform various geometrical transformations of 2D.. autofunction:: invert_affine_transform.. autofunction:: center_crop.. autofunction:: crop_and_resize+.. autofunction:: pyrdown+.. autofunction:: pyrup.. autofunction:: affine.. autofunction:: rotate@@ -24,3 +26,5 @@ The functions in this section perform various geometrical transformations of 2D.. autoclass:: Translate.. autoclass:: Scale.. autoclass:: Shear+.. autoclass:: PyrDown+.. autoclass:: PyrUpdiff --git a/docs/source/core.rst b/docs/source/geometry.rstsimilarity index 53%rename from docs/source/core.rstrename to docs/source/geometry.rstindex 125b7a802..9ad247af3 100644--- a/docs/source/core.rst+++ b/docs/source/geometry.rst@@ -1,7 +1,7 @@-torchgeometry.core-==================+torchgeometry.geometry+======================-.. currentmodule:: torchgeometry.core+.. currentmodule:: torchgeometry.geometry.. toctree:::maxdepth: 2diff --git a/docs/source/index.rst b/docs/source/index.rstindex 67e6aa392..191f86f1a 100644--- a/docs/source/index.rst+++ b/docs/source/index.rst@@ -20,17 +20,15 @@ TGM focuses on Image and tensor warping functions such as::maxdepth: 2:caption: Package Reference- corecolor+ contribfeaturefilters- transform+ geometrylossesmetrics- contributils-.. toctree:::maxdepth: 2:caption: Tutorialsdiff --git a/docs/source/pinhole.rst b/docs/source/pinhole.rstindex 7a95700cd..0494bc6c1 100644--- a/docs/source/pinhole.rst+++ b/docs/source/pinhole.rst@@ -1,7 +1,7 @@Pinhole Camera---------------.. currentmodule:: torchgeometry+.. currentmodule:: torchgeometry.geometryIn this module we have all the functions and data structures needed to describe the projection of a 3D scene space onto a 2D image plane.diff --git a/docs/source/transform.rst b/docs/source/transform.rstdeleted file mode 100644index ed434335c..000000000--- a/docs/source/transform.rst+++ /dev/null@@ -1,10 +0,0 @@-torchgeometry.transform--------------------------.. currentmodule:: torchgeometry.transform--.. autofunction:: pyrdown-.. autofunction:: pyrup--.. autoclass:: PyrDown-.. autoclass:: PyrUpdiff --git a/docs/source/transformations.rst b/docs/source/transformations.rstindex 9aa4aab1f..9c2bdaed8 100644--- a/docs/source/transformations.rst+++ b/docs/source/transformations.rst@@ -1,9 +1,9 @@Linear Transformations-----------------------.. currentmodule:: torchgeometry+.. currentmodule:: torchgeometry.geometry-.. autofunction:: boxminus_transformation-.. autofunction:: boxplus_transformation+.. autofunction:: relative_transformation+.. autofunction:: compose_transformations.. autofunction:: inverse_transformation.. autofunction:: transform_pointsdiff --git a/docs/source/warping.rst b/docs/source/warping.rstindex d55b11adc..aa83d9e1b 100644--- a/docs/source/warping.rst+++ b/docs/source/warping.rst@@ -1,7 +1,7 @@Warping--------.. currentmodule:: torchgeometry+.. currentmodule:: torchgeometry.geometry.. autoclass:: HomographyWarper:members:diff --git a/mypy_files.txt b/mypy_files.txtindex 331316af0..de05fbc1c 100644--- a/mypy_files.txt+++ b/mypy_files.txt@@ -1,10 +1,10 @@-torchgeometry/core/homography_warper.py-torchgeometry/core/depth_warper.py-torchgeometry/core/pinhole.py-torchgeometry/core/imgwarp.py-torchgeometry/core/crop.py-torchgeometry/core/affine.py-torchgeometry/transform/pyramid.py+torchgeometry/geometry/homography_warper.py+torchgeometry/geometry/depth_warper.py+torchgeometry/geometry/pinhole.py+torchgeometry/geometry/imgwarp.py+torchgeometry/geometry/crop.py+torchgeometry/geometry/affine_warp.py+torchgeometry/geometry/pyramid.pytorchgeometry/feature/harris.pytorchgeometry/filters/gaussian.pytorchgeometry/filters/laplacian.py@@ -19,5 +19,6 @@ torchgeometry/losses/tversky.pytorchgeometry/losses/depth_smooth.pytorchgeometry/contrib/spatial_soft_argmax2d.pytorchgeometry/contrib/extract_patches.py+torchgeometry/contrib/max_blur_pool.pytorchgeometry/metrics/confusion_matrix.pytorchgeometry/metrics/mean_iou.pydiff --git a/test/test_affine.py b/test/geometry/test_affine.pysimilarity index 100%rename from test/test_affine.pyrename to test/geometry/test_affine.pydiff --git a/test/test_conversions.py b/test/geometry/test_conversions.pysimilarity index 100%rename from test/test_conversions.pyrename to test/geometry/test_conversions.pydiff --git a/test/test_crop.py b/test/geometry/test_crop.pysimilarity index 100%rename from test/test_crop.pyrename to test/geometry/test_crop.pydiff --git a/test/test_depth_warper.py b/test/geometry/test_depth_warper.pysimilarity index 98%rename from test/test_depth_warper.pyrename to test/geometry/test_depth_warper.pyindex 24b5bfcb8..267b29f25 100644--- a/test/test_depth_warper.py+++ b/test/geometry/test_depth_warper.py@@ -5,7 +5,7 @@ import torchgeometry as tgmfrom torch.autograd import gradcheckimport utils # test utils-from torchgeometry.core.depth_warper import normalize_pixel_coordinates+from torchgeometry.geometry.depth_warper import normalize_pixel_coordinatesclass TestDepthWarper:diff --git a/test/test_homography_warper.py b/test/geometry/test_homography_warper.pysimilarity index 100%rename from test/test_homography_warper.pyrename to test/geometry/test_homography_warper.pydiff --git a/test/test_imgwarp.py b/test/geometry/test_imgwarp.pysimilarity index 100%rename from test/test_imgwarp.pyrename to test/geometry/test_imgwarp.pydiff --git a/test/test_pinhole.py b/test/geometry/test_pinhole.pysimilarity index 100%rename from test/test_pinhole.pyrename to test/geometry/test_pinhole.pydiff --git a/test/transform/test_pyramid.py b/test/geometry/test_pyramid.pysimilarity index 75%rename from test/transform/test_pyramid.pyrename to test/geometry/test_pyramid.pyindex 08961a136..e57fda7c5 100644--- a/test/transform/test_pyramid.py+++ b/test/geometry/test_pyramid.py@@ -11,12 +11,12 @@ import utils # test utilsclass TestPyrUp:def test_shape(self):inp = torch.zeros(1, 2, 4, 4)- pyr = tgm.transform.PyrUp()+ pyr = tgm.geometry.PyrUp()assert pyr(inp).shape == (1, 2, 8, 8)def test_shape_batch(self):inp = torch.zeros(2, 2, 4, 4)- pyr = tgm.transform.PyrUp()+ pyr = tgm.geometry.PyrUp()assert pyr(inp).shape == (2, 2, 8, 8)def test_gradcheck(self):@@ -24,27 +24,27 @@ class TestPyrUp:img = torch.rand(batch_size, channels, height, width)img = utils.tensor_to_gradcheck_var(img) # to var- assert gradcheck(tgm.transform.pyrup, (img,), raise_exception=True)+ assert gradcheck(tgm.geometry.pyrup, (img,), raise_exception=True)def test_jit(self):@torch.jit.scriptdef op_script(input):- return tgm.transform.pyrup(input)+ return tgm.geometry.pyrup(input)img = torch.rand(2, 3, 4, 5)actual = op_script(img)- expected = tgm.transform.pyrup(img)+ expected = tgm.geometry.pyrup(img)assert_allclose(actual, expected)class TestPyrDown:def test_shape(self):inp = torch.zeros(1, 2, 4, 4)- pyr = tgm.transform.PyrDown()+ pyr = tgm.geometry.PyrDown()assert pyr(inp).shape == (1, 2, 2, 2)def test_shape_batch(self):inp = torch.zeros(2, 2, 4, 4)- pyr = tgm.transform.PyrDown()+ pyr = tgm.geometry.PyrDown()assert pyr(inp).shape == (2, 2, 2, 2)def test_gradcheck(self):@@ -52,13 +52,13 @@ class TestPyrDown:img = torch.rand(batch_size, channels, height, width)img = utils.tensor_to_gradcheck_var(img) # to var- assert gradcheck(tgm.transform.pyrdown, (img,), raise_exception=True)+ assert gradcheck(tgm.geometry.pyrdown, (img,), raise_exception=True)def test_jit(self):@torch.jit.scriptdef op_script(input):- return tgm.transform.pyrdown(input)+ return tgm.geometry.pyrdown(input)img = torch.rand(2, 3, 4, 5)actual = op_script(img)- expected = tgm.transform.pyrdown(img)+ expected = tgm.geometry.pyrdown(img)assert_allclose(actual, expected)diff --git a/test/test_transformations.py b/test/geometry/test_transformations.pysimilarity index 93%rename from test/test_transformations.pyrename to test/geometry/test_transformations.pyindex 6f640fc58..2a2da7912 100644--- a/test/test_transformations.py+++ b/test/geometry/test_transformations.py@@ -90,7 +90,7 @@ class TestComposeTransforms:trans_12 = identity_matrix(batch_size=1)[0]trans_12[..., :3, -1] += offset # add offset to translation vector- trans_02 = tgm.boxplus_transformation(trans_01, trans_12)+ trans_02 = tgm.compose_transformations(trans_01, trans_12)assert utils.check_equal_torch(trans_02, trans_12)@pytest.mark.parametrize("batch_size", [1, 2, 5])@@ -100,7 +100,7 @@ class TestComposeTransforms:trans_12 = identity_matrix(batch_size)trans_12[..., :3, -1] += offset # add offset to translation vector- trans_02 = tgm.boxplus_transformation(trans_01, trans_12)+ trans_02 = tgm.compose_transformations(trans_01, trans_12)assert utils.check_equal_torch(trans_02, trans_12)@pytest.mark.parametrize("batch_size", [1, 2, 5])@@ -110,7 +110,7 @@ class TestComposeTransforms:trans_01 = utils.tensor_to_gradcheck_var(trans_01) # to vartrans_12 = utils.tensor_to_gradcheck_var(trans_12) # to var- assert gradcheck(tgm.boxplus_transformation, (trans_01, trans_12,),+ assert gradcheck(tgm.compose_transformations, (trans_01, trans_12,),raise_exception=True)@@ -166,8 +166,8 @@ class TestRelativeTransformation:trans_02 = identity_matrix(batch_size=1)[0]trans_02[..., :3, -1] += offset # add offset to translation vector- trans_12 = tgm.boxminus_transformation(trans_01, trans_02)- trans_02_hat = tgm.boxplus_transformation(trans_01, trans_12)+ trans_12 = tgm.relative_transformation(trans_01, trans_02)+ trans_02_hat = tgm.compose_transformations(trans_01, trans_12)assert utils.check_equal_torch(trans_02_hat, trans_02)@pytest.mark.parametrize("batch_size", [1, 2, 5])@@ -182,8 +182,8 @@ class TestRelativeTransformation:trans_02[..., :3, -1] += offset # add offset to translation vectortrans_02[..., :3, :3] = rmat_02[..., :3, :3]- trans_12 = tgm.boxminus_transformation(trans_01, trans_02)- trans_02_hat = tgm.boxplus_transformation(trans_01, trans_12)+ trans_12 = tgm.relative_transformation(trans_01, trans_02)+ trans_02_hat = tgm.compose_transformations(trans_01, trans_12)assert utils.check_equal_torch(trans_02_hat, trans_02)@pytest.mark.parametrize("batch_size", [1, 2, 5])@@ -193,5 +193,5 @@ class TestRelativeTransformation:trans_01 = utils.tensor_to_gradcheck_var(trans_01) # to vartrans_02 = utils.tensor_to_gradcheck_var(trans_02) # to var- assert gradcheck(tgm.boxminus_transformation, (trans_01, trans_02,),+ assert gradcheck(tgm.relative_transformation, (trans_01, trans_02,),raise_exception=True)diff --git a/torchgeometry/__init__.py b/torchgeometry/__init__.pyindex fe2dae3ca..e08129b69 100644--- a/torchgeometry/__init__.py+++ b/torchgeometry/__init__.py@@ -6,24 +6,14 @@ if sys.version_info < (3, 6, 0):from .version import __version__-from torchgeometry import core-from torchgeometry import losses-from torchgeometry import contrib-from torchgeometry import utils-from torchgeometry import metrics+from torchgeometry import geometryfrom torchgeometry import colorfrom torchgeometry import featurefrom torchgeometry import filters-from torchgeometry import transform+from torchgeometry import losses+from torchgeometry import contrib+from torchgeometry import metrics+from torchgeometry import utils-# Exposes ``torchgeometry.core`` package to top level-from .core.homography_warper import HomographyWarper, homography_warp-from .core.depth_warper import DepthWarper, depth_warp-from .core.pinhole import *-from .core.conversions import *-from .core.imgwarp import *-from .core.transformations import *-from .core.affine import (- affine, rotate, translate, scale, shear, Rotate, Translate, Scale, Shear-)-from .core.crop import center_crop, crop_and_resize+# Exposes ``torchgeometry.geometry`` package to top level+from torchgeometry.geometry import *diff --git a/torchgeometry/contrib/max_blur_pool.py b/torchgeometry/contrib/max_blur_pool.pyindex 16df59910..1f9a3fe76 100644--- a/torchgeometry/contrib/max_blur_pool.py+++ b/torchgeometry/contrib/max_blur_pool.py@@ -4,7 +4,7 @@ import torchimport torch.nn as nnimport torch.nn.functional as F-from torchgeometry.transform import pyrdown+from torchgeometry.geometry.pyramid import pyrdown__all__ = ["MaxBlurPool2d",diff --git a/torchgeometry/core/__init__.py b/torchgeometry/core/__init__.pydeleted file mode 100644index a0e766f52..000000000--- a/torchgeometry/core/__init__.py+++ /dev/null@@ -1,10 +0,0 @@-from .homography_warper import HomographyWarper, homography_warp-from .depth_warper import DepthWarper, depth_warp-from .pinhole import *-from .conversions import *-from .imgwarp import *-from .transformations import *-from .affine import (- affine, rotate, translate, scale, shear, Rotate, Translate, Scale, Shear-)-from .crop import center_crop, crop_and_resizediff --git a/torchgeometry/geometry/__init__.py b/torchgeometry/geometry/__init__.pynew file mode 100644index 000000000..627eb3563--- /dev/null+++ b/torchgeometry/geometry/__init__.py@@ -0,0 +1,16 @@+# image transforms+from .crop import *+from .affine_warp import *+from .imgwarp import *+from .pyramid import *++# linear transforms+from .transformations import *+from .conversions import *++# warpers+from .homography_warper import *+from .depth_warper import *++# camera models+from .pinhole import *diff --git a/torchgeometry/core/affine.py b/torchgeometry/geometry/affine_warp.pysimilarity index 97%rename from torchgeometry/core/affine.pyrename to torchgeometry/geometry/affine_warp.pyindex 293970532..7a903c228 100644--- a/torchgeometry/core/affine.py+++ b/torchgeometry/geometry/affine_warp.py@@ -3,8 +3,19 @@ from typing import Unionimport torchimport torch.nn as nn-from torchgeometry.core.imgwarp import warp_affine, get_rotation_matrix2d-+from torchgeometry.geometry.imgwarp import warp_affine, get_rotation_matrix2d++__all__ = [+ "affine",+ "scale",+ "rotate",+ "translate",+ "shear",+ "Scale",+ "Rotate",+ "Translate",+ "Shear",+]# utilities to compute affine matricesdiff --git a/torchgeometry/core/conversions.py b/torchgeometry/geometry/conversions.pysimilarity index 100%rename from torchgeometry/core/conversions.pyrename to torchgeometry/geometry/conversions.pydiff --git a/torchgeometry/core/crop.py b/torchgeometry/geometry/crop.pysimilarity index 97%rename from torchgeometry/core/crop.pyrename to torchgeometry/geometry/crop.pyindex 50b344be8..23a96d828 100644--- a/torchgeometry/core/crop.py+++ b/torchgeometry/geometry/crop.py@@ -2,8 +2,13 @@ from typing import Tupleimport torch-from torchgeometry.core.imgwarp import warp_perspective-from torchgeometry.core.imgwarp import get_perspective_transform+from torchgeometry.geometry.imgwarp import warp_perspective+from torchgeometry.geometry.imgwarp import get_perspective_transform++__all__ = [+ "crop_and_resize",+ "center_crop",+]def crop_and_resize(tensor: torch.Tensor, boxes: torch.Tensor,diff --git a/torchgeometry/core/depth_warper.py b/torchgeometry/geometry/depth_warper.pysimilarity index 94%rename from torchgeometry/core/depth_warper.pyrename to torchgeometry/geometry/depth_warper.pyindex 953e41a1c..c5dec66c7 100644--- a/torchgeometry/core/depth_warper.py+++ b/torchgeometry/geometry/depth_warper.py@@ -3,12 +3,12 @@ import torchimport torch.nn as nnimport torch.nn.functional as F-from torchgeometry.core.transformations import transform_points-from torchgeometry.core.transformations import boxminus_transformation-from torchgeometry.core.conversions import convert_points_to_homogeneous-from torchgeometry.core.pinhole import PinholeCamera, PinholeCamerasList-from torchgeometry.core.pinhole import normalize_pixel_coordinates-from torchgeometry.core.pinhole import cam2pixel, pixel2cam+from torchgeometry.geometry.transformations import transform_points+from torchgeometry.geometry.transformations import relative_transformation+from torchgeometry.geometry.conversions import convert_points_to_homogeneous+from torchgeometry.geometry.pinhole import PinholeCamera, PinholeCamerasList+from torchgeometry.geometry.pinhole import normalize_pixel_coordinates+from torchgeometry.geometry.pinhole import cam2pixel, pixel2camfrom torchgeometry.utils import create_meshgrid@@ -76,7 +76,7 @@ class DepthWarper(nn.Module):"PinholeCamera. Got {}".format(type(pinhole_src)))# compute the relative pose between the non reference and the reference# camera frames.- dst_trans_src: torch.Tensor = boxminus_transformation(+ dst_trans_src: torch.Tensor = relative_transformation(pinhole_src.extrinsics, self._pinhole_dst.extrinsics)# compute the projection matrix between the non reference cameras anddiff --git a/torchgeometry/core/homography_warper.py b/torchgeometry/geometry/homography_warper.pysimilarity index 98%rename from torchgeometry/core/homography_warper.pyrename to torchgeometry/geometry/homography_warper.pyindex c62bc0294..e3f674f7f 100644--- a/torchgeometry/core/homography_warper.py+++ b/torchgeometry/geometry/homography_warper.py@@ -5,7 +5,7 @@ import torch.nn as nnimport torch.nn.functional as Ffrom torchgeometry.utils import create_meshgrid-from torchgeometry.core.transformations import transform_points+from torchgeometry.geometry.transformations import transform_points__all__ = [diff --git a/torchgeometry/core/imgwarp.py b/torchgeometry/geometry/imgwarp.pysimilarity index 98%rename from torchgeometry/core/imgwarp.pyrename to torchgeometry/geometry/imgwarp.pyindex e0d0199f9..52e7e7be3 100644--- a/torchgeometry/core/imgwarp.py+++ b/torchgeometry/geometry/imgwarp.py@@ -3,10 +3,10 @@ from typing import Tuple, Optionalimport torchimport torch.nn.functional as F-from torchgeometry.core.conversions import deg2rad-from torchgeometry.core.homography_warper import homography_warp+from torchgeometry.geometry.conversions import deg2rad+from torchgeometry.geometry.homography_warper import homography_warp# TODO: move to utils or conversions-from torchgeometry.core.pinhole import normalize_pixel_coordinates+from torchgeometry.geometry.pinhole import normalize_pixel_coordinates__all__ = [diff --git a/torchgeometry/core/pinhole.py b/torchgeometry/geometry/pinhole.pysimilarity index 99%rename from torchgeometry/core/pinhole.pyrename to torchgeometry/geometry/pinhole.pyindex bf7f8dd9b..8ea3b4290 100644--- a/torchgeometry/core/pinhole.py+++ b/torchgeometry/geometry/pinhole.py@@ -4,9 +4,9 @@ import warningsimport torchimport torch.nn as nn-from torchgeometry.core.conversions import rtvec_to_pose-from torchgeometry.core.transformations import transform_points-from torchgeometry.core.transformations import inverse_transformation+from torchgeometry.geometry.conversions import rtvec_to_pose+from torchgeometry.geometry.transformations import transform_points+from torchgeometry.geometry.transformations import inverse_transformation__all__ = [diff --git a/torchgeometry/transform/pyramid.py b/torchgeometry/geometry/pyramid.pysimilarity index 98%rename from torchgeometry/transform/pyramid.pyrename to torchgeometry/geometry/pyramid.pyindex eb9981a9a..66005777a 100644--- a/torchgeometry/transform/pyramid.py+++ b/torchgeometry/geometry/pyramid.py@@ -2,6 +2,13 @@ import torchimport torch.nn as nnimport torch.nn.functional as F+__all__ = [+ "PyrDown",+ "PyrUp",+ "pyrdown",+ "pyrup",+]+def _get_pyramid_gaussian_kernel() -> torch.Tensor:"""Utility function that return a pre-computed gaussian kernel."""diff --git a/torchgeometry/core/transformations.py b/torchgeometry/geometry/transformations.pysimilarity index 96%rename from torchgeometry/core/transformations.pyrename to torchgeometry/geometry/transformations.pyindex 4a91608f0..e6570fa15 100644--- a/torchgeometry/core/transformations.py+++ b/torchgeometry/geometry/transformations.py@@ -3,20 +3,20 @@ from typing import Optionalimport torchimport torch.nn as nn-from torchgeometry.core.conversions import convert_points_to_homogeneous-from torchgeometry.core.conversions import convert_points_from_homogeneous+from torchgeometry.geometry.conversions import convert_points_to_homogeneous+from torchgeometry.geometry.conversions import convert_points_from_homogeneous__all__ = [- "boxplus_transformation",- "boxminus_transformation",+ "compose_transformations",+ "relative_transformation","inverse_transformation","transform_points","TransformPoints",]-def boxplus_transformation(+def compose_transformations(trans_01: torch.Tensor, trans_12: torch.Tensor) -> torch.Tensor:r"""Functions that composes two homogeneous transformations.@@ -125,7 +125,7 @@ def inverse_transformation(trans_12):return trans_21-def boxminus_transformation(+def relative_transformation(trans_01: torch.Tensor, trans_02: torch.Tensor) -> torch.Tensor:r"""Function that computes the relative homogenous transformation from areference transformation :math:`T_1^{0} = \begin{bmatrix} R_1 & t_1 \\@@ -171,7 +171,7 @@ def boxminus_transformation(raise ValueError("Input number of dims must match. Got {} and {}".format(trans_01.dim(), trans_02.dim()))trans_10: torch.Tensor = inverse_transformation(trans_01)- trans_12: torch.Tensor = boxplus_transformation(trans_10, trans_02)+ trans_12: torch.Tensor = compose_transformations(trans_10, trans_02)return trans_12diff --git a/torchgeometry/transform/__init__.py b/torchgeometry/transform/__init__.pydeleted file mode 100644index c2be9260f..000000000--- a/torchgeometry/transform/__init__.py+++ /dev/null@@ -1,8 +0,0 @@-from .pyramid import pyrdown, pyrup, PyrDown, PyrUp--__all__ = [- "PyrDown",- "PyrUp",- "pyrdown",- "pyrup",-]