π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix doctests in ci (#3402)
Edgar Ribadff89bd07529
diff --git a/docs/source/applications/object_detection.rst b/docs/source/applications/object_detection.rstdeleted file mode 100644index ad1ca1494..000000000--- a/docs/source/applications/object_detection.rst+++ /dev/null@@ -1,23 +0,0 @@-Object detection-================--.. image:: https://production-media.paperswithcode.com/thumbnails/task/task-0000000004-7757802e.jpg- :align: right- :width: 40%--Object detection consists in detecting objects belonging to a certain category from an image,-determining the absolute location and also assigning each detected instance a predefined category.-In the last few years, several models have emerged based on deep learning. Being the state of the art-models being based on two stages. First, regions with higher recall values are located, so that all-objects in the image adhere to the proposed regions. The second stage consists of classification models,-usually CNNs, used to determine the category of each proposed region (instances).--Learn more: `https://paperswithcode.com/task/object-detection <https://paperswithcode.com/task/object-detection>`_--Finetuning-------------In order to customize your model with your own data, you can use the models provided by Kornia or use existing libraries from the PyTorch ecosystem such-as `torchvision <https://pytorch.org/vision/stable/models.html>`_.--You can use standard PyTorch training loops with Kornia models and augmentations.diff --git a/kornia/augmentation/_2d/geometric/rotation.py b/kornia/augmentation/_2d/geometric/rotation.pyindex bbb4e7cda..4cabe6319 100644--- a/kornia/augmentation/_2d/geometric/rotation.py+++ b/kornia/augmentation/_2d/geometric/rotation.py@@ -152,7 +152,6 @@ class RandomRotation90(GeometricAugmentationBase2D):Examples:>>> rng = torch.manual_seed(1)- >>> torch.set_printoptions(sci_mode=False)>>> input = torch.tensor([[1., 0., 0., 2.],... [0., 0., 0., 0.],... [0., 1., 2., 0.],@@ -160,16 +159,15 @@ class RandomRotation90(GeometricAugmentationBase2D):>>> aug = RandomRotation90(times=(1, 1), p=1.)>>> out = aug(input)>>> out- tensor([[[[ 2.0000, 0.0000, 0.0000, 2.0000],- [ 0.0000, 0.0000, 2.0000, 1.0000],- [ 0.0000, 0.0000, 1.0000, 0.0000],- [ 1.0000, 0.0000, 0.0000, 0.0000]]]])+ tensor([[[[2.0000e+00, 0.0000e+00, 0.0000e+00, 2.0000e+00],+ [0.0000e+00, 0.0000e+00, 2.0000e+00, 1.0000e+00],+ [5.9605e-08, 0.0000e+00, 1.0000e+00, 0.0000e+00],+ [1.0000e+00, 5.9605e-08, 0.0000e+00, 0.0000e+00]]]])>>> aug.transform_matrix- tensor([[[ -0.0000, 1.0000, 0.0000],- [ -1.0000, -0.0000, 3.0000],- [ 0.0000, 0.0000, 1.0000]]])+ tensor([[[-4.3711e-08, 1.0000e+00, 1.1921e-07],+ [-1.0000e+00, -4.3711e-08, 3.0000e+00],+ [ 0.0000e+00, 0.0000e+00, 1.0000e+00]]])>>> inv = aug.inverse(out)- >>> torch.set_printoptions(profile='default')To apply the exact augmenation again, you may take the advantage of the previous parameter state:>>> input = torch.randn(1, 3, 32, 32)diff --git a/kornia/augmentation/_2d/mix/cutmix.py b/kornia/augmentation/_2d/mix/cutmix.pyindex 706376227..4a7cf52ec 100644--- a/kornia/augmentation/_2d/mix/cutmix.py+++ b/kornia/augmentation/_2d/mix/cutmix.py@@ -74,7 +74,7 @@ class RandomCutMixV2(MixAugmentationBaseV2):>>> input = torch.rand(2, 1, 3, 3)>>> input[0] = torch.ones((1, 3, 3))>>> label = torch.tensor([0, 1])- >>> cutmix = RandomCutMixV2(data_keys=["input", "class"])+ >>> cutmix = RandomCutMixV2(data_keys=["input", "class"], use_correct_lambda=True)>>> cutmix(input, label)[tensor([[[[0.8879, 0.4510, 1.0000],[0.1498, 0.4015, 1.0000],@@ -83,8 +83,8 @@ class RandomCutMixV2(MixAugmentationBaseV2):<BLANKLINE>[[[1.0000, 1.0000, 0.7995],[1.0000, 1.0000, 0.0542],- [0.4594, 0.1756, 0.9492]]]]), tensor([[[0.0000, 1.0000, 0.4444],- [1.0000, 0.0000, 0.4444]]])]+ [0.4594, 0.1756, 0.9492]]]]), tensor([[[0.0000, 1.0000, 0.5556],+ [1.0000, 0.0000, 0.5556]]])]"""diff --git a/kornia/enhance/jpeg.py b/kornia/enhance/jpeg.pyindex d318dd689..9344f7cd6 100644--- a/kornia/enhance/jpeg.py+++ b/kornia/enhance/jpeg.py@@ -39,6 +39,8 @@ from kornia.utils.misc import (differentiable_polynomial_rounding,)+_DCT8_CACHE: dict[tuple[Dtype, Device], tuple[Tensor, Tensor]] = {}+__all__ = ["JPEGCodecDifferentiable", "jpeg_codec_differentiable"]@@ -127,13 +129,7 @@ def _dct_8x8(input: Tensor) -> Tensor:# Get dtype and devicedtype: Dtype = input.dtypedevice: Device = input.device- # Make DCT tensor and scaling- index: Tensor = torch.arange(8, dtype=dtype, device=device)- x, y, u, v = torch.meshgrid(index, index, index, index)- dct_tensor: Tensor = ((2.0 * x + 1.0) * u * pi / 16.0).cos() * ((2.0 * y + 1.0) * v * pi / 16.0).cos()- alpha: Tensor = torch.ones(8, dtype=dtype, device=device)- alpha[0] = 1.0 / (2**0.5)- dct_scale: Tensor = torch.einsum("i, j -> ij", alpha, alpha) * 0.25+ dct_tensor, dct_scale = _get_dct8_basis_scale(dtype, device)# Apply DCToutput: Tensor = dct_scale[None, None] * torch.tensordot(input - 128.0, dct_tensor)return output@@ -159,7 +155,7 @@ def _idct_8x8(input: Tensor) -> Tensor:input = input * dct_scale[None, None]# Make DCT tensor and scalingindex: Tensor = torch.arange(8, dtype=dtype, device=device)- x, y, u, v = torch.meshgrid(index, index, index, index)+ x, y, u, v = torch.meshgrid(index, index, index, index, indexing="ij")idct_tensor: Tensor = ((2.0 * u + 1.0) * x * pi / 16.0).cos() * ((2.0 * v + 1.0) * y * pi / 16.0).cos()# Apply DCToutput: Tensor = 0.25 * torch.tensordot(input, idct_tensor, dims=2) + 128.0@@ -584,6 +580,19 @@ def jpeg_codec_differentiable(return image_rgb_jpeg+def _get_dct8_basis_scale(dtype: Dtype, device: Device) -> tuple[Tensor, Tensor]:+ key = (dtype, device)+ if key not in _DCT8_CACHE:+ index: Tensor = torch.arange(8, dtype=dtype, device=device)+ x, y, u, v = torch.meshgrid(index, index, index, index, indexing="ij")+ dct_tensor: Tensor = ((2.0 * x + 1.0) * u * pi / 16.0).cos() * ((2.0 * y + 1.0) * v * pi / 16.0).cos()+ alpha: Tensor = torch.ones(8, dtype=dtype, device=device)+ alpha[0] = 1.0 / (2**0.5)+ dct_scale: Tensor = torch.outer(alpha, alpha) * 0.25+ _DCT8_CACHE[key] = (dct_tensor, dct_scale)+ return _DCT8_CACHE[key]++class JPEGCodecDifferentiable(Module):r"""Differentiable JPEG encoding-decoding module.diff --git a/kornia/feature/integrated.py b/kornia/feature/integrated.pyindex 1c26856ad..9330aedba 100644--- a/kornia/feature/integrated.py+++ b/kornia/feature/integrated.py@@ -252,7 +252,7 @@ class GFTTAffNetHardNet(LocalFeature):num_features,config,ori_module=PassLAF() if upright else LAFOrienter(19),- aff_module=LAFAffNetShapeEstimator(True).eval(),+ aff_module=LAFAffNetShapeEstimator(True, preserve_orientation=False).eval(),).to(device)descriptor = LAFDescriptor(None, patch_size=32, grayscale_descriptor=True).to(device)super().__init__(detector, descriptor)@@ -277,7 +277,7 @@ class HesAffNetHardNet(LocalFeature):num_features,config,ori_module=PassLAF() if upright else LAFOrienter(19),- aff_module=LAFAffNetShapeEstimator(True).eval(),+ aff_module=LAFAffNetShapeEstimator(True, preserve_orientation=False).eval(),).to(device)descriptor = LAFDescriptor(None, patch_size=32, grayscale_descriptor=True).to(device)super().__init__(detector, descriptor)@@ -318,7 +318,10 @@ class KeyNetAffNetHardNet(LocalFeature):device = torch.device("cpu")ori_module = PassLAF() if upright else LAFOrienter(angle_detector=OriNet(True))detector = KeyNetDetector(- True, num_features=num_features, ori_module=ori_module, aff_module=LAFAffNetShapeEstimator(True).eval()+ True,+ num_features=num_features,+ ori_module=ori_module,+ aff_module=LAFAffNetShapeEstimator(True, preserve_orientation=False).eval(),).to(device)descriptor = LAFDescriptor(None, patch_size=32, grayscale_descriptor=True).to(device)super().__init__(detector, descriptor, scale_laf)diff --git a/kornia/sensors/camera/projection_model.py b/kornia/sensors/camera/projection_model.pyindex 18fee3443..44fd2eeec 100644--- a/kornia/sensors/camera/projection_model.py+++ b/kornia/sensors/camera/projection_model.py@@ -40,7 +40,11 @@ class Z1Projection:"""xy = points.data[..., :2]z = points.z- uv = (xy.T @ z.diag().inverse()).T if len(z.shape) else xy.T * 1 / z+ if len(z.shape):+ uv = (xy.mT @ z.diag().inverse()).mT+ else:+ # For scalar z, xy is 1-D, so no transpose needed+ uv = xy * 1 / zreturn Vector2(uv)def unproject(self, points: Vector2, depth: Tensor | float) -> Vector3: