Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

mega refactor gfor geometry module

edgarribafef0dda78947
diff --git a/docs/source/color.rst b/docs/source/color.rst
index 37c3eef4b..2a31c0700 100644
--- a/docs/source/color.rst
+++ b/docs/source/color.rst
@@ -5,16 +5,16 @@ torchgeometry.color
The functions in this section perform various color space conversions.
-.. autofunction:: normalize
.. autofunction:: rgb_to_grayscale
.. autofunction:: rgb_to_hsv
.. autofunction:: hsv_to_rgb
.. autofunction:: rgb_to_bgr
.. autofunction:: bgr_to_rgb
+.. autofunction:: normalize
-.. autoclass:: Normalize
.. autoclass:: RgbToGrayscale
.. autoclass:: RgbToHsv
.. autoclass:: HsvToRgb
.. autoclass:: RgbToBgr
-.. autoclass:: BgrToRgb
+.. autoclass:: BgrToRgb
+.. autoclass:: Normalize
diff --git a/docs/source/geometry.camera.rst b/docs/source/geometry.camera.rst
new file mode 100644
index 000000000..c1e54fa8e
--- /dev/null
+++ b/docs/source/geometry.camera.rst
@@ -0,0 +1,9 @@
+torchgeometry.geometry.camera
+=============================
+
+.. currentmodule:: torchgeometry.geometry.camera
+
+.. toctree::
+ :maxdepth: 2
+
+ pinhole
diff --git a/docs/source/conversions.rst b/docs/source/geometry.conversions.rst
similarity index 67%
rename from docs/source/conversions.rst
rename to docs/source/geometry.conversions.rst
index 732c61d76..eaec327c8 100644
--- a/docs/source/conversions.rst
+++ b/docs/source/geometry.conversions.rst
@@ -1,7 +1,7 @@
-Conversions
------------
+torchgeometry.geometry.conversions
+==================================
-.. currentmodule:: torchgeometry.geometry
+.. currentmodule:: torchgeometry.geometry.conversions
.. autofunction:: rad2deg
.. autofunction:: deg2rad
@@ -13,8 +13,4 @@ Conversions
.. autofunction:: quaternion_to_angle_axis
.. autofunction:: angle_axis_to_quaternion
.. autofunction:: rtvec_to_pose
-
-.. autoclass:: RadToDeg
-.. autoclass:: DegToRad
-.. autoclass:: ConvertPointsFromHomogeneous
-.. autoclass:: ConvertPointsToHomogeneous
+.. autofunction:: normalize_pixel_coordinates
diff --git a/docs/source/transformations.rst b/docs/source/geometry.linalg.rst
similarity index 59%
rename from docs/source/transformations.rst
rename to docs/source/geometry.linalg.rst
index 9c2bdaed8..6cea3ad81 100644
--- a/docs/source/transformations.rst
+++ b/docs/source/geometry.linalg.rst
@@ -1,7 +1,8 @@
-Linear Transformations
-----------------------
+torchgeometry.geometry.linalg
+=============================
+
+.. currentmodule:: torchgeometry.geometry.linalg
-.. currentmodule:: torchgeometry.geometry
.. autofunction:: relative_transformation
.. autofunction:: compose_transformations
diff --git a/docs/source/geometry.rst b/docs/source/geometry.rst
index 9ad247af3..89b63e096 100644
--- a/docs/source/geometry.rst
+++ b/docs/source/geometry.rst
@@ -6,8 +6,8 @@ torchgeometry.geometry
.. toctree::
:maxdepth: 2
- geometric
- transformations
- pinhole
- conversions
- warping
+ geometry.camera
+ geometry.conversions
+ geometry.linalg
+ geometry.transform
+ geometry.warp
diff --git a/docs/source/geometric.rst b/docs/source/geometry.transform.rst
similarity index 85%
rename from docs/source/geometric.rst
rename to docs/source/geometry.transform.rst
index e5e12b2c6..90de04e36 100644
--- a/docs/source/geometric.rst
+++ b/docs/source/geometry.transform.rst
@@ -1,7 +1,7 @@
-Image Transformations
----------------------
+torchgeometry.geometry.transform
+================================
-.. currentmodule:: torchgeometry.geometry
+.. currentmodule:: torchgeometry.geometry.transform
The functions in this section perform various geometrical transformations of 2D images.
diff --git a/docs/source/warping.rst b/docs/source/geometry.warp.rst
similarity index 59%
rename from docs/source/warping.rst
rename to docs/source/geometry.warp.rst
index aa83d9e1b..0a6df83fd 100644
--- a/docs/source/warping.rst
+++ b/docs/source/geometry.warp.rst
@@ -1,7 +1,7 @@
-Warping
--------
+torchgeometry.geometry.warp
+===========================
-.. currentmodule:: torchgeometry.geometry
+.. currentmodule:: torchgeometry.geometry.warp
.. autoclass:: HomographyWarper
:members:
diff --git a/docs/source/pinhole.rst b/docs/source/pinhole.rst
index 0494bc6c1..92684c6ee 100644
--- a/docs/source/pinhole.rst
+++ b/docs/source/pinhole.rst
@@ -1,7 +1,7 @@
Pinhole Camera
--------------
-.. currentmodule:: torchgeometry.geometry
+.. currentmodule:: torchgeometry.geometry.camera
In 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.
@@ -48,17 +48,6 @@ The camera rotation and translation are expressed in terms of Euclidean coordina
.. autoclass:: PinholeCamera
:members:
-.. autoclass:: PinholeCamerasList
.. autofunction:: cam2pixel
.. autofunction:: pixel2cam
-.. autofunction:: normalize_pixel_coordinates
-
-.. TODO(edgar): deprecate in v0.2
-.. autofunction:: homography_i_H_ref
-.. autofunction:: pinhole_matrix
-.. autofunction:: inverse_pinhole_matrix
-.. autofunction:: scale_pinhole
-
-.. autoclass:: PinholeMatrix
-.. autoclass:: InversePinholeMatrix
diff --git a/docs/source/metrics.rst b/docs/source/utils.metrics.rst
similarity index 100%
rename from docs/source/metrics.rst
rename to docs/source/utils.metrics.rst
diff --git a/docs/source/utils.rst b/docs/source/utils.rst
index ec94f0b97..6699410a5 100644
--- a/docs/source/utils.rst
+++ b/docs/source/utils.rst
@@ -11,4 +11,4 @@ torchgeometry.utils
.. toctree::
:maxdepth: 2
- metrics
+ utils.metrics
diff --git a/mypy_files.txt b/mypy_files.txt
index a5b0202b6..62c5189bd 100644
--- a/mypy_files.txt
+++ b/mypy_files.txt
@@ -12,13 +12,15 @@ torchgeometry/filters/gaussian.py
torchgeometry/filters/laplacian.py
torchgeometry/filters/median.py
torchgeometry/filters/sobel.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.py
+torchgeometry/geometry/conversions.py
+torchgeometry/geometry/linalg.py
+torchgeometry/geometry/camera/pinhole.py
+torchgeometry/geometry/transform/affwarp.py
+torchgeometry/geometry/transform/imgwarp.py
+torchgeometry/geometry/transform/crop.py
+torchgeometry/geometry/transform/pyramid.py
+torchgeometry/geometry/warp/homography_warper.py
+torchgeometry/geometry/warp/depth_warper.py
torchgeometry/losses/ssim.py
torchgeometry/losses/dice.py
torchgeometry/losses/focal.py
diff --git a/test/geometry/test_conversions.py b/test/geometry/test_conversions.py
index 386de40a8..f8ff8120e 100644
--- a/test/geometry/test_conversions.py
+++ b/test/geometry/test_conversions.py
@@ -120,10 +120,6 @@ def test_rad2deg(batch_shape, device_type):
# compute error
error = utils.compute_mse(x_rad, x_deg_to_rad)
- assert pytest.approx(error.item(), 0.0)
-
- # functional
- assert torch.allclose(x_deg, tgm.RadToDeg()(x_rad))
# evaluate function gradient
assert gradcheck(tgm.rad2deg, (utils.tensor_to_gradcheck_var(x_rad),),
@@ -145,9 +141,6 @@ def test_deg2rad(batch_shape, device_type):
error = utils.compute_mse(x_deg, x_rad_to_deg)
assert pytest.approx(error.item(), 0.0)
- # functional
- assert torch.allclose(x_rad, tgm.DegToRad()(x_deg))
-
assert gradcheck(tgm.deg2rad, (utils.tensor_to_gradcheck_var(x_deg),),
raise_exception=True)
@@ -165,9 +158,6 @@ def test_convert_points_to_homogeneous(batch_shape, device_type):
assert points_h.shape[-2] == batch_shape[-2]
assert (points_h[..., -1] == torch.ones(points_h[..., -1].shape)).all()
- # functional
- assert torch.allclose(points_h, tgm.ConvertPointsToHomogeneous()(points))
-
# evaluate function gradient
points = utils.tensor_to_gradcheck_var(points) # to var
assert gradcheck(tgm.convert_points_to_homogeneous, (points,),
diff --git a/test/geometry/test_transformations.py b/test/geometry/test_linalg.py
similarity index 99%
rename from test/geometry/test_transformations.py
rename to test/geometry/test_linalg.py
index 2a2da7912..99d4e050f 100644
--- a/test/geometry/test_transformations.py
+++ b/test/geometry/test_linalg.py
@@ -78,7 +78,7 @@ class TestTransformPoints:
# evaluate function gradient
points_src = utils.tensor_to_gradcheck_var(points_src) # to var
dst_homo_src = utils.tensor_to_gradcheck_var(dst_homo_src) # to var
- assert gradcheck(tgm.TransformPoints(dst_homo_src), (points_src,),
+ assert gradcheck(tgm.transform_points, (dst_homo_src, points_src,),
raise_exception=True)
diff --git a/test/geometry/test_pinhole.py b/test/geometry/test_pinhole.py
index 630a94d34..e0deaaae0 100644
--- a/test/geometry/test_pinhole.py
+++ b/test/geometry/test_pinhole.py
@@ -124,71 +124,6 @@ class TestPinholeCamera:
assert pinhole.rotation_matrix.shape == (batch_size, 3, 3)
assert pinhole.translation_vector.shape == (batch_size, 3, 1)
- def test_pinhole_camera_list_attributes(self):
- batch_size = 1
- height, width = 4, 6
- fx, fy, cx, cy = 1, 2, width / 2, height / 2
- tx, ty, tz = 1, 2, 3
-
- intrinsics = self._create_intrinsics(batch_size, fx, fy, cx, cy)
- extrinsics = self._create_extrinsics(batch_size, tx, ty, tz)
- height = torch.ones(batch_size) * height
- width = torch.ones(batch_size) * width
-
- pinhole_1 = tgm.PinholeCamera(intrinsics, extrinsics, height, width)
- pinhole_2 = pinhole_1.clone()
- pinholes_list = [pinhole_1, pinhole_2]
- pinholes = tgm.PinholeCamerasList(pinholes_list)
-
- assert pinholes.batch_size == batch_size
- assert pinholes.num_cameras == 2
- assert torch.allclose(pinholes.fx, torch.ones(1, 2) * fx)
- assert torch.allclose(pinholes.fy, torch.ones(1, 2) * fy)
- assert torch.allclose(pinholes.cx, torch.ones(1, 2) * cx)
- assert torch.allclose(pinholes.cy, torch.ones(1, 2) * cy)
- assert torch.allclose(pinholes.tx, torch.ones(1, 2) * tx)
- assert torch.allclose(pinholes.ty, torch.ones(1, 2) * ty)
- assert torch.allclose(pinholes.tz, torch.ones(1, 2) * tz)
- assert pinholes.rt_matrix.shape == (batch_size, 2, 3, 4)
- assert pinholes.camera_matrix.shape == (batch_size, 2, 3, 3)
- assert pinholes.rotation_matrix.shape == (batch_size, 2, 3, 3)
- assert pinholes.translation_vector.shape == (batch_size, 2, 3, 1)
-
- def test_pinhole_camera_list_get_pinhole(self):
- batch_size = 1
- height, width = 4, 6
- fx, fy, cx, cy = 1, 2, width / 2, height / 2
- tx, ty, tz = 1, 2, 3
-
- intrinsics = self._create_intrinsics(batch_size, fx, fy, cx, cy)
- extrinsics = self._create_extrinsics(batch_size, tx, ty, tz)
- height = torch.ones(batch_size) * height
- width = torch.ones(batch_size) * width
-
- pinhole_1 = tgm.PinholeCamera(intrinsics, extrinsics, height, width)
- pinhole_2 = pinhole_1.clone()
- pinholes_list = [pinhole_1, pinhole_2]
- pinholes = tgm.PinholeCamerasList(pinholes_list)
-
- pinhole_11 = pinholes.get_pinhole(0)
-
- assert pinhole_1.batch_size == pinhole_11.batch_size
- assert torch.allclose(pinhole_1.fx, pinhole_11.fx)
- assert torch.allclose(pinhole_1.fy, pinhole_11.fy)
- assert torch.allclose(pinhole_1.cx, pinhole_11.cx)
- assert torch.allclose(pinhole_1.cy, pinhole_11.cy)
- assert torch.allclose(pinhole_1.tx, pinhole_11.tx)
- assert torch.allclose(pinhole_1.ty, pinhole_11.ty)
- assert torch.allclose(pinhole_1.tz, pinhole_11.tz)
- assert torch.allclose(pinhole_1.rt_matrix, pinhole_11.rt_matrix)
- assert torch.allclose(
- pinhole_1.camera_matrix,
- pinhole_11.camera_matrix)
- assert torch.allclose(
- pinhole_1.rotation_matrix, pinhole_11.rotation_matrix)
- assert torch.allclose(
- pinhole_1.translation_vector, pinhole_11.translation_vector)
-
def test_pinhole_camera_scale(self):
batch_size = 2
height, width = 4, 6
@@ -259,7 +194,7 @@ class TestPinholeCamera:
pinhole_scale.width, pinhole.width * scale_val)
[email protected]("batch_size", [1, 2, 5, 6])
+'''@pytest.mark.parametrize("batch_size", [1, 2, 5, 6])
def test_scale_pinhole(batch_size, device_type):
# generate input data
device = torch.device(device_type)
@@ -386,7 +321,7 @@ def test_homography_i_H_ref(batch_size, device_type):
assert 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)
+ raise_exception=True)'''
class TestNormalizePixelCoordinates:
diff --git a/test/geometry/test_affine.py b/test/geometry/transform/test_affine.py
similarity index 100%
rename from test/geometry/test_affine.py
rename to test/geometry/transform/test_affine.py
diff --git a/test/geometry/test_crop.py b/test/geometry/transform/test_crop.py
similarity index 100%
rename from test/geometry/test_crop.py
rename to test/geometry/transform/test_crop.py
diff --git a/test/geometry/test_imgwarp.py b/test/geometry/transform/test_imgwarp.py
similarity index 100%
rename from test/geometry/test_imgwarp.py
rename to test/geometry/transform/test_imgwarp.py
diff --git a/test/geometry/test_pyramid.py b/test/geometry/transform/test_pyramid.py
similarity index 100%
rename from test/geometry/test_pyramid.py
rename to test/geometry/transform/test_pyramid.py
diff --git a/test/geometry/test_depth_warper.py b/test/geometry/warp/test_depth_warper.py
similarity index 98%
rename from test/geometry/test_depth_warper.py
rename to test/geometry/warp/test_depth_warper.py
index 267b29f25..4718a9987 100644
--- a/test/geometry/test_depth_warper.py
+++ b/test/geometry/warp/test_depth_warper.py
@@ -5,7 +5,7 @@ import torchgeometry as tgm
from torch.autograd import gradcheck
import utils # test utils
-from torchgeometry.geometry.depth_warper import normalize_pixel_coordinates
+from torchgeometry.geometry.conversions import normalize_pixel_coordinates
class TestDepthWarper:
diff --git a/test/geometry/test_homography_warper.py b/test/geometry/warp/test_homography_warper.py
similarity index 100%
rename from test/geometry/test_homography_warper.py
rename to test/geometry/warp/test_homography_warper.py
diff --git a/test/utils/test_metrics.py b/test/utils/test_metrics.py
index 00bbeb9e8..29acf82ea 100644
--- a/test/utils/test_metrics.py
+++ b/test/utils/test_metrics.py
@@ -100,7 +100,8 @@ class TestConfusionMatrix:
predicted = torch.tensor(
[[1, 1, 1, 1, 0, 0, 0, 1]])
- conf_mat = tgm.utils.metrics.confusion_matrix(predicted, actual, num_classes)
+ conf_mat = tgm.utils.metrics.confusion_matrix(
+ predicted, actual, num_classes)
conf_mat_real = torch.tensor(
[[[3, 1],
[0, 4]]], dtype=torch.float32)
@@ -114,7 +115,8 @@ class TestConfusionMatrix:
predicted = torch.tensor(
[[1, 1, 1, 1, 0, 0, 0, 1]]).repeat(batch_size, 1)
- conf_mat = tgm.utils.metrics.confusion_matrix(predicted, actual, num_classes)
+ conf_mat = tgm.utils.metrics.confusion_matrix(
+ predicted, actual, num_classes)
conf_mat_real = torch.tensor(
[[[3, 1],
[0, 4]]], dtype=torch.float32)
@@ -127,7 +129,8 @@ class TestConfusionMatrix:
predicted = torch.tensor(
[[2, 1, 0, 0, 0, 0, 0, 1, 0, 2, 2, 1, 0, 0, 2, 2]])
- conf_mat = tgm.utils.metrics.confusion_matrix(predicted, actual, num_classes)
+ conf_mat = tgm.utils.metrics.confusion_matrix(
+ predicted, actual, num_classes)
conf_mat_real = torch.tensor(
[[[4, 1, 2],
[3, 0, 2],
@@ -141,7 +144,8 @@ class TestConfusionMatrix:
predicted = torch.tensor(
[[3, 2, 1, 1, 1, 1, 1, 2, 1, 3, 3, 2, 1, 1, 3, 3]])
- conf_mat = tgm.utils.metrics.confusion_matrix(predicted, actual, num_classes)
+ conf_mat = tgm.utils.metrics.confusion_matrix(
+ predicted, actual, num_classes)
conf_mat_real = torch.tensor(
[[[0, 0, 0, 0],
[0, 4, 1, 2],
@@ -179,7 +183,8 @@ class TestConfusionMatrix:
[2, 2, 3, 3],
[2, 2, 3, 3]]])
- conf_mat = tgm.utils.metrics.confusion_matrix(predicted, actual, num_classes)
+ conf_mat = tgm.utils.metrics.confusion_matrix(
+ predicted, actual, num_classes)
conf_mat_real = torch.tensor(
[[[4, 0, 0, 0],
[0, 4, 0, 0],
@@ -200,7 +205,8 @@ class TestConfusionMatrix:
[2, 2, 1, 3],
[2, 2, 3, 3]]])
- conf_mat = tgm.utils.metrics.confusion_matrix(predicted, actual, num_classes)
+ conf_mat = tgm.utils.metrics.confusion_matrix(
+ predicted, actual, num_classes)
conf_mat_real = torch.tensor(
[[[3, 0, 0, 1],
[1, 3, 0, 0],
@@ -221,7 +227,8 @@ class TestConfusionMatrix:
[2, 2, 3, 3],
[2, 2, 3, 3]]])
- conf_mat = tgm.utils.metrics.confusion_matrix(predicted, actual, num_classes)
+ conf_mat = tgm.utils.metrics.confusion_matrix(
+ predicted, actual, num_classes)
conf_mat_real = torch.tensor(
[[[0, 0, 0, 4],
[0, 4, 0, 0],
@@ -242,7 +249,8 @@ class TestConfusionMatrix:
[2, 2, 3, 3],
[2, 2, 3, 3]]])
- conf_mat = tgm.utils.metrics.confusion_matrix(predicted, actual, num_classes)
+ conf_mat = tgm.utils.metrics.confusion_matrix(
+ predicted, actual, num_classes)
conf_mat_real = torch.tensor(
[[[0, 0, 4, 4],
[0, 0, 0, 0],
diff --git a/torchgeometry/color/normalize.py b/torchgeometry/color/normalize.py
index 24999fbb2..870c3126b 100644
--- a/torchgeometry/color/normalize.py
+++ b/torchgeometry/color/normalize.py
@@ -8,7 +8,7 @@ class Normalize(nn.Module):
or a batch of tensors (*, C, H, W).
Given mean: ``(M1,...,Mn)`` and std: ``(S1,..,Sn)`` for ``n`` channels,
- this transform will normalize each channel of the input ``torch.*Tensor``
+ this transform will normalize each channel of the input ``torch.Tensor``
i.e. ``input[channel] = (input[channel] - mean[channel]) / std[channel]``
Args:
@@ -43,7 +43,7 @@ def normalize(data: torch.Tensor, mean: torch.Tensor,
std (torch.Tensor): Standard deviations for each channel.
Returns:
- Tensor: The normalised image tensor.
+ torch.Tensor: The normalised image tensor.
"""
if not torch.is_tensor(data):
diff --git a/torchgeometry/contrib/max_blur_pool.py b/torchgeometry/contrib/max_blur_pool.py
index 1f9a3fe76..d5d226da0 100644
--- a/torchgeometry/contrib/max_blur_pool.py
+++ b/torchgeometry/contrib/max_blur_pool.py
@@ -4,11 +4,11 @@ import torch
import torch.nn as nn
import torch.nn.functional as F
-from torchgeometry.geometry.pyramid import pyrdown
+from torchgeometry.geometry.transform.pyramid import pyrdown
__all__ = [
- "MaxBlurPool2d",
"max_blur_pool2d",
+ "MaxBlurPool2d",
]
diff --git a/torchgeometry/geometry/__init__.py b/torchgeometry/geometry/__init__.py
index 627eb3563..626641512 100644
--- a/torchgeometry/geometry/__init__.py
+++ b/torchgeometry/geometry/__init__.py
@@ -1,16 +1,5 @@
-# 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 *
+from torchgeometry.geometry.camera import *
+from torchgeometry.geometry.conversions import *
+from torchgeometry.geometry.linalg import *
+from torchgeometry.geometry.transform import *
+from torchgeometry.geometry.warp import *
diff --git a/torchgeometry/geometry/camera/__init__.py b/torchgeometry/geometry/camera/__init__.py
new file mode 100644
index 000000000..7429d9655
--- /dev/null
+++ b/torchgeometry/geometry/camera/__init__.py
@@ -0,0 +1,7 @@
+from .pinhole import PinholeCamera, pixel2cam, cam2pixel
+
+__all__ = [
+ "PinholeCamera",
+ "pixel2cam",
+ "cam2pixel",
+]
diff --git a/torchgeometry/geometry/pinhole.py b/torchgeometry/geometry/camera/pinhole.py
similarity index 90%
rename from torchgeometry/geometry/pinhole.py
rename to torchgeometry/geometry/camera/pinhole.py
index 8ea3b4290..767ab018e 100644
--- a/torchgeometry/geometry/pinhole.py
+++ b/torchgeometry/geometry/camera/pinhole.py
@@ -5,25 +5,8 @@ import torch
import torch.nn as nn
from torchgeometry.geometry.conversions import rtvec_to_pose
-from torchgeometry.geometry.transformations import transform_points
-from torchgeometry.geometry.transformations import inverse_transformation
-
-
-__all__ = [
- "PinholeCamera",
- "PinholeCamerasList",
- # functional api
- "pinhole_matrix",
- "inverse_pinhole_matrix",
- "scale_pinhole",
- "homography_i_H_ref",
- "pixel2cam",
- "cam2pixel",
- "normalize_pixel_coordinates",
- # layer api
- "PinholeMatrix",
- "InversePinholeMatrix",
-]
+from torchgeometry.geometry.linalg import transform_points
+from torchgeometry.geometry.linalg import inverse_transformation
class PinholeCamera:
@@ -413,9 +396,9 @@ def pinhole_matrix(pinholes, eps=1e-6):
>>> pinhole = torch.rand(1, 12) # Nx12
>>> pinhole_matrix = tgm.pinhole_matrix(pinhole) # Nx4x4
"""
- warnings.warn("pinhole_matrix will be deprecated in version 0.2, "
- "use PinholeCamera.camera_matrix instead",
- PendingDeprecationWarning)
+ # warnings.warn("pinhole_matrix will be deprecated in version 0.2, "
+ # "use PinholeCamera.camera_matrix instead",
+ # PendingDeprecationWarning)
assert len(pinholes.shape) == 2 and pinholes.shape[1] == 12, pinholes.shape
# unpack pinhole values
fx, fy, cx, cy = torch.chunk(pinholes[..., :4], 4, dim=1) # Nx1
@@ -451,9 +434,9 @@ def inverse_pinhole_matrix(pinhole, eps=1e-6):
>>> pinhole = torch.rand(1, 12) # Nx12
>>> pinhole_matrix_inv = tgm.inverse_pinhole_matrix(pinhole) # Nx4x4
"""
- warnings.warn("inverse_pinhole_matrix will be deprecated in version 0.2, "
- "use PinholeCamera.intrinsics_inverse() instead",
- PendingDeprecationWarning)
+ # warnings.warn("inverse_pinhole_matrix will be deprecated in version 0.2, "
+ # "use PinholeCamera.intrinsics_inverse() instead",
+ # PendingDeprecationWarning)
assert len(pinhole.shape) == 2 and pinhole.shape[1] == 12, pinhole.shape
# unpack pinhole values
fx, fy, cx, cy = torch.chunk(pinhole[..., :4], 4, dim=1) # Nx1
@@ -491,9 +474,9 @@ def scale_pinhole(pinholes, scale):
>>> scales = 2.0 * torch.ones(1) # N
>>> pinhole_i_scaled = tgm.scale_pinhole(pinhole_i) # Nx12
"""
- warnings.warn("scale_pinhole will be deprecated in version 0.2, "
- "use PinholeCamera.scale() instead",
- PendingDeprecationWarning)
+ # warnings.warn("scale_pinhole will be deprecated in version 0.2, "
+ # "use PinholeCamera.scale() instead",
+ # PendingDeprecationWarning)
assert len(pinholes.shape) == 2 and pinholes.shape[1] == 12, pinholes.shape
assert len(scale.shape) == 1, scale.shape
pinholes_scaled = pinholes.clone()
@@ -597,42 +580,6 @@ def pixel2cam(depth: torch.Tensor, intrinsics_inv: torch.Tensor,
return cam_coords * depth.permute(0, 2, 3, 1)
-# based on:
-# https://github.com/ClementPinard/SfmLearner-Pytorch/blob/master/inverse_warp.py#L65-L71
-
-def normalize_pixel_coordinates(
- pixel_coordinates: torch.Tensor,
- height: int,
- width: int) -> torch.Tensor:
- r"""Normalize pixel coordinates between -1 and 1.
-
- Normalized, -1 if on extreme left, 1 if on extreme right (x = w-1).
-
- Args:
- pixel_coordinate (torch.Tensor): the grid with pixel coordinates.
- Shape must be :math:`(B, H, W, 2)`.
- width (int): the maximum width in the x-axis.
- height (int): the maximum height in the y-axis.
-
- Return:
- torch.Tensor: the nornmalized pixel coordinates.
- """
- if pixel_coordinates.shape[-1] != 2:
- raise ValueError("Input pixel_coordinates must be of shape (*, 2). "
- "Got {}".format(pixel_coordinates.shape))
- # compute normalization factor
- hw: torch.Tensor = torch.stack([
- torch.tensor(width), torch.tensor(height)
- ]).to(pixel_coordinates.device).to(pixel_coordinates.dtype)
-
- factor: torch.Tensor = torch.tensor(2.) / (hw - torch.tensor(1.))
-
- # normalize coordinates and return
- pixel_coordinates_norm: torch.Tensor = \
- factor * pixel_coordinates - torch.tensor(1.)
- return pixel_coordinates_norm
-
-
# based on
# https://github.com/ClementPinard/SfmLearner-Pytorch/blob/master/inverse_warp.py#L43
@@ -677,7 +624,7 @@ def cam2pixel(
# layer api
-class PinholeMatrix(nn.Module):
+'''class PinholeMatrix(nn.Module):
r"""Creates an object that returns the pinhole matrix from a pinhole model
Args:
@@ -726,4 +673,4 @@ class InversePinholeMatrix(nn.Module):
super(InversePinholeMatrix, self).__init__()
def forward(self, input):
- return inverse_pinhole_matrix(input)
+ return inverse_pinhole_matrix(input)'''
diff --git a/torchgeometry/geometry/conversions.py b/torchgeometry/geometry/conversions.py
index ad60b2983..7a6100baf 100644
--- a/torchgeometry/geometry/conversions.py
+++ b/torchgeometry/geometry/conversions.py
@@ -1,8 +1,6 @@
import torch
import torch.nn as nn
-import torchgeometry as tgm
-
__all__ = [
# functional api
"pi",
@@ -16,28 +14,24 @@ __all__ = [
"quaternion_to_angle_axis",
"angle_axis_to_quaternion",
"rtvec_to_pose",
- # layer api
- "RadToDeg",
- "DegToRad",
- "ConvertPointsFromHomogeneous",
- "ConvertPointsToHomogeneous",
+ "normalize_pixel_coordinates",
]
+EPS = 1e-6
+
"""Constant with number pi
"""
pi = torch.tensor(3.14159265358979323846)
-def rad2deg(tensor):
+def rad2deg(tensor: torch.Tensor) -> torch.Tensor:
r"""Function that converts angles from radians to degrees.
- See :class:`~torchgeometry.RadToDeg` for details.
-
Args:
- tensor (Tensor): Tensor of arbitrary shape.
+ tensor (torch.Tensor): Tensor of arbitrary shape.
Returns:
- Tensor: Tensor with same shape as input.
+ torch.Tensor: Tensor with same shape as input.
Example:
>>> input = tgm.pi * torch.rand(1, 3, 3)
@@ -50,16 +44,14 @@ def rad2deg(tensor):
return 180. * tensor / pi.to(tensor.device).type(tensor.dtype)
-def deg2rad(tensor):
+def deg2rad(tensor: torch.Tensor) -> torch.Tensor:
r"""Function that converts angles from degrees to radians.
- See :class:`~torchgeometry.DegToRad` for details.
-
Args:
- tensor (Tensor): Tensor of arbitrary shape.
+ tensor (torch.Tensor): Tensor of arbitrary shape.
Returns:
- Tensor: Tensor with same shape as input.
+ torch.Tensor: tensor with same shape as input.
Examples::
@@ -73,12 +65,9 @@ def deg2rad(tensor):
return tensor * pi.to(tensor.device).type(tensor.dtype) / 180.
-def convert_points_from_homogeneous(points: torch.Tensor,
- eps=1e-6) -> torch.Tensor:
+def convert_points_from_homogeneous(points: torch.Tensor) -> torch.Tensor:
r"""Function that converts points from homogeneous to Euclidean space.
- See :class:`~torchgeometry.ConvertPointsFromHomogeneous` for details.
-
Examples::
>>> input = torch.rand(2, 4, 3) # BxNx3
@@ -93,16 +82,14 @@ def convert_points_from_homogeneous(points: torch.Tensor,
# we check for points at infinity
z_vec: torch.Tensor = points[..., -1:]
- scale: torch.Tensor = torch.tensor(1.) / torch.clamp(z_vec, eps)
+ scale: torch.Tensor = torch.tensor(1.) / torch.clamp(z_vec, EPS)
return scale * points[..., :-1]
-def convert_points_to_homogeneous(points):
+def convert_points_to_homogeneous(points: torch.Tensor) -> torch.Tensor:
r"""Function that converts points from Euclidean to homogeneous space.
- See :class:`~torchgeometry.ConvertPointsToHomogeneous` for details.
-
Examples::
>>> input = torch.rand(2, 4, 3) # BxNx3
@@ -118,14 +105,14 @@ def convert_points_to_homogeneous(points):
return nn.functional.pad(points, (0, 1), "constant", 1.0)
-def angle_axis_to_rotation_matrix(angle_axis):
+def angle_axis_to_rotation_matrix(angle_axis: torch.Tensor) -> torch.Tensor:
"""Convert 3d vector of axis-angle rotation to 4x4 rotation matrix
Args:
- angle_axis (Tensor): tensor of 3d vector of axis-angle rotations.
+ angle_axis (torch.Tensor): tensor of 3d vector of axis-angle rotations.
Returns:
- Tensor: tensor of 4x4 rotation matrices.
+ torch.Tensor: tensor of 4x4 rotation matrices.
Shape:
- Input: :math:`(N, 3)`
@@ -193,15 +180,15 @@ def angle_axis_to_rotation_matrix(angle_axis):
return rotation_matrix # Nx4x4
-def rtvec_to_pose(rtvec):
+def rtvec_to_pose(rtvec: torch.Tensor) -> torch.Tensor:
"""
Convert axis-angle rotation and translation vector to 4x4 pose matrix
Args:
- rtvec (Tensor): Rodrigues vector transformations
+ rtvec (torch.Tensor): Rodrigues vector transformations
Returns:
- Tensor: transformation matrices
+ torch.Tensor: transformation matrices
Shape:
- Input: :math:`(N, 6)`
@@ -212,19 +199,20 @@ def rtvec_to_pose(rtvec):
>>> output = tgm.rtvec_to_pose(input) # Nx4x4
"""
assert rtvec.shape[-1] == 6, 'rtvec=[rx, ry, rz, tx, ty, tz]'
- pose = angle_axis_to_rotation_matrix(rtvec[..., :3])
+ pose: torch.Tensor = angle_axis_to_rotation_matrix(rtvec[..., :3])
pose[..., :3, 3] = rtvec[..., 3:]
return pose
-def rotation_matrix_to_angle_axis(rotation_matrix):
+def rotation_matrix_to_angle_axis(
+ rotation_matrix: torch.Tensor) -> torch.Tensor:
"""Convert 3x4 rotation matrix to Rodrigues vector
Args:
- rotation_matrix (Tensor): rotation matrix.
+ rotation_matrix (torch.Tensor): rotation matrix.
Returns:
- Tensor: Rodrigues vector transformation.
+ torch.Tensor: Rodrigues vector transformation.
Shape:
- Input: :math:`(N, 3, 4)`
@@ -235,21 +223,22 @@ def rotation_matrix_to_angle_axis(rotation_matrix):
>>> output = tgm.rotation_matrix_to_angle_axis(input) # Nx3
"""
# todo add check that matrix is a valid rotation matrix
- quaternion = rotation_matrix_to_quaternion(rotation_matrix)
+ quaternion: torch.Tensor = rotation_matrix_to_quaternion(rotation_matrix)
return quaternion_to_angle_axis(quaternion)
-def rotation_matrix_to_quaternion(rotation_matrix, eps=1e-6):
+def rotation_matrix_to_quaternion(
+ rotation_matrix: torch.Tensor) -> torch.Tensor:
"""Convert 3x4 rotation matrix to 4d quaternion vector
This algorithm is based on algorithm described in
https://github.com/KieranWynn/pyquaternion/blob/master/pyquaternion/quaternion.py#L201
Args:
- rotation_matrix (Tensor): the rotation matrix to convert.
+ rotation_matrix (torch.Tensor): the rotation matrix to convert.
Return:
- Tensor: the rotation in quaternion
+ torch.Tensor: the rotation in quaternion.
Shape:
- Input: :math:`(N, 3, 4)`
@@ -274,7 +263,7 @@ def rotation_matrix_to_quaternion(rotation_matrix, eps=1e-6):
rmat_t = torch.transpose(rotation_matrix, 1, 2)
- mask_d2 = rmat_t[:, 2, 2] < eps
+ mask_d2 = rmat_t[:, 2, 2] < EPS
mask_d0_d1 = rmat_t[:, 0, 0] > rmat_t[:, 1, 1]
mask_d0_nd1 = rmat_t[:, 0, 0] < -rmat_t[:, 1, 1]
@@ -286,21 +275,21 @@ def rotation_matrix_to_quaternion(rotation_matrix, eps=1e-6):
], -1)
t0_rep = t0.repeat(4, 1).t()
- t1 = 1 - rmat_t[:, 0, 0] + rmat_t[:, 1, 1] - rmat_t[:, 2, 2]
+ t1 = torch.tensor(1.) - rmat_t[:, 0, 0] + rmat_t[:, 1, 1] - rmat_t[:, 2, 2]
q1 = torch.stack([
rmat_t[:, 2, 0] - rmat_t[:, 0, 2], rmat_t[:, 0, 1] + rmat_t[:, 1, 0],
t1, rmat_t[:, 1, 2] + rmat_t[:, 2, 1]
], -1)
t1_rep = t1.repeat(4, 1).t()
- t2 = 1 - rmat_t[:, 0, 0] - rmat_t[:, 1, 1] + rmat_t[:, 2, 2]
+ t2 = torch.tensor(1.) - rmat_t[:, 0, 0] - rmat_t[:, 1, 1] + rmat_t[:, 2, 2]
q2 = torch.stack([
rmat_t[:, 0, 1] - rmat_t[:, 1, 0], rmat_t[:, 2, 0] + rmat_t[:, 0, 2],
rmat_t[:, 1, 2] + rmat_t[:, 2, 1], t2
], -1)
t2_rep = t2.repeat(4, 1).t()
- t3 = 1 + rmat_t[:, 0, 0] + rmat_t[:, 1, 1] + rmat_t[:, 2, 2]
+ t3 = torch.tensor(1.) + rmat_t[:, 0, 0] + rmat_t[:, 1, 1] + rmat_t[:, 2, 2]
q3 = torch.stack([
t3, rmat_t[:, 1, 2] - rmat_t[:, 2, 1],
rmat_t[:, 2, 0] - rmat_t[:, 0, 2], rmat_t[:, 0, 1] - rmat_t[:, 1, 0]
@@ -308,9 +297,9 @@ def rotation_matrix_to_quaternion(rotation_matrix, eps=1e-6):
t3_rep = t3.repeat(4, 1).t()
mask_c0 = mask_d2 * mask_d0_d1
- mask_c1 = mask_d2 * (1 - mask_d0_d1)
- mask_c2 = (1 - mask_d2) * mask_d0_nd1
- mask_c3 = (1 - mask_d2) * (1 - mask_d0_nd1)
+ mask_c1 = mask_d2 * (torch.tensor(1.) - mask_d0_d1)
+ mask_c2 = (torch.tensor(1.) - mask_d2) * mask_d0_nd1
+ mask_c3 = (torch.tensor(1.) - mask_d2) * (torch.tensor(1.) - mask_d0_nd1)
mask_c0 = mask_c0.view(-1, 1).type_as(q0)
mask_c1 = mask_c1.view(-1, 1).type_as(q1)
mask_c2 = mask_c2.view(-1, 1).type_as(q2)
@@ -428,107 +417,41 @@ def angle_axis_to_quaternion(angle_axis: torch.Tensor) -> torch.Tensor:
return torch.cat([w, quaternion], dim=-1)
-# TODO: add below funtionalities
-# - pose_to_rtvec
-
-# layer api
-
-
-class RadToDeg(nn.Module):
- r"""Creates an object that converts angles from radians to degrees.
-
- Args:
- tensor (Tensor): Tensor of arbitrary shape.
-
- Returns:
- Tensor: Tensor with same shape as input.
-
- Examples::
-
- >>> input = tgm.pi * torch.rand(1, 3, 3)
- >>> output = tgm.RadToDeg()(input)
- """
-
- def __init__(self):
- super(RadToDeg, self).__init__()
-
- def forward(self, input):
- return rad2deg(input)
-
-
-class DegToRad(nn.Module):
- r"""Function that converts angles from degrees to radians.
-
- Args:
- tensor (Tensor): Tensor of arbitrary shape.
-
- Returns:
- Tensor: Tensor with same shape as input.
-
- Examples::
-
- >>> input = 360. * torch.rand(1, 3, 3)
- >>> output = tgm.DegToRad()(input)
- """
-
- def __init__(self):
- super(DegToRad, self).__init__()
-
- def forward(self, input):
- return deg2rad(input)
+# based on:
+# https://github.com/ClementPinard/SfmLearner-Pytorch/blob/master/inverse_warp.py#L65-L71
+def normalize_pixel_coordinates(
+ pixel_coordinates: torch.Tensor,
+ height: int,
+ width: int) -> torch.Tensor:
+ r"""Normalize pixel coordinates between -1 and 1.
-class ConvertPointsFromHomogeneous(nn.Module):
- r"""Creates a transformation that converts points from homogeneous to
- Euclidean space.
+ Normalized, -1 if on extreme left, 1 if on extreme right (x = w-1).
Args:
- points (Tensor): tensor of N-dimensional points.
+ pixel_coordinate (torch.Tensor): the grid with pixel coordinates.
+ Shape must be :math:`(B, H, W, 2)`.
+ width (int): the maximum width in the x-axis.
+ height (int): the maximum height in the y-axis.
- Returns:
- Tensor: tensor of N-1-dimensional points.
-
- Shape:
- - Input: :math:`(B, D, N)` or :math:`(D, N)`
- - Output: :math:`(B, D, N + 1)` or :math:`(D, N + 1)`
-
- Examples::
-
- >>> input = torch.rand(2, 4, 3) # BxNx3
- >>> transform = tgm.ConvertPointsFromHomogeneous()
- >>> output = transform(input) # BxNx2
+ Return:
+ torch.Tensor: the nornmalized pixel coordinates.
"""
+ if pixel_coordinates.shape[-1] != 2:
+ raise ValueError("Input pixel_coordinates must be of shape (*, 2). "
+ "Got {}".format(pixel_coordinates.shape))
+ # compute normalization factor
+ hw: torch.Tensor = torch.stack([
+ torch.tensor(width), torch.tensor(height)
+ ]).to(pixel_coordinates.device).to(pixel_coordinates.dtype)
- def __init__(self):
- super(ConvertPointsFromHomogeneous, self).__init__()
+ factor: torch.Tensor = torch.tensor(2.) / (hw - torch.tensor(1.))
- def forward(self, input):
- return convert_points_from_homogeneous(input)
+ # normalize coordinates and return
+ pixel_coordinates_norm: torch.Tensor = \
+ factor * pixel_coordinates - torch.tensor(1.)
+ return pixel_coordinates_norm
-class ConvertPointsToHomogeneous(nn.Module):
- r"""Creates a transformation to convert points from Euclidean to
- homogeneous space.
-
- Args:
- points (Tensor): tensor of N-dimensional points.
-
- Returns:
- Tensor: tensor of N+1-dimensional points.
-
- Shape:
- - Input: :math:`(B, D, N)` or :math:`(D, N)`
- - Output: :math:`(B, D, N + 1)` or :math:`(D, N + 1)`
-
- Examples::
-
- >>> input = torch.rand(2, 4, 3) # BxNx3
- >>> transform = tgm.ConvertPointsToHomogeneous()
- >>> output = transform(input) # BxNx4
- """
-
- def __init__(self):
- super(ConvertPointsToHomogeneous, self).__init__()
-
- def forward(self, input):
- return convert_points_to_homogeneous(input)
+# TODO: add below funtionalities
+# - pose_to_rtvec
diff --git a/torchgeometry/geometry/transformations.py b/torchgeometry/geometry/linalg.py
similarity index 98%
rename from torchgeometry/geometry/transformations.py
rename to torchgeometry/geometry/linalg.py
index e6570fa15..36dc65a83 100644
--- a/torchgeometry/geometry/transformations.py
+++ b/torchgeometry/geometry/linalg.py
@@ -12,7 +12,6 @@ __all__ = [
"relative_transformation",
"inverse_transformation",
"transform_points",
- "TransformPoints",
]
@@ -213,11 +212,14 @@ def transform_points(trans_01: torch.Tensor,
points_0 = convert_points_from_homogeneous(points_0_h) # BxNxD
return points_0
+# TODO:
+# - project_points: from opencv
-# layer api
+# layer api
-class TransformPoints(nn.Module):
+# NOTE: is it needed ?
+'''class TransformPoints(nn.Module):
r"""Creates an object to transform a set of points.
Args:
@@ -246,7 +248,7 @@ class TransformPoints(nn.Module):
return transform_points(self.dst_homo_src, points_src)
-'''class InversePose(nn.Module):
+class InversePose(nn.Module):
r"""Creates a transformation that inverts a 4x4 pose.
Args:
diff --git a/torchgeometry/geometry/transform/__init__.py b/torchgeometry/geometry/transform/__init__.py
new file mode 100644
index 000000000..51ad7bff8
--- /dev/null
+++ b/torchgeometry/geometry/transform/__init__.py
@@ -0,0 +1,4 @@
+from torchgeometry.geometry.transform.crop import *
+from torchgeometry.geometry.transform.imgwarp import *
+from torchgeometry.geometry.transform.pyramid import *
+from torchgeometry.geometry.transform.affwarp import *
diff --git a/torchgeometry/geometry/affine_warp.py b/torchgeometry/geometry/transform/affwarp.py
similarity index 99%
rename from torchgeometry/geometry/affine_warp.py
rename to torchgeometry/geometry/transform/affwarp.py
index 7a903c228..553f8ba18 100644
--- a/torchgeometry/geometry/affine_warp.py
+++ b/torchgeometry/geometry/transform/affwarp.py
@@ -3,7 +3,9 @@ from typing import Union
import torch
import torch.nn as nn
-from torchgeometry.geometry.imgwarp import warp_affine, get_rotation_matrix2d
+from torchgeometry.geometry.transform.imgwarp import (
+ warp_affine, get_rotation_matrix2d,
+)
__all__ = [
"affine",
diff --git a/torchgeometry/geometry/crop.py b/torchgeometry/geometry/transform/crop.py
similarity index 98%
rename from torchgeometry/geometry/crop.py
rename to torchgeometry/geometry/transform/crop.py
index 23a96d828..19c2680fc 100644
--- a/torchgeometry/geometry/crop.py
+++ b/torchgeometry/geometry/transform/crop.py
@@ -2,8 +2,9 @@ from typing import Tuple
import torch
-from torchgeometry.geometry.imgwarp import warp_perspective
-from torchgeometry.geometry.imgwarp import get_perspective_transform
+from torchgeometry.geometry.transform.imgwarp import (
+ warp_perspective, get_perspective_transform
+)
__all__ = [
"crop_and_resize",
diff --git a/torchgeometry/geometry/imgwarp.py b/torchgeometry/geometry/transform/imgwarp.py
similarity index 98%
rename from torchgeometry/geometry/imgwarp.py
rename to torchgeometry/geometry/transform/imgwarp.py
index 52e7e7be3..3f399431f 100644
--- a/torchgeometry/geometry/imgwarp.py
+++ b/torchgeometry/geometry/transform/imgwarp.py
@@ -3,11 +3,11 @@ from typing import Tuple, Optional
import torch
import torch.nn.functional as F
-from torchgeometry.geometry.conversions import deg2rad
-from torchgeometry.geometry.homography_warper import homography_warp
+from torchgeometry.geometry.warp.homography_warper import homography_warp
# TODO: move to utils or conversions
-from torchgeometry.geometry.pinhole import normalize_pixel_coordinates
-
+from torchgeometry.geometry.conversions import (
+ deg2rad, normalize_pixel_coordinates
+)
__all__ = [
"warp_perspective",
diff --git a/torchgeometry/geometry/pyramid.py b/torchgeometry/geometry/transform/pyramid.py
similarity index 100%
rename from torchgeometry/geometry/pyramid.py
rename to torchgeometry/geometry/transform/pyramid.py
diff --git a/torchgeometry/geometry/warp/__init__.py b/torchgeometry/geometry/warp/__init__.py
new file mode 100644
index 000000000..bca220bca
--- /dev/null
+++ b/torchgeometry/geometry/warp/__init__.py
@@ -0,0 +1,2 @@
+from torchgeometry.geometry.warp.homography_warper import *
+from torchgeometry.geometry.warp.depth_warper import *
diff --git a/torchgeometry/geometry/depth_warper.py b/torchgeometry/geometry/warp/depth_warper.py
similarity index 95%
rename from torchgeometry/geometry/depth_warper.py
rename to torchgeometry/geometry/warp/depth_warper.py
index c5dec66c7..8f3bf05eb 100644
--- a/torchgeometry/geometry/depth_warper.py
+++ b/torchgeometry/geometry/warp/depth_warper.py
@@ -3,12 +3,12 @@ import torch
import torch.nn as nn
import torch.nn.functional as F
-from torchgeometry.geometry.transformations import transform_points
-from torchgeometry.geometry.transformations import relative_transformation
+from torchgeometry.geometry.linalg import transform_points
+from torchgeometry.geometry.linalg 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, pixel2cam
+from torchgeometry.geometry.conversions import normalize_pixel_coordinates
+from torchgeometry.geometry.camera import PinholeCamera
+from torchgeometry.geometry.camera import cam2pixel, pixel2cam
from torchgeometry.utils import create_meshgrid
@@ -202,7 +202,7 @@ def depth_warp(pinhole_dst: PinholeCamera,
r"""Function that warps a tensor from destination frame to reference
given the depth in the reference frame.
- See :class:`~torchgeometry.DepthWarper` for details.
+ See :class:`~torchgeometry.geometry.warp.DepthWarper` for details.
Example:
>>> # pinholes camera models
diff --git a/torchgeometry/geometry/homography_warper.py b/torchgeometry/geometry/warp/homography_warper.py
similarity index 97%
rename from torchgeometry/geometry/homography_warper.py
rename to torchgeometry/geometry/warp/homography_warper.py
index e3f674f7f..5cbea71a4 100644
--- a/torchgeometry/geometry/homography_warper.py
+++ b/torchgeometry/geometry/warp/homography_warper.py
@@ -5,7 +5,7 @@ import torch.nn as nn
import torch.nn.functional as F
from torchgeometry.utils import create_meshgrid
-from torchgeometry.geometry.transformations import transform_points
+from torchgeometry.geometry.linalg import transform_points
__all__ = [
@@ -120,7 +120,7 @@ def homography_warp(patch_src: torch.Tensor,
padding_mode: Optional[str] = 'zeros') -> torch.Tensor:
r"""Function that warps image patchs or tensors by homographies.
- See :class:`~torchgeometry.HomographyWarper` for details.
+ See :class:`~torchgeometry.geometry.warp.HomographyWarper` for details.
Args:
patch_src (torch.Tensor): The image or tensor to warp. Should be from
diff --git a/torchgeometry/utils/image.py b/torchgeometry/utils/image.py
index b6a09b758..691a6e270 100644
--- a/torchgeometry/utils/image.py
+++ b/torchgeometry/utils/image.py
@@ -57,4 +57,4 @@ def tensor_to_image(tensor: torch.Tensor) -> np.array:
if len(input_shape) == 2:
tensor = torch.squeeze(tensor, dim=-1)
- return tensor.contiguous().cpu().detach().numpy()
+ return tensor.cpu().detach().numpy()