Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Fix precommit by disabling pyproject-fmt (#3050)

Edgar Riba3687a5480005
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index c49419ae0..e4e4160f3 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -13,11 +13,11 @@ repos:
- id: requirements-txt-fixer
- id: pretty-format-json
exclude: ^$|.devcontainer
-
- - repo: https://github.com/tox-dev/pyproject-fmt
- rev: "2.4.3"
- hooks:
- - id: pyproject-fmt
+ # TODO: enable pyproject-fmt again if it's not breaking the build
+ #- repo: https://github.com/tox-dev/pyproject-fmt
+ # rev: "2.4.3"
+ # hooks:
+ # - id: pyproject-fmt
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
@@ -37,7 +37,7 @@ repos:
- "*.bib,*.ipynb"
- repo: https://github.com/PyCQA/docformatter
- rev: v1.7.5
+ rev: 06907d0
hooks:
- id: docformatter
- args: [--in-place, --wrap-summaries=115, --wrap-descriptions=120]
+ args: [--in-place, --config, ./pyproject.toml, --wrap-summaries=115, --wrap-descriptions=120]
diff --git a/README.md b/README.md
index 58d1d334a..e2e532224 100644
--- a/README.md
+++ b/README.md
@@ -182,7 +182,7 @@ tf_kornia = kornia.to_tensorflow()
```
<p align="center">
- Powered by
+ Powered by
<a href="https://github.com/ivy-llc/ivy" target="_blank">
<div class="dark-light" style="display: block;" align="center">
<img class="dark-light" width="15%" src="https://raw.githubusercontent.com/ivy-llc/assets/refs/heads/main/assets/logos/ivy-long.svg"/>
diff --git a/docs/source/get-started/multi-framework-support.rst b/docs/source/get-started/multi-framework-support.rst
index b0877974a..79035a222 100644
--- a/docs/source/get-started/multi-framework-support.rst
+++ b/docs/source/get-started/multi-framework-support.rst
@@ -11,7 +11,7 @@ Multi-Framework Support
=======================
Kornia can now be used with `TensorFlow <https://www.tensorflow.org/>`_, `JAX <https://jax.readthedocs.io/en/latest/index.html>`_,
-and `Numpy <https://numpy.org/>`_ thanks to an integration with `Ivy <https://github.com/ivy-llc/ivy>`_.
+and `Numpy <https://numpy.org/>`_ thanks to an integration with `Ivy <https://github.com/ivy-llc/ivy>`_.
This can be accomplished using the following functions, which are now part of the Kornia api:
@@ -56,7 +56,7 @@ So what's happening here? Let's break it down.
#. Subsequent function calls
- The good news is any calls of the function after the initial call will be much faster, as it has already been transpiled,
+ The good news is any calls of the function after the initial call will be much faster, as it has already been transpiled,
and should approximately match the speed of the original kornia function.
.. code-block:: python
@@ -112,7 +112,7 @@ Limitations
From the Ivy Team
-----------------
-We hope you find using Kornia with TensorFlow, JAX and NumPy useful! Ivy is still very much under development,
+We hope you find using Kornia with TensorFlow, JAX and NumPy useful! Ivy is still very much under development,
so if you find any issues/bugs, feel free to raise an issue on the `ivy <https://github.com/ivy-llc/ivy>`_ repository.
We'd also really appreciate a star, if you'd like to show your support!
diff --git a/docs/source/index.rst b/docs/source/index.rst
index 5fa8a3c49..b226bcf1d 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -68,7 +68,7 @@ You can now use Kornia with `NumPy <https://numpy.org/>`_, `TensorFlow <https://
.. raw:: html
<p align="center">
- Powered by
+ Powered by
<a href="https://github.com/ivy-llc/ivy" target="_blank">
<div class="dark-light" style="display: block;" align="center">
<img class="dark-light" width="15%" src="https://raw.githubusercontent.com/ivy-llc/assets/refs/heads/main/assets/logos/ivy-long.svg"/>
diff --git a/kornia/color/__init__.py b/kornia/color/__init__.py
index 0b7522e37..f62975cf2 100644
--- a/kornia/color/__init__.py
+++ b/kornia/color/__init__.py
@@ -9,27 +9,27 @@ from .rgb import (
BgrToRgb,
BgrToRgba,
LinearRgbToRgb,
+ NormalsToRgb255,
+ Rgb255ToNormals,
+ Rgb255ToRgb,
RgbaToBgr,
RgbaToRgb,
RgbToBgr,
RgbToLinearRgb,
- RgbToRgba,
RgbToRgb255,
- Rgb255ToNormals,
- Rgb255ToRgb,
- NormalsToRgb255,
+ RgbToRgba,
bgr_to_rgb,
bgr_to_rgba,
linear_rgb_to_rgb,
+ normals_to_rgb255,
+ rgb255_to_normals,
+ rgb255_to_rgb,
rgb_to_bgr,
rgb_to_linear_rgb,
+ rgb_to_rgb255,
rgb_to_rgba,
rgba_to_bgr,
rgba_to_rgb,
- rgb255_to_normals,
- rgb255_to_rgb,
- rgb_to_rgb255,
- normals_to_rgb255
)
from .sepia import Sepia, sepia_from_rgb
from .xyz import RgbToXyz, XyzToRgb, rgb_to_xyz, xyz_to_rgb
diff --git a/kornia/color/hls.py b/kornia/color/hls.py
index eaad3db62..05185ac07 100644
--- a/kornia/color/hls.py
+++ b/kornia/color/hls.py
@@ -1,6 +1,7 @@
from __future__ import annotations
+
import math
-from typing import ClassVar, List, Tuple
+from typing import ClassVar
import torch
@@ -36,7 +37,7 @@ def rgb_to_hls(image: Tensor, eps: float = 1e-8) -> Tensor:
_RGB2HSL_IDX = tensor([[[0.0]], [[1.0]], [[2.0]]], device=image.device, dtype=image.dtype) # 3x1x1
- _img_max: Tuple[Tensor, Tensor] = image.max(-3)
+ _img_max: tuple[Tensor, Tensor] = image.max(-3)
maxc = _img_max[0]
imax = _img_max[1]
minc: Tensor = image.min(-3)[0]
@@ -53,7 +54,11 @@ def rgb_to_hls(image: Tensor, eps: float = 1e-8) -> Tensor:
# so, h, l and s require inplace operations
# NOTE: stack() increases in a 10% the cost in colab
image_hls = torch.empty_like(image)
- h, l_, s = image_hls[..., 0, :, :], image_hls[..., 1, :, :], image_hls[..., 2, :, :]
+ h, l_, s = (
+ image_hls[..., 0, :, :],
+ image_hls[..., 1, :, :],
+ image_hls[..., 2, :, :],
+ )
torch.add(maxc, minc, out=l_) # l = max + min
torch.sub(maxc, minc, out=s) # s = max - min
diff --git a/kornia/color/hsv.py b/kornia/color/hsv.py
index ecdd3d90f..365e40eb9 100644
--- a/kornia/color/hsv.py
+++ b/kornia/color/hsv.py
@@ -1,6 +1,7 @@
from __future__ import annotations
+
import math
-from typing import ClassVar, List
+from typing import ClassVar
import torch
diff --git a/kornia/color/lab.py b/kornia/color/lab.py
index e279a039a..417b1e1d5 100644
--- a/kornia/color/lab.py
+++ b/kornia/color/lab.py
@@ -2,8 +2,10 @@
https://github.com/scikit-image/scikit-image/blob/a48bf6774718c64dade4548153ae16065b595ca9/skimage/color/colorconv.py
"""
+
from __future__ import annotations
-from typing import ClassVar, List
+
+from typing import ClassVar
import torch
diff --git a/kornia/color/luv.py b/kornia/color/luv.py
index 2bc2932bd..7b6756a21 100644
--- a/kornia/color/luv.py
+++ b/kornia/color/luv.py
@@ -2,8 +2,10 @@
https://github.com/scikit-image/scikit-image/blob/a48bf6774718c64dade4548153ae16065b595ca9/skimage/color/colorconv.py
"""
+
from __future__ import annotations
-from typing import ClassVar, List, Tuple
+
+from typing import ClassVar
import torch
@@ -48,10 +50,14 @@ def rgb_to_luv(image: torch.Tensor, eps: float = 1e-12) -> torch.Tensor:
z: torch.Tensor = xyz_im[..., 2, :, :]
threshold = 0.008856
- L: torch.Tensor = torch.where(y > threshold, 116.0 * torch.pow(y.clamp(min=threshold), 1.0 / 3.0) - 16.0, 903.3 * y)
+ L: torch.Tensor = torch.where(
+ y > threshold,
+ 116.0 * torch.pow(y.clamp(min=threshold), 1.0 / 3.0) - 16.0,
+ 903.3 * y,
+ )
# Compute reference white point
- xyz_ref_white: Tuple[float, float, float] = (0.95047, 1.0, 1.08883)
+ xyz_ref_white: tuple[float, float, float] = (0.95047, 1.0, 1.08883)
u_w: float = (4 * xyz_ref_white[0]) / (xyz_ref_white[0] + 15 * xyz_ref_white[1] + 3 * xyz_ref_white[2])
v_w: float = (9 * xyz_ref_white[1]) / (xyz_ref_white[0] + 15 * xyz_ref_white[1] + 3 * xyz_ref_white[2])
@@ -94,7 +100,7 @@ def luv_to_rgb(image: torch.Tensor, eps: float = 1e-12) -> torch.Tensor:
y: torch.Tensor = torch.where(L > 7.999625, torch.pow((L + 16) / 116, 3.0), L / 903.3)
# Compute white point
- xyz_ref_white: Tuple[float, float, float] = (0.95047, 1.0, 1.08883)
+ xyz_ref_white: tuple[float, float, float] = (0.95047, 1.0, 1.08883)
u_w: float = (4 * xyz_ref_white[0]) / (xyz_ref_white[0] + 15 * xyz_ref_white[1] + 3 * xyz_ref_white[2])
v_w: float = (9 * xyz_ref_white[1]) / (xyz_ref_white[0] + 15 * xyz_ref_white[1] + 3 * xyz_ref_white[2])
diff --git a/kornia/color/raw.py b/kornia/color/raw.py
index 738923ad4..fee2dc2a2 100644
--- a/kornia/color/raw.py
+++ b/kornia/color/raw.py
@@ -1,6 +1,7 @@
from __future__ import annotations
+
from enum import Enum
-from typing import ClassVar, List
+from typing import ClassVar
import torch
diff --git a/kornia/color/rgb.py b/kornia/color/rgb.py
index 33b34d210..f882f1994 100644
--- a/kornia/color/rgb.py
+++ b/kornia/color/rgb.py
@@ -1,4 +1,5 @@
from __future__ import annotations
+
from typing import ClassVar, Union, cast
import torch
@@ -234,13 +235,13 @@ def linear_rgb_to_rgb(image: Tensor) -> Tensor:
def normals_to_rgb255(image: Tensor) -> Tensor:
r"""Convert surface normals to RGB [0, 255] for visualization purposes.
-
+
Args:
image: surface normals to be converted to RGB with quantization of shape :math:`(*,3,H,W)`.
-
+
Returns:
RGB version of the image with shape of shape :math:`(*,3,H,W)`.
-
+
Example:
>>> input = torch.rand(2, 3, 4, 5)
>>> output = normals_to_rgb255(input) # 2x3x4x5
@@ -248,7 +249,7 @@ def normals_to_rgb255(image: Tensor) -> Tensor:
KORNIA_CHECK_IS_COLOR(image)
rgb255 = (0.5 * (image + 1.0)).clip(0.0, 1.0) * 255
return rgb255
-
+
def rgb_to_rgb255(image: Tensor) -> Tensor:
r"""Convert an image from RGB to RGB [0, 255] for visualization purposes.
@@ -616,4 +617,4 @@ class Rgb255ToNormals(Module):
"""
def forward(self, image: Tensor) -> Tensor:
- return rgb255_to_normals(image)
\ No newline at end of file
+ return rgb255_to_normals(image)
diff --git a/kornia/color/xyz.py b/kornia/color/xyz.py
index 82b89ceff..5affc1f72 100644
--- a/kornia/color/xyz.py
+++ b/kornia/color/xyz.py
@@ -1,4 +1,5 @@
from __future__ import annotations
+
from typing import ClassVar
import torch
diff --git a/kornia/color/ycbcr.py b/kornia/color/ycbcr.py
index cc291783c..7c3ba1740 100644
--- a/kornia/color/ycbcr.py
+++ b/kornia/color/ycbcr.py
@@ -1,4 +1,5 @@
from __future__ import annotations
+
from typing import ClassVar
import torch
diff --git a/kornia/color/yuv.py b/kornia/color/yuv.py
index dab622144..c52ad7707 100644
--- a/kornia/color/yuv.py
+++ b/kornia/color/yuv.py
@@ -1,5 +1,6 @@
from __future__ import annotations
-from typing import ClassVar, Tuple
+
+from typing import ClassVar
import torch
@@ -49,7 +50,7 @@ def rgb_to_yuv(image: Tensor) -> Tensor:
return out
-def rgb_to_yuv420(image: Tensor) -> Tuple[Tensor, Tensor]:
+def rgb_to_yuv420(image: Tensor) -> tuple[Tensor, Tensor]:
r"""Convert an RGB image to YUV 420 (subsampled).
Input need to be padded to be evenly divisible by 2 horizontal and vertical.
@@ -83,10 +84,13 @@ def rgb_to_yuv420(image: Tensor) -> Tuple[Tensor, Tensor]:
yuvimage = rgb_to_yuv(image)
- return (yuvimage[..., :1, :, :], yuvimage[..., 1:3, :, :].unfold(-2, 2, 2).unfold(-2, 2, 2).mean((-1, -2)))
+ return (
+ yuvimage[..., :1, :, :],
+ yuvimage[..., 1:3, :, :].unfold(-2, 2, 2).unfold(-2, 2, 2).mean((-1, -2)),
+ )
-def rgb_to_yuv422(image: Tensor) -> Tuple[Tensor, Tensor]:
+def rgb_to_yuv422(image: Tensor) -> tuple[Tensor, Tensor]:
r"""Convert an RGB image to YUV 422 (subsampled).
Input need to be padded to be evenly divisible by 2 vertical.
@@ -213,7 +217,10 @@ def yuv420_to_rgb(imagey: Tensor, imageuv: Tensor) -> Tensor:
)
# first upsample
- yuv444image = torch.cat([imagey, imageuv.repeat_interleave(2, dim=-1).repeat_interleave(2, dim=-2)], dim=-3)
+ yuv444image = torch.cat(
+ [imagey, imageuv.repeat_interleave(2, dim=-1).repeat_interleave(2, dim=-2)],
+ dim=-3,
+ )
# then convert the yuv444 tensor
return yuv_to_rgb(yuv444image)
@@ -331,7 +338,7 @@ class RgbToYuv420(Module):
# TODO: Handle multiple inputs and outputs models later
ONNX_EXPORTABLE = False
- def forward(self, yuvinput: Tensor) -> Tuple[Tensor, Tensor]: # skipcq: PYL-R0201
+ def forward(self, yuvinput: Tensor) -> tuple[Tensor, Tensor]: # skipcq: PYL-R0201
return rgb_to_yuv420(yuvinput)
@@ -365,7 +372,7 @@ class RgbToYuv422(Module):
# TODO: Handle multiple inputs and outputs models later
ONNX_EXPORTABLE = False
- def forward(self, yuvinput: Tensor) -> Tuple[Tensor, Tensor]: # skipcq: PYL-R0201
+ def forward(self, yuvinput: Tensor) -> tuple[Tensor, Tensor]: # skipcq: PYL-R0201
return rgb_to_yuv422(yuvinput)
diff --git a/kornia/core/module.py b/kornia/core/module.py
index ab75ea6c0..b8dd6ed9e 100644
--- a/kornia/core/module.py
+++ b/kornia/core/module.py
@@ -1,12 +1,12 @@
from __future__ import annotations
+
import datetime
import math
import os
from functools import wraps
-from typing import Any, Callable, ClassVar, List, Optional, Tuple, Union
-
-import torch
+from typing import Any, Callable, Optional, Union
+# TODO: not use top level import
import kornia
from ._backend import Module, Sequential, Tensor, from_numpy
@@ -25,7 +25,9 @@ class ImageModuleMixIn:
_output_image: Any
def convert_input_output(
- self, input_names_to_handle: Optional[List[Any]] = None, output_type: str = "tensor"
+ self,
+ input_names_to_handle: Optional[list[Any]] = None,
+ output_type: str = "tensor",
) -> Callable[[Any], Any]:
"""Decorator to convert input and output types for a function.
@@ -39,7 +41,7 @@ class ImageModuleMixIn:
def decorator(func: Callable[[Any], Any]) -> Callable[[Any], Any]:
@wraps(func)
- def wrapper(*args: Any, **kwargs: Any) -> Union[Any, List[Any]]:
+ def wrapper(*args: Any, **kwargs: Any) -> Union[Any, list[Any]]:
# If input_names_to_handle is None, handle all inputs
if input_names_to_handle is None:
# Convert all args to tensors
@@ -139,7 +141,7 @@ class ImageModuleMixIn:
return np.array(x) # type: ignore
raise TypeError("Input type not supported")
- def to_pil(self, x: Any) -> "Image.Image": # type: ignore
+ def to_pil(self, x: Any) -> Image.Image: # type: ignore
"""Convert input to PIL image.
Args:
@@ -165,8 +167,8 @@ class ImageModuleMixIn:
raise TypeError("Input type not supported")
def _detach_tensor_to_cpu(
- self, output_image: Union[Tensor, List[Tensor], Tuple[Tensor]]
- ) -> Union[Tensor, List[Tensor], Tuple[Tensor]]:
+ self, output_image: Union[Tensor, list[Tensor], tuple[Tensor]]
+ ) -> Union[Tensor, list[Tensor], tuple[Tensor]]:
if isinstance(output_image, (Tensor,)):
return output_image.detach().cpu()
if isinstance(
@@ -250,7 +252,7 @@ class ImageModule(Module, ImageModuleMixIn, ONNXExportMixin):
def __call__(
self,
*inputs: Any,
- input_names_to_handle: Optional[List[Any]] = None,
+ input_names_to_handle: Optional[list[Any]] = None,
output_type: str = "tensor",
**kwargs: Any,
) -> Any:
@@ -306,7 +308,7 @@ class ImageSequential(Sequential, ImageModuleMixIn, ONNXExportMixin):
def __call__(
self,
*inputs: Any,
- input_names_to_handle: Optional[List[Any]] = None,
+ input_names_to_handle: Optional[list[Any]] = None,
output_type: str = "tensor",
**kwargs: Any,
) -> Any:
diff --git a/kornia/enhance/adjust.py b/kornia/enhance/adjust.py
index 379094747..66a056de0 100644
--- a/kornia/enhance/adjust.py
+++ b/kornia/enhance/adjust.py
@@ -1,4 +1,5 @@
from __future__ import annotations
+
from math import pi
from typing import ClassVar, Optional, Union
diff --git a/kornia/geometry/calibration/pnp.py b/kornia/geometry/calibration/pnp.py
index dd0d78f14..910aa7e3e 100644
--- a/kornia/geometry/calibration/pnp.py
+++ b/kornia/geometry/calibration/pnp.py
@@ -4,11 +4,11 @@ import torch
from torch.linalg import qr as linalg_qr
from kornia.core import arange, ones_like, where, zeros
+from kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_IS_TENSOR, KORNIA_CHECK_SAME_SHAPE, KORNIA_CHECK_SHAPE
from kornia.geometry.conversions import convert_points_to_homogeneous, normalize_points_with_intrinsics
from kornia.geometry.linalg import transform_points
from kornia.utils import eye_like
from kornia.utils.helpers import _torch_linalg_svdvals, _torch_svd_cast
-from kornia.core.check import KORNIA_CHECK_SHAPE, KORNIA_CHECK_IS_TENSOR, KORNIA_CHECK_SAME_SHAPE, KORNIA_CHECK
def _mean_isotropic_scale_normalize(points: torch.Tensor, eps: float = 1e-8) -> Tuple[torch.Tensor, torch.Tensor]:
@@ -45,7 +45,7 @@ def solve_pnp_dlt(
img_points: torch.Tensor,
intrinsics: torch.Tensor,
weights: Optional[torch.Tensor] = None,
- svd_eps: float = 1e-4
+ svd_eps: float = 1e-4,
) -> torch.Tensor:
r"""This function attempts to solve the Perspective-n-Point (PnP) problem using Direct Linear Transform (DLT).
@@ -134,9 +134,9 @@ def solve_pnp_dlt(
KORNIA_CHECK_SHAPE(world_points, ["B", "N", "3"])
KORNIA_CHECK_SHAPE(img_points, ["B", "N", "2"])
KORNIA_CHECK_SHAPE(intrinsics, ["B", "3", "3"])
- KORNIA_CHECK_SAME_SHAPE(world_points[:,:, 0], img_points[:,:, 0])
+ KORNIA_CHECK_SAME_SHAPE(world_points[:, :, 0], img_points[:, :, 0])
KORNIA_CHECK(world_points.shape[1] >= 6)
- if (weights is not None):
+ if weights is not None:
KORNIA_CHECK_IS_TENSOR(weights)
B, N = world_points.shape[:2]
diff --git a/kornia/geometry/calibration/undistort.py b/kornia/geometry/calibration/undistort.py
index 93f21403c..3084a2645 100644
--- a/kornia/geometry/calibration/undistort.py
+++ b/kornia/geometry/calibration/undistort.py
@@ -5,10 +5,10 @@ from typing import Optional
import torch
from kornia.core import stack
+from kornia.core.check import KORNIA_CHECK_SHAPE
from kornia.geometry.linalg import transform_points
from kornia.geometry.transform import remap
from kornia.utils import create_meshgrid
-from kornia.core.check import KORNIA_CHECK_SHAPE
from .distort import distort_points, tilt_projection
@@ -48,7 +48,7 @@ def undistort_points(
"""
KORNIA_CHECK_SHAPE(points, ["*", "N", "2"])
KORNIA_CHECK_SHAPE(K, ["*", "3", "3"])
-
+
if points.dim() < 2 and points.shape[-1] != 2:
raise ValueError(f"points shape is invalid. Got {points.shape}.")
diff --git a/kornia/geometry/conversions.py b/kornia/geometry/conversions.py
index 9f79d152e..ed323a11e 100644
--- a/kornia/geometry/conversions.py
+++ b/kornia/geometry/conversions.py
@@ -1177,7 +1177,7 @@ def normalize_points_with_intrinsics(point_2d: Tensor, camera_matrix: Tensor) ->
# unpack coordinates
cxcy = camera_matrix[..., :2, 2]
fxfy = camera_matrix[..., :2, :2].diagonal(dim1=-2, dim2=-1)
- if len(cxcy.shape) < len(point_2d.shape): # broadcast intrinsics:
+ if len(cxcy.shape) < len(point_2d.shape): # broadcast intrinsics:
cxcy, fxfy = cxcy.unsqueeze(-2), fxfy.unsqueeze(-2)
xy = (point_2d - cxcy) / fxfy
return xy
@@ -1217,7 +1217,7 @@ def denormalize_points_with_intrinsics(point_2d_norm: Tensor, camera_matrix: Ten
cx: Tensor = camera_matrix[..., 0, 2]
cy: Tensor = camera_matrix[..., 1, 2]
- if len(cx.shape) < len(x_coord.shape): # broadcast intrinsics
+ if len(cx.shape) < len(x_coord.shape): # broadcast intrinsics
cx, cy, fx, fy = cx.unsqueeze(-1), cy.unsqueeze(-1), fx.unsqueeze(-1), fy.unsqueeze(-1)
# apply intrinsics ans return
diff --git a/kornia/geometry/depth.py b/kornia/geometry/depth.py
index 7c85db649..addce206d 100644
--- a/kornia/geometry/depth.py
+++ b/kornia/geometry/depth.py
@@ -145,8 +145,8 @@ def depth_to_3d(depth: Tensor, camera_matrix: Tensor, normalize_points: bool = F
"""
KORNIA_CHECK_IS_TENSOR(depth)
KORNIA_CHECK_IS_TENSOR(camera_matrix)
- KORNIA_CHECK_SHAPE(depth, ["B", "1", "H", "W"])
- KORNIA_CHECK_SHAPE(camera_matrix, ["B", "3", "3"])
+ KORNIA_CHECK_SHAPE(depth, ["B", "1", "H", "W"])
+ KORNIA_CHECK_SHAPE(camera_matrix, ["B", "3", "3"])
# create base coordinates grid
_, _, height, width = depth.shape
@@ -185,8 +185,8 @@ def depth_to_normals(depth: Tensor, camera_matrix: Tensor, normalize_points: boo
"""
KORNIA_CHECK_IS_TENSOR(depth)
KORNIA_CHECK_IS_TENSOR(camera_matrix)
- KORNIA_CHECK_SHAPE(depth, ["B", "1", "H", "W"])
- KORNIA_CHECK_SHAPE(camera_matrix, ["B", "3", "3"])
+ KORNIA_CHECK_SHAPE(depth, ["B", "1", "H", "W"])
+ KORNIA_CHECK_SHAPE(camera_matrix, ["B", "3", "3"])
# compute the 3d points from depth
xyz: Tensor = depth_to_3d(depth, camera_matrix, normalize_points) # Bx3xHxW
@@ -202,14 +202,9 @@ def depth_to_normals(depth: Tensor, camera_matrix: Tensor, normalize_points: boo
def depth_from_plane_equation(
- plane_normals: Tensor,
- plane_offsets: Tensor,
- points_uv: Tensor,
- camera_matrix: Tensor,
- eps: float = 1e-8
+ plane_normals: Tensor, plane_offsets: Tensor, points_uv: Tensor, camera_matrix: Tensor, eps: float = 1e-8
) -> Tensor:
- """
- Compute depth values from plane equations and pixel coordinates.
+ """Compute depth values from plane equations and pixel coordinates.
Parameters:
plane_normals (Tensor): Plane normal vectors of shape (B, 3).
diff --git a/kornia/geometry/epipolar/essential.py b/kornia/geometry/epipolar/essential.py
index 2d0a429e7..7257123b4 100644
--- a/kornia/geometry/epipolar/essential.py
+++ b/kornia/geometry/epipolar/essential.py
@@ -403,7 +403,7 @@ def essential_from_Rt(R1: torch.Tensor, t1: torch.Tensor, R2: torch.Tensor, t2:
KORNIA_CHECK_SHAPE(R2, ["*", "3", "3"])
KORNIA_CHECK_SHAPE(t1, ["*", "3", "1"])
KORNIA_CHECK_SHAPE(t2, ["*", "3", "1"])
-
+
# first compute the camera relative motion
R, t = relative_camera_motion(R1, t1, R2, t2)
diff --git a/kornia/geometry/epipolar/fundamental.py b/kornia/geometry/epipolar/fundamental.py
index 5d0497544..0450c76fb 100644
--- a/kornia/geometry/epipolar/fundamental.py
+++ b/kornia/geometry/epipolar/fundamental.py
@@ -5,7 +5,7 @@ from typing import Literal, Optional, Tuple
import torch
from kornia.core import Tensor, concatenate, ones_like, stack, where, zeros
-from kornia.core.check import KORNIA_CHECK_SHAPE, KORNIA_CHECK_SAME_SHAPE
+from kornia.core.check import KORNIA_CHECK_SAME_SHAPE, KORNIA_CHECK_SHAPE
from kornia.geometry.conversions import convert_points_from_homogeneous, convert_points_to_homogeneous
from kornia.geometry.linalg import transform_points
from kornia.geometry.solvers import solve_cubic
diff --git a/kornia/geometry/epipolar/projection.py b/kornia/geometry/epipolar/projection.py
index abc253f84..cec8da7cd 100644
--- a/kornia/geometry/epipolar/projection.py
+++ b/kornia/geometry/epipolar/projection.py
@@ -6,9 +6,10 @@ import torch
from torch.linalg import qr as linalg_qr
from kornia.core import Tensor, concatenate, ones_like, pad, stack, zeros_like
+from kornia.core.check import KORNIA_CHECK_SHAPE
from kornia.utils import eye_like, vec_like
from kornia.utils.helpers import _torch_svd_cast
-from kornia.core.check import KORNIA_CHECK_SHAPE
+
from .numeric import cross_product_matrix
diff --git a/kornia/geometry/epipolar/triangulation.py b/kornia/geometry/epipolar/triangulation.py
index dbaceb453..d81302e06 100644
--- a/kornia/geometry/epipolar/triangulation.py
+++ b/kornia/geometry/epipolar/triangulation.py
@@ -3,9 +3,9 @@
import torch
from kornia.core import zeros
+from kornia.core.check import KORNIA_CHECK_SHAPE
from kornia.geometry.conversions import convert_points_from_homogeneous
from kornia.utils.helpers import _torch_svd_cast
-from kornia.core.check import KORNIA_CHECK_SHAPE, KORNIA_CHECK_SAME_SHAPE
# https://github.com/opencv/opencv_contrib/blob/master/modules/sfm/src/triangulation.cpp#L68
diff --git a/kornia/models/_hf_models/hf_onnx_community.py b/kornia/models/_hf_models/hf_onnx_community.py
index a440aa32c..a50c33562 100644
--- a/kornia/models/_hf_models/hf_onnx_community.py
+++ b/kornia/models/_hf_models/hf_onnx_community.py
@@ -1,4 +1,5 @@
from __future__ import annotations
+
import os
from typing import Any, Optional
@@ -43,7 +44,7 @@ class HFONNXComunnityModelLoader:
def load_model(
self, download: bool = True, io_name_mapping: Optional[dict[str, str]] = None, **kwargs: Any
- ) -> "onnx.ModelProto": # type:ignore
+ ) -> onnx.ModelProto: # type:ignore
onnx_model = ONNXLoader.load_model(
self.model_url, download=download, with_data=self.with_data, cache_dir=self.cache_dir, **kwargs
)
@@ -61,9 +62,9 @@ class HFONNXComunnityModelLoader:
def _add_metadata(
self,
- model: "onnx.ModelProto", # type:ignore
+ model: onnx.ModelProto, # type:ignore
additional_metadata: dict[str, Any] = {},
- ) -> "onnx.ModelProto": # type:ignore
+ ) -> onnx.ModelProto: # type:ignore
for key, value in additional_metadata.items():
metadata_props = model.metadata_props.add()
metadata_props.key = key
@@ -76,9 +77,9 @@ class HFONNXComunnityModel(ONNXSequential, ModelBaseMixin):
def __init__(
self,
- model: "onnx.ModelProto", # type: ignore
- pre_processor: Optional["onnx.ModelProto"] = None, # type: ignore
- post_processor: Optional["onnx.ModelProto"] = None, # type: ignore
+ model: onnx.ModelProto, # type: ignore
+ pre_processor: Optional[onnx.ModelProto] = None, # type: ignore
+ post_processor: Optional[onnx.ModelProto] = None, # type: ignore
name: Optional[str] = None,
auto_ir_version_conversion: bool = True,
io_maps: Optional[list[tuple[str, str]]] = None,
@@ -115,7 +116,7 @@ class HFONNXComunnityModel(ONNXSequential, ModelBaseMixin):
save: bool = True,
additional_metadata: list[tuple[str, str]] = [],
**kwargs: Any,
- ) -> "onnx.ModelProto": # type:ignore
+ ) -> onnx.ModelProto: # type:ignore
"""Exports a depth estimation model to ONNX format.
Args:
diff --git a/kornia/models/_hf_models/preprocessor.py b/kornia/models/_hf_models/preprocessor.py
index 82d6aff5b..14f52b729 100644
--- a/kornia/models/_hf_models/preprocessor.py
+++ b/kornia/models/_hf_models/preprocessor.py
@@ -1,4 +1,5 @@
from __future__ import annotations
+
from typing import Any
from kornia.core import ImageSequential, Module, Tensor, tensor
diff --git a/kornia/models/tracking/boxmot_tracker.py b/kornia/models/tracking/boxmot_tracker.py
index cb1486448..fe73c02d9 100644
--- a/kornia/models/tracking/boxmot_tracker.py
+++ b/kornia/models/tracking/boxmot_tracker.py
@@ -1,4 +1,5 @@
from __future__ import annotations
+
import datetime
import logging
import os
diff --git a/kornia/onnx/utils.py b/kornia/onnx/utils.py
index 00eaa080f..05b6544f0 100644
--- a/kornia/onnx/utils.py
+++ b/kornia/onnx/utils.py
@@ -9,8 +9,7 @@ from typing import Any
import kornia
from kornia.config import kornia_config
from kornia.core.external import numpy as np
-from kornia.core.external import onnx
-from kornia.core.external import requests
+from kornia.core.external import onnx, requests
from kornia.utils.download import CachedDownloader
__all__ = ["ONNXLoader", "io_name_conversion", "add_metadata"]
diff --git a/kornia/transpiler/__init__.py b/kornia/transpiler/__init__.py
index 06a836b08..5344ce648 100644
--- a/kornia/transpiler/__init__.py
+++ b/kornia/transpiler/__init__.py
@@ -1,3 +1,3 @@
-from .transpiler import *
+from .transpiler import to_jax, to_numpy, to_tensorflow
__all__ = ["to_jax", "to_numpy", "to_tensorflow"]
diff --git a/kornia/transpiler/transpiler.py b/kornia/transpiler/transpiler.py
index 596143c1d..4d002140a 100644
--- a/kornia/transpiler/transpiler.py
+++ b/kornia/transpiler/transpiler.py
@@ -1,3 +1,5 @@
+"""Module for transpiling Kornia to other frameworks."""
+
import kornia
from kornia.core.external import ivy
@@ -5,10 +7,10 @@ from kornia.core.external import ivy
def to_jax():
"""Convert Kornia to JAX.
- Transpiles the Kornia library to JAX using [ivy](https://github.com/ivy-llc/ivy). The transpilation process
- occurs lazily, so the transpilation on a given kornia function/class will only occur when it's called or instantiated
- for the first time. This will make any functions/classes slow when being used for the first time, but any
- subsequent uses should be as fast as expected.
+ Transpiles the Kornia library to JAX using [ivy](https://github.com/ivy-llc/ivy). The transpilation process
+ occurs lazily, so the transpilation on a given kornia function/class will only occur when it's called or
+ instantiated for the first time. This will make any functions/classes slow when being used for the first time,
+ but any subsequent uses should be as fast as expected.
Return:
The Kornia library transpiled to JAX
@@ -30,10 +32,10 @@ def to_jax():
def to_numpy():
"""Convert Kornia to NumPy.
- Transpiles the Kornia library to NumPy using [ivy](https://github.com/ivy-llc/ivy). The transpilation process
- occurs lazily, so the transpilation on a given kornia function/class will only occur when it's called or instantiated
- for the first time. This will make any functions/classes slow when being used for the first time, but any
- subsequent uses should be as fast as expected.
+ Transpiles the Kornia library to NumPy using [ivy](https://github.com/ivy-llc/ivy). The transpilation process
+ occurs lazily, so the transpilation on a given kornia function/class will only occur when it's called or
+ instantiated for the first time. This will make any functions/classes slow when being used for the first time,
+ but any subsequent uses should be as fast as expected.
Return:
The Kornia library transpiled to NumPy
@@ -58,10 +60,10 @@ def to_numpy():
def to_tensorflow():
"""Convert Kornia to TensorFlow.
- Transpiles the Kornia library to TensorFlow using [ivy](https://github.com/ivy-llc/ivy). The transpilation process
- occurs lazily, so the transpilation on a given kornia function/class will only occur when it's called or instantiated
- for the first time. This will make any functions/classes slow when being used for the first time, but any
- subsequent uses should be as fast as expected.
+ Transpiles the Kornia library to TensorFlow using [ivy](https://github.com/ivy-llc/ivy). The transpilation process
+ occurs lazily, so the transpilation on a given kornia function/class will only occur when it's called or
+ instantiated for the first time. This will make any functions/classes slow when being used for the first time,
+ but any subsequent uses should be as fast as expected.
Return:
The Kornia library transpiled to TensorFlow
diff --git a/kornia/utils/sample.py b/kornia/utils/sample.py
index f6b44852f..c2fdce4af 100644
--- a/kornia/utils/sample.py
+++ b/kornia/utils/sample.py
@@ -5,8 +5,8 @@ from typing import Any, List, Optional, Tuple, Union
import kornia
from kornia.core import Tensor, stack
from kornia.core.external import PILImage as Image
-from kornia.io import load_image
from kornia.core.external import requests
+from kornia.io import load_image
__all__ = [
"get_sample_images",
diff --git a/tests/color/test_rgb.py b/tests/color/test_rgb.py
index c7f7ae75a..55130bf70 100644
--- a/tests/color/test_rgb.py
+++ b/tests/color/test_rgb.py
@@ -49,11 +49,23 @@ class TestRgbToBgr(BaseTester):
def test_unit(self, device, dtype):
data = torch.tensor(
- [[[1.0, 1.0], [1.0, 1.0]], [[2.0, 2.0], [2.0, 2.0]], [[3.0, 3.0], [3.0, 3.0]]], device=device, dtype=dtype
+ [
+ [[1.0, 1.0], [1.0, 1.0]],
+ [[2.0, 2.0], [2.0, 2.0]],
+ [[3.0, 3.0], [3.0, 3.0]],
+ ],
+ device=device,
+ dtype=dtype,
) # 3x2x2
expected = torch.tensor(
- [[[3.0, 3.0], [3.0, 3.0]], [[2.0, 2.0], [2.0, 2.0]], [[1.0, 1.0], [1.0, 1.0]]], device=device, dtype=dtype
+ [
+ [[3.0, 3.0], [3.0, 3.0]],
+ [[2.0, 2.0], [2.0, 2.0]],
+ [[1.0, 1.0], [1.0, 1.0]],
+ ],
+ device=device,
+ dtype=dtype,
) # 3x2x2
f = kornia.color.rgb_to_bgr
@@ -151,7 +163,15 @@ class TestRgbToRgba(BaseTester):
@pytest.mark.parametrize("aval", [0.4, 45.0])
def test_unit(self, device, dtype, aval):
data = torch.tensor(
- [[[[1.0, 1.0], [1.0, 1.0]], [[2.0, 2.0], [2.0, 2.0]], [[3.0, 3.0], [3.0, 3.0]]]], device=device, dtype=dtype
+ [
+ [
+ [[1.0, 1.0], [1.0, 1.0]],
+ [[2.0, 2.0], [2.0, 2.0]],
+ [[3.0, 3.0], [3.0, 3.0]],
+ ]
+ ],
+ device=device,
+ dtype=dtype,
) # Bx3x2x2
expected = torch.tensor(
@@ -172,7 +192,15 @@ class TestRgbToRgba(BaseTester):
@pytest.mark.parametrize("aval", [0.4, 45.0])
def test_unit_aval_th(self, device, dtype, aval):
data = torch.tensor(
- [[[[1.0, 1.0], [1.0, 1.0]], [[2.0, 2.0], [2.0, 2.0]], [[3.0, 3.0], [3.0, 3.0]]]], device=device, dtype=dtype
+ [
+ [
+ [[1.0, 1.0], [1.0, 1.0]],
+ [[2.0, 2.0], [2.0, 2.0]],
+ [[3.0, 3.0], [3.0, 3.0]],
+ ]
+ ],
+ device=device,
+ dtype=dtype,
) # Bx3x2x2
expected = torch.tensor(
@@ -288,125 +316,15 @@ class TestLinearRgb(BaseTester):
def test_unit(self, device, dtype):
data = torch.tensor(
- [[[1.0, 0.0], [0.5, 0.1]], [[1.0, 0.0], [0.5, 0.2]], [[1.0, 0.0], [0.5, 0.3]]], device=device, dtype=dtype
- ) # 3x2x2
-
- expected = torch.tensor(
[
- [[1.00000000, 0.00000000], [0.21404116, 0.01002283]],
- [[1.00000000, 0.00000000], [0.21404116, 0.03310477]],
- [[1.00000000, 0.00000000], [0.21404116, 0.07323898]],
- ],
- device=device,
- dtype=dtype,
- ) # 3x2x2
-
- f = kornia.color.rgb_to_linear_rgb
- self.assert_close(f(data), expected)
-
- def test_unit_linear(self, device, dtype):
- data = torch.tensor(
- [
- [[1.00000000, 0.00000000], [0.21404116, 0.01002283]],
- [[1.00000000, 0.00000000], [0.21404116, 0.03310477]],
- [[1.00000000, 0.00000000], [0.21404116, 0.07323898]],
+ [[1.0, 0.0], [0.5, 0.1]],
+ [[1.0, 0.0], [0.5, 0.2]],
+ [[1.0, 0.0], [0.5, 0.3]],
],
device=device,
dtype=dtype,
) # 3x2x2
- expected = torch.tensor(
- [[[1.0, 0.0], [0.5, 0.1]], [[1.0, 0.0], [0.5, 0.2]], [[1.0, 0.0], [0.5, 0.3]]], device=device, dtype=dtype
- ) # 3x2x2
-
- f = kornia.color.linear_rgb_to_rgb
- self.assert_close(f(data), expected)
-
- @pytest.mark.grad()
- def test_gradcheck(self, device, dtype):
- B, C, H, W = 2, 3, 4, 4
- img = torch.ones(B, C, H, W, device=device, dtype=torch.float64, requires_grad=True)
- assert gradcheck(kornia.color.rgb_to_linear_rgb, (img,), raise_exception=True, fast_mode=True)
- assert gradcheck(kornia.color.linear_rgb_to_rgb, (img,), raise_exception=True, fast_mode=True)
-
- @pytest.mark.jit()
- def test_jit(self, device, dtype):
- B, C, H, W = 2, 3, 4, 4
- img = torch.ones(B, C, H, W, device=device, dtype=dtype)
- op = kornia.color.rgb_to_linear_rgb
- op_jit = torch.jit.script(op)
- self.assert_close(op(img), op_jit(img))
-
- @pytest.mark.jit()
- def test_jit_linear(self, device, dtype):
- B, C, H, W = 2, 3, 4, 4
- img = torch.ones(B, C, H, W, device=device, dtype=dtype)
- op = kornia.color.linear_rgb_to_rgb
- op_jit = torch.jit.script(op)
- self.assert_close(op(img), op_jit(img))
-
- def test_module(self, device, dtype):
- B, C, H, W = 2, 3, 4, 4
- img = torch.ones(B, C, H, W, device=device, dtype=dtype)
- ops = kornia.color.RgbToLinearRgb().to(device, dtype)
- fcn = kornia.color.rgb_to_linear_rgb
- self.assert_close(ops(img), fcn(img))
-
- def test_module_linear(self, device, dtype):
- B, C, H, W = 2, 3, 4, 4
- img = torch.ones(B, C, H, W, device=device, dtype=dtype)
- ops = kornia.color.LinearRgbToRgb().to(device, dtype)
- fcn = kornia.color.linear_rgb_to_rgb
- self.assert_close(ops(img), fcn(img))
-
-
-class TestLinearRgb(BaseTester):
- def test_smoke(self, device, dtype):
- C, H, W = 3, 4, 5
- img = torch.rand(C, H, W, device=device, dtype=dtype)
- assert isinstance(kornia.color.rgb_to_linear_rgb(img), torch.Tensor)
- assert isinstance(kornia.color.linear_rgb_to_rgb(img), torch.Tensor)
-
- @pytest.mark.parametrize("shape", [(1, 3, 4, 4), (2, 3, 2, 4), (3, 3, 4, 1), (3, 2, 1)])
- def test_cardinality(self, device, dtype, shape):
- img = torch.ones(shape, device=device, dtype=dtype)
- assert kornia.color.rgb_to_linear_rgb(img).shape == shape
- assert kornia.color.linear_rgb_to_rgb(img).shape == shape
-
- def test_exception(self, device, dtype):
- with pytest.raises(TypeError):
- assert kornia.color.rgb_to_linear_rgb([0.0])
-
- with pytest.raises(ValueError):
- img = torch.ones(1, 1, device=device, dtype=dtype)
- assert kornia.color.rgb_to_linear_rgb(img)
-
- with pytest.raises(ValueError):
- img = torch.ones(2, 1, 1, device=device, dtype=dtype)
- assert kornia.color.rgb_to_linear_rgb(img)
-
- with pytest.raises(TypeError):
- assert kornia.color.linear_rgb_to_rgb([0.0])
-
- with pytest.raises(ValueError):
- img = torch.ones(1, 1, device=device, dtype=dtype)
- assert kornia.color.linear_rgb_to_rgb(img)
-
- with pytest.raises(ValueError):
- img = torch.ones(2, 1, 1, device=device, dtype=dtype)
- assert kornia.color.linear_rgb_to_rgb(img)
-
- def test_back_and_forth(self, device, dtype):
- data_bgr = torch.rand(1, 3, 3, 2, device=device, dtype=dtype)
- data_rgb = kornia.color.rgb_to_linear_rgb(data_bgr)
- data_bgr_new = kornia.color.linear_rgb_to_rgb(data_rgb)
- self.assert_close(data_bgr, data_bgr_new)
-
- def test_unit(self, device, dtype):
- data = torch.tensor(
- [[[1.0, 0.0], [0.5, 0.1]], [[1.0, 0.0], [0.5, 0.2]], [[1.0, 0.0], [0.5, 0.3]]], device=device, dtype=dtype
- ) # 3x2x2
-
expected = torch.tensor(
[
[[1.00000000, 0.00000000], [0.21404116, 0.01002283]],
@@ -432,7 +350,13 @@ class TestLinearRgb(BaseTester):
) # 3x2x2
expected = torch.tensor(
- [[[1.0, 0.0], [0.5, 0.1]], [[1.0, 0.0], [0.5, 0.2]], [[1.0, 0.0], [0.5, 0.3]]], device=device, dtype=dtype
+ [
+ [[1.0, 0.0], [0.5, 0.1]],
+ [[1.0, 0.0], [0.5, 0.2]],
+ [[1.0, 0.0], [0.5, 0.3]],
+ ],
+ device=device,
+ dtype=dtype,
) # 3x2x2
f = kornia.color.linear_rgb_to_rgb
@@ -501,7 +425,7 @@ class TestRgb255Normals(BaseTester):
rgb255 = kornia.color.rgb_to_rgb255(data_rgb)
rgb_restored = kornia.color.rgb255_to_rgb(rgb255)
torch.testing.assert_close(data_rgb, rgb_restored, atol=1e-4, rtol=1e-4)
-
+
data_normals = torch.nn.functional.normalize(torch.rand(1, 3, 3, 2, device=device, dtype=dtype), p=2, dim=1)
rgb255_normals = kornia.color.normals_to_rgb255(data_normals)
normals_restored = kornia.color.rgb255_to_normals(rgb255_normals)
@@ -520,7 +444,12 @@ class TestRgb255Normals(BaseTester):
def test_jit(self, device, dtype):
B, C, H, W = 2, 3, 4, 4
img = torch.ones(B, C, H, W, device=device, dtype=dtype)
- for op in [kornia.color.normals_to_rgb255, kornia.color.rgb_to_rgb255, kornia.color.rgb255_to_rgb, kornia.color.rgb255_to_normals]:
+ for op in [
+ kornia.color.normals_to_rgb255,
+ kornia.color.rgb_to_rgb255,
+ kornia.color.rgb255_to_rgb,
+ kornia.color.rgb255_to_normals,
+ ]:
op_jit = torch.jit.script(op)
self.assert_close(op(img), op_jit(img))
@@ -528,8 +457,10 @@ class TestRgb255Normals(BaseTester):
B, C, H, W = 2, 3, 4, 4
img = torch.ones(B, C, H, W, device=device, dtype=dtype)
- for (fcn, Mod) in [(kornia.color.normals_to_rgb255, kornia.color.NormalsToRgb255()),
- (kornia.color.rgb255_to_rgb, kornia.color.Rgb255ToRgb()),
- (kornia.color.rgb_to_rgb255, kornia.color.RgbToRgb255()),
- (kornia.color.rgb255_to_normals,kornia.color.Rgb255ToNormals())]:
- self.assert_close(fcn(img), Mod(img))
\ No newline at end of file
+ for fcn, Mod in [
+ (kornia.color.normals_to_rgb255, kornia.color.NormalsToRgb255()),
+ (kornia.color.rgb255_to_rgb, kornia.color.Rgb255ToRgb()),
+ (kornia.color.rgb_to_rgb255, kornia.color.RgbToRgb255()),
+ (kornia.color.rgb255_to_normals, kornia.color.Rgb255ToNormals()),
+ ]:
+ self.assert_close(fcn(img), Mod(img))
diff --git a/tests/geometry/calibration/test_pnp.py b/tests/geometry/calibration/test_pnp.py
index f785cf588..1f57bed41 100644
--- a/tests/geometry/calibration/test_pnp.py
+++ b/tests/geometry/calibration/test_pnp.py
@@ -131,7 +131,6 @@ class TestSolvePnpDlt(BaseTester):
pred_world_to_cam = kornia.geometry.solve_pnp_dlt(world_points, img_points, intrinsics, weights)
self.assert_close(pred_world_to_cam, gt_world_to_cam, atol=1e-4, rtol=1e-3)
-
@pytest.mark.parametrize("num_points", (6, 20))
def test_project(self, num_points, device, dtype):
intrinsics, _, world_points, img_points = self._get_test_data(num_points, device, dtype)
diff --git a/tests/geometry/test_depth.py b/tests/geometry/test_depth.py
index 88670583f..93387ba7b 100644
--- a/tests/geometry/test_depth.py
+++ b/tests/geometry/test_depth.py
@@ -423,16 +423,13 @@ class TestDepthFromPlaneEquation(BaseTester):
camera_matrix = torch.eye(3, device=device, dtype=dtype)
depth = kornia.geometry.depth.depth_from_plane_equation(
- plane_normals.expand(B, -1),
- plane_offsets.expand(B, -1),
- points_uv,
- camera_matrix.expand(B, -1, -1)
+ plane_normals.expand(B, -1), plane_offsets.expand(B, -1), points_uv, camera_matrix.expand(B, -1, -1)
)
assert depth.shape == (B, N), f"Expected depth shape to be ({B}, {N}), but got {depth.shape}"
def test_simple(self, device, dtype):
- """
- Test the function with a simple plane equation to verify numerical correctness.
+ """Test the function with a simple plane equation to verify numerical correctness.
+
Plane equation: z = 2 (plane normal [0, 0, 1], offset 2)
Expected depth for any point is 2.
"""
@@ -442,12 +439,7 @@ class TestDepthFromPlaneEquation(BaseTester):
# Define pixel coordinates
points_uv = torch.tensor(
- [
- [[0.0, 0.0],
- [1.0, 0.0],
- [0.0, 1.0],
- [1.0, 1.0]]
- ],
+ [[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]]],
device=device,
dtype=dtype,
) # Shape: (B, N, 2)