π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
[Feat] Enabled doctest for CI (#641)
shijianjian0a605561daeb
diff --git a/.circleci/config.yml.old b/.circleci/config.yml.oldindex 94b8f030a..9396929a8 100644--- a/.circleci/config.yml.old+++ b/.circleci/config.yml.old@@ -19,6 +19,9 @@ commands:- run:name: static checkcommand: make mypy+ - run:+ name: doctest+ command: make doctest- run:name: unit testscommand: make test-cpudiff --git a/kornia/contrib/extract_patches.py b/kornia/contrib/extract_patches.pyindex 0ddb82993..e91f16471 100644--- a/kornia/contrib/extract_patches.py+++ b/kornia/contrib/extract_patches.py@@ -54,14 +54,14 @@ class ExtractTensorPatches(nn.Module):Examples:>>> input = torch.arange(9.).view(1, 1, 3, 3)- >>> patches = kornia.contrib.extract_tensor_patches(input, (2, 3))+ >>> patches = extract_tensor_patches(input, (2, 3))>>> inputtensor([[[[0., 1., 2.],[3., 4., 5.],[6., 7., 8.]]]])>>> patches[:, -1]- tensor([[[[3.0000, 4.0000, 5.0000],- [6.0000, 7.0000, 8.0000]]]])+ tensor([[[[3., 4., 5.],+ [6., 7., 8.]]]])"""def __init__(diff --git a/kornia/contrib/max_blur_pool.py b/kornia/contrib/max_blur_pool.pyindex 046ef1650..56a1004f0 100644--- a/kornia/contrib/max_blur_pool.py+++ b/kornia/contrib/max_blur_pool.py@@ -37,7 +37,7 @@ class MaxBlurPool2d(nn.Module):Examples:>>> input = torch.rand(1, 4, 4, 8)- >>> pool = kornia.contrib.MaxBlurPool2d(kernel_size=3)+ >>> pool = MaxBlurPool2d(kernel_size=3)>>> output = pool(input) # 1x4x2x4"""diff --git a/kornia/enhance/zca.py b/kornia/enhance/zca.pyindex d0675823c..b8011f760 100644--- a/kornia/enhance/zca.py+++ b/kornia/enhance/zca.py@@ -46,13 +46,13 @@ class ZCAWhitening(nn.Module):Examples:>>> x = torch.tensor([[0,1],[1,0],[-1,0],[0,-1]], dtype = torch.float32)- >>> zca = kornia.color.ZCAWhitening().fit(x)+ >>> zca = ZCAWhitening().fit(x)>>> x_whiten = zca(x)- >>> zca = kornia.color.ZCAWhitening()+ >>> zca = ZCAWhitening()>>> x_whiten = zca(x, include_fit = True) # Includes the fitting step>>> x_whiten = zca(x) # Can run now without the fitting set>>> # Enable backprop through ZCA fitting process- >>> zca = kornia.color.ZCAWhitening(detach_transforms = False)+ >>> zca = ZCAWhitening(detach_transforms = False)>>> x_whiten = zca(x, include_fit = True) # Includes the fitting stepNote:@@ -147,9 +147,6 @@ class ZCAWhitening(nn.Module):returns:torch.Tensor: original data---"""if not self.fitted:@@ -195,7 +192,6 @@ def zca_mean(inp: torch.Tensor, dim: int = 0,then it returns the inverse ZCA matrix, otherwise it returns None.Examples:- >>> from kornia.color import zca_mean>>> x = torch.tensor([[0,1],[1,0],[-1,0],[0,-1]], dtype = torch.float32)>>> transform_matrix, mean_vector,_ = zca_mean(x) # Returns transformation matrix and data mean>>> x = torch.rand(3,20,2,2)@@ -284,11 +280,11 @@ def zca_whiten(inp: torch.Tensor, dim: int = 0,torch.Tensor : Whiten Input dataExamples:- >>> import torch- >>> import kornia>>> x = torch.tensor([[0,1],[1,0],[-1,0]], dtype = torch.float32)- >>> x_whiten = kornia.color.zca_whiten(x)-+ >>> zca_whiten(x)+ tensor([[ 0.0000, 1.1547],+ [ 1.0000, -0.5773],+ [-1.0000, -0.5773]])"""if not isinstance(inp, torch.Tensor):@@ -343,16 +339,16 @@ def linear_transform(inp: torch.Tensor, transform_matrix: torch.Tensor,>>> inp = torch.ones((10,3,4,5))>>> transform_mat = torch.ones((10*3*4,10*3*4))>>> mean = 2*torch.ones((1,10*3*4))- >>> out = kornia.color.linear_transform(inp, transform_mat, mean, 3)- >>> print(out) # Should a be (10,3,4,5) tensor of -120s+ >>> out = linear_transform(inp, transform_mat, mean, 3)+ >>> print(out.shape, out.unique()) # Should a be (10,3,4,5) tensor of -120s+ torch.Size([10, 3, 4, 5]) tensor([-120.])>>> # Example where dim = 0>>> inp = torch.ones((10,2))>>> transform_mat = torch.ones((2,2))>>> mean = torch.zeros((1,2))- >>> out = kornia.color.linear_transform(inp, transform_mat, mean)- >>> print(out) # Should a be (10,3,4,5) tensor of 2s--+ >>> out = linear_transform(inp, transform_mat, mean)+ >>> print(out.shape, out.unique()) # Should a be (10,2) tensor of 2s+ torch.Size([10, 2]) tensor([2.])"""inp_size = inp.size()diff --git a/kornia/feature/hardnet.py b/kornia/feature/hardnet.pyindex 9afcac5e3..b9d392849 100644--- a/kornia/feature/hardnet.py+++ b/kornia/feature/hardnet.py@@ -28,7 +28,7 @@ class HardNet(nn.Module):Examples:>>> input = torch.rand(16, 1, 32, 32)- >>> hardnet = kornia.feature.HardNet()+ >>> hardnet = HardNet()>>> descs = hardnet(input) # 16x128"""diff --git a/kornia/feature/laf.py b/kornia/feature/laf.pyindex bb7396141..b77f68d87 100644--- a/kornia/feature/laf.py+++ b/kornia/feature/laf.py@@ -37,7 +37,7 @@ def get_laf_scale(LAF: torch.Tensor) -> torch.Tensor:Example:>>> input = torch.ones(1, 5, 2, 3) # BxNx2x3- >>> output = kornia.get_laf_scale(input) # BxNx1x1+ >>> output = get_laf_scale(input) # BxNx1x1"""raise_error_if_laf_is_not_valid(LAF)eps = 1e-10@@ -60,7 +60,7 @@ def get_laf_center(LAF: torch.Tensor) -> torch.Tensor:Example:>>> input = torch.ones(1, 5, 2, 3) # BxNx2x3- >>> output = kornia.get_laf_center(input) # BxNx2+ >>> output = get_laf_center(input) # BxNx2"""raise_error_if_laf_is_not_valid(LAF)out: torch.Tensor = LAF[..., 2]@@ -82,7 +82,7 @@ def get_laf_orientation(LAF: torch.Tensor) -> torch.Tensor:Example:>>> input = torch.ones(1, 5, 2, 3) # BxNx2x3- >>> output = kornia.get_laf_orientation(input) # BxNx1+ >>> output = get_laf_orientation(input) # BxNx1"""raise_error_if_laf_is_not_valid(LAF)angle_rad: torch.Tensor = torch.atan2(LAF[..., 0, 1], LAF[..., 0, 0])@@ -145,7 +145,7 @@ def scale_laf(laf: torch.Tensor, scale_coef: Union[float, torch.Tensor]) -> torcExample:>>> input = torch.ones(1, 5, 2, 3) # BxNx2x3>>> scale = 0.5- >>> output = kornia.scale_laf(input, scale) # BxNx2x3+ >>> output = scale_laf(input, scale) # BxNx2x3"""if (type(scale_coef) is not float) and (type(scale_coef) is not torch.Tensor):raise TypeError(@@ -173,7 +173,7 @@ def make_upright(laf: torch.Tensor, eps: float = 1e-9) -> torch.Tensor:Example:>>> input = torch.ones(1, 5, 2, 3) # BxNx2x3- >>> output = kornia.make_upright(input) # BxNx2x3+ >>> output = make_upright(input) # BxNx2x3"""raise_error_if_laf_is_not_valid(laf)det = get_laf_scale(laf)@@ -210,7 +210,7 @@ def ellipse_to_laf(ells: torch.Tensor) -> torch.Tensor:Example:>>> input = torch.ones(1, 10, 5) # BxNx5- >>> output = kornia.ellipse_to_laf(input) # BxNx2x3+ >>> output = ellipse_to_laf(input) # BxNx2x3"""n_dims = len(ells.size())if n_dims != 3:@@ -289,12 +289,13 @@ def get_laf_pts_to_draw(LAF: torch.Tensor,- Output: :math:`(B, N, n_pts, 2)`Examples:- >>> x, y = kornia.feature.laf.get_laf_pts_to_draw(LAF, img_idx)- >>> plt.figure()- >>> plt.imshow(kornia.utils.tensor_to_image(img[img_idx]))- >>> plt.plot(x, y, 'r')- >>> plt.show()+ x, y = get_laf_pts_to_draw(LAF, img_idx)+ plt.figure()+ plt.imshow(kornia.utils.tensor_to_image(img[img_idx]))+ plt.plot(x, y, 'r')+ plt.show()"""+ # TODO: Refactor doctestraise_error_if_laf_is_not_valid(LAF)pts = laf_to_boundary_points(LAF[img_idx:img_idx + 1])[0]pts_np = pts.detach().permute(1, 0, 2).cpu().numpy()@@ -303,8 +304,8 @@ def get_laf_pts_to_draw(LAF: torch.Tensor,def denormalize_laf(LAF: torch.Tensor, images: torch.Tensor) -> torch.Tensor:"""De-normalizes LAFs from scale to image scale.- >>> B,N,H,W = images.size()- >>> MIN_SIZE = min(H,W)+ B,N,H,W = images.size()+ MIN_SIZE = min(H,W)[a11 a21 x][a21 a22 y]becomes@@ -335,8 +336,8 @@ def denormalize_laf(LAF: torch.Tensor, images: torch.Tensor) -> torch.Tensor:def normalize_laf(LAF: torch.Tensor, images: torch.Tensor) -> torch.Tensor:"""Normalizes LAFs to [0,1] scale from pixel scale. See below:- >>> B,N,H,W = images.size()- >>> MIN_SIZE = min(H,W)+ B,N,H,W = images.size()+ MIN_SIZE = min(H,W)[a11 a21 x][a21 a22 y]becomes:diff --git a/kornia/feature/responses.py b/kornia/feature/responses.pyindex 665818011..a5fd724dc 100644--- a/kornia/feature/responses.py+++ b/kornia/feature/responses.py@@ -47,24 +47,25 @@ def harris_response(input: torch.Tensor,Examples:>>> input = torch.tensor([[[- [0., 0., 0., 0., 0., 0., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 0., 0., 0., 0., 0., 0.],- ]]]) # 1x1x7x7+ ... [0., 0., 0., 0., 0., 0., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 0., 0., 0., 0., 0., 0.],+ ... ]]]) # 1x1x7x7>>> # compute the response map- >>> output = harris_response(input, 0.04)+ 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]]]])+ [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]]]])"""+ # TODO: Recompute doctestif not torch.is_tensor(input):raise TypeError("Input type is not a torch.Tensor. Got {}".format(type(input)))@@ -133,24 +134,25 @@ def gftt_response(input: torch.Tensor,Examples:>>> input = torch.tensor([[[- [0., 0., 0., 0., 0., 0., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 0., 0., 0., 0., 0., 0.],- ]]]) # 1x1x7x7+ ... [0., 0., 0., 0., 0., 0., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 0., 0., 0., 0., 0., 0.],+ ... ]]]) # 1x1x7x7>>> # compute the response map- >>> output = gftt_response(input)+ 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]]]])+ [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]]]])"""+ # TODO: Recompute doctestif not torch.is_tensor(input):raise TypeError("Input type is not a torch.Tensor. Got {}".format(type(input)))@@ -216,25 +218,26 @@ def hessian_response(input: torch.Tensor,- Output: :math:`(B, C, H, W)`Examples:- >>> input = torch.tensor([[[- [0., 0., 0., 0., 0., 0., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 1., 1., 1., 1., 1., 0.],- [0., 0., 0., 0., 0., 0., 0.],- ]]]) # 1x1x7x7- >>> # compute the response map- >>> output = 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]]]])+ >>> input = torch.tensor([[[+ ... [0., 0., 0., 0., 0., 0., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [0., 1., 1., 1., 1., 1., 0.],+ ... [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]]]])"""+ # TODO: Recompute doctestif not torch.is_tensor(input):raise TypeError("Input type is not a torch.Tensor. Got {}".format(type(input)))diff --git a/kornia/feature/siftdesc.py b/kornia/feature/siftdesc.pyindex d0bf2c715..eb3f778c4 100644--- a/kornia/feature/siftdesc.py+++ b/kornia/feature/siftdesc.py@@ -71,7 +71,7 @@ class SIFTDescriptor(nn.Module):Examples::>>> input = torch.rand(23, 1, 32, 32)- >>> SIFT = kornia.SIFTDescriptor(32, 8, 4)+ >>> SIFT = SIFTDescriptor(32, 8, 4)>>> descs = SIFT(input) # 23x128"""diff --git a/kornia/feature/sosnet.py b/kornia/feature/sosnet.pyindex 3986d5f70..3acfb77cb 100644--- a/kornia/feature/sosnet.py+++ b/kornia/feature/sosnet.py@@ -23,7 +23,7 @@ class SOSNet(nn.Module):Examples:>>> input = torch.rand(8, 1, 32, 32)- >>> sosnet = kornia.feature.SOSNet()+ >>> sosnet = SOSNet()>>> descs = sosnet(input) # 8x128"""diff --git a/kornia/filters/blur.py b/kornia/filters/blur.pyindex b28090fa4..028f2e8c0 100644--- a/kornia/filters/blur.py+++ b/kornia/filters/blur.py@@ -38,7 +38,7 @@ class BoxBlur(nn.Module):Example:>>> input = torch.rand(2, 4, 5, 7)- >>> blur = kornia.filters.BoxBlur((3, 3))+ >>> blur = BoxBlur((3, 3))>>> output = blur(input) # 2x4x5x7"""diff --git a/kornia/filters/filter.py b/kornia/filters/filter.pyindex 1fd94731f..e669df695 100644--- a/kornia/filters/filter.py+++ b/kornia/filters/filter.py@@ -62,12 +62,12 @@ def filter2D(input: torch.Tensor, kernel: torch.Tensor,... [0., 0., 0., 0., 0.],... [0., 0., 0., 0., 0.],]]])>>> kernel = torch.ones(1, 3, 3)- >>> kornia.filter2D(input, kernel)- torch.tensor([[[[0., 0., 0., 0., 0.]- [0., 5., 5., 5., 0.]- [0., 5., 5., 5., 0.]- [0., 5., 5., 5., 0.]- [0., 0., 0., 0., 0.]]]])+ >>> filter2D(input, kernel)+ tensor([[[[0., 0., 0., 0., 0.],+ [0., 5., 5., 5., 0.],+ [0., 5., 5., 5., 0.],+ [0., 5., 5., 5., 0.],+ [0., 0., 0., 0., 0.]]]])"""testing.check_is_tensor(input)testing.check_is_tensor(kernel)@@ -138,35 +138,36 @@ def filter3D(input: torch.Tensor, kernel: torch.Tensor,... [0., 0., 0., 0., 0.],... [0., 0., 0., 0., 0.],... [0., 0., 0., 0., 0.]],- ...... [[0., 0., 0., 0., 0.],... [0., 0., 0., 0., 0.],... [0., 0., 5., 0., 0.],... [0., 0., 0., 0., 0.],... [0., 0., 0., 0., 0.]],- ...... [[0., 0., 0., 0., 0.],... [0., 0., 0., 0., 0.],... [0., 0., 0., 0., 0.],... [0., 0., 0., 0., 0.],- ... [0., 0., 0., 0., 0.]]]])+ ... [0., 0., 0., 0., 0.]]+ ... ]]])>>> kernel = torch.ones(1, 3, 3, 3)- >>> kornia.filter3D(input, kernel)- torch.tensor([[[[[0., 0., 0., 0., 0.],- [0., 5., 5., 5., 0.],- [0., 5., 5., 5., 0.],- [0., 5., 5., 5., 0.],- [0., 0., 0., 0., 0.]],- [[0., 0., 0., 0., 0.],- [0., 5., 5., 5., 0.],- [0., 5., 5., 5., 0.],- [0., 5., 5., 5., 0.],- [0., 0., 0., 0., 0.]],- [[0., 0., 0., 0., 0.],- [0., 5., 5., 5., 0.],- [0., 5., 5., 5., 0.],- [0., 5., 5., 5., 0.],- [0., 0., 0., 0., 0.]]]])+ >>> filter3D(input, kernel)+ tensor([[[[[0., 0., 0., 0., 0.],+ [0., 5., 5., 5., 0.],+ [0., 5., 5., 5., 0.],+ [0., 5., 5., 5., 0.],+ [0., 0., 0., 0., 0.]],+ <BLANKLINE>+ [[0., 0., 0., 0., 0.],+ [0., 5., 5., 5., 0.],+ [0., 5., 5., 5., 0.],+ [0., 5., 5., 5., 0.],+ [0., 0., 0., 0., 0.]],+ <BLANKLINE>+ [[0., 0., 0., 0., 0.],+ [0., 5., 5., 5., 0.],+ [0., 5., 5., 5., 0.],+ [0., 5., 5., 5., 0.],+ [0., 0., 0., 0., 0.]]]]])"""testing.check_is_tensor(input)testing.check_is_tensor(kernel)diff --git a/kornia/filters/gaussian.py b/kornia/filters/gaussian.pyindex fafffa588..058b0ebdd 100644--- a/kornia/filters/gaussian.py+++ b/kornia/filters/gaussian.py@@ -30,7 +30,7 @@ class GaussianBlur2d(nn.Module):Examples::>>> input = torch.rand(2, 4, 5, 5)- >>> gauss = kornia.filters.GaussianBlur((3, 3), (1.5, 1.5))+ >>> gauss = GaussianBlur2d((3, 3), (1.5, 1.5))>>> output = gauss(input) # 2x4x5x5"""diff --git a/kornia/filters/kernels.py b/kornia/filters/kernels.pyindex e4937c1ff..905951561 100644--- a/kornia/filters/kernels.py+++ b/kornia/filters/kernels.py@@ -401,12 +401,12 @@ def get_gaussian_kernel1d(kernel_size: int,Shape:- Output: :math:`(\text{kernel_size})`- Examples::+ Examples:- >>> kornia.filters.get_gaussian_kernel1d(3, 2.5)+ >>> get_gaussian_kernel1d(3, 2.5)tensor([0.3243, 0.3513, 0.3243])- >>> kornia.filters.get_gaussian_kernel1d(5, 1.5)+ >>> get_gaussian_kernel1d(5, 1.5)tensor([0.1201, 0.2339, 0.2921, 0.2339, 0.1201])"""if (not isinstance(kernel_size, int) or (@@ -438,12 +438,12 @@ def get_gaussian_discrete_kernel1d(kernel_size: int,Shape:- Output: :math:`(\text{kernel_size})`- Examples::+ Examples:- >>> kornia.filters.get_gaussian_discrete_kernel1d(3, 2.5)+ >>> get_gaussian_discrete_kernel1d(3, 2.5)tensor([0.3235, 0.3531, 0.3235])- >>> kornia.filters.get_gaussian_discrete_kernel1d(5, 1.5)+ >>> get_gaussian_discrete_kernel1d(5, 1.5)tensor([0.1096, 0.2323, 0.3161, 0.2323, 0.1096])"""if (not isinstance(kernel_size, int) or (@@ -475,12 +475,12 @@ def get_gaussian_erf_kernel1d(kernel_size: int,Shape:- Output: :math:`(\text{kernel_size})`- Examples::+ Examples:- >>> kornia.filters.get_gaussian_erf_kernel1d(3, 2.5)+ >>> get_gaussian_erf_kernel1d(3, 2.5)tensor([0.3245, 0.3511, 0.3245])- >>> kornia.filters.get_gaussian_erf_kernel1d(5, 1.5)+ >>> get_gaussian_erf_kernel1d(5, 1.5)tensor([0.1226, 0.2331, 0.2887, 0.2331, 0.1226])"""if (not isinstance(kernel_size, int) or (@@ -513,14 +513,12 @@ def get_gaussian_kernel2d(Shape:- Output: :math:`(\text{kernel_size}_x, \text{kernel_size}_y)`- Examples::-- >>> kornia.filters.get_gaussian_kernel2d((3, 3), (1.5, 1.5))+ Examples:+ >>> get_gaussian_kernel2d((3, 3), (1.5, 1.5))tensor([[0.0947, 0.1183, 0.0947],[0.1183, 0.1478, 0.1183],[0.0947, 0.1183, 0.0947]])-- >>> kornia.filters.get_gaussian_kernel2d((3, 5), (1.5, 1.5))+ >>> get_gaussian_kernel2d((3, 5), (1.5, 1.5))tensor([[0.0370, 0.0720, 0.0899, 0.0720, 0.0370],[0.0462, 0.0899, 0.1123, 0.0899, 0.0462],[0.0370, 0.0720, 0.0899, 0.0720, 0.0370]])@@ -557,11 +555,10 @@ def get_laplacian_kernel1d(kernel_size: int) -> torch.Tensor:Shape:- Output: math:`(\text{kernel_size})`- Examples::- >>> kornia.filters.get_laplacian_kernel(3)+ Examples:+ >>> get_laplacian_kernel1d(3)tensor([ 1., -2., 1.])-- >>> kornia.filters.get_laplacian_kernel(5)+ >>> get_laplacian_kernel1d(5)tensor([ 1., 1., -4., 1., 1.])"""@@ -585,20 +582,17 @@ def get_laplacian_kernel2d(kernel_size: int) -> torch.Tensor:Shape:- Output: :math:`(\text{kernel_size}_x, \text{kernel_size}_y)`- Examples::-- >>> kornia.filters.get_laplacian_kernel2d(3)+ Examples:+ >>> get_laplacian_kernel2d(3)tensor([[ 1., 1., 1.],[ 1., -8., 1.],[ 1., 1., 1.]])-- >>> kornia.filters.get_laplacian_kernel2d(5)+ >>> get_laplacian_kernel2d(5)tensor([[ 1., 1., 1., 1., 1.],[ 1., 1., 1., 1., 1.],[ 1., 1., -24., 1., 1.],[ 1., 1., 1., 1., 1.],[ 1., 1., 1., 1., 1.]])-"""if not isinstance(kernel_size, int) or kernel_size % 2 == 0 or \kernel_size <= 0:@@ -630,19 +624,19 @@ def get_motion_kernel2d(kernel_size: int, angle: Union[torch.Tensor, float],Shape:- Output: :math:`(ksize, ksize)`- Examples::- >>> kornia.filters.get_motion_kernel2d(5, 0., 0.)+ Examples:+ get_motion_kernel2d(5, 0., 0.)tensor([[0.0000, 0.0000, 0.0000, 0.0000, 0.0000],[0.0000, 0.0000, 0.0000, 0.0000, 0.0000],[0.2000, 0.2000, 0.2000, 0.2000, 0.2000],[0.0000, 0.0000, 0.0000, 0.0000, 0.0000],[0.0000, 0.0000, 0.0000, 0.0000, 0.0000]])- >>> kornia.filters.get_motion_kernel2d(3, 215., -0.5)- tensor([[0.0000, 0.0412, 0.0732],- [0.1920, 0.3194, 0.0804],- [0.2195, 0.0743, 0.0000]])+ get_motion_kernel2d(3, 215., -0.5)+ tensor([[0.0000, 0.0412, 0.0732],+ [0.1920, 0.3194, 0.0804],+ [0.2195, 0.0743, 0.0000]])"""-+ # TODO: Enable doctest after #782device, dtype = _extract_device_dtype([angle if isinstance(angle, torch.Tensor) else None,direction if isinstance(direction, torch.Tensor) else None,@@ -706,18 +700,19 @@ def get_motion_kernel3d(kernel_size: int, angle: Union[torch.Tensor, Tuple[floatShape:- Output: :math:`(ksize, ksize)`- Examples::- >>> kornia.filters.get_motion_kernel2d(5, 0., 0.)+ Examples:+ get_motion_kernel2d(5, 0., 0.)tensor([[0.0000, 0.0000, 0.0000, 0.0000, 0.0000],[0.0000, 0.0000, 0.0000, 0.0000, 0.0000],[0.2000, 0.2000, 0.2000, 0.2000, 0.2000],[0.0000, 0.0000, 0.0000, 0.0000, 0.0000],[0.0000, 0.0000, 0.0000, 0.0000, 0.0000]])- >>> kornia.filters.get_motion_kernel2d(3, 215., -0.5)- tensor([[0.0000, 0.0412, 0.0732],- [0.1920, 0.3194, 0.0804],- [0.2195, 0.0743, 0.0000]])+ get_motion_kernel2d(3, 215., -0.5)+ tensor([[0.0000, 0.0412, 0.0732],+ [0.1920, 0.3194, 0.0804],+ [0.2195, 0.0743, 0.0000]])"""+ # TODO: Enable doctest after #782if not isinstance(kernel_size, int) or kernel_size % 2 == 0 or kernel_size < 3:raise TypeError(f"ksize must be an odd integer >= than 3. Got {kernel_size}.")diff --git a/kornia/filters/laplacian.py b/kornia/filters/laplacian.pyindex b0c2de6d4..d9b5f5be5 100644--- a/kornia/filters/laplacian.py+++ b/kornia/filters/laplacian.py@@ -31,7 +31,7 @@ class Laplacian(nn.Module):Examples::>>> input = torch.rand(2, 4, 5, 5)- >>> laplace = kornia.filters.Laplacian(5)+ >>> laplace = Laplacian(5)>>> output = laplace(input) # 2x4x5x5"""diff --git a/kornia/filters/median.py b/kornia/filters/median.pyindex 4283f501e..a1cd30c19 100644--- a/kornia/filters/median.py+++ b/kornia/filters/median.py@@ -27,7 +27,7 @@ class MedianBlur(nn.Module):Example:>>> input = torch.rand(2, 4, 5, 7)- >>> blur = kornia.filters.MedianBlur((3, 3))+ >>> blur = MedianBlur((3, 3))>>> output = blur(input) # 2x4x5x7"""diff --git a/kornia/filters/motion.py b/kornia/filters/motion.pyindex 628e7f97a..0e3b66f56 100644--- a/kornia/filters/motion.py+++ b/kornia/filters/motion.py@@ -131,7 +131,7 @@ def motion_blur(>>> torch.allclose(out_1[0], out_1[1])True>>> # perform element-wise motion blur accross the batch- >>> out_1 = motion_blur(input, 5, torch.tensor([90., 180,]), torch.tensor([1, -1]))+ >>> out_1 = motion_blur(input, 5, torch.tensor([90., 180,]), torch.tensor([1., -1.]))>>> torch.allclose(out_1[0], out_1[1])False"""diff --git a/kornia/filters/sobel.py b/kornia/filters/sobel.pyindex eca461b87..bea48e94d 100644--- a/kornia/filters/sobel.py+++ b/kornia/filters/sobel.py@@ -19,7 +19,7 @@ class SpatialGradient(nn.Module):Examples:>>> input = torch.rand(1, 3, 4, 4)- >>> output = kornia.filters.SpatialGradient()(input) # 1x3x2x4x4+ >>> output = SpatialGradient()(input) # 1x3x2x4x4"""def __init__(self,@@ -78,7 +78,7 @@ class SpatialGradient3d(nn.Module):Examples:>>> input = torch.rand(1, 3, 4, 4)- >>> output = kornia.filters.SpatialGradient()(input) # 1x3x2x4x4+ >>> output = SpatialGradient()(input) # 1x3x2x4x4"""def __init__(self,@@ -136,7 +136,7 @@ class Sobel(nn.Module):Examples:>>> input = torch.rand(1, 3, 4, 4)- >>> output = kornia.filters.Sobel()(input) # 1x3x4x4+ >>> output = Sobel()(input) # 1x3x4x4"""def __init__(self,diff --git a/kornia/geometry/camera/pinhole.py b/kornia/geometry/camera/pinhole.pyindex 3ef418840..5b52c0611 100644--- a/kornia/geometry/camera/pinhole.py+++ b/kornia/geometry/camera/pinhole.py@@ -392,8 +392,13 @@ def pinhole_matrix(pinholes, eps=1e-6):- Output: :math:`(N, 4, 4)`Example:+ >>> rng = torch.manual_seed(0)>>> pinhole = torch.rand(1, 12) # Nx12- >>> pinhole_matrix = kornia.pinhole_matrix(pinhole) # Nx4x4+ >>> pinhole_matrix(pinhole) # Nx4x4+ tensor([[[4.9626e-01, 1.0000e-06, 8.8477e-02, 1.0000e-06],+ [1.0000e-06, 7.6822e-01, 1.3203e-01, 1.0000e-06],+ [1.0000e-06, 1.0000e-06, 1.0000e+00, 1.0000e-06],+ [1.0000e-06, 1.0000e-06, 1.0000e-06, 1.0000e+00]]])"""# warnings.warn("pinhole_matrix will be deprecated in version 0.2, "# "use PinholeCamera.camera_matrix instead",@@ -430,8 +435,13 @@ def inverse_pinhole_matrix(pinhole, eps=1e-6):- Output: :math:`(N, 4, 4)`Example:- >>> pinhole = torch.rand(1, 12) # Nx12- >>> pinhole_matrix_inv = kornia.inverse_pinhole_matrix(pinhole) # Nx4x4+ >>> rng = torch.manual_seed(0)+ >>> pinhole = torch.rand(1, 12) # Nx12+ >>> inverse_pinhole_matrix(pinhole) # Nx4x4+ tensor([[[ 2.0151, 0.0000, -0.1783, 0.0000],+ [ 0.0000, 1.3017, -0.1719, 0.0000],+ [ 0.0000, 0.0000, 1.0000, 0.0000],+ [ 0.0000, 0.0000, 0.0000, 1.0000]]])"""# warnings.warn("inverse_pinhole_matrix will be deprecated in version 0.2, "# "use PinholeCamera.intrinsics_inverse() instead",@@ -469,9 +479,12 @@ def scale_pinhole(pinholes, scale):- Output: :math:`(N, 12)`Example:+ >>> rng = torch.manual_seed(0)>>> pinhole_i = torch.rand(1, 12) # Nx12>>> scales = 2.0 * torch.ones(1) # N- >>> pinhole_i_scaled = kornia.scale_pinhole(pinhole_i) # Nx12+ >>> scale_pinhole(pinhole_i, scales) # Nx12+ tensor([[0.9925, 1.5364, 0.1770, 0.2641, 0.6148, 1.2682, 0.4901, 0.8964, 0.4556,+ 0.6323, 0.3489, 0.4017]])"""# warnings.warn("scale_pinhole will be deprecated in version 0.2, "# "use PinholeCamera.scale() instead",@@ -496,6 +509,7 @@ def get_optical_pose_base(pinholes):"""assert len(pinholes.shape) == 2 and pinholes.shape[1] == 12, pinholes.shapeoptical_pose_parent = pinholes[..., 6:]+ # TODO: where is rtvec_to_pose?return rtvec_to_pose(optical_pose_parent)@@ -534,7 +548,7 @@ def homography_i_H_ref(pinhole_i, pinhole_ref):Example:>>> pinhole_i = torch.rand(1, 12) # Nx12>>> pinhole_ref = torch.rand(1, 12) # Nx12- >>> i_H_ref = kornia.homography_i_H_ref(pinhole_i, pinhole_ref) # Nx4x4+ >>> homography_i_H_ref(pinhole_i, pinhole_ref) # Nx4x4"""assert len(pinhole_i.shape) == 2 and pinhole_i.shape[1] == 12, pinhole.shape@@ -638,7 +652,7 @@ def cam2pixel(Example:>>> pinhole = torch.rand(1, 12) # Nx12- >>> transform = kornia.PinholeMatrix()+ >>> transform = PinholeMatrix()>>> pinhole_matrix = transform(pinhole) # Nx4x4"""diff --git a/kornia/geometry/conversions.py b/kornia/geometry/conversions.pyindex 4739e27c1..163f6c96d 100644--- a/kornia/geometry/conversions.py+++ b/kornia/geometry/conversions.py@@ -38,8 +38,8 @@ def rad2deg(tensor: torch.Tensor) -> torch.Tensor:torch.Tensor: Tensor with same shape as input.Example:- >>> input = kornia.pi * torch.rand(1, 3, 3)- >>> output = kornia.rad2deg(input)+ >>> input = torch.tensor(3.1415926535) * torch.rand(1, 3, 3)+ >>> output = rad2deg(input)"""if not isinstance(tensor, torch.Tensor):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -60,7 +60,7 @@ def deg2rad(tensor: torch.Tensor) -> torch.Tensor:Examples::>>> input = 360. * torch.rand(1, 3, 3)- >>> output = kornia.deg2rad(input)+ >>> output = deg2rad(input)"""if not isinstance(tensor, torch.Tensor):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -76,7 +76,7 @@ def convert_points_from_homogeneous(Examples::>>> input = torch.rand(2, 4, 3) # BxNx3- >>> output = kornia.convert_points_from_homogeneous(input) # BxNx2+ >>> output = convert_points_from_homogeneous(input) # BxNx2"""if not isinstance(points, torch.Tensor):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -105,7 +105,7 @@ def convert_points_to_homogeneous(points: torch.Tensor) -> torch.Tensor:Examples::>>> input = torch.rand(2, 4, 3) # BxNx3- >>> output = kornia.convert_points_to_homogeneous(input) # BxNx4+ >>> output = convert_points_to_homogeneous(input) # BxNx4"""if not isinstance(points, torch.Tensor):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -129,7 +129,7 @@ def convert_affinematrix_to_homography(A: torch.Tensor) -> torch.Tensor:Examples::>>> input = torch.rand(2, 2, 3) # Bx2x3- >>> output = kornia.convert_affinematrix_to_homography(input) # Bx3x3+ >>> output = convert_affinematrix_to_homography(input) # Bx3x3"""if not isinstance(A, torch.Tensor):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -146,7 +146,7 @@ def convert_affinematrix_to_homography3d(A: torch.Tensor) -> torch.Tensor:Examples::>>> input = torch.rand(2, 3, 4) # Bx3x4- >>> output = kornia.convert_affinematrix_to_homography(input) # Bx4x4+ >>> output = convert_affinematrix_to_homography3d(input) # Bx4x4"""if not isinstance(A, torch.Tensor):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -172,7 +172,7 @@ def angle_axis_to_rotation_matrix(angle_axis: torch.Tensor) -> torch.Tensor:Example:>>> input = torch.rand(1, 3) # Nx3- >>> output = kornia.angle_axis_to_rotation_matrix(input) # Nx3x3+ >>> output = angle_axis_to_rotation_matrix(input) # Nx3x3"""if not isinstance(angle_axis, torch.Tensor):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -256,7 +256,7 @@ def rotation_matrix_to_angle_axis(Example:>>> input = torch.rand(2, 3, 3) # Nx3x3- >>> output = kornia.rotation_matrix_to_angle_axis(input) # Nx3+ >>> output = rotation_matrix_to_angle_axis(input) # Nx3"""if not isinstance(rotation_matrix, torch.Tensor):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -289,7 +289,7 @@ def rotation_matrix_to_quaternion(Example:>>> input = torch.rand(4, 3, 3) # Nx3x3- >>> output = kornia.rotation_matrix_to_quaternion(input) # Nx4+ >>> output = rotation_matrix_to_quaternion(input) # Nx4"""if not isinstance(rotation_matrix, torch.Tensor):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -370,7 +370,7 @@ def normalize_quaternion(quaternion: torch.Tensor,Example:>>> quaternion = torch.tensor([1., 0., 1., 0.])- >>> kornia.normalize_quaternion(quaternion)+ >>> normalize_quaternion(quaternion)tensor([0.7071, 0.0000, 0.7071, 0.0000])"""if not isinstance(quaternion, torch.Tensor):@@ -401,10 +401,10 @@ def quaternion_to_rotation_matrix(quaternion: torch.Tensor) -> torch.Tensor:Example:>>> quaternion = torch.tensor([0., 0., 1., 0.])- >>> kornia.quaternion_to_rotation_matrix(quaternion)- tensor([[[-1., 0., 0.],- [ 0., -1., 0.],- [ 0., 0., 1.]]])+ >>> quaternion_to_rotation_matrix(quaternion)+ tensor([[-1., 0., 0.],+ [ 0., -1., 0.],+ [ 0., 0., 1.]])"""if not isinstance(quaternion, torch.Tensor):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -464,7 +464,7 @@ def quaternion_to_angle_axis(quaternion: torch.Tensor) -> torch.Tensor:Example:>>> quaternion = torch.rand(2, 4) # Nx4- >>> angle_axis = kornia.quaternion_to_angle_axis(quaternion) # Nx3+ >>> angle_axis = quaternion_to_angle_axis(quaternion) # Nx3"""if not torch.is_tensor(quaternion):raise TypeError("Input type is not a torch.Tensor. Got {}".format(@@ -511,7 +511,7 @@ def quaternion_log_to_exp(quaternion: torch.Tensor,Example:>>> quaternion = torch.tensor([0., 0., 0.])- >>> kornia.quaternion_log_to_exp(quaternion)+ >>> quaternion_log_to_exp(quaternion)tensor([0., 0., 0., 1.])"""if not isinstance(quaternion, torch.Tensor):@@ -550,7 +550,7 @@ def quaternion_exp_to_log(quaternion: torch.Tensor,Example:>>> quaternion = torch.tensor([0., 0., 0., 1.])- >>> kornia.quaternion_exp_to_log(quaternion)+ >>> quaternion_exp_to_log(quaternion)tensor([0., 0., 0.])"""if not isinstance(quaternion, torch.Tensor):@@ -596,8 +596,8 @@ def angle_axis_to_quaternion(angle_axis: torch.Tensor) -> torch.Tensor:- Output: :math:`(*, 4)`Example:- >>> angle_axis = torch.rand(2, 4) # Nx4- >>> quaternion = kornia.angle_axis_to_quaternion(angle_axis) # Nx3+ >>> angle_axis = torch.rand(2, 3) # Nx3+ >>> quaternion = angle_axis_to_quaternion(angle_axis) # Nx4"""if not torch.is_tensor(angle_axis):raise TypeError("Input type is not a torch.Tensor. Got {}".format(diff --git a/kornia/geometry/linalg.py b/kornia/geometry/linalg.pyindex b4dbc0373..d371e9a2f 100644--- a/kornia/geometry/linalg.py+++ b/kornia/geometry/linalg.py@@ -44,7 +44,7 @@ def compose_transformations(Example::>>> trans_01 = torch.eye(4) # 4x4>>> trans_12 = torch.eye(4) # 4x4- >>> trans_02 = kornia.compose_transformations(trans_01, trans_12) # 4x4+ >>> trans_02 = compose_transformations(trans_01, trans_12) # 4x4"""if not torch.is_tensor(trans_01):@@ -103,7 +103,7 @@ def inverse_transformation(trans_12):Example:>>> trans_12 = torch.rand(1, 4, 4) # Nx4x4- >>> trans_21 = kornia.inverse_transformation(trans_12) # Nx4x4+ >>> trans_21 = inverse_transformation(trans_12) # Nx4x4"""if not torch.is_tensor(trans_12):raise TypeError("Input type is not a torch.Tensor. Got {}"@@ -155,7 +155,7 @@ def relative_transformation(Example::>>> trans_01 = torch.eye(4) # 4x4>>> trans_02 = torch.eye(4) # 4x4- >>> trans_12 = kornia.relative_transformation(trans_01, trans_02) # 4x4+ >>> trans_12 = relative_transformation(trans_01, trans_02) # 4x4"""if not torch.is_tensor(trans_01):raise TypeError("Input trans_01 type is not a torch.Tensor. Got {}"@@ -195,7 +195,7 @@ def transform_points(trans_01: torch.Tensor,>>> points_1 = torch.rand(2, 4, 3) # BxNx3>>> trans_01 = torch.eye(4).view(1, 4, 4) # Bx4x4- >>> points_0 = kornia.transform_points(trans_01, points_1) # BxNx3+ >>> points_0 = transform_points(trans_01, points_1) # BxNx3"""check_is_tensor(trans_01)check_is_tensor(points_1)@@ -287,10 +287,37 @@ def perspective_transform_lafs(trans_01: torch.Tensor,- Output: :math:`(B, N, 2, 3)`Examples:-+ >>> rng = torch.manual_seed(0)>>> lafs_1 = torch.rand(2, 4, 2, 3) # BxNx2x3- >>> trans_01 = torch.eye(3).view(1, 3, 3) # Bx3x3- >>> lafs_0 = kornia.perspective_transform_lafs(trans_01, lafs_1) # BxNx2x3+ >>> lafs_1+ tensor([[[[0.4963, 0.7682, 0.0885],+ [0.1320, 0.3074, 0.6341]],+ <BLANKLINE>+ [[0.4901, 0.8964, 0.4556],+ [0.6323, 0.3489, 0.4017]],+ <BLANKLINE>+ [[0.0223, 0.1689, 0.2939],+ [0.5185, 0.6977, 0.8000]],+ <BLANKLINE>+ [[0.1610, 0.2823, 0.6816],+ [0.9152, 0.3971, 0.8742]]],+ <BLANKLINE>+ <BLANKLINE>+ [[[0.4194, 0.5529, 0.9527],+ [0.0362, 0.1852, 0.3734]],+ <BLANKLINE>+ [[0.3051, 0.9320, 0.1759],+ [0.2698, 0.1507, 0.0317]],+ <BLANKLINE>+ [[0.2081, 0.9298, 0.7231],+ [0.7423, 0.5263, 0.2437]],+ <BLANKLINE>+ [[0.5846, 0.0332, 0.1387],+ [0.2422, 0.8155, 0.7932]]]])+ >>> trans_01 = torch.eye(3).repeat(2, 1, 1) # Bx3x3+ >>> trans_01.shape+ torch.Size([2, 3, 3])+ >>> lafs_0 = perspective_transform_lafs(trans_01, lafs_1) # BxNx2x3"""kornia.feature.laf.raise_error_if_laf_is_not_valid(lafs_1)if not torch.is_tensor(trans_01):diff --git a/kornia/geometry/subpix/dsnt.py b/kornia/geometry/subpix/dsnt.pyindex b8a207899..2aab133c7 100644--- a/kornia/geometry/subpix/dsnt.py+++ b/kornia/geometry/subpix/dsnt.py@@ -38,10 +38,21 @@ def spatial_softmax2d(Shape:- Input: :math:`(B, N, H, W)`- Output: :math:`(B, N, H, W)`++ Examples:+ >>> heatmaps = torch.tensor([[[+ ... [0., 0., 0.],+ ... [0., 0., 0.],+ ... [0., 1., 2.]]]])+ >>> spatial_softmax2d(heatmaps)+ tensor([[[[0.0585, 0.0585, 0.0585],+ [0.0585, 0.0585, 0.0585],+ [0.0585, 0.1589, 0.4319]]]])"""_validate_batched_image_tensor_input(input)batch_size, channels, height, width = input.shape+ temperature = temperature.to(device=input.device, dtype=input.dtype)x: torch.Tensor = input.view(batch_size, channels, -1)x_soft: torch.Tensor = F.softmax(x * temperature, dim=-1)@@ -75,11 +86,11 @@ def spatial_expectation2d(Examples:>>> heatmaps = torch.tensor([[[- [0., 0., 0.],- [0., 0., 0.],- [0., 1., 0.]]]])- >>> coords = spatial_expectation_2d(heatmaps, False)- tensor([[[1.0000, 2.0000]]])+ ... [0., 0., 0.],+ ... [0., 0., 0.],+ ... [0., 1., 0.]]]])+ >>> spatial_expectation2d(heatmaps, False)+ tensor([[[1., 2.]]])"""_validate_batched_image_tensor_input(input)diff --git a/kornia/geometry/subpix/spatial_soft_argmax.py b/kornia/geometry/subpix/spatial_soft_argmax.pyindex 1be8f4305..e127ac7e3 100644--- a/kornia/geometry/subpix/spatial_soft_argmax.py+++ b/kornia/geometry/subpix/spatial_soft_argmax.py@@ -262,7 +262,7 @@ def conv_soft_argmax2d(input: torch.Tensor,Examples::>>> input = torch.randn(20, 16, 50, 32)- >>> nms_coords, nms_val = conv_soft_argmax2d(input, (3,3), (2,2), (1,1))+ >>> nms_coords, nms_val = conv_soft_argmax2d(input, (3,3), (2,2), (1,1), output_value=True)"""if not torch.is_tensor(input):raise TypeError("Input type is not a torch.Tensor. Got {}"@@ -391,7 +391,7 @@ def conv_soft_argmax3d(input: torch.Tensor,Examples:>>> input = torch.randn(20, 16, 3, 50, 32)- >>> nms_coords, nms_val = conv_soft_argmax2d(input, (3, 3, 3), (1, 2, 2), (0, 1, 1))+ >>> nms_coords, nms_val = conv_soft_argmax3d(input, (3, 3, 3), (1, 2, 2), (0, 1, 1))"""if not torch.is_tensor(input):raise TypeError("Input type is not a torch.Tensor. Got {}"@@ -506,10 +506,10 @@ def spatial_soft_argmax2d(Examples:>>> input = torch.tensor([[[- [0., 0., 0.],- [0., 10., 0.],- [0., 0., 0.]]]])- >>> coords = kornia.spatial_soft_argmax2d(input, False)+ ... [0., 0., 0.],+ ... [0., 10., 0.],+ ... [0., 0., 0.]]]])+ >>> spatial_soft_argmax2d(input, normalized_coordinates=False)tensor([[[1.0000, 1.0000]]])"""input_soft: torch.Tensor = dsnt.spatial_softmax2d(input, temperature)diff --git a/kornia/geometry/transform/__init__.py b/kornia/geometry/transform/__init__.pyindex 9b888a33a..903db82c0 100644--- a/kornia/geometry/transform/__init__.py+++ b/kornia/geometry/transform/__init__.py@@ -1,4 +1,6 @@-from kornia.geometry.transform.crop import *+from kornia.geometry.transform import crop+from kornia.geometry.transform.crop.crop2d import *+from kornia.geometry.transform.crop.crop3d import *from kornia.geometry.transform.imgwarp import *from kornia.geometry.transform.pyramid import *from kornia.geometry.transform.affwarp import *diff --git a/kornia/geometry/transform/crop/crop2d.py b/kornia/geometry/transform/crop/crop2d.pyindex ab1476f54..8586b51c0 100644--- a/kornia/geometry/transform/crop/crop2d.py+++ b/kornia/geometry/transform/crop/crop2d.py@@ -37,21 +37,21 @@ def crop_and_resize(tensor: torch.Tensor, boxes: torch.Tensor, size: Tuple[int,torch.Tensor: tensor containing the patches with shape BxCxN1xN2.Example:- >>> input = torch.tensor([[- [1., 2., 3., 4.],- [5., 6., 7., 8.],- [9., 10., 11., 12.],- [13., 14., 15., 16.],- ]])+ >>> input = torch.tensor([[[+ ... [1., 2., 3., 4.],+ ... [5., 6., 7., 8.],+ ... [9., 10., 11., 12.],+ ... [13., 14., 15., 16.],+ ... ]]])>>> boxes = torch.tensor([[- [1., 1.],- [2., 1.],- [2., 2.],- [1., 2.],- ]]) # 1x4x2- >>> kornia.crop_and_resize(input, boxes, (2, 2))- tensor([[[ 6.0000, 7.0000],- [ 10.0000, 11.0000]]])+ ... [1., 1.],+ ... [2., 1.],+ ... [2., 2.],+ ... [1., 2.],+ ... ]]) # 1x4x2+ >>> crop_and_resize(input, boxes, (2, 2), interpolation='nearest', align_corners=True)+ tensor([[[[ 6., 7.],+ [10., 11.]]]])"""if not isinstance(tensor, torch.Tensor):raise TypeError("Input tensor type is not a torch.Tensor. Got {}"@@ -98,15 +98,15 @@ def center_crop(tensor: torch.Tensor, size: Tuple[int, int],torch.Tensor: the output tensor with patches.Examples:- >>> input = torch.tensor([[- [1., 2., 3., 4.],- [5., 6., 7., 8.],- [9., 10., 11., 12.],- [13., 14., 15., 16.],- ]])- >>> kornia.center_crop(input, (2, 4))- tensor([[[ 5.0000, 6.0000, 7.0000, 8.0000],- [ 9.0000, 10.0000, 11.0000, 12.0000]]])+ >>> input = torch.tensor([[[+ ... [1., 2., 3., 4.],+ ... [5., 6., 7., 8.],+ ... [9., 10., 11., 12.],+ ... [13., 14., 15., 16.],+ ... ]]])+ >>> center_crop(input, (2, 4), interpolation='nearest', align_corners=True)+ tensor([[[[ 5., 6., 7., 8.],+ [ 9., 10., 11., 12.]]]])"""if not isinstance(tensor, torch.Tensor):raise TypeError("Input tensor type is not a torch.Tensor. Got {}"@@ -180,7 +180,7 @@ def crop_by_boxes(tensor: torch.Tensor, src_box: torch.Tensor, dst_box: torch.Tetorch.Tensor: the output tensor with patches.Examples:- >>> input = torch.arange(16, dtype=torch.float32).reshape((1, 4, 4))+ >>> input = torch.arange(16, dtype=torch.float32).reshape((1, 1, 4, 4))>>> src_box = torch.tensor([[... [1., 1.],... [2., 1.],@@ -194,8 +194,8 @@ def crop_by_boxes(tensor: torch.Tensor, src_box: torch.Tensor, dst_box: torch.Te... [0., 1.],... ]]) # 1x4x2>>> crop_by_boxes(input, src_box, dst_box, align_corners=True)- tensor([[[ 5.0000, 6.0000],- [ 9.0000, 10.0000]]])+ tensor([[[[ 5.0000, 6.0000],+ [ 9.0000, 10.0000]]]])Note:If the src_box is smaller than dst_box, the following error will be thrown.@@ -345,14 +345,14 @@ def bbox_generator(>>> height = torch.tensor([7, 4])>>> bbox_generator(x_start, y_start, width, height)tensor([[[0, 1],- [4, 1],- [4, 7],- [0, 7]],+ [5, 1],+ [5, 8],+ [0, 8]],<BLANKLINE>[[1, 0],- [3, 0],- [3, 3],- [1, 3]]])+ [4, 0],+ [4, 4],+ [1, 4]]])"""assert x_start.shape == y_start.shape and x_start.dim() in [0, 1], \f"`x_start` and `y_start` must be a scalar or (B,). Got {x_start}, {y_start}."diff --git a/kornia/geometry/transform/crop/crop3d.py b/kornia/geometry/transform/crop/crop3d.pyindex 16ab552e0..3da3626cb 100644--- a/kornia/geometry/transform/crop/crop3d.py+++ b/kornia/geometry/transform/crop/crop3d.py@@ -246,7 +246,7 @@ def crop_by_boxes3d(tensor: torch.Tensor, src_box: torch.Tensor, dst_box: torch.torch.Tensor: the output tensor with patches.Examples:- >>> input = torch.tensor([[+ >>> input = torch.tensor([[[... [[ 0., 1., 2., 3.],... [ 4., 5., 6., 7.],... [ 8., 9., 10., 11.],@@ -258,7 +258,7 @@ def crop_by_boxes3d(tensor: torch.Tensor, src_box: torch.Tensor, dst_box: torch.... [[32., 33., 34., 35.],... [36., 37., 38., 39.],... [40., 41., 42., 43.],- ... [44., 45., 46., 47.]]]])+ ... [44., 45., 46., 47.]]]]])>>> src_box = torch.tensor([[... [1., 1., 1.],... [3., 1., 1.],@@ -280,13 +280,13 @@ def crop_by_boxes3d(tensor: torch.Tensor, src_box: torch.Tensor, dst_box: torch.... [0., 2., 1.],... ]]) # 1x8x3>>> crop_by_boxes3d(input, src_box, dst_box, interpolation='nearest', align_corners=True)- tensor([[[[21., 22., 23.],- [25., 26., 27.],- [29., 30., 31.]],+ tensor([[[[[21., 22., 23.],+ [25., 26., 27.],+ [29., 30., 31.]],<BLANKLINE>- [[37., 38., 39.],- [41., 42., 43.],- [45., 46., 47.]]]])+ [[37., 38., 39.],+ [41., 42., 43.],+ [45., 46., 47.]]]]])"""validate_bboxes3d(src_box)diff --git a/kornia/geometry/transform/flips.py b/kornia/geometry/transform/flips.pyindex fd15b3b4b..cc284af87 100644--- a/kornia/geometry/transform/flips.py+++ b/kornia/geometry/transform/flips.py@@ -13,14 +13,16 @@ class Vflip(nn.Module):torch.Tensor: The vertically flipped image tensorExamples:+ >>> vflip = Vflip()>>> input = torch.tensor([[[- [0., 0., 0.],- [0., 0., 0.],- [0., 1., 1.]]]])- >>> kornia.vflip(input)- tensor([[[0, 1, 1],- [0, 0, 0],- [0, 0, 0]]])+ ... [0., 0., 0.],+ ... [0., 0., 0.],+ ... [0., 1., 1.]+ ... ]]])+ >>> vflip(input)+ tensor([[[[0., 1., 1.],+ [0., 0., 0.],+ [0., 0., 0.]]]])"""def __init__(self) -> None:@@ -45,14 +47,16 @@ class Hflip(nn.Module):torch.Tensor: The horizontally flipped image tensorExamples:+ >>> hflip = Hflip()>>> input = torch.tensor([[[- [0., 0., 0.],- [0., 0., 0.],- [0., 1., 1.]]]])- >>> kornia.hflip(input)- tensor([[[0, 0, 0],- [0, 0, 0],- [1, 1, 0]]])+ ... [0., 0., 0.],+ ... [0., 0., 0.],+ ... [0., 1., 1.]+ ... ]]])+ >>> hflip(input)+ tensor([[[[0., 0., 0.],+ [0., 0., 0.],+ [1., 1., 0.]]]])"""def __init__(self) -> None:@@ -68,22 +72,24 @@ class Hflip(nn.Module):class Rot180(nn.Module):r"""Rotate a tensor image or a batch of tensor images- 180 degrees. Input must be a tensor of shape (C, H, W)- or a batch of tensors :math:`(*, C, H, W)`.-- Args:- input (torch.Tensor): input tensor-- Examples:- >>> input = torch.tensor([[[- [0., 0., 0.],- [0., 0., 0.],- [0., 1., 1.]]]])- >>> kornia.rot180(input)- tensor([[[1, 1, 0],- [0, 0, 0],- [0, 0, 0]]])- """+ 180 degrees. Input must be a tensor of shape (C, H, W)+ or a batch of tensors :math:`(*, C, H, W)`.++ Args:+ input (torch.Tensor): input tensor++ Examples:+ >>> rot180 = Rot180()+ >>> input = torch.tensor([[[+ ... [0., 0., 0.],+ ... [0., 0., 0.],+ ... [0., 1., 1.]+ ... ]]])+ >>> rot180(input)+ tensor([[[[1., 1., 0.],+ [0., 0., 0.],+ [0., 0., 0.]]]])+ """def __init__(self) -> None:diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.pyindex 3ef2501a0..2bb172c4d 100644--- a/kornia/geometry/transform/imgwarp.py+++ b/kornia/geometry/transform/imgwarp.py@@ -266,7 +266,7 @@ def angle_to_rotation_matrix(angle: torch.Tensor) -> torch.Tensor:Example:>>> input = torch.rand(1, 3) # Nx3- >>> output = kornia.angle_to_rotation_matrix(input) # Nx3x2x2+ >>> output = angle_to_rotation_matrix(input) # Nx3x2x2"""ang_rad = deg2rad(angle)cos_a: torch.Tensor = torch.cos(ang_rad)@@ -391,10 +391,11 @@ def remap(tensor: torch.Tensor, map_x: torch.Tensor,torch.Tensor: the warped tensor.Example:- >>> grid = kornia.utils.create_meshgrid(2, 2, False) # 1x2x2x2+ >>> from kornia.utils import create_meshgrid+ >>> grid = create_meshgrid(2, 2, False) # 1x2x2x2>>> grid += 1 # apply offset in both directions>>> input = torch.ones(1, 1, 2, 2)- >>> kornia.remap(input, grid[..., 0], grid[..., 1]) # 1x1x2x2+ >>> remap(input, grid[..., 0], grid[..., 1], align_corners=True) # 1x1x2x2tensor([[[[1., 0.],[0., 0.]]]])diff --git a/kornia/geometry/transform/pyramid.py b/kornia/geometry/transform/pyramid.pyindex 3429df9c7..ce994c940 100644--- a/kornia/geometry/transform/pyramid.py+++ b/kornia/geometry/transform/pyramid.py@@ -48,7 +48,7 @@ class PyrDown(nn.Module):Examples:>>> input = torch.rand(1, 2, 4, 4)- >>> output = kornia.transform.PyrDown()(input) # 1x2x2x2+ >>> output = PyrDown()(input) # 1x2x2x2"""def __init__(self, border_type: str = 'reflect', align_corners: bool = False) -> None:@@ -92,7 +92,7 @@ class PyrUp(nn.Module):Examples:>>> input = torch.rand(1, 2, 4, 4)- >>> output = kornia.transform.PyrUp()(input) # 1x2x8x8+ >>> output = PyrUp()(input) # 1x2x8x8"""def __init__(self, border_type: str = 'reflect', align_corners: bool = False):@@ -141,7 +141,7 @@ class ScalePyramid(nn.Module):Examples::>>> input = torch.rand(2, 4, 100, 100)- >>> sp, sigmas, pds = kornia.ScalePyramid(3, 15)(input)+ >>> sp, sigmas, pds = ScalePyramid(3, 15)(input)"""def __init__(self,diff --git a/kornia/geometry/warp/depth_warper.py b/kornia/geometry/warp/depth_warper.pyindex 5a4d713f8..9603c480f 100644--- a/kornia/geometry/warp/depth_warper.py+++ b/kornia/geometry/warp/depth_warper.py@@ -183,11 +183,13 @@ class DepthWarper(nn.Module):Example:>>> # pinholes camera models- >>> pinhole_dst = kornia.PinholeCamera(...)- >>> pinhole_src = kornia.PinholeCamera(...)+ >>> pinhole_dst = PinholeCamera(torch.randn(1, 4, 4), torch.randn(1, 4, 4),+ ... torch.tensor([32]), torch.tensor([32]))+ >>> pinhole_src = PinholeCamera(torch.randn(1, 4, 4), torch.randn(1, 4, 4),+ ... torch.tensor([32]), torch.tensor([32]))>>> # create the depth warper, compute the projection matrix- >>> warper = kornia.DepthWarper(pinhole_dst, height, width)- >>> warper.compute_projection_matrix(pinhole_src)+ >>> warper = DepthWarper(pinhole_dst, 32, 32)+ >>> _ = warper.compute_projection_matrix(pinhole_src)>>> # warp the destionation frame to reference by depth>>> depth_src = torch.ones(1, 1, 32, 32) # Nx1xHxW>>> image_dst = torch.rand(1, 3, 32, 32) # NxCxHxW@@ -213,13 +215,14 @@ def depth_warp(pinhole_dst: PinholeCamera,Example:>>> # pinholes camera models- >>> pinhole_dst = kornia.PinholeCamera(...)- >>> pinhole_src = kornia.PinholeCamera(...)+ >>> pinhole_dst = PinholeCamera(torch.randn(1, 4, 4), torch.randn(1, 4, 4),+ ... torch.tensor([32]), torch.tensor([32]))+ >>> pinhole_src = PinholeCamera(torch.randn(1, 4, 4), torch.randn(1, 4, 4),+ ... torch.tensor([32]), torch.tensor([32]))>>> # warp the destionation frame to reference by depth>>> depth_src = torch.ones(1, 1, 32, 32) # Nx1xHxW>>> image_dst = torch.rand(1, 3, 32, 32) # NxCxHxW- >>> image_src = kornia.depth_warp(pinhole_dst, pinhole_src,- >>> depth_src, image_dst, height, width) # NxCxHxW+ >>> image_src = depth_warp(pinhole_dst, pinhole_src, depth_src, image_dst, 32, 32) # NxCxHxW"""warper = DepthWarper(pinhole_dst, height, width, align_corners=align_corners)warper.compute_projection_matrix(pinhole_src)diff --git a/kornia/geometry/warp/homography_warper.py b/kornia/geometry/warp/homography_warper.pyindex f3102de11..ca3d8dd03 100644--- a/kornia/geometry/warp/homography_warper.py+++ b/kornia/geometry/warp/homography_warper.py@@ -104,7 +104,7 @@ def homography_warp(patch_src: torch.Tensor,Example:>>> input = torch.rand(1, 3, 32, 32)>>> homography = torch.eye(3).view(1, 3, 3)- >>> output = kornia.homography_warp(input, homography, (32, 32))+ >>> output = homography_warp(input, homography, (32, 32))"""if not src_homo_dst.device == patch_src.device:raise TypeError("Patch and homography must be on the same device. \@@ -150,7 +150,7 @@ def homography_warp3d(patch_src: torch.Tensor,Example:>>> input = torch.rand(1, 3, 32, 32)>>> homography = torch.eye(3).view(1, 3, 3)- >>> output = kornia.homography_warp(input, homography, (32, 32))+ >>> output = homography_warp(input, homography, (32, 32))"""if not src_homo_dst.device == patch_src.device:raise TypeError("Patch and homography must be on the same device. \@@ -247,7 +247,7 @@ class HomographyWarper(nn.Module):Example:>>> input = torch.rand(1, 3, 32, 32)>>> homography = torch.eye(3).view(1, 3, 3)- >>> warper = kornia.HomographyWarper(32, 32)+ >>> warper = HomographyWarper(32, 32)>>> # without precomputing the warp>>> output = warper(input, homography) # NxCxHxW>>> # precomputing the warpdiff --git a/kornia/losses/depth_smooth.py b/kornia/losses/depth_smooth.pyindex 05c6e2f7e..a6d428e5a 100644--- a/kornia/losses/depth_smooth.py+++ b/kornia/losses/depth_smooth.py@@ -90,7 +90,7 @@ class InverseDepthSmoothnessLoss(nn.Module):>>> idepth = torch.rand(1, 1, 4, 5)>>> image = torch.rand(1, 3, 4, 5)- >>> smooth = kornia.losses.DepthSmoothnessLoss()+ >>> smooth = InverseDepthSmoothnessLoss()>>> loss = smooth(idepth, image)"""diff --git a/kornia/losses/dice.py b/kornia/losses/dice.pyindex 6e05a56b9..07fc22c7f 100644--- a/kornia/losses/dice.py+++ b/kornia/losses/dice.py@@ -77,7 +77,7 @@ class DiceLoss(nn.Module):Examples:>>> N = 5 # num_classes- >>> loss = kornia.losses.DiceLoss()+ >>> loss = DiceLoss()>>> input = torch.randn(1, N, 3, 5, requires_grad=True)>>> target = torch.empty(1, 3, 5, dtype=torch.long).random_(N)>>> output = loss(input, target)diff --git a/kornia/losses/focal.py b/kornia/losses/focal.pyindex 84e95495e..977b18d96 100644--- a/kornia/losses/focal.py+++ b/kornia/losses/focal.py@@ -99,7 +99,7 @@ class FocalLoss(nn.Module):Examples:>>> N = 5 # num_classes>>> kwargs = {"alpha": 0.5, "gamma": 2.0, "reduction": 'mean'}- >>> loss = kornia.losses.FocalLoss(**kwargs)+ >>> loss = FocalLoss(**kwargs)>>> input = torch.randn(1, N, 3, 5, requires_grad=True)>>> target = torch.empty(1, 3, 5, dtype=torch.long).random_(N)>>> output = loss(input, target)diff --git a/kornia/losses/psnr.py b/kornia/losses/psnr.pyindex f7fd881b2..ce91d374c 100644--- a/kornia/losses/psnr.py+++ b/kornia/losses/psnr.py@@ -29,8 +29,8 @@ class PSNRLoss(nn.Module):- output: :math:`()` a scalarExamples:- >>> kornia.losses.psnr_loss(torch.ones(1), 1.2*torch.ones(1), 2)- tensor(20.0000) # 10 * log(4/((1.2-1)**2)) / log(10)+ >>> psnr_loss(torch.ones(1), 1.2*torch.ones(1), 2) # 10 * log(4/((1.2-1)**2)) / log(10)+ tensor(20.0000)Reference:https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio#Definitiondiff --git a/kornia/losses/ssim.py b/kornia/losses/ssim.pyindex 1a073fb96..d9c6c6358 100644--- a/kornia/losses/ssim.py+++ b/kornia/losses/ssim.py@@ -56,7 +56,7 @@ class SSIM(nn.Module):>>> input1 = torch.rand(1, 4, 5, 5)>>> input2 = torch.rand(1, 4, 5, 5)- >>> ssim = kornia.losses.SSIM(5, reduction='none')+ >>> ssim = SSIM(5, reduction='none')>>> loss = ssim(input1, input2) # 1x4x5x5"""diff --git a/kornia/losses/total_variation.py b/kornia/losses/total_variation.pyindex a71618635..4abacfab5 100644--- a/kornia/losses/total_variation.py+++ b/kornia/losses/total_variation.py@@ -10,10 +10,13 @@ class TotalVariation(nn.Module):- Output: :math:`(N,)` or :math:`()`Examples:- >>> kornia.losses.total_variation(torch.ones(3,4,4)) # tensor(0.)- >>> tv = kornia.losses.TotalVariation()- >>> output = tv(torch.ones(2,3,4,4)) # tensor([0., 0.])- >>> output.backward()+ >>> total_variation(torch.ones(3, 4, 4))+ tensor(0.)+ >>> tv = TotalVariation()+ >>> output = tv(torch.ones((2, 3, 4, 4), requires_grad=True))+ >>> output.data+ tensor([0., 0.])+ >>> output.sum().backward() # grad can be implicitly created only for scalar outputsReference:[1] https://en.wikipedia.org/wiki/Total_variationdiff --git a/kornia/losses/tversky.py b/kornia/losses/tversky.pyindex 9991a73ca..0a0d0b051 100644--- a/kornia/losses/tversky.py+++ b/kornia/losses/tversky.py@@ -81,7 +81,7 @@ class TverskyLoss(nn.Module):Examples:>>> N = 5 # num_classes- >>> loss = kornia.losses.TverskyLoss(alpha=0.5, beta=0.5)+ >>> loss = TverskyLoss(alpha=0.5, beta=0.5)>>> input = torch.randn(1, N, 3, 5, requires_grad=True)>>> target = torch.empty(1, 3, 5, dtype=torch.long).random_(N)>>> output = loss(input, target)diff --git a/kornia/utils/one_hot.py b/kornia/utils/one_hot.pyindex 2531166eb..958e935b4 100644--- a/kornia/utils/one_hot.py+++ b/kornia/utils/one_hot.py@@ -27,13 +27,16 @@ def one_hot(labels: torch.Tensor,Examples::>>> labels = torch.LongTensor([[[0, 1], [2, 0]]])- >>> kornia.losses.one_hot(labels, num_classes=3)- tensor([[[[1., 0.],- [0., 1.]],- [[0., 1.],- [0., 0.]],- [[0., 0.],- [1., 0.]]]]+ >>> one_hot(labels, num_classes=3)+ tensor([[[[1.0000e+00, 1.0000e-06],+ [1.0000e-06, 1.0000e+00]],+ <BLANKLINE>+ [[1.0000e-06, 1.0000e+00],+ [1.0000e-06, 1.0000e-06]],+ <BLANKLINE>+ [[1.0000e-06, 1.0000e-06],+ [1.0000e+00, 1.0000e-06]]]])+"""if not torch.is_tensor(labels):raise TypeError("Input labels type is not a torch.Tensor. Got {}"