Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix minor mypy issues across versions (#1132)

Edgar Riba91dcef465110
diff --git a/kornia/augmentation/container/augment.py b/kornia/augmentation/container/augment.py
index 852346dae..0865d1d8c 100644
--- a/kornia/augmentation/container/augment.py
+++ b/kornia/augmentation/container/augment.py
@@ -158,7 +158,8 @@ class AugmentationSequential(ImageSequential):
if param is not None:
assert module_name == param.name
if module is None:
- module = self.get_submodule(module_name)
+ # TODO (jian): double check why typing is crashing
+ module = self.get_submodule(module_name) # type: ignore
if DataKey.get(dcate) in [DataKey.INPUT]:
return self.apply_to_input(input, module_name, module, param)
if DataKey.get(dcate) in [DataKey.MASK]:
diff --git a/kornia/augmentation/container/image.py b/kornia/augmentation/container/image.py
index 43ba35a29..197f4e444 100644
--- a/kornia/augmentation/container/image.py
+++ b/kornia/augmentation/container/image.py
@@ -153,7 +153,8 @@ class ImageSequential(nn.Sequential):
param: Optional[ParamItem] = None,
) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
if module is None:
- module = self.get_submodule(module_name)
+ # TODO (jian): double check why typing is crashing
+ module = self.get_submodule(module_name) # type: ignore
if param is not None:
assert module_name == param.name
_param = param.data
diff --git a/kornia/geometry/camera/stereo.py b/kornia/geometry/camera/stereo.py
index a647150c2..469417847 100644
--- a/kornia/geometry/camera/stereo.py
+++ b/kornia/geometry/camera/stereo.py
@@ -56,14 +56,14 @@ class StereoCamera:
of shape :math:`(B, 3, 4)`
"""
# Ensure correct shapes
- if rectified_left_camera.ndim != 3:
+ if len(rectified_left_camera.shape) != 3:
raise StereoException(
- f"Expected 'rectified_left_camera' to have 3 dimensions. " f"Got {rectified_left_camera.ndim}."
+ f"Expected 'rectified_left_camera' to have 3 dimensions. " f"Got {rectified_left_camera.shape}."
)
- if rectified_right_camera.ndim != 3:
+ if len(rectified_right_camera.shape) != 3:
raise StereoException(
- f"Expected 'rectified_right_camera' to have 3 dimension. " f"Got {rectified_right_camera.ndim}."
+ f"Expected 'rectified_right_camera' to have 3 dimension. " f"Got {rectified_right_camera.shape}."
)
if rectified_left_camera.shape[:1] == (3, 4):
@@ -231,8 +231,8 @@ def _check_disparity_tensor(disparity_tensor: torch.Tensor):
f"Expected 'disparity_tensor' to be an instance of torch.Tensor but got {type(disparity_tensor)}."
)
- if disparity_tensor.ndim != 4:
- raise StereoException(f"Expected 'disparity_tensor' to have 4 dimensions." f"Got {disparity_tensor.ndim}.")
+ if len(disparity_tensor.shape) != 4:
+ raise StereoException(f"Expected 'disparity_tensor' to have 4 dimensions." f"Got {disparity_tensor.shape}.")
if disparity_tensor.shape[-1] != 1:
raise StereoException(
@@ -257,8 +257,8 @@ def _check_Q_matrix(Q_matrix: torch.Tensor):
if not isinstance(Q_matrix, torch.Tensor):
raise StereoException(f"Expected 'Q_matrix' to be an instance of torch.Tensor but got {type(Q_matrix)}.")
- if not Q_matrix.ndim == 3:
- raise StereoException(f"Expected 'Q_matrix' to have 3 dimenstions." f"Got {Q_matrix.ndim}")
+ if not len(Q_matrix.shape) == 3:
+ raise StereoException(f"Expected 'Q_matrix' to have 3 dimenstions." f"Got {Q_matrix.shape}")
if not Q_matrix.shape[1:] == (4, 4):
raise StereoException(
diff --git a/kornia/testing/__init__.py b/kornia/testing/__init__.py
index becd68dad..9d1aaa752 100644
--- a/kornia/testing/__init__.py
+++ b/kornia/testing/__init__.py
@@ -134,7 +134,7 @@ def _get_precision_by_name(
try:
# torch.testing.assert_close is only available for torch>=1.9
- from torch.testing import assert_close as _assert_close
+ from torch.testing import assert_close as _assert_close # type: ignore
from torch.testing._core import _get_default_tolerance
def assert_close(