Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Added docs for VideoSequential (#857)

shijianjian576ac2126a17
diff --git a/docs/source/augmentation.base.rst b/docs/source/augmentation.base.rst
new file mode 100644
index 000000000..c52cd3652
--- /dev/null
+++ b/docs/source/augmentation.base.rst
@@ -0,0 +1,63 @@
+kornia.augmentation.base
+========================
+
+.. currentmodule:: kornia.augmentation.base
+
+Base Classes
+------------
+
+This is the base class for creating a new transform. The user only needs to override: `generate_parameters`, `apply_transform` and optionally, `compute_transformation`.
+
+
+.. autoclass:: AugmentationBase2D
+
+ .. automethod:: generate_parameters
+ .. automethod:: compute_transformation
+ .. automethod:: apply_transform
+
+.. autoclass:: AugmentationBase3D
+
+ .. automethod:: generate_parameters
+ .. automethod:: compute_transformation
+ .. automethod:: apply_transform
+
+
+Create your own transformation:
+
+.. code-block:: python
+
+ import torch
+ import kornia as K
+
+ from kornia.augmentation import AugmentationBase2D
+
+ class MyRandomTransform(AugmentationBase2D):
+ def __init__(self, return_transform: bool = False) -> None:
+ super(MyRandomTransform, self).__init__(return_transform)
+
+ def generate_parameters(self, input_shape: torch.Size):
+ # generate the random parameters for your use case.
+ angles_rad torch.Tensor = torch.rand(input_shape[0]) * K.pi
+ angles_deg = kornia.rad2deg(angles_rad)
+ return dict(angles=angles_deg)
+
+ def compute_transformation(self, input, params):
+
+ B, _, H, W = input.shape
+
+ # compute transformation
+ angles: torch.Tensor = params['angles'].type_as(input)
+ center = torch.tensor([[W / 2, H / 2]] * B).type_as(input)
+ transform = K.get_rotation_matrix2d(
+ center, angles, torch.ones_like(angles))
+ return transform
+
+ def apply_transform(self, input, params):
+
+ _, _, H, W = input.shape
+ # compute transformation
+ transform = self.compute_transformation(input, params)
+
+ # apply transformation and return
+ output = K.warp_affine(input, transform, (H, W))
+ return (output, transform)
diff --git a/docs/source/augmentation.container.rst b/docs/source/augmentation.container.rst
new file mode 100644
index 000000000..d295944f8
--- /dev/null
+++ b/docs/source/augmentation.container.rst
@@ -0,0 +1,31 @@
+kornia.augmentation.container
+=============================
+
+.. currentmodule:: kornia.augmentation.container
+
+The classes in this section are containers for augmenting different data formats (e.g. videos).
+
+
+Video Data Augmentation
+-----------------------
+
+.. autoclass:: VideoSequential
+
+ .. automethod:: forward
+
+
+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, `VideoSequential` can be used to do such trick as same as `nn.Sequential`.
+Currently, `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.ColorJitter(0.2, 0.3, 0.2, 0.3),
+ data_format="BCTHW",
+ same_on_frame=True
+ )
diff --git a/docs/source/augmentation.module.rst b/docs/source/augmentation.module.rst
new file mode 100644
index 000000000..cd8107abf
--- /dev/null
+++ b/docs/source/augmentation.module.rst
@@ -0,0 +1,60 @@
+kornia.augmentation
+===================
+
+.. currentmodule:: kornia.augmentation
+
+Transforms2D
+------------
+
+Set of operators to perform data augmentation on 2D image tensors.
+
+.. autoclass:: CenterCrop
+.. autoclass:: ColorJitter
+.. autoclass:: GaussianBlur
+.. autoclass:: RandomAffine
+.. autoclass:: RandomCrop
+.. autoclass:: RandomErasing
+.. autoclass:: RandomGrayscale
+.. autoclass:: RandomHorizontalFlip
+.. autoclass:: RandomVerticalFlip
+.. autoclass:: RandomMotionBlur
+.. autoclass:: RandomPerspective
+.. autoclass:: RandomResizedCrop
+.. autoclass:: RandomRotation
+.. autoclass:: RandomSolarize
+.. autoclass:: RandomPosterize
+.. autoclass:: RandomSharpness
+.. autoclass:: RandomEqualize
+.. autoclass:: RandomMixUp
+.. autoclass:: RandomCutMix
+
+Transforms3D
+------------
+
+Set of operators to perform data augmentation on 3D volumetric tensors.
+
+.. autoclass:: RandomDepthicalFlip3D
+.. autoclass:: RandomHorizontalFlip3D
+.. autoclass:: RandomVerticalFlip3D
+.. autoclass:: RandomRotation3D
+.. autoclass:: RandomAffine3D
+.. autoclass:: RandomCrop3D
+.. autoclass:: CenterCrop3D
+.. autoclass:: RandomMotionBlur3D
+.. autoclass:: RandomEqualize3D
+
+Normalizations
+--------------
+
+Normalization operations are shape-agnostic for both 2D and 3D tensors.
+
+.. autoclass:: Denormalize
+.. autoclass:: Normalize
+
+Functional
+----------
+
+.. automodule:: kornia.augmentation.functional.functional
+ :members:
+.. automodule:: kornia.augmentation.functional.functional3d
+ :members:
diff --git a/docs/source/augmentation.rst b/docs/source/augmentation.rst
index 5d5d339d3..06eaa3396 100644
--- a/docs/source/augmentation.rst
+++ b/docs/source/augmentation.rst
@@ -12,63 +12,6 @@ Kornia provides Torchvision-like augmentation APIs while may not reproduce Torch
For detailed comparison, please checkout the `Colab: Kornia Playground <https://colab.research.google.com/drive/1T20UNAG4SdlE2n2wstuhiewve5Q81VpS#revisionId=0B4unZG1uMc-WR3NVeTBDcmRwN0NxcGNNVlUwUldPMVprb1dJPQ>`_.
-Containers
-----------
-
-This is the base class for creating a new transform. The user only needs to override: `generate_parameters`, `apply_transform` and optionally, `compute_transformation`.
-
-
-.. autoclass:: AugmentationBase2D
-
- .. automethod:: generate_parameters
- .. automethod:: compute_transformation
- .. automethod:: apply_transform
-
-.. autoclass:: AugmentationBase3D
-
- .. automethod:: generate_parameters
- .. automethod:: compute_transformation
- .. automethod:: apply_transform
-
-Create your own transformation:
-
-.. code-block:: python
-
- import torch
- import kornia as K
-
- from kornia.augmentation import AugmentationBase2D
-
- class MyRandomTransform(AugmentationBase2D):
- def __init__(self, return_transform: bool = False) -> None:
- super(MyRandomTransform, self).__init__(return_transform)
-
- def generate_parameters(self, input_shape: torch.Size):
- # generate the random parameters for your use case.
- angles_rad torch.Tensor = torch.rand(input_shape[0]) * K.pi
- angles_deg = kornia.rad2deg(angles_rad)
- return dict(angles=angles_deg)
-
- def compute_transformation(self, input, params):
-
- B, _, H, W = input.shape
-
- # compute transformation
- angles: torch.Tensor = params['angles'].type_as(input)
- center = torch.tensor([[W / 2, H / 2]] * B).type_as(input)
- transform = K.get_rotation_matrix2d(
- center, angles, torch.ones_like(angles))
- return transform
-
- def apply_transform(self, input, params):
-
- _, _, H, W = input.shape
- # compute transformation
- transform = self.compute_transformation(input, params)
-
- # apply transformation and return
- output = K.warp_affine(input, transform, (H, W))
- return (output, transform)
Module API
----------
@@ -130,51 +73,9 @@ Example for semantic segmentation using low-level randomness control:
mask = self.jit(mask, jit_params)
return input, mask
-Transforms2D
-------------
-
-Set of operators to perform data augmentation on 2D image tensors.
-
-.. autoclass:: CenterCrop
-.. autoclass:: ColorJitter
-.. autoclass:: Denormalize
-.. autoclass:: Normalize
-.. autoclass:: RandomAffine
-.. autoclass:: RandomCrop
-.. autoclass:: RandomErasing
-.. autoclass:: RandomGrayscale
-.. autoclass:: RandomHorizontalFlip
-.. autoclass:: RandomVerticalFlip
-.. autoclass:: RandomMotionBlur
-.. autoclass:: RandomPerspective
-.. autoclass:: RandomResizedCrop
-.. autoclass:: RandomRotation
-.. autoclass:: RandomSolarize
-.. autoclass:: RandomPosterize
-.. autoclass:: RandomSharpness
-.. autoclass:: RandomEqualize
-.. autoclass:: RandomMixUp
-.. autoclass:: RandomCutMix
-
-Transforms3D
-------------
-
-Set of operators to perform data augmentation on 3D image tensors and volumetric data.
-
-.. autoclass:: RandomDepthicalFlip3D
-.. autoclass:: RandomHorizontalFlip3D
-.. autoclass:: RandomVerticalFlip3D
-.. autoclass:: RandomRotation3D
-.. autoclass:: RandomAffine3D
-.. autoclass:: RandomCrop3D
-.. autoclass:: CenterCrop3D
-.. autoclass:: RandomMotionBlur3D
-.. autoclass:: RandomEqualize3D
-
-Functional
-----------
+.. toctree::
+ :maxdepth: 2
-.. automodule:: kornia.augmentation.functional.functional
- :members:
-.. automodule:: kornia.augmentation.functional.functional3d
- :members:
+ augmentation.base
+ augmentation.module
+ augmentation.container
\ No newline at end of file