Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

[pre-commit.ci] pre-commit suggestions (#2174)

pre-commit-ci[bot]f139cfe0ab09
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 933e6e790..93afdfd2c 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -66,7 +66,7 @@ repos:
- "B101,B311"
- repo: https://github.com/PyCQA/docformatter
- rev: v1.5.1
+ rev: v1.6.0.rc1
hooks:
- id: docformatter
args: [--in-place, --wrap-summaries=115, --wrap-descriptions=120]
diff --git a/kornia/augmentation/container/ops.py b/kornia/augmentation/container/ops.py
index 3fa230ee8..b8e2f2353 100644
--- a/kornia/augmentation/container/ops.py
+++ b/kornia/augmentation/container/ops.py
@@ -130,7 +130,6 @@ class AugmentationSequentialOps:
def make_input_only_sequential(module: 'kornia.augmentation.ImageSequential') -> Callable[..., Tensor]:
"""Disable all other additional inputs (e.g. ) for ImageSequential."""
-
def f(*args, **kwargs):
out = module(*args, **kwargs)
return out
@@ -221,7 +220,6 @@ class MaskSequentialOps(SequentialOpsInterface[Tensor]):
to apply transformations.
param: the corresponding parameters to the module.
"""
-
if isinstance(module, (GeometricAugmentationBase2D,)):
if module.transform_matrix is None:
raise ValueError(f"No valid transformation matrix found in {module.__class__}.")
diff --git a/kornia/augmentation/utils/helpers.py b/kornia/augmentation/utils/helpers.py
index 082543758..b7f166116 100644
--- a/kornia/augmentation/utils/helpers.py
+++ b/kornia/augmentation/utils/helpers.py
@@ -19,7 +19,6 @@ def _validate_input(f: Callable[..., Any]) -> Callable[..., Any]:
Returns:
the wrapped function after input is validated.
"""
-
@wraps(f)
def wrapper(input: Tensor, *args, **kwargs):
if not torch.is_tensor(input):
@@ -42,7 +41,6 @@ def _validate_input3d(f: Callable[..., Any]) -> Callable[..., Any]:
Returns:
the wrapped function after input is validated.
"""
-
@wraps(f)
def wrapper(input: Tensor, *args, **kwargs):
if not torch.is_tensor(input):
diff --git a/kornia/color/rgb.py b/kornia/color/rgb.py
index e311b003e..e8b4d377f 100644
--- a/kornia/color/rgb.py
+++ b/kornia/color/rgb.py
@@ -190,7 +190,6 @@ def rgb_to_linear_rgb(image: torch.Tensor) -> torch.Tensor:
>>> input = torch.rand(2, 3, 4, 5)
>>> output = rgb_to_linear_rgb(input) # 2x3x4x5
"""
-
if not isinstance(image, torch.Tensor):
raise TypeError(f"Input type is not a torch.Tensor. Got {type(image)}")
@@ -215,7 +214,6 @@ def linear_rgb_to_rgb(image: torch.Tensor) -> torch.Tensor:
>>> input = torch.rand(2, 3, 4, 5)
>>> output = linear_rgb_to_rgb(input) # 2x3x4x5
"""
-
if not isinstance(image, torch.Tensor):
raise TypeError(f"Input type is not a torch.Tensor. Got {type(image)}")
diff --git a/kornia/color/yuv.py b/kornia/color/yuv.py
index e1d738708..6172cce5b 100644
--- a/kornia/color/yuv.py
+++ b/kornia/color/yuv.py
@@ -155,7 +155,6 @@ def yuv420_to_rgb(imagey: torch.Tensor, imageuv: torch.Tensor) -> torch.Tensor:
>>> inputuv = torch.rand(2, 2, 2, 3)
>>> output = yuv420_to_rgb(inputy, inputuv) # 2x3x4x6
"""
-
if not isinstance(imagey, torch.Tensor):
raise TypeError(f"Input type is not a torch.Tensor. Got {type(imagey)}")
@@ -206,7 +205,6 @@ def yuv422_to_rgb(imagey: torch.Tensor, imageuv: torch.Tensor) -> torch.Tensor:
>>> inputuv = torch.rand(2, 2, 2, 3)
>>> output = yuv420_to_rgb(inputy, inputuv) # 2x3x4x5
"""
-
if not isinstance(imagey, torch.Tensor):
raise TypeError(f"Input type is not a torch.Tensor. Got {type(imagey)}")
diff --git a/kornia/contrib/histogram_matching.py b/kornia/contrib/histogram_matching.py
index 06a16030a..9bf8058a2 100644
--- a/kornia/contrib/histogram_matching.py
+++ b/kornia/contrib/histogram_matching.py
@@ -19,7 +19,6 @@ def histogram_matching(source: torch.Tensor, template: torch.Tensor) -> torch.Te
Note:
This function does not matches histograms element-wisely if input a batched tensor.
"""
-
oldshape = source.shape
source = source.ravel()
template = template.ravel()
diff --git a/kornia/enhance/adjust.py b/kornia/enhance/adjust.py
index 44886ba97..6a2de22a7 100644
--- a/kornia/enhance/adjust.py
+++ b/kornia/enhance/adjust.py
@@ -16,7 +16,6 @@ def adjust_saturation_raw(image: Tensor, factor: Union[float, Tensor]) -> Tensor
Expecting image to be in hsv format already.
"""
-
KORNIA_CHECK_IS_TENSOR(image, "Expected shape (*, H, W)")
KORNIA_CHECK(isinstance(factor, (float, Tensor)), "Factor should be float or Tensor.")
@@ -70,7 +69,6 @@ def adjust_saturation_with_gray_subtraction(image: Tensor, factor: Union[float,
>>> adjust_saturation_with_gray_subtraction(x, y).shape
torch.Size([2, 3, 3, 3])
"""
-
KORNIA_CHECK_IS_TENSOR(image, "Expected shape (*, H, W)")
KORNIA_CHECK(isinstance(factor, (float, Tensor)), "Factor should be float or Tensor.")
KORNIA_CHECK_IS_COLOR_OR_GRAY(image, "Image should be an RGB or gray image")
@@ -129,7 +127,6 @@ def adjust_saturation(image: Tensor, factor: Union[float, Tensor]) -> Tensor:
>>> adjust_saturation(x, y).shape
torch.Size([2, 3, 3, 3])
"""
-
# convert the rgb image to hsv
x_hsv: Tensor = rgb_to_hsv(image)
@@ -147,7 +144,6 @@ def adjust_hue_raw(image: Tensor, factor: Union[float, Tensor]) -> Tensor:
Expecting image to be in hsv format already.
"""
-
KORNIA_CHECK_IS_TENSOR(image, "Expected shape (*, H, W)")
KORNIA_CHECK(
isinstance(factor, (float, Tensor)),
@@ -207,7 +203,6 @@ def adjust_hue(image: Tensor, factor: Union[float, Tensor]) -> Tensor:
>>> adjust_hue(x, y).shape
torch.Size([2, 3, 3, 3])
"""
-
# convert the rgb image to hsv
x_hsv: Tensor = rgb_to_hsv(image)
@@ -253,7 +248,6 @@ def adjust_gamma(input: Tensor, gamma: Union[float, Tensor], gain: Union[float,
>>> adjust_gamma(x, y1, y2).shape
torch.Size([2, 5, 3, 3])
"""
-
if not isinstance(input, Tensor):
raise TypeError(f"Input type is not a Tensor. Got {type(input)}")
diff --git a/kornia/enhance/histogram.py b/kornia/enhance/histogram.py
index f663c0c97..36a8216a8 100644
--- a/kornia/enhance/histogram.py
+++ b/kornia/enhance/histogram.py
@@ -61,7 +61,6 @@ def joint_pdf(kernel_values1: torch.Tensor, kernel_values2: torch.Tensor, epsilo
Returns:
shape [BxNUM_BINSxNUM_BINS].
"""
-
if not isinstance(kernel_values1, torch.Tensor):
raise TypeError(f"Input kernel_values1 type is not a torch.Tensor. Got {type(kernel_values1)}")
@@ -108,7 +107,6 @@ def histogram(x: torch.Tensor, bins: torch.Tensor, bandwidth: torch.Tensor, epsi
>>> hist.shape
torch.Size([1, 128])
"""
-
pdf, _ = marginal_pdf(x.unsqueeze(2), bins, bandwidth, epsilon)
return pdf
diff --git a/kornia/enhance/shift_rgb.py b/kornia/enhance/shift_rgb.py
index e6088af3f..7f4c43a6c 100644
--- a/kornia/enhance/shift_rgb.py
+++ b/kornia/enhance/shift_rgb.py
@@ -8,7 +8,6 @@ def shift_rgb(image: torch.Tensor, r_shift: torch.Tensor, g_shift: torch.Tensor,
Shift each image's channel by either r_shift for red, g_shift for green and b_shift for blue channels.
"""
-
KORNIA_CHECK_IS_TENSOR(image)
KORNIA_CHECK_IS_COLOR(image, f"with shape {image.shape}")
diff --git a/kornia/enhance/zca.py b/kornia/enhance/zca.py
index c967c77e5..2a2860743 100644
--- a/kornia/enhance/zca.py
+++ b/kornia/enhance/zca.py
@@ -95,7 +95,6 @@ class ZCAWhitening(Module):
returns:
Returns a fitted ZCAWhiten object instance.
"""
-
T, mean, T_inv = zca_mean(x, self.dim, self.unbiased, self.eps, self.compute_inv)
self.mean_vector = mean
@@ -124,7 +123,6 @@ class ZCAWhitening(Module):
Returns:
The transformed data.
"""
-
if include_fit:
self.fit(x)
@@ -144,7 +142,6 @@ class ZCAWhitening(Module):
Returns:
Original data.
"""
-
if not self.fitted:
raise RuntimeError("Needs to be fitted first before running. Please call fit or set include_fit to True.")
@@ -286,7 +283,6 @@ def zca_whiten(inp: Tensor, dim: int = 0, unbiased: bool = True, eps: float = 1e
[ 1.0000, -0.5773],
[-1.0000, -0.5773]])
"""
-
if not isinstance(inp, Tensor):
raise TypeError(f"Input type is not a Tensor. Got {type(inp)}")
@@ -346,7 +342,6 @@ def linear_transform(inp: Tensor, transform_matrix: Tensor, mean_vector: Tensor,
>>> print(out.shape, out.unique()) # Should a be (10,2) tensor of 2s
torch.Size([10, 2]) tensor([2.])
"""
-
inp_size = inp.size()
if dim >= len(inp_size) or dim < -len(inp_size):
diff --git a/kornia/feature/integrated.py b/kornia/feature/integrated.py
index 3ea67722e..16ae5a13c 100644
--- a/kornia/feature/integrated.py
+++ b/kornia/feature/integrated.py
@@ -150,7 +150,8 @@ class SIFTFeature(LocalFeature):
"""Convenience module, which implements DoG detector + (Root)SIFT descriptor.
Using `kornia.feature.MultiResolutionDetector` without blur pyramid Still not as good as OpenCV/VLFeat because of
- https://github.com/kornia/kornia/pull/884, but we are working on it
+ https://github.com/kornia/kornia/pull/884,
+ but we are working on it
"""
def __init__(
diff --git a/kornia/feature/loftr/loftr.py b/kornia/feature/loftr/loftr.py
index 52c771958..ed8fb6ba7 100644
--- a/kornia/feature/loftr/loftr.py
+++ b/kornia/feature/loftr/loftr.py
@@ -116,7 +116,6 @@ class LoFTR(Module):
- ``confidence``, confidence score [0, 1] :math:`(NC)`.
- ``batch_indexes``, batch indexes for the keypoints and lafs :math:`(NC)`.
"""
-
# 1. Local Feature CNN
_data: Dict[str, Union[Tensor, int, torch.Size]] = {
'bs': data['image0'].size(0),
diff --git a/kornia/feature/loftr/loftr_module/linear_attention.py b/kornia/feature/loftr/loftr_module/linear_attention.py
index dcba7319f..c5ed6dc74 100644
--- a/kornia/feature/loftr/loftr_module/linear_attention.py
+++ b/kornia/feature/loftr/loftr_module/linear_attention.py
@@ -73,7 +73,6 @@ class FullAttention(Module):
Returns:
queried_values: (N, L, H, D)
"""
-
# Compute the unnormalized attention and apply the masks
QK = torch.einsum("nlhd,nshd->nlsh", queries, keys)
if kv_mask is not None:
diff --git a/kornia/feature/loftr/loftr_module/transformer.py b/kornia/feature/loftr/loftr_module/transformer.py
index ff4211fc8..0b1c37ec1 100644
--- a/kornia/feature/loftr/loftr_module/transformer.py
+++ b/kornia/feature/loftr/loftr_module/transformer.py
@@ -89,7 +89,6 @@ class LocalFeatureTransformer(nn.Module):
mask0 (torch.Tensor): [N, L] (optional)
mask1 (torch.Tensor): [N, S] (optional)
"""
-
if self.d_model != feat0.size(2):
msg = "the feature number of src and transformer must be equal"
raise ValueError(msg)
diff --git a/kornia/feature/mkd.py b/kornia/feature/mkd.py
index 8dd4626f2..9f07e6dcd 100644
--- a/kornia/feature/mkd.py
+++ b/kornia/feature/mkd.py
@@ -473,7 +473,6 @@ class Whitening(nn.Module):
def _modify_lw(self) -> None:
"""No modification required."""
-
def _modify_pcaws(self) -> None:
"""Shrinkage for eigenvalues."""
alpha = self.evals[self.keval]
diff --git a/kornia/filters/kernels.py b/kornia/filters/kernels.py
index 585072477..034f1be8f 100644
--- a/kornia/filters/kernels.py
+++ b/kornia/filters/kernels.py
@@ -403,7 +403,6 @@ def get_gaussian_kernel1d_t(kernel_size: int, sigma: torch.Tensor, force_even: b
tensor([[0.1201, 0.2339, 0.2921, 0.2339, 0.1201],
[0.0096, 0.2054, 0.5699, 0.2054, 0.0096]])
"""
-
if not isinstance(kernel_size, int) or ((kernel_size % 2 == 0) and not force_even) or (kernel_size <= 0):
raise TypeError("kernel_size must be an odd positive integer. " "Got {}".format(kernel_size))
diff --git a/kornia/geometry/camera/stereo.py b/kornia/geometry/camera/stereo.py
index 122bbfb80..5be257243 100644
--- a/kornia/geometry/camera/stereo.py
+++ b/kornia/geometry/camera/stereo.py
@@ -254,7 +254,6 @@ def _check_Q_matrix(Q_matrix: Tensor):
Args:
Q_matrix: The Q matrix for reprojecting disparity to a point cloud of shape :math:`(B, 4, 4)`
"""
-
if not isinstance(Q_matrix, Tensor):
raise StereoException(f"Expected 'Q_matrix' to be an instance of Tensor but got {type(Q_matrix)}.")
diff --git a/kornia/geometry/keypoints.py b/kornia/geometry/keypoints.py
index 735552149..ca55d2670 100644
--- a/kornia/geometry/keypoints.py
+++ b/kornia/geometry/keypoints.py
@@ -138,7 +138,6 @@ class Keypoints:
Returns:
Keypoints tensor :math:`(B, N, 2)`
"""
-
if as_padded_sequence:
raise NotImplementedError
return self._data
@@ -273,7 +272,6 @@ class Keypoints3D:
Returns:
Keypoints tensor :math:`(B, N, 3)`
"""
-
if as_padded_sequence:
raise NotImplementedError
return self._data
diff --git a/kornia/geometry/transform/flips.py b/kornia/geometry/transform/flips.py
index eae60eea0..db81e48dc 100644
--- a/kornia/geometry/transform/flips.py
+++ b/kornia/geometry/transform/flips.py
@@ -108,7 +108,6 @@ def rot180(input: Tensor) -> Tensor:
Returns:
The rotated image tensor.
"""
-
return torch.flip(input, [-2, -1])
@@ -142,6 +141,5 @@ def vflip(input: Tensor) -> Tensor:
Returns:
The vertically flipped image tensor.
"""
-
h = input.shape[-2]
return input[..., torch.arange(h - 1, -1, -1, device=input.device), :]
diff --git a/kornia/losses/psnr.py b/kornia/losses/psnr.py
index 895b44b05..e091ac729 100644
--- a/kornia/losses/psnr.py
+++ b/kornia/losses/psnr.py
@@ -28,7 +28,6 @@ def psnr_loss(input: torch.Tensor, target: torch.Tensor, max_val: float) -> torc
>>> psnr_loss(ones, 1.2 * ones, 2.) # 10 * log(4/((1.2-1)**2)) / log(10)
tensor(-20.0000)
"""
-
return -1.0 * metrics.psnr(input, target, max_val)
diff --git a/kornia/nerf/camera_utils.py b/kornia/nerf/camera_utils.py
index 5660ec353..05283e7e7 100755
--- a/kornia/nerf/camera_utils.py
+++ b/kornia/nerf/camera_utils.py
@@ -138,7 +138,6 @@ def create_spiral_path(cameras: PinholeCamera, rad: float, num_views: int, num_c
num_views: Number of created cameras: int
num_circles: Number of spiral circles: int
"""
-
# Average locations over all cameras
mean_center = cameras.translation_vector.mean(0, False).squeeze(-1)
device = cameras.intrinsics.device
diff --git a/kornia/nerf/data_utils.py b/kornia/nerf/data_utils.py
index 2d06a513b..b7394301e 100755
--- a/kornia/nerf/data_utils.py
+++ b/kornia/nerf/data_utils.py
@@ -161,7 +161,6 @@ def instantiate_ray_dataloader(dataset: RayDataset, batch_size: int = 1, shuffle
batch_size: Number of rays to sample in a batch: int
shuffle: Whether to shuffle rays or sample then sequentially: bool
"""
-
def collate_rays(items: List[RayGroup]) -> RayGroup:
return items[0]
diff --git a/kornia/nerf/rays.py b/kornia/nerf/rays.py
index 985dc365a..94caa5035 100755
--- a/kornia/nerf/rays.py
+++ b/kornia/nerf/rays.py
@@ -96,7 +96,6 @@ class RaySampler:
cameras: scene cameras: PinholeCamera
points_2d_camera: a dictionary that groups Point2D objects by total number of casted rays
"""
-
# Unproject 2d points in image plane to 3d world for two depths
origins = []
directions = []
diff --git a/kornia/testing/__init__.py b/kornia/testing/__init__.py
index 1eb63147f..58566fafc 100644
--- a/kornia/testing/__init__.py
+++ b/kornia/testing/__init__.py
@@ -320,7 +320,6 @@ def KORNIA_CHECK_SHAPE(x: Tensor, shape: List[str]) -> None:
>>> x = torch.rand(2, 3, 4, 4)
>>> KORNIA_CHECK_SHAPE(x, ["2","3", "H", "W"]) # explicit
"""
-
if '*' == shape[0]:
shape_to_check = shape[1:]
x_shape_to_check = x.shape[-len(shape) + 1 :]
diff --git a/kornia/utils/draw.py b/kornia/utils/draw.py
index e7bffbc67..64fd20cf2 100644
--- a/kornia/utils/draw.py
+++ b/kornia/utils/draw.py
@@ -47,7 +47,6 @@ def draw_line(image: torch.Tensor, p1: torch.Tensor, p2: torch.Tensor, color: to
[ 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0.]]])
"""
-
if (len(p1) != 2) or (len(p2) != 2):
raise ValueError("p1 and p2 must have length 2.")
@@ -220,7 +219,6 @@ def _get_convex_edges(polygon: Tensor, h: int, w: int) -> Tuple[Tensor, Tensor]:
Returns:
The left and right edges of the polygon of shape (B,B).
"""
-
dtype = polygon.dtype
# Check if polygons are in loop closed format, if not -> make it so
diff --git a/kornia/utils/image.py b/kornia/utils/image.py
index 4cc989b15..b42864601 100644
--- a/kornia/utils/image.py
+++ b/kornia/utils/image.py
@@ -215,7 +215,6 @@ def perform_keep_shape_image(f: Callable[..., Tensor]) -> Callable[..., Tensor]:
It works by first viewing the image as `(B, C, H, W)`, applying the function and re-viewing the image as original
shape.
"""
-
@wraps(f)
def _wrapper(input: Tensor, *args, **kwargs) -> Tensor:
if not isinstance(input, Tensor):
@@ -247,7 +246,6 @@ def perform_keep_shape_video(f: Callable[..., Tensor]) -> Callable[..., Tensor]:
It works by first viewing the image as `(B, C, D, H, W)`, applying the function and re-viewing the image as original
shape.
"""
-
@wraps(f)
def _wrapper(input: Tensor, *args, **kwargs) -> Tensor:
if not isinstance(input, Tensor):
diff --git a/test/enhance/test_zca.py b/test/enhance/test_zca.py
index f1ff21bb7..e16f3d28f 100644
--- a/test/enhance/test_zca.py
+++ b/test/enhance/test_zca.py
@@ -59,7 +59,6 @@ class TestZCA(BaseTester):
@pytest.mark.parametrize("input_shape,eps", [((15, 2, 2, 2), 1e-6), ((10, 4), 0.1), ((20, 3, 2, 2), 1e-3)])
def test_identity(self, input_shape, eps, device, dtype):
"""Assert that data can be recovered by the inverse transform."""
-
data = torch.randn(*input_shape, device=device, dtype=dtype)
zca = kornia.enhance.ZCAWhitening(compute_inv=True, eps=eps).fit(data)
@@ -72,7 +71,6 @@ class TestZCA(BaseTester):
def test_grad_zca_individual_transforms(self, device, dtype):
"""Check if the gradients of the transforms are correct w.r.t to the input data."""
-
data = torch.tensor([[2, 0], [0, 1], [-2, 0], [0, -1]], device=device, dtype=dtype)
data = utils.tensor_to_gradcheck_var(data)