🐍 Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
docs(feature): make the response doctests actually run, and fix laf/sift docstrings (#4072)
Dmytro Mishkinb95777536aa2
diff --git a/kornia/feature/laf.py b/kornia/feature/laf.pyindex 8118af832..655dac9ea 100644--- a/kornia/feature/laf.py+++ b/kornia/feature/laf.py@@ -314,17 +314,17 @@ def get_laf_pts_to_draw(LAF: torch.Tensor, img_idx: int = 0) -> Tuple[List[int],def denormalize_laf(LAF: torch.Tensor, images: torch.Tensor) -> torch.Tensor:- """De-F.normalize LAFs from scale to image scale.+ """Denormalize LAFs from the [0, 1] scale to image (pixel) scale.The convention is that center of 5-pixel image (coordinates from 0 to 4) is 2, and not 2.5.- B,N,H,W = images.size()+ B,CH,H,W = images.size()MIN_SIZE = min(H - 1, W -1)- [a11 a21 x]+ [a11 a12 x][a21 a22 y]becomes- [a11*MIN_SIZE a21*MIN_SIZE x*(W-1)]- [a21*MIN_SIZE a22*MIN_SIZE y*(W-1)]+ [a11*MIN_SIZE a12*MIN_SIZE x*(W-1)]+ [a21*MIN_SIZE a22*MIN_SIZE y*(H-1)]Args:LAF: :math:`(B, N, 2, 3)`@@ -349,12 +349,12 @@ def normalize_laf(LAF: torch.Tensor, images: torch.Tensor) -> torch.Tensor:"""Normalize LAFs to [0,1] scale from pixel scale.See below:- B,N,H,W = images.size()+ B,CH,H,W = images.size()MIN_SIZE = min(H - 1, W -1)- [a11 a21 x]+ [a11 a12 x][a21 a22 y]becomes:- [a11/MIN_SIZE a21/MIN_SIZE x/(W-1)]+ [a11/MIN_SIZE a12/MIN_SIZE x/(W-1)][a21/MIN_SIZE a22/MIN_SIZE y/(H-1)]Args:@@ -362,7 +362,7 @@ def normalize_laf(LAF: torch.Tensor, images: torch.Tensor) -> torch.Tensor:images: :math:`(B, CH, H, W)`Returns:- the denormalized LAF: :math:`(B, N, 2, 3)`, scale in image percentage (0, 1)+ the normalized LAF: :math:`(B, N, 2, 3)`, scale in image percentage (0, 1)"""KORNIA_CHECK_LAF(LAF)diff --git a/kornia/feature/responses.py b/kornia/feature/responses.pyindex b5b1fbcb7..5e8ee8d4a 100644--- a/kornia/feature/responses.py+++ b/kornia/feature/responses.py@@ -84,18 +84,17 @@ def harris_response(... [0., 1., 1., 1., 1., 1., 0.],... [0., 0., 0., 0., 0., 0., 0.],... ]]]) # 1x1x7x7- >>> # compute the response map- harris_response(input, 0.04)- tensor([[[[0.0012, 0.0039, 0.0020, 0.0000, 0.0020, 0.0039, 0.0012],- [0.0039, 0.0065, 0.0040, 0.0000, 0.0040, 0.0065, 0.0039],- [0.0020, 0.0040, 0.0029, 0.0000, 0.0029, 0.0040, 0.0020],- [0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],- [0.0020, 0.0040, 0.0029, 0.0000, 0.0029, 0.0040, 0.0020],- [0.0039, 0.0065, 0.0040, 0.0000, 0.0040, 0.0065, 0.0039],- [0.0012, 0.0039, 0.0020, 0.0000, 0.0020, 0.0039, 0.0012]]]])+ >>> # compute the response map; rounded for a platform-stable display+ >>> harris_response(input, 0.04).round(decimals=4) + 0.0+ tensor([[[[0.0042, 0.0054, 0.0035, 0.0006, 0.0035, 0.0054, 0.0042],+ [0.0054, 0.0068, 0.0046, 0.0014, 0.0046, 0.0068, 0.0054],+ [0.0035, 0.0046, 0.0034, 0.0014, 0.0034, 0.0046, 0.0035],+ [0.0006, 0.0014, 0.0014, 0.0006, 0.0014, 0.0014, 0.0006],+ [0.0035, 0.0046, 0.0034, 0.0014, 0.0034, 0.0046, 0.0035],+ [0.0054, 0.0068, 0.0046, 0.0014, 0.0046, 0.0068, 0.0054],+ [0.0042, 0.0054, 0.0035, 0.0006, 0.0035, 0.0054, 0.0042]]]])"""- # TODO: Recompute doctestKORNIA_CHECK_SHAPE(input, ["B", "C", "H", "W"])if sigmas is not None:@@ -167,18 +166,17 @@ def gftt_response(... [0., 1., 1., 1., 1., 1., 0.],... [0., 0., 0., 0., 0., 0., 0.],... ]]]) # 1x1x7x7- >>> # compute the response map- gftt_response(input)- tensor([[[[0.0155, 0.0334, 0.0194, 0.0000, 0.0194, 0.0334, 0.0155],- [0.0334, 0.0575, 0.0339, 0.0000, 0.0339, 0.0575, 0.0334],- [0.0194, 0.0339, 0.0497, 0.0000, 0.0497, 0.0339, 0.0194],- [0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],- [0.0194, 0.0339, 0.0497, 0.0000, 0.0497, 0.0339, 0.0194],- [0.0334, 0.0575, 0.0339, 0.0000, 0.0339, 0.0575, 0.0334],- [0.0155, 0.0334, 0.0194, 0.0000, 0.0194, 0.0334, 0.0155]]]])+ >>> # compute the response map; rounded for a platform-stable display+ >>> gftt_response(input).round(decimals=4) + 0.0+ tensor([[[[0.0379, 0.0456, 0.0283, 0.0121, 0.0283, 0.0456, 0.0379],+ [0.0456, 0.0598, 0.0402, 0.0168, 0.0402, 0.0598, 0.0456],+ [0.0283, 0.0402, 0.0545, 0.0245, 0.0545, 0.0402, 0.0283],+ [0.0121, 0.0168, 0.0245, 0.0276, 0.0245, 0.0168, 0.0121],+ [0.0283, 0.0402, 0.0545, 0.0245, 0.0545, 0.0402, 0.0283],+ [0.0456, 0.0598, 0.0402, 0.0168, 0.0402, 0.0598, 0.0456],+ [0.0379, 0.0456, 0.0283, 0.0121, 0.0283, 0.0456, 0.0379]]]])"""- # TODO: Recompute doctestKORNIA_CHECK_SHAPE(input, ["B", "C", "H", "W"])gradients: torch.Tensor = spatial_gradient(input, grads_mode)@@ -248,18 +246,17 @@ def hessian_response(... [0., 1., 1., 1., 1., 1., 0.],... [0., 0., 0., 0., 0., 0., 0.],... ]]]) # 1x1x7x7- >>> # compute the response map- hessian_response(input)- tensor([[[[0.0155, 0.0334, 0.0194, 0.0000, 0.0194, 0.0334, 0.0155],- [0.0334, 0.0575, 0.0339, 0.0000, 0.0339, 0.0575, 0.0334],- [0.0194, 0.0339, 0.0497, 0.0000, 0.0497, 0.0339, 0.0194],- [0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],- [0.0194, 0.0339, 0.0497, 0.0000, 0.0497, 0.0339, 0.0194],- [0.0334, 0.0575, 0.0339, 0.0000, 0.0339, 0.0575, 0.0334],- [0.0155, 0.0334, 0.0194, 0.0000, 0.0194, 0.0334, 0.0155]]]])+ >>> # compute the response map; rounded for a platform-stable display+ >>> hessian_response(input).round(decimals=4) + 0.0+ tensor([[[[-0.0564, -0.0759, -0.0253, 0.0000, -0.0253, -0.0759, -0.0564],+ [-0.0759, -0.0330, 0.0333, 0.0000, 0.0333, -0.0330, -0.0759],+ [-0.0253, 0.0333, 0.0542, 0.0000, 0.0542, 0.0333, -0.0253],+ [ 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000],+ [-0.0253, 0.0333, 0.0542, 0.0000, 0.0542, 0.0333, -0.0253],+ [-0.0759, -0.0330, 0.0333, 0.0000, 0.0333, -0.0330, -0.0759],+ [-0.0564, -0.0759, -0.0253, 0.0000, -0.0253, -0.0759, -0.0564]]]])"""- # TODO: Recompute doctestKORNIA_CHECK_SHAPE(input, ["B", "C", "H", "W"])if sigmas is not None:diff --git a/kornia/feature/siftdesc.py b/kornia/feature/siftdesc.pyindex 9f4324684..3b72f47e4 100644--- a/kornia/feature/siftdesc.py+++ b/kornia/feature/siftdesc.py@@ -83,9 +83,9 @@ def get_sift_bin_ksize_stride_pad(patch_size: int, num_spatial_bins: int) -> Tupout_size: int = (patch_size + 2 * pad - (ksize - 1) - 1) // stride + 1if out_size != num_spatial_bins:raise ValueError(- f"Patch size {patch_size} is incompatible with requested number of spatial bins"- f" {num_spatial_bins} for SIFT descriptor. Usually it happens when patch size is too small "- " for num_spatial_bins specified"+ f"Patch size {patch_size} is incompatible with the requested number of spatial bins "+ f"{num_spatial_bins} for SIFT descriptor. Usually it happens when patch size is too small "+ "for num_spatial_bins specified")return ksize, stride, pad@@ -101,10 +101,10 @@ class SIFTDescriptor(nn.Module):rootsift: if ``True``, RootSIFT (Arandjelović et. al, 2012) is computed.Returns:- SIFT descriptor of the patches with shape.+ SIFT descriptor of the patches.Shape:- - Input: :math:`(B, 1, \text{num_spatial_bins}, \text{num_spatial_bins})`+ - Input: :math:`(B, 1, \text{patch_size}, \text{patch_size})`- Output: :math:`(B, \text{num_ang_bins * num_spatial_bins ** 2})`Example:@@ -242,8 +242,8 @@ class DenseSIFTDescriptor(nn.Module):Args:num_ang_bins: Number of angular bins. (8 is default)- num_spatial_bins: Number of spatial bins per descriptor (4 is default).- You might want to set odd number and relevant padding to keep feature map size+ num_spatial_bins: Number of spatial bins per descriptor (4 is default). You might want to set an odd+ number and relevant padding to keep the feature map size.spatial_bin_size: Size of a spatial bin in pixels (4 is default)clipval: clipping value to reduce single-bin dominancerootsift: (bool) if True, RootSIFT (Arandjelović et. al, 2012) is computed