Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

reorganize api, move main code to core package and expose to top level

edgarribaf506d0fafeeb
diff --git a/docs/source/core.rst b/docs/source/core.rst
new file mode 100644
index 000000000..125b7a802
--- /dev/null
+++ b/docs/source/core.rst
@@ -0,0 +1,13 @@
+torchgeometry.core
+==================
+
+.. currentmodule:: torchgeometry.core
+
+.. toctree::
+ :maxdepth: 2
+
+ geometric
+ transformations
+ pinhole
+ conversions
+ warping
diff --git a/docs/source/index.rst b/docs/source/index.rst
index 48213caef..85e460210 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -20,11 +20,7 @@ TGM focuses on Image and tensor warping functions such as:
:maxdepth: 2
:caption: Package Reference
- geometric
- transformations
- pinhole
- conversions
- warping
+ core
image
losses
contrib
diff --git a/mypy_files.txt b/mypy_files.txt
index 8067b8860..bcde574dc 100644
--- a/mypy_files.txt
+++ b/mypy_files.txt
@@ -1,9 +1,9 @@
+torchgeometry/core/homography_warper.py
torchgeometry/image/gaussian.py
torchgeometry/losses/ssim.py
torchgeometry/losses/dice.py
torchgeometry/losses/focal.py
torchgeometry/losses/tversky.py
torchgeometry/losses/depth_smooth.py
-torchgeometry/homography_warper.py
torchgeometry/contrib/spatial_soft_argmax2d.py
torchgeometry/contrib/extract_patches.py
diff --git a/test/test_imgwarp.py b/test/test_imgwarp.py
index d5f624c3b..ef15bdf9a 100644
--- a/test/test_imgwarp.py
+++ b/test/test_imgwarp.py
@@ -162,13 +162,13 @@ def test_warp_perspective_crop(batch_size, device_type, channels):
points_src, points_dst)
# create points grid in normalized coordinates
- grid_src_norm = tgm.create_meshgrid(src_h, src_w,
- normalized_coordinates=True)
+ grid_src_norm = tgm.utils.create_meshgrid(
+ src_h, src_w, normalized_coordinates=True)
grid_src_norm = grid_src_norm.repeat(batch_size, 1, 1, 1).to(device)
# create points grid in pixel coordinates
- grid_src_pix = tgm.create_meshgrid(src_h, src_w,
- normalized_coordinates=False)
+ grid_src_pix = tgm.utils.create_meshgrid(
+ src_h, src_w, normalized_coordinates=False)
grid_src_pix = grid_src_pix.repeat(batch_size, 1, 1, 1).to(device)
src_norm_trans_src_pix = tgm.normal_transform_pixel(src_h, src_w).repeat(
diff --git a/test/test_utils.py b/test/test_utils.py
index b6f840222..f486fbfa7 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -11,7 +11,7 @@ import utils # test utils
[(4, 4), (1, 4, 4), (3, 4, 4), ])
def test_tensor_to_image(batch_shape):
tensor = torch.ones(batch_shape)
- image = tgm.tensor_to_image(tensor)
+ image = tgm.utils.tensor_to_image(tensor)
assert image.shape[:2] == batch_shape[-2:]
assert isinstance(image, np.ndarray)
@@ -20,7 +20,7 @@ def test_tensor_to_image(batch_shape):
[(4, 4), (4, 4, 1), (4, 4, 3), ])
def test_image_to_tensor(batch_shape):
image = np.ones(batch_shape)
- tensor = tgm.image_to_tensor(image)
+ tensor = tgm.utils.image_to_tensor(image)
assert tensor.shape[-2:] == batch_shape[:2]
assert isinstance(tensor, torch.Tensor)
@@ -30,7 +30,8 @@ def test_create_meshgrid():
normalized_coordinates = False
# create the meshgrid and verify shape
- grid = tgm.create_meshgrid(height, width, normalized_coordinates)
+ grid = tgm.utils.create_meshgrid(
+ height, width, normalized_coordinates)
assert grid.shape == (1, height, width, 2)
# check grid corner values
@@ -45,11 +46,11 @@ def test_normalize_pixel_grid():
height, width = 2, 4
# create points grid
- grid_norm = tgm.create_meshgrid(height, width,
- normalized_coordinates=True)
+ grid_norm = tgm.utils.create_meshgrid(
+ height, width, normalized_coordinates=True)
grid_norm = torch.unsqueeze(grid_norm, dim=0)
- grid_pix = tgm.create_meshgrid(height, width,
- normalized_coordinates=False)
+ grid_pix = tgm.utils.create_meshgrid(
+ height, width, normalized_coordinates=False)
grid_pix = torch.unsqueeze(grid_pix, dim=0)
# grid from pixel space to normalized
diff --git a/torchgeometry/__init__.py b/torchgeometry/__init__.py
index f2ffb8bce..73ab5755e 100644
--- a/torchgeometry/__init__.py
+++ b/torchgeometry/__init__.py
@@ -1,14 +1,17 @@
-from .homography_warper import HomographyWarper, homography_warp
-from .depth_warper import DepthWarper, depth_warp
-from .pinhole import *
-from .conversions import *
-from .utils import *
-from .imgwarp import *
-from .transformations import *
-
+from torchgeometry import core
from torchgeometry import image
from torchgeometry import losses
from torchgeometry import contrib
+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 *
+# TODO(edgar): move to a separated file
__version__ = '0.1.2rc1' # the current version of the lib
diff --git a/torchgeometry/core/__init__.py b/torchgeometry/core/__init__.py
new file mode 100644
index 000000000..01976bdb3
--- /dev/null
+++ b/torchgeometry/core/__init__.py
@@ -0,0 +1,6 @@
+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 *
diff --git a/torchgeometry/conversions.py b/torchgeometry/core/conversions.py
similarity index 100%
rename from torchgeometry/conversions.py
rename to torchgeometry/core/conversions.py
diff --git a/torchgeometry/depth_warper.py b/torchgeometry/core/depth_warper.py
similarity index 100%
rename from torchgeometry/depth_warper.py
rename to torchgeometry/core/depth_warper.py
diff --git a/torchgeometry/homography_warper.py b/torchgeometry/core/homography_warper.py
similarity index 98%
rename from torchgeometry/homography_warper.py
rename to torchgeometry/core/homography_warper.py
index 574f63893..1f41fd0c4 100644
--- a/torchgeometry/homography_warper.py
+++ b/torchgeometry/core/homography_warper.py
@@ -4,8 +4,8 @@ import torch
import torch.nn as nn
import torch.nn.functional as F
-from .utils import create_meshgrid
-from .conversions import transform_points
+from torchgeometry.utils import create_meshgrid
+from torchgeometry.core.conversions import transform_points
__all__ = [
diff --git a/torchgeometry/imgwarp.py b/torchgeometry/core/imgwarp.py
similarity index 100%
rename from torchgeometry/imgwarp.py
rename to torchgeometry/core/imgwarp.py
diff --git a/torchgeometry/pinhole.py b/torchgeometry/core/pinhole.py
similarity index 100%
rename from torchgeometry/pinhole.py
rename to torchgeometry/core/pinhole.py
diff --git a/torchgeometry/transformations.py b/torchgeometry/core/transformations.py
similarity index 100%
rename from torchgeometry/transformations.py
rename to torchgeometry/core/transformations.py