Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

create kornia.geometry.subpix (#610)

Edgar Riba7c7aae5f12fd
diff --git a/docs/source/geometry.homography.rst b/docs/source/geometry.homography.rst
index d14dd37a4..8c7015817 100644
--- a/docs/source/geometry.homography.rst
+++ b/docs/source/geometry.homography.rst
@@ -3,6 +3,5 @@ kornia.geometry.homography
Module with useful functionalities for homographies manipulation.
-
.. automodule:: kornia.geometry.homography
:members:
diff --git a/docs/source/geometry.rst b/docs/source/geometry.rst
index d4a715522..b006b1cc7 100644
--- a/docs/source/geometry.rst
+++ b/docs/source/geometry.rst
@@ -12,24 +12,6 @@ kornia.geometry
geometry.epipolar
geometry.homography
geometry.linalg
+ geometry.subpix
geometry.transform
geometry.warp
-
-Coordinates Subpixel
---------------------
-
-.. autofunction:: spatial_soft_argmax2d
-.. autofunction:: conv_soft_argmax2d
-.. autofunction:: conv_soft_argmax3d
-.. autofunction:: conv_quad_interp3d
-.. autofunction:: spatial_softmax2d
-.. autofunction:: spatial_expectation2d
-.. autofunction:: render_gaussian2d
-
-Module
-------
-
-.. autoclass:: SpatialSoftArgmax2d
-.. autoclass:: ConvSoftArgmax2d
-.. autoclass:: ConvSoftArgmax3d
-.. autoclass:: ConvQuadInterp3d
diff --git a/docs/source/geometry.subpix.rst b/docs/source/geometry.subpix.rst
new file mode 100644
index 000000000..ed990d165
--- /dev/null
+++ b/docs/source/geometry.subpix.rst
@@ -0,0 +1,22 @@
+kornia.geometry.subpix
+======================
+
+.. currentmodule:: kornia.geometry.subpix
+
+Module with useful functionalities to extract coordinates sub=pixel accuracy.
+
+.. autofunction:: spatial_soft_argmax2d
+.. autofunction:: conv_soft_argmax2d
+.. autofunction:: conv_soft_argmax3d
+.. autofunction:: conv_quad_interp3d
+.. autofunction:: spatial_softmax2d
+.. autofunction:: spatial_expectation2d
+.. autofunction:: render_gaussian2d
+
+Module
+------
+
+.. autoclass:: SpatialSoftArgmax2d
+.. autoclass:: ConvSoftArgmax2d
+.. autoclass:: ConvSoftArgmax3d
+.. autoclass:: ConvQuadInterp3d
diff --git a/kornia/geometry/__init__.py b/kornia/geometry/__init__.py
index ab3384430..adbd7c690 100644
--- a/kornia/geometry/__init__.py
+++ b/kornia/geometry/__init__.py
@@ -4,7 +4,6 @@ from kornia.geometry.linalg import *
from kornia.geometry.transform import *
from kornia.geometry.warp import *
from kornia.geometry.depth import *
-from kornia.geometry.dsnt import *
-from kornia.geometry.spatial_soft_argmax import *
+from kornia.geometry.subpix import *
from kornia.geometry.epipolar import *
from kornia.geometry.homography import *
diff --git a/kornia/geometry/subpix/__init__.py b/kornia/geometry/subpix/__init__.py
new file mode 100644
index 000000000..a963a37e5
--- /dev/null
+++ b/kornia/geometry/subpix/__init__.py
@@ -0,0 +1,2 @@
+from .dsnt import *
+from .spatial_soft_argmax import *
diff --git a/kornia/geometry/dsnt.py b/kornia/geometry/subpix/dsnt.py
similarity index 100%
rename from kornia/geometry/dsnt.py
rename to kornia/geometry/subpix/dsnt.py
diff --git a/kornia/geometry/spatial_soft_argmax.py b/kornia/geometry/subpix/spatial_soft_argmax.py
similarity index 98%
rename from kornia/geometry/spatial_soft_argmax.py
rename to kornia/geometry/subpix/spatial_soft_argmax.py
index 21e8826ec..1be8f4305 100644
--- a/kornia/geometry/spatial_soft_argmax.py
+++ b/kornia/geometry/subpix/spatial_soft_argmax.py
@@ -1,12 +1,13 @@
+from typing import Tuple, Union
+
import torch
import torch.nn as nn
import torch.nn.functional as F
import kornia
-from kornia.geometry import dsnt
+from kornia.geometry.subpix import dsnt
from kornia.utils import create_meshgrid, create_meshgrid3d
from kornia.geometry import normalize_pixel_coordinates, normalize_pixel_coordinates3d
-from typing import Tuple, Union
def _get_window_grid_kernel2d(h: int, w: int,
@@ -126,7 +127,7 @@ def _get_window_grid_kernel3d(d: int, h: int, w: int,
class ConvSoftArgmax2d(nn.Module):
r"""Module that calculates soft argmax 2d per window.
- See :func:`~kornia.geometry.conv_soft_argmax2d` for details.
+ See :func:`~kornia.geometry.subpix.conv_soft_argmax2d` for details.
"""
def __init__(self,
@@ -170,7 +171,7 @@ class ConvSoftArgmax2d(nn.Module):
class ConvSoftArgmax3d(nn.Module):
r"""Module that calculates soft argmax 3d per window.
- See :func:`~kornia.geometry.conv_soft_argmax3d` for details.
+ See :func:`~kornia.geometry.subpix.conv_soft_argmax3d` for details.
"""
def __init__(self,
@@ -519,7 +520,7 @@ def spatial_soft_argmax2d(
class SpatialSoftArgmax2d(nn.Module):
r"""Module that computes the Spatial Soft-Argmax 2D of a given heatmap.
- See :func:`~kornia.contrib.spatial_soft_argmax2d` for details.
+ See :func:`~kornia.geometry.subpix.spatial_soft_argmax2d` for details.
"""
def __init__(self,
@@ -625,7 +626,7 @@ def conv_quad_interp3d(input: torch.Tensor, strict_maxima_bonus: float = 10.0, e
class ConvQuadInterp3d(nn.Module):
r"""Module that calculates soft argmax 3d per window
- See :func:`~kornia.geometry.conv_quad_interp3d` for details.
+ See :func:`~kornia.geometry.subpix.conv_quad_interp3d` for details.
"""
def __init__(self,
diff --git a/test/geometry/test_dsnt.py b/test/geometry/subpix/test_dsnt.py
similarity index 100%
rename from test/geometry/test_dsnt.py
rename to test/geometry/subpix/test_dsnt.py
diff --git a/test/geometry/test_spatial_softargmax.py b/test/geometry/subpix/test_spatial_softargmax.py
similarity index 99%
rename from test/geometry/test_spatial_softargmax.py
rename to test/geometry/subpix/test_spatial_softargmax.py
index e95771989..9f1a0c029 100644
--- a/test/geometry/test_spatial_softargmax.py
+++ b/test/geometry/subpix/test_spatial_softargmax.py
@@ -1,13 +1,13 @@
import pytest
-import kornia as kornia
-import kornia.testing as utils # test utils
-
import torch
from torch.nn.functional import mse_loss
from torch.autograd import gradcheck
from torch.testing import assert_allclose
-from kornia.geometry.spatial_soft_argmax import _get_center_kernel2d, _get_center_kernel3d
+
+import kornia as kornia
+import kornia.testing as utils # test utils
+from kornia.geometry.subpix.spatial_soft_argmax import _get_center_kernel2d, _get_center_kernel3d
class TestCenterKernel2d: