Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

[doc] Refined docs (#1280)

Jian Shi66dcea33217f
diff --git a/docs/source/applications/image_augmentations.rst b/docs/source/applications/image_augmentations.rst
index 0000bbd43..01f874bbc 100644
--- a/docs/source/applications/image_augmentations.rst
+++ b/docs/source/applications/image_augmentations.rst
@@ -37,6 +37,63 @@ For detailed comparison, please checkout the `Colab: Kornia Playground <https://
K.ColorJitter(0.2, 0.3, 0.2, 0.3)
)
+
+Best Practices 1: Image Augmentation
+++++++++++++++++++++++++++++++++++++
+
+Kornia augmentations provides simple on-device augmentation framework with the support of various syntax sugars
+(e.g. return transformation matrix, inverse geometric transform). Therefore, we provide advanced augmentation
+container :py:class:`kornia.augmentation.ImageSequential` to ease the pain of building augmenation pipelines. This API would also provide predefined routines
+for automating the processing of masks, bounding boxes, and keypoints.
+
+.. code-block:: python
+
+ import kornia.augmentation as K
+
+ aug = K.AugmentationSequential(
+ K.ColorJitter(0.1, 0.1, 0.1, 0.1, p=1.0),
+ K.RandomAffine(360, [0.1, 0.1], [0.7, 1.2], [30., 50.], p=1.0),
+ K.RandomPerspective(0.5, p=1.0),
+ data_keys=["input", "bbox", "keypoints", "mask"], # Just to define the future input here.
+ return_transform=False,
+ same_on_batch=False,
+ )
+ # forward the operation
+ out_tensors = aug(img_tensor, bbox, keypoints, mask)
+ # Inverse the operation
+ out_tensor_inv = aug.inverse(*out_tensor)
+
+.. image:: https://discuss.pytorch.org/uploads/default/optimized/3X/2/4/24bb0f4520f547d3a321440293c1d44921ecadf8_2_690x119.jpeg
+
+From left to right: the original image, the transformed image, and the inversed image.
+
+
+Best Practices 2: Video Augmentation
+++++++++++++++++++++++++++++++++++++
+
+Video data is a special case of 3D volumetric data that contains both spatial and temporal information, which can be referred as 2.5D than 3D.
+In most applications, augmenting video data requires a static temporal dimension to have the same augmentations are performed for each frame.
+Thus, :py:class:`kornia.augmentation.VideoSequential` can be used to do such trick as same as `nn.Sequential`.
+Currently, :py:class:`kornia.augmentation.VideoSequential` supports data format like :math:`(B, C, T, H, W)` and :math:`(B, T, C, H, W)`.
+
+.. code-block:: python
+
+ import kornia.augmentation as K
+
+ transform = K.VideoSequential(
+ K.RandomAffine(360),
+ K.RandomGrayscale(p=0.5),
+ K.RandomAffine(p=0.5)
+ data_format="BCTHW",
+ same_on_frame=True
+ )
+
+.. image:: https://user-images.githubusercontent.com/17788259/101993516-4625ca80-3c89-11eb-843e-0b87dca6e2b8.png
+
+
+Customization
++++++++++++++
+
Kornia augmentation implementations have two additional parameters compare to TorchVision,
``return_transform`` and ``same_on_batch``. The former provides the ability of undoing one geometry
transformation while the latter can be used to control the randomness for a batched transformation.
diff --git a/docs/source/applications/image_matching.rst b/docs/source/applications/image_matching.rst
index 4192be583..2ec7cffc5 100644
--- a/docs/source/applications/image_matching.rst
+++ b/docs/source/applications/image_matching.rst
@@ -20,4 +20,5 @@ However we recommend to start with high-level API, such as :py:class:`~kornia.fe
.. image:: https://raw.githubusercontent.com/kornia/data/main/matching/matching_loftr.jpg
-You also can go through or full tutorial using Colab found `here <https://kornia-tutorials.readthedocs.io/en/latest/image_matching.html>`_ .
+
+You also can go through or full tutorial using Colab found `here <https://kornia-tutorials.readthedocs.io/en/latest/image_matching.html>`_.
diff --git a/docs/source/augmentation.rst b/docs/source/augmentation.rst
index 03b8e65a7..3564693f7 100644
--- a/docs/source/augmentation.rst
+++ b/docs/source/augmentation.rst
@@ -1,6 +1,19 @@
kornia.augmentation
===================
+This module implements in a high level logic. The main features of this module, and similar to the rest of the
+library, is that can it perform data augmentation routines in a batch mode, using any supported device,
+and can be used for backpropagation. Some of the available functionalities which are worth to mention are the
+following: random rotations; affine and perspective transformations; several random color intensities transformations,
+image noise distortion, motion blurring, and many of the different differentiable data augmentation policies.
+In addition, we include a novel feature which is not found in other augmentations frameworks,
+which allows the user to retrieve the applied transformation or chained transformations after each
+call e.g. the generated random rotation matrix which can be used later to undo the image transformation
+itself, or to be applied to additional metadata such as the label images for semantic segmentation,
+in bounding boxes or landmark keypoints for object detection tasks. It gives the user the flexibility to
+perform complex data augmentations pipelines.
+
+
.. currentmodule:: kornia.augmentation
.. toctree::
diff --git a/docs/source/geometry.rst b/docs/source/geometry.rst
index 3a2fb488c..b5bd0afef 100644
--- a/docs/source/geometry.rst
+++ b/docs/source/geometry.rst
@@ -1,6 +1,44 @@
kornia.geometry
===============
+Geometric image transformations is another key ingredient in computer vision to manipulate images.
+Since geometry operations are typically performed in 2D or 3D, we provide several algorithms to work
+with both cases. This module, the original core of the library, consists of the following submodules:
+transforms, camera, conversions, linalg and depth. We next describe each of them:
+
+- `transforms`: The module provides low level interfaces to manipulate 2D images, with routines for Rotating,
+ Scaling, Translating, Shearing; Cropping functions in several modalities such as central crops,
+ crop and resize; Flipping transformations in the vertical and horizontal axis; Resizing operations;
+ Functions to warp tensors given affine or perspective transformations,
+ and utilities to compute the transformation matrices to perform the mentioned operations.
+- `camera`: A set of routines specific to different types of camera representations such as Pinhole
+ or Orthographic models containing functionalities such as projecting and unprojecting points from the
+ camera to a world frame.
+- `conversions`: Routines to perform conversions between angle representation such as
+ radians to degrees, coordinates normalization, and homogeneous to euclidean. Moreover, we include advanced
+ conversions for 3D geometry representations such as Quaternion, Axis-Angle, Rotation Matrix, or Rodrigues
+ formula.
+- `linalg`: Functions to perform general rigid-body homogeneous transformations. We include implementations to
+ transform points between frames and for homogeneous transformations, manipulation such as composition,
+ inverse and to compute relative poses.
+- `depth`: A set of layers to manipulate depth maps such as how to compute 3D point clouds given depth maps and
+ calibrated cameras; compute surface normals per pixel and warp tensor frames given calibrated cameras setup.
+
+
+:Resources:
+
+ **align_corners**
+
+ align_corners is a switch that widely offered in PyTorch geometric transform functions.
+ Here is a simple illustration showing how a 4x4 image is upsampled to 8x8, made by
+ `bkkm16 <https://discuss.pytorch.org/t/what-we-should-use-align-corners-false/22663/9?u=ducha-aiki>`_.
+
+ .. image:: https://user-images.githubusercontent.com/4803565/110627988-df8a4d00-81a2-11eb-8e13-06d3f7b09ef1.png
+
+ - `align_corners=True`, pixels are arranged as a grid of points. Points at the corners are aligned.
+ - `align_corners=False`, pixels are arranged as 1x1 areas. Area boundaries, rather than their centers, are aligned.
+
+
.. currentmodule:: kornia.geometry
.. toctree::
diff --git a/kornia/augmentation/container/augment.py b/kornia/augmentation/container/augment.py
index 9817c10b2..3c669c2dd 100644
--- a/kornia/augmentation/container/augment.py
+++ b/kornia/augmentation/container/augment.py
@@ -27,7 +27,7 @@ class AugmentationSequential(ImageSequential):
.. image:: https://kornia-tutorials.readthedocs.io/en/latest/_images/data_augmentation_sequential_5_1.png
:width: 49 %
- .. image:: https://kornia-tutorials.readthedocs.io/en/latest/_images/data_augmentation_sequential_7_2.png
+ .. image:: https://kornia-tutorials.readthedocs.io/en/latest/_images/data_augmentation_sequential_7_0.png
:width: 49 %
Args:
diff --git a/kornia/augmentation/container/patch.py b/kornia/augmentation/container/patch.py
index 5e7f54bda..c04171fef 100644
--- a/kornia/augmentation/container/patch.py
+++ b/kornia/augmentation/container/patch.py
@@ -21,7 +21,7 @@ class PatchParamItem(NamedTuple):
class PatchSequential(ImageSequential):
r"""Container for performing patch-level image data augmentation.
- .. image:: https://kornia-tutorials.readthedocs.io/en/latest/_images/data_patch_sequential_5_1.png
+ .. image:: https://kornia-tutorials.readthedocs.io/en/latest/_images/data_patch_sequential_7_0.png
PatchSequential breaks input images into patches by a given grid size, which will be resembled back
afterwards.
diff --git a/kornia/losses/hausdorff.py b/kornia/losses/hausdorff.py
index bdcecca22..e9d835177 100644
--- a/kornia/losses/hausdorff.py
+++ b/kornia/losses/hausdorff.py
@@ -116,12 +116,26 @@ class _HausdorffERLossBase(nn.Module):
class HausdorffERLoss(_HausdorffERLossBase):
- """Binary Hausdorff loss based on morphological erosion.
+ r"""Binary Hausdorff loss based on morphological erosion.
- This is an Hausdorff Distance (HD) Loss that based on morphological erosion,which provided
+ Hausdorff Distance loss measures the maximum distance of a predicted segmentation boundary to
+ the nearest ground-truth edge pixel. For two segmentation point sets X and Y ,
+ the one-sided HD from X to Y is defined as:
+
+ .. math::
+
+ hd(X,Y) = \max_{x \in X} \min_{y \in Y}||x - y||_2
+
+ Furthermore, the bidirectional HD is:
+
+ .. math::
+
+ HD(X,Y) = max(hd(X, Y), hd(Y, X))
+
+ This is an Hausdorff Distance (HD) Loss that based on morphological erosion, which provided
a differentiable approximation of Hausdorff distance as stated in :cite:`karimi2019reducing`.
The code is refactored on top of `here <https://github.com/PatRyg99/HausdorffLoss/
- blob/master/hausdorff_loss.py>`__.
+ blob/master/hausdorff_loss.py>`__.
Args:
alpha: controls the erosion rate in each iteration.
@@ -168,12 +182,26 @@ class HausdorffERLoss(_HausdorffERLossBase):
class HausdorffERLoss3D(_HausdorffERLossBase):
- """Binary 3D Hausdorff loss based on morphological erosion.
+ r"""Binary 3D Hausdorff loss based on morphological erosion.
- This is a 3D Hausdorff Distance (HD) Loss that based on morphological erosion,which provided
+ Hausdorff Distance loss measures the maximum distance of a predicted segmentation boundary to
+ the nearest ground-truth edge pixel. For two segmentation point sets X and Y ,
+ the one-sided HD from X to Y is defined as:
+
+ .. math::
+
+ hd(X,Y) = \max_{x \in X} \min_{y \in Y}||x - y||_2
+
+ Furthermore, the bidirectional HD is:
+
+ .. math::
+
+ HD(X,Y) = max(hd(X, Y), hd(Y, X))
+
+ This is a 3D Hausdorff Distance (HD) Loss that based on morphological erosion, which provided
a differentiable approximation of Hausdorff distance as stated in :cite:`karimi2019reducing`.
The code is refactored on top of `here <https://github.com/PatRyg99/HausdorffLoss/
- blob/master/hausdorff_loss.py>`__.
+ blob/master/hausdorff_loss.py>`__.
Args:
alpha: controls the erosion rate in each iteration.