🐍 Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Update precommit hooks (#2521)
João Gustavo A. Amorim2933cc57b307
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex d0a8d2f7f..0e23127cc 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -15,12 +15,12 @@ repos:exclude: ^$|.devcontainer- repo: https://github.com/tox-dev/pyproject-fmt- rev: "0.13.0"+ rev: "0.13.1"hooks:- id: pyproject-fmt- repo: https://github.com/astral-sh/ruff-pre-commit- rev: v0.0.282+ rev: v0.0.284hooks:- id: ruffargs: [--fix, --exit-non-zero-on-fix]diff --git a/kornia/augmentation/_2d/geometric/center_crop.py b/kornia/augmentation/_2d/geometric/center_crop.pyindex 95c32cb09..6789bebb9 100644--- a/kornia/augmentation/_2d/geometric/center_crop.py+++ b/kornia/augmentation/_2d/geometric/center_crop.py@@ -77,7 +77,7 @@ class CenterCrop(GeometricAugmentationBase2D):elif isinstance(size, int):self.size = (size, size)else:- raise Exception(f"Invalid size type. Expected (int, tuple(int, int). " f"Got: {type(size)}.")+ raise Exception(f"Invalid size type. Expected (int, tuple(int, int). Got: {type(size)}.")self.flags = {"resample": Resample.get(resample),diff --git a/kornia/augmentation/_2d/geometric/pad.py b/kornia/augmentation/_2d/geometric/pad.pyindex 5c18f0db8..dcd568cc6 100644--- a/kornia/augmentation/_2d/geometric/pad.py+++ b/kornia/augmentation/_2d/geometric/pad.py@@ -1,4 +1,4 @@-from typing import Any, Dict, Optional, Tuple, Union+from typing import Any, Dict, Optional, Tupleimport torchfrom torch import Tensor@@ -46,7 +46,7 @@ class PadTo(GeometricAugmentationBase2D):"""def __init__(- self, size: Tuple[int, int], pad_mode: str = "constant", pad_value: Union[int, float] = 0, keepdim: bool = False+ self, size: Tuple[int, int], pad_mode: str = "constant", pad_value: float = 0, keepdim: bool = False) -> None:super().__init__(p=1.0, same_on_batch=True, p_batch=1.0, keepdim=keepdim)self.flags = {"size": size, "pad_mode": pad_mode, "pad_value": pad_value}diff --git a/kornia/augmentation/_2d/intensity/normalize.py b/kornia/augmentation/_2d/intensity/normalize.pyindex e3b1908c8..577f118ce 100644--- a/kornia/augmentation/_2d/intensity/normalize.py+++ b/kornia/augmentation/_2d/intensity/normalize.py@@ -41,8 +41,8 @@ class Normalize(IntensityAugmentationBase2D):def __init__(self,- mean: Tensor | tuple[float | int] | list[float | int] | float | int,- std: Tensor | tuple[float | int] | list[float | int] | float | int,+ mean: Tensor | tuple[float] | list[float] | float,+ std: Tensor | tuple[float] | list[float] | float,p: float = 1.0,keepdim: bool = False,) -> None:diff --git a/kornia/augmentation/random_generator/_2d/color_jiggle.py b/kornia/augmentation/random_generator/_2d/color_jiggle.pyindex 9e1228fed..46b16180a 100644--- a/kornia/augmentation/random_generator/_2d/color_jiggle.py+++ b/kornia/augmentation/random_generator/_2d/color_jiggle.py@@ -51,10 +51,7 @@ class ColorJiggleGenerator(RandomGeneratorBase):self.hue = huedef __repr__(self) -> str:- repr = (- f"brightness={self.brightness}, contrast={self.contrast}, saturation=" f"{self.saturation}, hue={self.hue}"- )- return repr+ return f"brightness={self.brightness}, contrast={self.contrast}, saturation={self.saturation}, hue={self.hue}"def make_samplers(self, device: torch.device, dtype: torch.dtype) -> None:brightness = _range_bound(self.brightness, 'brightness', center=1.0, bounds=(0, 2), device=device, dtype=dtype)diff --git a/kornia/augmentation/random_generator/_2d/color_jitter.py b/kornia/augmentation/random_generator/_2d/color_jitter.pyindex b2f61d322..a1a565560 100644--- a/kornia/augmentation/random_generator/_2d/color_jitter.py+++ b/kornia/augmentation/random_generator/_2d/color_jitter.py@@ -55,10 +55,7 @@ class ColorJitterGenerator(RandomGeneratorBase):self.hue = huedef __repr__(self) -> str:- repr = (- f"brightness={self.brightness}, contrast={self.contrast}, saturation=" f"{self.saturation}, hue={self.hue}"- )- return repr+ return f"brightness={self.brightness}, contrast={self.contrast}, saturation={self.saturation}, hue={self.hue}"def make_samplers(self, device: torch.device, dtype: torch.dtype) -> None:brightness: Tensor = _range_bound(self.brightness, 'brightness', center=1.0, device=device, dtype=dtype)diff --git a/kornia/augmentation/random_generator/_2d/crop.py b/kornia/augmentation/random_generator/_2d/crop.pyindex ba4a24cbc..9a6b0f904 100644--- a/kornia/augmentation/random_generator/_2d/crop.py+++ b/kornia/augmentation/random_generator/_2d/crop.py@@ -274,7 +274,7 @@ def center_crop_generator(_common_param_check(batch_size)if not isinstance(size, (tuple, list)) and len(size) == 2:raise ValueError(f"Input size must be a tuple/list of length 2. Got {size}")- if not (type(height) is int and height > 0 and type(width) is int and width > 0):+ if not (isinstance(height, int) and height > 0 and isinstance(width, int) and width > 0):raise AssertionError(f"'height' and 'width' must be integers. Got {height}, {width}.")if not (height >= size[0] and width >= size[1]):raise AssertionError(f"Crop size must be smaller than input size. Got ({height}, {width}) and {size}.")diff --git a/kornia/augmentation/random_generator/_2d/cutmix.py b/kornia/augmentation/random_generator/_2d/cutmix.pyindex fa3f2ea17..ddf12a182 100644--- a/kornia/augmentation/random_generator/_2d/cutmix.py+++ b/kornia/augmentation/random_generator/_2d/cutmix.py@@ -80,7 +80,7 @@ class CutmixGenerator(RandomGeneratorBase):height = batch_shape[-2]width = batch_shape[-1]- if not (type(height) is int and height > 0 and type(width) is int and width > 0):+ if not (isinstance(height, int) and height > 0 and isinstance(width, int) and width > 0):raise AssertionError(f"'height' and 'width' must be integers. Got {height}, {width}.")_device, _dtype = _extract_device_dtype([self.beta, self.cut_size])_common_param_check(batch_size, same_on_batch)diff --git a/kornia/augmentation/random_generator/_2d/perspective.py b/kornia/augmentation/random_generator/_2d/perspective.pyindex de7066b2b..c832496ec 100644--- a/kornia/augmentation/random_generator/_2d/perspective.py+++ b/kornia/augmentation/random_generator/_2d/perspective.py@@ -58,7 +58,7 @@ class PerspectiveGenerator(RandomGeneratorBase):_device, _dtype = _extract_device_dtype([self.distortion_scale])_common_param_check(batch_size, same_on_batch)- if not (type(height) is int and height > 0 and type(width) is int and width > 0):+ if not (isinstance(height, int) and height > 0 and isinstance(width, int) and width > 0):raise AssertionError(f"'height' and 'width' must be integers. Got {height}, {width}.")start_points: Tensor = tensor(diff --git a/kornia/augmentation/random_generator/_2d/rectangle_earase.py b/kornia/augmentation/random_generator/_2d/rectangle_earase.pyindex 5cd4b0eca..99967a2fd 100644--- a/kornia/augmentation/random_generator/_2d/rectangle_earase.py+++ b/kornia/augmentation/random_generator/_2d/rectangle_earase.py@@ -75,7 +75,7 @@ class RectangleEraseGenerator(RandomGeneratorBase):batch_size = batch_shape[0]height = batch_shape[-2]width = batch_shape[-1]- if not (type(height) is int and height > 0 and type(width) is int and width > 0):+ if not (isinstance(height, int) and height > 0 and isinstance(width, int) and width > 0):raise AssertionError(f"'height' and 'width' must be integers. Got {height}, {width}.")_common_param_check(batch_size, same_on_batch)diff --git a/kornia/augmentation/random_generator/_3d/affine.py b/kornia/augmentation/random_generator/_3d/affine.pyindex c5ad03e29..eec40b9a7 100644--- a/kornia/augmentation/random_generator/_3d/affine.py+++ b/kornia/augmentation/random_generator/_3d/affine.py@@ -150,7 +150,12 @@ class AffineGenerator3D(RandomGeneratorBase):width = batch_shape[-1]if not (- type(depth) is int and depth > 0 and type(height) is int and height > 0 and type(width) is int and width > 0+ isinstance(depth, int)+ and depth > 0+ and isinstance(height, int)+ and height > 0+ and isinstance(width, int)+ and width > 0):raise AssertionError(f"'depth', 'height' and 'width' must be integers. Got {depth}, {height}, {width}.")diff --git a/kornia/augmentation/random_generator/_3d/crop.py b/kornia/augmentation/random_generator/_3d/crop.pyindex cf3bbd184..4eeb6c41c 100644--- a/kornia/augmentation/random_generator/_3d/crop.py+++ b/kornia/augmentation/random_generator/_3d/crop.py@@ -165,7 +165,12 @@ def center_crop_generator3d(if not isinstance(size, (tuple, list)) and len(size) == 3:raise ValueError(f"Input size must be a tuple/list of length 3. Got {size}")if not (- type(depth) is int and depth > 0 and type(height) is int and height > 0 and type(width) is int and width > 0+ isinstance(depth, int)+ and depth > 0+ and isinstance(height, int)+ and height > 0+ and isinstance(width, int)+ and width > 0):raise AssertionError(f"'depth', 'height' and 'width' must be integers. Got {depth}, {height}, {width}.")if not (depth >= size[0] and height >= size[1] and width >= size[2]):diff --git a/kornia/augmentation/utils/helpers.py b/kornia/augmentation/utils/helpers.pyindex e17bf6467..3e8f03c82 100644--- a/kornia/augmentation/utils/helpers.py+++ b/kornia/augmentation/utils/helpers.py@@ -228,8 +228,8 @@ def _adapted_sampling(def _adapted_uniform(shape: Union[Tuple[int, ...], torch.Size],- low: Union[float, int, Tensor],- high: Union[float, int, Tensor],+ low: Union[float, Tensor],+ high: Union[float, Tensor],same_on_batch: bool = False,) -> Tensor:r"""The uniform sampling function that accepts 'same_on_batch'.@@ -253,8 +253,8 @@ def _adapted_uniform(def _adapted_beta(shape: Union[Tuple[int, ...], torch.Size],- a: Union[float, int, Tensor],- b: Union[float, int, Tensor],+ a: Union[float, Tensor],+ b: Union[float, Tensor],same_on_batch: bool = False,) -> Tensor:r"""The beta sampling function that accepts 'same_on_batch'.diff --git a/kornia/augmentation/utils/param_validation.py b/kornia/augmentation/utils/param_validation.pyindex 9777cbd44..78e825141 100644--- a/kornia/augmentation/utils/param_validation.py+++ b/kornia/augmentation/utils/param_validation.py@@ -7,9 +7,9 @@ from kornia.core import Tensor, as_tensor, tensordef _common_param_check(batch_size: int, same_on_batch: Optional[bool] = None) -> None:"""Valid batch_size and same_on_batch params."""- if not (type(batch_size) is int and batch_size >= 0):+ if not (isinstance(batch_size, int) and batch_size >= 0):raise AssertionError(f"`batch_size` shall be a positive integer. Got {batch_size}.")- if same_on_batch is not None and type(same_on_batch) is not bool:+ if same_on_batch is not None and not isinstance(same_on_batch, bool):raise AssertionError(f"`same_on_batch` shall be boolean. Got {same_on_batch}.")@@ -62,9 +62,7 @@ def _joint_range_check(ranged_factor: Tensor, name: str, bounds: Optional[Tuple[if not bounds[0] <= ranged_factor[0] <= ranged_factor[1] <= bounds[1]:raise ValueError(f"{name}[0] should be smaller than {name}[1] got {ranged_factor}")else:- raise TypeError(- f"{name} should be a tensor with length 2 whose values between {bounds}. " f"Got {ranged_factor}."- )+ raise TypeError(f"{name} should be a tensor with length 2 whose values between {bounds}. Got {ranged_factor}.")def _singular_range_check(diff --git a/kornia/color/gray.py b/kornia/color/gray.pyindex bb3b8fa32..f37f4e38c 100644--- a/kornia/color/gray.py+++ b/kornia/color/gray.py@@ -27,7 +27,7 @@ def grayscale_to_rgb(image: Tensor) -> Tensor:KORNIA_CHECK_IS_TENSOR(image)if len(image.shape) < 3 or image.shape[-3] != 1:- raise ValueError(f"Input size must have a shape of (*, 1, H, W). " f"Got {image.shape}.")+ raise ValueError(f"Input size must have a shape of (*, 1, H, W). Got {image.shape}.")return concatenate([image, image, image], -3)diff --git a/kornia/color/raw.py b/kornia/color/raw.pyindex f62d63c2a..b2d9fa2b9 100644--- a/kornia/color/raw.py+++ b/kornia/color/raw.py@@ -47,10 +47,10 @@ def raw_to_rgb(image: torch.Tensor, cfa: CFA) -> torch.Tensor:>>> rgb = raw_to_rgb(rawinput, CFA.RG) # 2x3x4x6"""if not isinstance(image, torch.Tensor):- raise TypeError(f"Input type is not a torch.Tensor. " f"Got {type(image)}")+ raise TypeError(f"Input type is not a torch.Tensor. Got {type(image)}")if image.dim() < 3 or image.size(-3) != 1:- raise ValueError(f"Input size must have a shape of (*, 1, H, W). " f"Got {image.shape}.")+ raise ValueError(f"Input size must have a shape of (*, 1, H, W). Got {image.shape}.")if len(image.shape) < 2 or image.shape[-2] % 2 == 1 or image.shape[-1] % 2 == 1:raise ValueError(f"Input H&W must be evenly disible by 2. Got {image.shape}")@@ -82,7 +82,7 @@ def raw_to_rgb(image: torch.Tensor, cfa: CFA) -> torch.Tensor:rpad = (0, 1, 1, 0)bpad = (1, 0, 0, 1)else:- raise ValueError(f"Unsupported CFA " f"Got {cfa}.")+ raise ValueError(f"Unsupported CFA Got {cfa}.")# upscaling r and b with bi-linear gives reasonable quality# Note that depending on where these are sampled we need to pad appropriately@@ -157,7 +157,7 @@ def raw_to_rgb(image: torch.Tensor, cfa: CFA) -> torch.Tensor:g_up[:, :, 1::2, 1::2] = image[:, :, 1::2, 1::2]g_up[:, :, ::2, ::2] = image[:, :, ::2, ::2]else:- raise ValueError(f"Unsupported CFA " f"Got {cfa}.")+ raise ValueError(f"Unsupported CFA Got {cfa}.")r_up = r_up.view(imagesize)g_up = g_up.view(imagesize)diff --git a/kornia/color/yuv.py b/kornia/color/yuv.pyindex 7f9dddd8b..8f322efd1 100644--- a/kornia/color/yuv.py+++ b/kornia/color/yuv.py@@ -177,7 +177,7 @@ def yuv420_to_rgb(imagey: torch.Tensor, imageuv: torch.Tensor) -> torch.Tensor:or imagey.shape[-1] / imageuv.shape[-1] != 2):raise ValueError(- f"Input imageuv H&W must be half the size of the luma plane. " f"Got {imagey.shape} and {imageuv.shape}"+ f"Input imageuv H&W must be half the size of the luma plane. Got {imagey.shape} and {imageuv.shape}")# first upsample@@ -222,7 +222,7 @@ def yuv422_to_rgb(imagey: torch.Tensor, imageuv: torch.Tensor) -> torch.Tensor:if len(imageuv.shape) < 2 or len(imagey.shape) < 2 or imagey.shape[-1] / imageuv.shape[-1] != 2:raise ValueError(- f"Input imageuv W must be half the size of the luma plane. " f"Got {imagey.shape} and {imageuv.shape}"+ f"Input imageuv W must be half the size of the luma plane. Got {imagey.shape} and {imageuv.shape}")# first upsamplediff --git a/kornia/enhance/adjust.py b/kornia/enhance/adjust.pyindex 8f04fd01c..7e73637b8 100644--- a/kornia/enhance/adjust.py+++ b/kornia/enhance/adjust.py@@ -146,7 +146,7 @@ def adjust_hue_raw(image: Tensor, factor: Union[float, Tensor]) -> Tensor:KORNIA_CHECK_IS_TENSOR(image, "Expected shape (*, H, W)")KORNIA_CHECK(isinstance(factor, (float, Tensor)),- f"The factor should be a float number or Tensor in the range between" f" [-PI, PI]. Got {type(factor)}",+ f"The factor should be a float number or Tensor in the range between [-PI, PI]. Got {type(factor)}",)if isinstance(factor, float):@@ -612,7 +612,7 @@ def _solarize(input: Tensor, thresholds: Union[float, Tensor] = 0.5) -> Tensor:raise TypeError(f"Input type is not a Tensor. Got {type(input)}")if not isinstance(thresholds, (float, Tensor)):- raise TypeError(f"The factor should be either a float or Tensor. " f"Got {type(thresholds)}")+ raise TypeError(f"The factor should be either a float or Tensor. Got {type(thresholds)}")if isinstance(thresholds, Tensor) and len(thresholds.shape) != 0:if not (input.size(0) == len(thresholds) and len(thresholds.shape) == 1):@@ -663,14 +663,14 @@ def solarize(raise TypeError(f"Input type is not a Tensor. Got {type(input)}")if not isinstance(thresholds, (float, Tensor)):- raise TypeError(f"The factor should be either a float or Tensor. " f"Got {type(thresholds)}")+ raise TypeError(f"The factor should be either a float or Tensor. Got {type(thresholds)}")if isinstance(thresholds, float):thresholds = torch.as_tensor(thresholds)if additions is not None:if not isinstance(additions, (float, Tensor)):- raise TypeError(f"The factor should be either a float or Tensor. " f"Got {type(additions)}")+ raise TypeError(f"The factor should be either a float or Tensor. Got {type(additions)}")if isinstance(additions, float):additions = torch.as_tensor(additions)diff --git a/kornia/enhance/histogram.py b/kornia/enhance/histogram.pyindex 36a8216a8..4684a60e6 100644--- a/kornia/enhance/histogram.py+++ b/kornia/enhance/histogram.py@@ -31,13 +31,13 @@ def marginal_pdf(raise TypeError(f"Input sigma type is not a torch.Tensor. Got {type(sigma)}")if not values.dim() == 3:- raise ValueError("Input values must be a of the shape BxNx1." " Got {}".format(values.shape))+ raise ValueError(f"Input values must be a of the shape BxNx1. Got {values.shape}")if not bins.dim() == 1:- raise ValueError("Input bins must be a of the shape NUM_BINS" " Got {}".format(bins.shape))+ raise ValueError(f"Input bins must be a of the shape NUM_BINS. Got {bins.shape}")if not sigma.dim() == 0:- raise ValueError("Input sigma must be a of the shape 1" " Got {}".format(sigma.shape))+ raise ValueError(f"Input sigma must be a of the shape 1. Got {sigma.shape}")residuals = values - bins.unsqueeze(0).unsqueeze(0)kernel_values = torch.exp(-0.5 * (residuals / sigma).pow(2))@@ -68,15 +68,15 @@ def joint_pdf(kernel_values1: torch.Tensor, kernel_values2: torch.Tensor, epsiloraise TypeError(f"Input kernel_values2 type is not a torch.Tensor. Got {type(kernel_values2)}")if not kernel_values1.dim() == 3:- raise ValueError("Input kernel_values1 must be a of the shape BxN." " Got {}".format(kernel_values1.shape))+ raise ValueError(f"Input kernel_values1 must be a of the shape BxN. Got {kernel_values1.shape}")if not kernel_values2.dim() == 3:- raise ValueError("Input kernel_values2 must be a of the shape BxN." " Got {}".format(kernel_values2.shape))+ raise ValueError(f"Input kernel_values2 must be a of the shape BxN. Got {kernel_values2.shape}")if kernel_values1.shape != kernel_values2.shape:raise ValueError("Inputs kernel_values1 and kernel_values2 must have the same shape."- " Got {} and {}".format(kernel_values1.shape, kernel_values2.shape)+ f" Got {kernel_values1.shape} and {kernel_values2.shape}")joint_kernel_values = torch.matmul(kernel_values1.transpose(1, 2), kernel_values2)@@ -231,7 +231,7 @@ def image_histogram2d(else: # kernel == "epanechnikov"kernel_values = (1.0 - u**2) * maskelse:- raise ValueError(f"Kernel must be 'triangular', 'gaussian', " f"'uniform' or 'epanechnikov'. Got {kernel}.")+ raise ValueError(f"Kernel must be 'triangular', 'gaussian', 'uniform' or 'epanechnikov'. Got {kernel}.")hist = torch.sum(kernel_values, dim=(-2, -1)).permute(1, 2, 0)diff --git a/kornia/feature/defmo.py b/kornia/feature/defmo.pyindex 4aeac4fc1..b4df2cb45 100644--- a/kornia/feature/defmo.py+++ b/kornia/feature/defmo.py@@ -118,7 +118,7 @@ class ResNet(Module):if len(replace_stride_with_dilation) != 3:raise ValueError("replace_stride_with_dilation should be None "- "or a 3-element tuple, got {}".format(replace_stride_with_dilation)+ f"or a 3-element tuple, got {replace_stride_with_dilation}")self.groups = groupsself.base_width = width_per_groupdiff --git a/kornia/feature/laf.py b/kornia/feature/laf.pyindex 5c79f1de3..504e52c34 100644--- a/kornia/feature/laf.py+++ b/kornia/feature/laf.py@@ -147,8 +147,8 @@ def scale_laf(laf: Tensor, scale_coef: Union[float, Tensor]) -> Tensor:>>> scale = 0.5>>> output = scale_laf(input, scale) # BxNx2x3"""- if (type(scale_coef) is not float) and (type(scale_coef) is not Tensor):- raise TypeError("scale_coef should be float or Tensor " "Got {}".format(type(scale_coef)))+ if not isinstance(scale_coef, (float, Tensor)):+ raise TypeError(f"scale_coef should be float or Tensor. Got {type(scale_coef)}")KORNIA_CHECK_LAF(laf)centerless_laf = laf[:, :, :2, :2]return concatenate([scale_coef * centerless_laf, laf[:, :, :, 2:]], dim=3)diff --git a/kornia/feature/loftr/utils/coarse_matching.py b/kornia/feature/loftr/utils/coarse_matching.pyindex a1ef3b017..ea6d0dfe9 100644--- a/kornia/feature/loftr/utils/coarse_matching.py+++ b/kornia/feature/loftr/utils/coarse_matching.py@@ -9,7 +9,7 @@ from kornia.core import Module, TensorINF = 1e9-def mask_border(m: Tensor, b: int, v: Union[Tensor, float, int, bool]) -> None:+def mask_border(m: Tensor, b: int, v: Union[Tensor, float, bool]) -> None:"""Mask borders with valueArgs:m (torch.Tensor): [N, H0, W0, H1, W1]@@ -29,9 +29,7 @@ def mask_border(m: Tensor, b: int, v: Union[Tensor, float, int, bool]) -> None:m[:, :, :, :, -b:] = v-def mask_border_with_padding(- m: Tensor, bd: int, v: Union[Tensor, float, int, bool], p_m0: Tensor, p_m1: Tensor-) -> None:+def mask_border_with_padding(m: Tensor, bd: int, v: Union[Tensor, float, bool], p_m0: Tensor, p_m1: Tensor) -> None:if bd <= 0:returndiff --git a/kornia/feature/orientation.py b/kornia/feature/orientation.pyindex b217044f7..6a02ec66b 100644--- a/kornia/feature/orientation.py+++ b/kornia/feature/orientation.py@@ -74,8 +74,7 @@ class PatchDominantGradientOrientation(nn.Module):_, CH, W, H = patch.size()if (W != self.patch_size) or (H != self.patch_size) or (CH != 1):raise TypeError(- "input shape should be must be [Bx1x{}x{}]. "- "Got {}".format(self.patch_size, self.patch_size, patch.size())+ f"input shape should be must be [Bx1x{self.patch_size}x{self.patch_size}]. Got {patch.size()}")self.weighting = self.weighting.to(patch.dtype).to(patch.device)self.angular_smooth = self.angular_smooth.to(patch.dtype).to(patch.device)diff --git a/kornia/feature/responses.py b/kornia/feature/responses.pyindex 51bb70d6a..f1bd1e0f7 100644--- a/kornia/feature/responses.py+++ b/kornia/feature/responses.py@@ -7,7 +7,7 @@ from kornia.core.check import KORNIA_CHECK_SHAPEfrom kornia.filters import gaussian_blur2d, spatial_gradient-def _get_kernel_size(sigma: Union[float, int]) -> int:+def _get_kernel_size(sigma: float) -> int:ksize = int(2.0 * 4.0 * sigma + 1.0)# matches OpenCV, but may cause padding problem for small imagesdiff --git a/kornia/geometry/calibration/pnp.py b/kornia/geometry/calibration/pnp.pyindex c93ac7613..2f45568a1 100644--- a/kornia/geometry/calibration/pnp.py+++ b/kornia/geometry/calibration/pnp.py@@ -144,7 +144,7 @@ def solve_pnp_dlt(f"of torch.Tensor. Type of weights is {type(weights)}")- if type(svd_eps) is not float:+ if not isinstance(svd_eps, float):raise AssertionError(f"Type of svd_eps is not float. Got {type(svd_eps)}")accepted_dtypes = (torch.float32, torch.float64)@@ -184,7 +184,7 @@ def solve_pnp_dlt(if world_points.shape[1] < 6:raise AssertionError(- f"At least 6 points are required to use this function. " f"Got {world_points.shape[1]} points."+ f"At least 6 points are required to use this function. Got {world_points.shape[1]} points.")B, N = world_points.shape[:2]diff --git a/kornia/geometry/camera/perspective.py b/kornia/geometry/camera/perspective.pyindex 66ffc84ce..9a542b358 100644--- a/kornia/geometry/camera/perspective.py+++ b/kornia/geometry/camera/perspective.py@@ -69,7 +69,7 @@ def unproject_points(raise TypeError(f"Input depth type is not a torch.Tensor. Got {type(depth)}")if not depth.shape[-1] == 1:- raise ValueError("Input depth must be in the shape of (*, 1)." " Got {}".format(depth.shape))+ raise ValueError(f"Input depth must be in the shape of (*, 1). Got {depth.shape}")xy: torch.Tensor = normalize_points_with_intrinsics(point_2d, camera_matrix)xyz: torch.Tensor = convert_points_to_homogeneous(xy)diff --git a/kornia/geometry/camera/pinhole.py b/kornia/geometry/camera/pinhole.pyindex 2bda29cf8..1df00fdfe 100644--- a/kornia/geometry/camera/pinhole.py+++ b/kornia/geometry/camera/pinhole.py@@ -49,17 +49,14 @@ class PinholeCamera:def _check_valid_params(data: Tensor, data_name: str) -> bool:if len(data.shape) not in (3, 4) and data.shape[-2:] != (4, 4): # Shouldn't this be an OR logic than AND?raise ValueError(- "Argument {} shape must be in the following shape"- " Bx4x4 or BxNx4x4. Got {}".format(data_name, data.shape)+ f"Argument {data_name} shape must be in the following shape Bx4x4 or BxNx4x4. Got {data.shape}")return True@staticmethoddef _check_valid_shape(data: Tensor, data_name: str) -> bool:if not len(data.shape) == 1:- raise ValueError(- "Argument {} shape must be in the following shape" " B. Got {}".format(data_name, data.shape)- )+ raise ValueError(f"Argument {data_name} shape must be in the following shape B. Got {data.shape}")return True@staticmethod@@ -153,7 +150,7 @@ class PinholeCamera:return self.extrinsics[..., 0, -1]@tx.setter- def tx(self, value: Union[Tensor, float, int]) -> 'PinholeCamera':+ def tx(self, value: Union[Tensor, float]) -> 'PinholeCamera':r"""Set the x-coordinate of the translation vector with the given value."""self.extrinsics[..., 0, -1] = valuereturn self@@ -168,7 +165,7 @@ class PinholeCamera:return self.extrinsics[..., 1, -1]@ty.setter- def ty(self, value: Union[Tensor, float, int]) -> 'PinholeCamera':+ def ty(self, value: Union[Tensor, float]) -> 'PinholeCamera':r"""Set the y-coordinate of the translation vector with the given value."""self.extrinsics[..., 1, -1] = valuereturn self@@ -183,7 +180,7 @@ class PinholeCamera:return self.extrinsics[..., 2, -1]@tz.setter- def tz(self, value: Union[Tensor, float, int]) -> 'PinholeCamera':+ def tz(self, value: Union[Tensor, float]) -> 'PinholeCamera':r"""Set the y-coordinate of the translation vector with the given value."""self.extrinsics[..., 2, -1] = valuereturn self@@ -262,7 +259,7 @@ class PinholeCamera:width: Tensor = scale_factor * self.width.clone()return PinholeCamera(intrinsics, self.extrinsics, height, width)- def scale_(self, scale_factor: Union[float, int, Tensor]) -> 'PinholeCamera':+ def scale_(self, scale_factor: Union[float, Tensor]) -> 'PinholeCamera':r"""Scale the pinhole model in-place.Args:@@ -405,7 +402,7 @@ class PinholeCamerasList(PinholeCamera):intrinsics, extrinsics = [], []for pinhole in pinholes:if not isinstance(pinhole, PinholeCamera):- raise TypeError("Argument pinhole must be from type " "PinholeCamera. Got {}".format(type(pinhole)))+ raise TypeError(f"Argument pinhole must be from type PinholeCamera. Got {type(pinhole)}")height.append(pinhole.height)width.append(pinhole.width)intrinsics.append(pinhole.intrinsics)@@ -644,11 +641,11 @@ def pixel2cam(depth: Tensor, intrinsics_inv: Tensor, pixel_coords: Tensor) -> Tetensor of shape BxHxWx3 with (x, y, z) cam coordinates."""if not len(depth.shape) == 4 and depth.shape[1] == 1:- raise ValueError("Input depth has to be in the shape of " "Bx1xHxW. Got {}".format(depth.shape))+ raise ValueError(f"Input depth has to be in the shape of Bx1xHxW. Got {depth.shape}")if not len(intrinsics_inv.shape) == 3:- raise ValueError("Input intrinsics_inv has to be in the shape of " "Bx4x4. Got {}".format(intrinsics_inv.shape))+ raise ValueError(f"Input intrinsics_inv has to be in the shape of Bx4x4. Got {intrinsics_inv.shape}")if not len(pixel_coords.shape) == 4 and pixel_coords.shape[3] == 3:- raise ValueError("Input pixel_coords has to be in the shape of " "BxHxWx3. Got {}".format(intrinsics_inv.shape))+ raise ValueError(f"Input pixel_coords has to be in the shape of BxHxWx3. Got {intrinsics_inv.shape}")cam_coords: Tensor = transform_points(intrinsics_inv[:, None], pixel_coords)return cam_coords * depth.permute(0, 2, 3, 1)@@ -670,11 +667,9 @@ def cam2pixel(cam_coords_src: Tensor, dst_proj_src: Tensor, eps: float = 1e-12)tensor of shape BxHxWx2 with (u, v) pixel coordinates."""if not len(cam_coords_src.shape) == 4 and cam_coords_src.shape[3] == 3:- raise ValueError(- "Input cam_coords_src has to be in the shape of " "BxHxWx3. Got {}".format(cam_coords_src.shape)- )+ raise ValueError(f"Input cam_coords_src has to be in the shape of BxHxWx3. Got {cam_coords_src.shape}")if not len(dst_proj_src.shape) == 3 and dst_proj_src.shape[-2:] == (4, 4):- raise ValueError("Input dst_proj_src has to be in the shape of " "Bx4x4. Got {}".format(dst_proj_src.shape))+ raise ValueError(f"Input dst_proj_src has to be in the shape of Bx4x4. Got {dst_proj_src.shape}")# apply projection matrix to pointspoint_coords: Tensor = transform_points(dst_proj_src[:, None], cam_coords_src)x_coord: Tensor = point_coords[..., 0]diff --git a/kornia/geometry/camera/stereo.py b/kornia/geometry/camera/stereo.pyindex 2f81344c1..cce37390b 100644--- a/kornia/geometry/camera/stereo.py+++ b/kornia/geometry/camera/stereo.py@@ -60,12 +60,12 @@ class StereoCamera:# Ensure correct shapesif len(rectified_left_camera.shape) != 3:raise StereoException(- f"Expected 'rectified_left_camera' to have 3 dimensions. " f"Got {rectified_left_camera.shape}."+ f"Expected 'rectified_left_camera' to have 3 dimensions. Got {rectified_left_camera.shape}.")if len(rectified_right_camera.shape) != 3:raise StereoException(- f"Expected 'rectified_right_camera' to have 3 dimension. " f"Got {rectified_right_camera.shape}."+ f"Expected 'rectified_right_camera' to have 3 dimension. Got {rectified_right_camera.shape}.")if rectified_left_camera.shape[:1] == (3, 4):@@ -107,7 +107,7 @@ class StereoCamera:# Ensure that tx * fx is negative and exists.tx_fx = rectified_right_camera[..., 0, 3]if torch.all(torch.gt(tx_fx, 0)):- raise StereoException(f"Expected :math:`T_x * f_x` to be negative." f"Got {tx_fx}.")+ raise StereoException(f"Expected :math:`T_x * f_x` to be negative. Got {tx_fx}.")@propertydef batch_size(self) -> int:@@ -235,7 +235,7 @@ def _check_disparity_tensor(disparity_tensor: Tensor) -> None:)if len(disparity_tensor.shape) != 4:- raise StereoException(f"Expected 'disparity_tensor' to have 4 dimensions." f"Got {disparity_tensor.shape}.")+ raise StereoException(f"Expected 'disparity_tensor' to have 4 dimensions. Got {disparity_tensor.shape}.")if disparity_tensor.shape[-1] != 1:raise StereoException(@@ -260,16 +260,14 @@ def _check_Q_matrix(Q_matrix: Tensor) -> None:raise StereoException(f"Expected 'Q_matrix' to be an instance of Tensor but got {type(Q_matrix)}.")if not len(Q_matrix.shape) == 3:- raise StereoException(f"Expected 'Q_matrix' to have 3 dimensions." f"Got {Q_matrix.shape}")+ raise StereoException(f"Expected 'Q_matrix' to have 3 dimensions. Got {Q_matrix.shape}")if not Q_matrix.shape[1:] == (4, 4):- raise StereoException(- f"Expected last two dimensions of 'Q_matrix' to be of shape (4, 4)." f"Got {Q_matrix.shape}"- )+ raise StereoException(f"Expected last two dimensions of 'Q_matrix' to be of shape (4, 4). Got {Q_matrix.shape}")if Q_matrix.dtype not in (torch.float16, torch.float32, torch.float64):raise StereoException(- f"Expected 'Q_matrix' to be of type torch.float16, torch.float32 or torch.float64." f"Got {Q_matrix.dtype}"+ f"Expected 'Q_matrix' to be of type torch.float16, torch.float32 or torch.float64. Got {Q_matrix.dtype}")diff --git a/kornia/geometry/conversions.py b/kornia/geometry/conversions.pyindex c0ba8b7da..9b077c1d2 100644--- a/kornia/geometry/conversions.py+++ b/kornia/geometry/conversions.py@@ -856,7 +856,7 @@ def normalize_pixel_coordinates(pixel_coordinates: Tensor, height: int, width: itensor([[1.0408, 1.0202]])"""if pixel_coordinates.shape[-1] != 2:- raise ValueError("Input pixel_coordinates must be of shape (*, 2). " "Got {}".format(pixel_coordinates.shape))+ raise ValueError(f"Input pixel_coordinates must be of shape (*, 2). Got {pixel_coordinates.shape}")# compute normalization factorhw: Tensor = stack(@@ -891,7 +891,7 @@ def denormalize_pixel_coordinates(pixel_coordinates: Tensor, height: int, width:tensor([[0., 0.]])"""if pixel_coordinates.shape[-1] != 2:- raise ValueError("Input pixel_coordinates must be of shape (*, 2). " "Got {}".format(pixel_coordinates.shape))+ raise ValueError(f"Input pixel_coordinates must be of shape (*, 2). Got {pixel_coordinates.shape}")# compute normalization factorhw: Tensor = stack([tensor(width), tensor(height)]).to(pixel_coordinates.device).to(pixel_coordinates.dtype)@@ -918,7 +918,7 @@ def normalize_pixel_coordinates3d(the normalized pixel coordinates."""if pixel_coordinates.shape[-1] != 3:- raise ValueError("Input pixel_coordinates must be of shape (*, 3). " "Got {}".format(pixel_coordinates.shape))+ raise ValueError(f"Input pixel_coordinates must be of shape (*, 3). Got {pixel_coordinates.shape}")# compute normalization factordhw: Tensor = (stack([tensor(depth), tensor(width), tensor(height)]).to(pixel_coordinates.device).to(pixel_coordinates.dtype)@@ -947,7 +947,7 @@ def denormalize_pixel_coordinates3d(the denormalized pixel coordinates."""if pixel_coordinates.shape[-1] != 3:- raise ValueError("Input pixel_coordinates must be of shape (*, 3). " "Got {}".format(pixel_coordinates.shape))+ raise ValueError(f"Input pixel_coordinates must be of shape (*, 3). Got {pixel_coordinates.shape}")# compute normalization factordhw: Tensor = (stack([tensor(depth), tensor(width), tensor(height)]).to(pixel_coordinates.device).to(pixel_coordinates.dtype)@@ -1506,7 +1506,7 @@ def vector_to_skew_symmetric_matrix(vec: Tensor) -> Tensor:"""# KORNIA_CHECK_SHAPE(vec, ["B", "3"])if vec.shape[-1] != 3 or len(vec.shape) > 2:- raise ValueError(f"Input vector must be of shape (B, 3) or (3,). " f"Got {vec.shape}")+ raise ValueError(f"Input vector must be of shape (B, 3) or (3,). Got {vec.shape}")v1, v2, v3 = vec[..., 0], vec[..., 1], vec[..., 2]zeros = zeros_like(v1)skew_symmetric_matrix = stack(diff --git a/kornia/geometry/depth.py b/kornia/geometry/depth.pyindex 3d066182f..e96367930 100644--- a/kornia/geometry/depth.py+++ b/kornia/geometry/depth.py@@ -41,10 +41,10 @@ def depth_to_3d(depth: Tensor, camera_matrix: Tensor, normalize_points: bool = Fraise ValueError(f"Input depth musth have a shape (B, 1, H, W). Got: {depth.shape}")if not isinstance(camera_matrix, Tensor):- raise TypeError(f"Input camera_matrix type is not a Tensor. " f"Got {type(camera_matrix)}.")+ raise TypeError(f"Input camera_matrix type is not a Tensor. Got {type(camera_matrix)}.")if not (len(camera_matrix.shape) == 3 and camera_matrix.shape[-2:] == (3, 3)):- raise ValueError(f"Input camera_matrix must have a shape (B, 3, 3). " f"Got: {camera_matrix.shape}.")+ raise ValueError(f"Input camera_matrix must have a shape (B, 3, 3). Got: {camera_matrix.shape}.")# create base coordinates grid_, _, height, width = depth.shape@@ -88,10 +88,10 @@ def depth_to_normals(depth: Tensor, camera_matrix: Tensor, normalize_points: booraise ValueError(f"Input depth musth have a shape (B, 1, H, W). Got: {depth.shape}")if not isinstance(camera_matrix, Tensor):- raise TypeError(f"Input camera_matrix type is not a Tensor. " f"Got {type(camera_matrix)}.")+ raise TypeError(f"Input camera_matrix type is not a Tensor. Got {type(camera_matrix)}.")if not (len(camera_matrix.shape) == 3 and camera_matrix.shape[-2:] == (3, 3)):- raise ValueError(f"Input camera_matrix must have a shape (B, 3, 3). " f"Got: {camera_matrix.shape}.")+ raise ValueError(f"Input camera_matrix must have a shape (B, 3, 3). Got: {camera_matrix.shape}.")# compute the 3d points from depthxyz: Tensor = depth_to_3d(depth, camera_matrix, normalize_points) # Bx3xHxW@@ -138,16 +138,16 @@ def warp_frame_depth(raise ValueError(f"Input depth_dst musth have a shape (B, 1, H, W). Got: {depth_dst.shape}")if not isinstance(src_trans_dst, Tensor):- raise TypeError(f"Input src_trans_dst type is not a Tensor. " f"Got {type(src_trans_dst)}.")+ raise TypeError(f"Input src_trans_dst type is not a Tensor. Got {type(src_trans_dst)}.")if not (len(src_trans_dst.shape) == 3 and src_trans_dst.shape[-2:] == (4, 4)):- raise ValueError(f"Input src_trans_dst must have a shape (B, 4, 4). " f"Got: {src_trans_dst.shape}.")+ raise ValueError(f"Input src_trans_dst must have a shape (B, 4, 4). Got: {src_trans_dst.shape}.")if not isinstance(camera_matrix, Tensor):- raise TypeError(f"Input camera_matrix type is not a Tensor. " f"Got {type(camera_matrix)}.")+ raise TypeError(f"Input camera_matrix type is not a Tensor. Got {type(camera_matrix)}.")if not (len(camera_matrix.shape) == 3 and camera_matrix.shape[-2:] == (3, 3)):- raise ValueError(f"Input camera_matrix must have a shape (B, 3, 3). " f"Got: {camera_matrix.shape}.")+ raise ValueError(f"Input camera_matrix must have a shape (B, 3, 3). Got: {camera_matrix.shape}.")# unproject source points to camera framepoints_3d_dst: Tensor = depth_to_3d(depth_dst, camera_matrix, normalize_points) # Bx3xHxW@@ -219,13 +219,10 @@ class DepthWarper(Module):r"""Compute the projection matrix from the source to destination frame."""if not isinstance(self._pinhole_dst, PinholeCamera):raise TypeError(- "Member self._pinhole_dst expected to be of class "- "PinholeCamera. Got {}".format(type(self._pinhole_dst))+ f"Member self._pinhole_dst expected to be of class PinholeCamera. Got {type(self._pinhole_dst)}")if not isinstance(pinhole_src, PinholeCamera):- raise TypeError(- "Argument pinhole_src expected to be of class " "PinholeCamera. Got {}".format(type(pinhole_src))- )+ raise TypeError(f"Argument pinhole_src expected to be of class PinholeCamera. Got {type(pinhole_src)}")# compute the relative pose between the non reference and the reference# camera frames.dst_trans_src: Tensor = compose_transformations(@@ -241,7 +238,7 @@ class DepthWarper(Module):self._dst_proj_src = dst_proj_srcreturn self- def _compute_projection(self, x: Union[int, float], y: Union[int, float], invd: Union[int, float]) -> Tensor:+ def _compute_projection(self, x: float, y: float, invd: float) -> Tensor:if self._dst_proj_src is None or self._pinhole_src is None:raise ValueError("Please, call compute_projection_matrix.")@@ -279,7 +276,7 @@ class DepthWarper(Module):raise ValueError("Please, call compute_projection_matrix.")if len(depth_src.shape) != 4:- raise ValueError("Input depth_src has to be in the shape of " "Bx1xHxW. Got {}".format(depth_src.shape))+ raise ValueError(f"Input depth_src has to be in the shape of Bx1xHxW. Got {depth_src.shape}")# unpack depth attributesbatch_size, _, _, _ = depth_src.shape@@ -390,10 +387,10 @@ def depth_from_disparity(disparity: Tensor, baseline: Union[float, Tensor], focaKORNIA_CHECK_SHAPE(disparity, ["*", "H", "W"])KORNIA_CHECK(isinstance(baseline, (float, Tensor)),- f"Input baseline should be either a float or Tensor. " f"Got {type(baseline)}",+ f"Input baseline should be either a float or Tensor. Got {type(baseline)}",)KORNIA_CHECK(- isinstance(focal, (float, Tensor)), f"Input focal should be either a float or Tensor. " f"Got {type(focal)}"+ isinstance(focal, (float, Tensor)), f"Input focal should be either a float or Tensor. Got {type(focal)}")if isinstance(baseline, Tensor):diff --git a/kornia/geometry/linalg.py b/kornia/geometry/linalg.pyindex ae440983f..f12500d25 100644--- a/kornia/geometry/linalg.py+++ b/kornia/geometry/linalg.py@@ -46,10 +46,10 @@ def compose_transformations(trans_01: Tensor, trans_12: Tensor) -> Tensor:KORNIA_CHECK_IS_TENSOR(trans_12)if not ((trans_01.dim() in (2, 3)) and (trans_01.shape[-2:] == (4, 4))):- raise ValueError("Input trans_01 must be a of the shape Nx4x4 or 4x4." " Got {}".format(trans_01.shape))+ raise ValueError(f"Input trans_01 must be a of the shape Nx4x4 or 4x4. Got {trans_01.shape}")if not ((trans_12.dim() in (2, 3)) and (trans_12.shape[-2:] == (4, 4))):- raise ValueError("Input trans_12 must be a of the shape Nx4x4 or 4x4." " Got {}".format(trans_12.shape))+ raise ValueError(f"Input trans_12 must be a of the shape Nx4x4 or 4x4. Got {trans_12.shape}")if not trans_01.dim() == trans_12.dim():raise ValueError(f"Input number of dims must match. Got {trans_01.dim()} and {trans_12.dim()}")@@ -141,9 +141,9 @@ def relative_transformation(trans_01: Tensor, trans_02: Tensor) -> Tensor:KORNIA_CHECK_IS_TENSOR(trans_01)KORNIA_CHECK_IS_TENSOR(trans_02)if not ((trans_01.dim() in (2, 3)) and (trans_01.shape[-2:] == (4, 4))):- raise ValueError("Input must be a of the shape Nx4x4 or 4x4." " Got {}".format(trans_01.shape))+ raise ValueError(f"Input must be a of the shape Nx4x4 or 4x4. Got {trans_01.shape}")if not ((trans_02.dim() in (2, 3)) and (trans_02.shape[-2:] == (4, 4))):- raise ValueError("Input must be a of the shape Nx4x4 or 4x4." " Got {}".format(trans_02.shape))+ raise ValueError(f"Input must be a of the shape Nx4x4 or 4x4. Got {trans_02.shape}")if not trans_01.dim() == trans_02.dim():raise ValueError(f"Input number of dims must match. Got {trans_01.dim()} and {trans_02.dim()}")@@ -175,10 +175,10 @@ def transform_points(trans_01: Tensor, points_1: Tensor) -> Tensor:KORNIA_CHECK_IS_TENSOR(points_1)if not trans_01.shape[0] == points_1.shape[0] and trans_01.shape[0] != 1:raise ValueError(- "Input batch size must be the same for both tensors or 1." f"Got {trans_01.shape} and {points_1.shape}"+ f"Input batch size must be the same for both tensors or 1. Got {trans_01.shape} and {points_1.shape}")if not trans_01.shape[-1] == (points_1.shape[-1] + 1):- raise ValueError("Last input dimensions must differ by one unit" f"Got{trans_01} and {points_1}")+ raise ValueError(f"Last input dimensions must differ by one unit Got{trans_01} and {points_1}")# We reshape to BxNxD in case we get more dimensions, e.g., MxBxNxDshape_inp = list(points_1.shape)diff --git a/kornia/geometry/quaternion.py b/kornia/geometry/quaternion.pyindex 206080475..8fc817d92 100644--- a/kornia/geometry/quaternion.py+++ b/kornia/geometry/quaternion.py@@ -135,7 +135,7 @@ class Quaternion(Module):def __truediv__(self, right: 'Quaternion') -> 'Quaternion':return self.__div__(right)- def __pow__(self, t: Union[int, float]) -> 'Quaternion':+ def __pow__(self, t: float) -> 'Quaternion':"""Return the power of a quaternion raised to exponent t.Args:diff --git a/kornia/geometry/transform/affwarp.py b/kornia/geometry/transform/affwarp.pyindex 78dcf377f..c7f01fd9f 100644--- a/kornia/geometry/transform/affwarp.py+++ b/kornia/geometry/transform/affwarp.py@@ -270,7 +270,7 @@ def rotate(raise TypeError(f"Input center type is not a torch.Tensor. Got {type(center)}")if len(tensor.shape) not in (3, 4):- raise ValueError("Invalid tensor shape, we expect CxHxW or BxCxHxW. " "Got: {}".format(tensor.shape))+ raise ValueError(f"Invalid tensor shape, we expect CxHxW or BxCxHxW. Got: {tensor.shape}")# compute the rotation centerif center is None:@@ -334,7 +334,7 @@ def rotate3d(raise TypeError(f"Input center type is not a torch.Tensor. Got {type(center)}")if len(tensor.shape) not in (4, 5):- raise ValueError("Invalid tensor shape, we expect CxDxHxW or BxCxDxHxW. " "Got: {}".format(tensor.shape))+ raise ValueError(f"Invalid tensor shape, we expect CxDxHxW or BxCxDxHxW. Got: {tensor.shape}")# compute the rotation centerif center is None:@@ -391,7 +391,7 @@ def translate(raise TypeError(f"Input translation type is not a torch.Tensor. Got {type(translation)}")if len(tensor.shape) not in (3, 4):- raise ValueError("Invalid tensor shape, we expect CxHxW or BxCxHxW. " "Got: {}".format(tensor.shape))+ raise ValueError(f"Invalid tensor shape, we expect CxHxW or BxCxHxW. Got: {tensor.shape}")# compute the translation matrixtranslation_matrix: torch.Tensor = _compute_translation_matrix(translation)@@ -500,7 +500,7 @@ def shear(raise TypeError(f"Input shear type is not a torch.Tensor. Got {type(shear)}")if len(tensor.shape) not in (3, 4):- raise ValueError("Invalid tensor shape, we expect CxHxW or BxCxHxW. " "Got: {}".format(tensor.shape))+ raise ValueError(f"Invalid tensor shape, we expect CxHxW or BxCxHxW. Got: {tensor.shape}")# compute the translation matrixshear_matrix: torch.Tensor = _compute_shear_matrix(shear)diff --git a/kornia/losses/hausdorff.py b/kornia/losses/hausdorff.pyindex 53b00f16b..d3934bf33 100644--- a/kornia/losses/hausdorff.py+++ b/kornia/losses/hausdorff.py@@ -183,7 +183,7 @@ class HausdorffERLoss(_HausdorffERLossBase):if not (target.max() < pred.size(1) and target.min() >= 0 and target.dtype == torch.long):raise ValueError(- f"Expect long type target value in range (0, {pred.size(1)})." f"({target.min()}, {target.max()})"+ f"Expect long type target value in range (0, {pred.size(1)}). ({target.min()}, {target.max()})")return super().forward(pred, target)diff --git a/kornia/metrics/average_meter.py b/kornia/metrics/average_meter.pyindex 722e678e3..752c7c12f 100644--- a/kornia/metrics/average_meter.py+++ b/kornia/metrics/average_meter.py@@ -14,9 +14,9 @@ class AverageMeter:0.99"""- val: Union[int, float, bool, Tensor]+ val: Union[float, bool, Tensor]_avg: Union[float, Tensor]- sum: Union[int, float, Tensor]+ sum: Union[float, Tensor]count: intdef __init__(self) -> None:@@ -28,7 +28,7 @@ class AverageMeter:self.sum = 0self.count = 0- def update(self, val: Union[int, float, bool, Tensor], n: int = 1) -> None:+ def update(self, val: Union[float, bool, Tensor], n: int = 1) -> None:self.val = valself.sum += val * nself.count += ndiff --git a/kornia/metrics/confusion_matrix.py b/kornia/metrics/confusion_matrix.pyindex 9f7ac29eb..a96c68802 100644--- a/kornia/metrics/confusion_matrix.py+++ b/kornia/metrics/confusion_matrix.py@@ -33,21 +33,17 @@ def confusion_matrix([0., 0., 0.]]])"""if not torch.is_tensor(input) and input.dtype is not torch.int64:- raise TypeError("Input input type is not a torch.Tensor with " "torch.int64 dtype. Got {}".format(type(input)))+ raise TypeError(f"Input input type is not a torch.Tensor with torch.int64 dtype. Got {type(input)}")if not torch.is_tensor(target) and target.dtype is not torch.int64:- raise TypeError(- "Input target type is not a torch.Tensor with " "torch.int64 dtype. Got {}".format(type(target))- )+ raise TypeError(f"Input target type is not a torch.Tensor with torch.int64 dtype. Got {type(target)}")if not input.shape == target.shape:- raise ValueError(- "Inputs input and target must have the same shape. " "Got: {} and {}".format(input.shape, target.shape)- )+ raise ValueError(f"Inputs input and target must have the same shape. Got: {input.shape} and {target.shape}")if not input.device == target.device:- raise ValueError("Inputs must be in the same device. " "Got: {} - {}".format(input.device, target.device))+ raise ValueError(f"Inputs must be in the same device. Got: {input.device} - {target.device}")if not isinstance(num_classes, int) or num_classes < 2:- raise ValueError("The number of classes must be an integer bigger " "than two. Got: {}".format(num_classes))+ raise ValueError(f"The number of classes must be an integer bigger than two. Got: {num_classes}")batch_size: int = input.shape[0]diff --git a/kornia/metrics/mean_iou.py b/kornia/metrics/mean_iou.pyindex 5e47ccc0e..26173c8ba 100644--- a/kornia/metrics/mean_iou.py+++ b/kornia/metrics/mean_iou.py@@ -29,21 +29,17 @@ def mean_iou(input: torch.Tensor, target: torch.Tensor, num_classes: int, eps: ftensor([[1., 1., 1.]])"""if not torch.is_tensor(input) and input.dtype is not torch.int64:- raise TypeError("Input input type is not a torch.Tensor with " "torch.int64 dtype. Got {}".format(type(input)))+ raise TypeError(f"Input input type is not a torch.Tensor with torch.int64 dtype. Got {type(input)}")if not torch.is_tensor(target) and target.dtype is not torch.int64:- raise TypeError(- "Input target type is not a torch.Tensor with " "torch.int64 dtype. Got {}".format(type(target))- )+ raise TypeError(f"Input target type is not a torch.Tensor with torch.int64 dtype. Got {type(target)}")if not input.shape == target.shape:- raise ValueError(- "Inputs input and target must have the same shape. " "Got: {} and {}".format(input.shape, target.shape)- )+ raise ValueError(f"Inputs input and target must have the same shape. Got: {input.shape} and {target.shape}")if not input.device == target.device:- raise ValueError("Inputs must be in the same device. " "Got: {} - {}".format(input.device, target.device))+ raise ValueError(f"Inputs must be in the same device. Got: {input.device} - {target.device}")if not isinstance(num_classes, int) or num_classes < 2:- raise ValueError("The number of classes must be an integer bigger " "than two. Got: {}".format(num_classes))+ raise ValueError(f"The number of classes must be an integer bigger than two. Got: {num_classes}")# we first compute the confusion matrixconf_mat: torch.Tensor = confusion_matrix(input, target, num_classes)diff --git a/kornia/sensors/camera/projection_model.py b/kornia/sensors/camera/projection_model.pyindex 72c0de675..ee9840ace 100644--- a/kornia/sensors/camera/projection_model.py+++ b/kornia/sensors/camera/projection_model.py@@ -26,7 +26,7 @@ class Z1Projection:uv = (xy.T @ diag(z).inverse()).T if len(z.shape) else xy.T * 1 / zreturn Vector2(uv)- def unproject(self, points: Vector2, depth: Tensor | float | int) -> Vector3:+ def unproject(self, points: Vector2, depth: Tensor | float) -> Vector3:"""Unproject one or more Vector2 from the canonical z=1 plane into the camera frame.Args:diff --git a/kornia/utils/one_hot.py b/kornia/utils/one_hot.pyindex 593179033..4507e7222 100644--- a/kornia/utils/one_hot.py+++ b/kornia/utils/one_hot.py@@ -35,7 +35,7 @@ def one_hot(labels: Tensor, num_classes: int, device: torch.device, dtype: torchraise ValueError(f"labels must be of the same dtype torch.int64. Got: {labels.dtype}")if num_classes < 1:- raise ValueError("The number of classes must be bigger than one." " Got: {}".format(num_classes))+ raise ValueError(f"The number of classes must be bigger than one. Got: {num_classes}")shape = labels.shapeone_hot = zeros((shape[0], num_classes) + shape[1:], device=device, dtype=dtype)diff --git a/kornia/utils/pointcloud_io.py b/kornia/utils/pointcloud_io.pyindex 88d63e2b8..c6e2aa7c0 100644--- a/kornia/utils/pointcloud_io.py+++ b/kornia/utils/pointcloud_io.py@@ -13,13 +13,13 @@ def save_pointcloud_ply(filename: str, pointcloud: torch.Tensor) -> None:component is assumed to be a 3d point coordinate :math:`(X, Y, Z)`."""if not isinstance(filename, str) and filename[-3:] == '.ply':- raise TypeError("Input filename must be a string in with the .ply " "extension. Got {}".format(filename))+ raise TypeError(f"Input filename must be a string in with the .ply extension. Got {filename}")if not torch.is_tensor(pointcloud):raise TypeError(f"Input pointcloud type is not a torch.Tensor. Got {type(pointcloud)}")if not len(pointcloud.shape) == 3 and pointcloud.shape[-1] == 3:- raise TypeError("Input pointcloud must be in the following shape " "HxWx3. Got {}.".format(pointcloud.shape))+ raise TypeError(f"Input pointcloud must be in the following shape HxWx3. Got {pointcloud.shape}.")# flatten the input pointcloud in a vector to iterate pointsxyz_vec: torch.Tensor = pointcloud.reshape(-1, 3)@@ -61,7 +61,7 @@ def load_pointcloud_ply(filename: str, header_size: int = 8) -> torch.Tensor::math:`*` represents the number of points."""if not isinstance(filename, str) and filename[-3:] == '.ply':- raise TypeError("Input filename must be a string in with the .ply " "extension. Got {}".format(filename))+ raise TypeError(f"Input filename must be a string in with the .ply extension. Got {filename}")if not os.path.isfile(filename):raise ValueError("Input filename is not an existing file.")if not (isinstance(header_size, int) and header_size > 0):