Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

prune unused imports (#1092)

Jirka Borovec9681810cd2f2
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 62b3837d7..20659abea 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -2,9 +2,6 @@ import os
import sys
import sphinx_rtd_theme
-import torch
-
-import kornia
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
diff --git a/kornia/augmentation/augmentation3d.py b/kornia/augmentation/augmentation3d.py
index 210bd46ce..701709545 100644
--- a/kornia/augmentation/augmentation3d.py
+++ b/kornia/augmentation/augmentation3d.py
@@ -1,19 +1,17 @@
-from typing import Callable, cast, Dict, List, Optional, Tuple, Union
+from typing import cast, Dict, Optional, Tuple, Union
import torch
from torch.nn.functional import pad
-from kornia.constants import BorderType, pi, Resample
+from kornia.constants import BorderType, Resample
from kornia.enhance import equalize3d
from kornia.filters import motion_blur3d
from kornia.geometry import (
affine3d,
- crop_by_boxes3d,
crop_by_transform_mat3d,
deg2rad,
get_affine_matrix3d,
get_perspective_transform3d,
- rotate3d,
warp_affine3d,
warp_perspective3d,
)
diff --git a/kornia/augmentation/base.py b/kornia/augmentation/base.py
index dde3a221d..96b215e49 100644
--- a/kornia/augmentation/base.py
+++ b/kornia/augmentation/base.py
@@ -8,7 +8,6 @@ from torch.distributions import Bernoulli
import kornia
from kornia.utils.helpers import _torch_inverse_cast
-from . import functional as F
from .utils import (
_adapted_sampling,
_transform_input,
diff --git a/kornia/augmentation/functional/functional.py b/kornia/augmentation/functional/functional.py
index 9da2ce126..6e1d84804 100644
--- a/kornia/augmentation/functional/functional.py
+++ b/kornia/augmentation/functional/functional.py
@@ -1,4 +1,4 @@
-from typing import cast, Dict, List, Optional, Tuple, Union
+from typing import cast, Dict, Optional, Tuple
import torch
@@ -33,9 +33,8 @@ from kornia.geometry import (
)
from kornia.geometry.transform.affwarp import _compute_rotation_matrix, _compute_tensor_center
-from .. import random_generator as rg
-from ..utils import _range_bound, _shape_validation, _validate_input, _validate_input_dtype, _validate_input_shape
-from .__temp__ import __deprecation_warning, _deprecation_wrapper
+from ..utils import _shape_validation, _validate_input, _validate_input_shape
+from .__temp__ import _deprecation_wrapper
@_deprecation_wrapper
diff --git a/kornia/augmentation/functional/functional3d.py b/kornia/augmentation/functional/functional3d.py
index acb720bee..fa0e7c5d1 100644
--- a/kornia/augmentation/functional/functional3d.py
+++ b/kornia/augmentation/functional/functional3d.py
@@ -1,9 +1,9 @@
-from typing import cast, Dict, List, Optional, Tuple, Union
+from typing import cast, Dict
import torch
import kornia as K
-from kornia.constants import BorderType, pi, Resample
+from kornia.constants import BorderType, Resample
from kornia.enhance import equalize3d
from kornia.filters import motion_blur3d
from kornia.geometry import (
@@ -17,9 +17,8 @@ from kornia.geometry import (
from kornia.geometry.transform.affwarp import _compute_rotation_matrix3d, _compute_tensor_center3d
from kornia.geometry.transform.projwarp import warp_affine3d
-from .. import random_generator as rg
from ..utils import _validate_input3d
-from .__temp__ import __deprecation_warning, _deprecation_wrapper
+from .__temp__ import _deprecation_wrapper
@_deprecation_wrapper
diff --git a/kornia/augmentation/mix_augmentation.py b/kornia/augmentation/mix_augmentation.py
index b547c39f7..d5470fab7 100644
--- a/kornia/augmentation/mix_augmentation.py
+++ b/kornia/augmentation/mix_augmentation.py
@@ -1,15 +1,12 @@
-from typing import Callable, cast, Dict, List, Optional, Tuple, Union
+from typing import cast, Dict, Optional, Tuple, Union
import torch
-import torch.nn as nn
-from torch.nn.functional import pad
-from kornia.constants import BorderType, Resample
from kornia.geometry import bbox_to_mask, infer_box_shape
from . import random_generator as rg
from .base import MixAugmentationBase
-from .utils import _infer_batch_shape, _shape_validation
+from .utils import _shape_validation
class RandomMixUp(MixAugmentationBase):
diff --git a/kornia/augmentation/random_generator/random_generator.py b/kornia/augmentation/random_generator/random_generator.py
index b2dd6c98d..40c9d62f5 100644
--- a/kornia/augmentation/random_generator/random_generator.py
+++ b/kornia/augmentation/random_generator/random_generator.py
@@ -1,10 +1,8 @@
-import random
-from typing import cast, Dict, List, Optional, Tuple, Union
+from typing import cast, Dict, Optional, Tuple, Union
import torch
from torch.distributions import Bernoulli
-from kornia.constants import BorderType, Resample, SamplePadding
from kornia.geometry import bbox_generator
from kornia.utils import _extract_device_dtype
diff --git a/kornia/augmentation/random_generator/random_generator3d.py b/kornia/augmentation/random_generator/random_generator3d.py
index 6b571ea3f..37398e1b5 100644
--- a/kornia/augmentation/random_generator/random_generator3d.py
+++ b/kornia/augmentation/random_generator/random_generator3d.py
@@ -1,14 +1,11 @@
-import math
-import random
-from typing import cast, Dict, List, Optional, Tuple, Union
+from typing import Dict, Optional, Tuple, Union
import torch
-from kornia.constants import BorderType, Resample
from kornia.geometry import bbox_generator3d
from kornia.utils import _extract_device_dtype
-from ..utils import _adapted_uniform, _joint_range_check, _tuple_range_reader
+from ..utils import _adapted_uniform, _joint_range_check
def random_rotation_generator3d(
diff --git a/kornia/color/hls.py b/kornia/color/hls.py
index 43fe359e0..031ceb2f1 100644
--- a/kornia/color/hls.py
+++ b/kornia/color/hls.py
@@ -3,9 +3,6 @@ import math
import torch
import torch.nn as nn
-import kornia
-from kornia.constants import pi
-
def rgb_to_hls(image: torch.Tensor) -> torch.Tensor:
r"""Convert a RGB image to HLS.
diff --git a/kornia/color/lab.py b/kornia/color/lab.py
index b45fd334d..47b25fb5a 100644
--- a/kornia/color/lab.py
+++ b/kornia/color/lab.py
@@ -1,5 +1,3 @@
-from typing import Tuple
-
import torch
import torch.nn as nn
diff --git a/kornia/contrib/max_blur_pool.py b/kornia/contrib/max_blur_pool.py
index b3ab7d506..4ec5109ee 100644
--- a/kornia/contrib/max_blur_pool.py
+++ b/kornia/contrib/max_blur_pool.py
@@ -1,10 +1,7 @@
import warnings
-from typing import Tuple
import torch
-import torch.nn as nn # For doctest
-from kornia.filters.blur_pool import BlurPool2D
from kornia.filters.blur_pool import max_blur_pool2d as _max_blur_pool2d # For doctest
from kornia.filters.blur_pool import MaxBlurPool2D
diff --git a/kornia/enhance/zca.py b/kornia/enhance/zca.py
index c99ee704c..2d9e5bd8a 100644
--- a/kornia/enhance/zca.py
+++ b/kornia/enhance/zca.py
@@ -1,5 +1,4 @@
-from functools import reduce
-from typing import List, Optional, Tuple, Union
+from typing import List, Optional, Tuple
import torch
import torch.nn as nn
diff --git a/kornia/feature/affine_shape.py b/kornia/feature/affine_shape.py
index 43bdfd65b..31bb35db2 100644
--- a/kornia/feature/affine_shape.py
+++ b/kornia/feature/affine_shape.py
@@ -1,5 +1,5 @@
import math
-from typing import Dict, Optional, Tuple
+from typing import Dict, Optional
import torch
import torch.nn as nn
diff --git a/kornia/feature/nms.py b/kornia/feature/nms.py
index 1d3e0c0cd..9d1c27695 100644
--- a/kornia/feature/nms.py
+++ b/kornia/feature/nms.py
@@ -1,4 +1,4 @@
-from typing import Tuple, Union
+from typing import Tuple
import torch
import torch.nn as nn
diff --git a/kornia/feature/orientation.py b/kornia/feature/orientation.py
index 9d80b6e88..ed5cf4ab1 100644
--- a/kornia/feature/orientation.py
+++ b/kornia/feature/orientation.py
@@ -1,5 +1,5 @@
import math
-from typing import Dict, Optional, Tuple
+from typing import Dict, Optional
import torch
import torch.nn as nn
@@ -9,8 +9,6 @@ from kornia.constants import pi
from kornia.feature import (
extract_patches_from_pyramid,
get_laf_orientation,
- make_upright,
- normalize_laf,
raise_error_if_laf_is_not_valid,
set_laf_orientation,
)
diff --git a/kornia/feature/responses.py b/kornia/feature/responses.py
index 98eea33c8..0d0c1956c 100644
--- a/kornia/feature/responses.py
+++ b/kornia/feature/responses.py
@@ -1,4 +1,4 @@
-from typing import Optional, Tuple, Union
+from typing import Optional, Union
import torch
import torch.nn as nn
diff --git a/kornia/feature/scale_space_detector.py b/kornia/feature/scale_space_detector.py
index 0699a7954..1022143b5 100644
--- a/kornia/feature/scale_space_detector.py
+++ b/kornia/feature/scale_space_detector.py
@@ -4,10 +4,10 @@ import torch
import torch.nn as nn
import torch.nn.functional as F
-from kornia.feature.laf import denormalize_laf, laf_is_inside_image, normalize_laf, scale_laf
+from kornia.feature.laf import denormalize_laf, laf_is_inside_image, normalize_laf
from kornia.feature.orientation import PassLAF
from kornia.feature.responses import BlobHessian
-from kornia.geometry import angle_to_rotation_matrix, ConvSoftArgmax3d
+from kornia.geometry import ConvSoftArgmax3d
from kornia.geometry.transform import ScalePyramid
diff --git a/kornia/feature/tfeat.py b/kornia/feature/tfeat.py
index 8a2023660..338ad679a 100644
--- a/kornia/feature/tfeat.py
+++ b/kornia/feature/tfeat.py
@@ -2,7 +2,6 @@ from typing import Dict
import torch
import torch.nn as nn
-import torch.nn.functional as F
urls: Dict[str, str] = {}
urls[
diff --git a/kornia/filters/blur_pool.py b/kornia/filters/blur_pool.py
index a5f966de6..d733e04e9 100644
--- a/kornia/filters/blur_pool.py
+++ b/kornia/filters/blur_pool.py
@@ -1,12 +1,9 @@
-from typing import List, Tuple
+from typing import Tuple
-import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
-import kornia
-
from .kernels import get_pascal_kernel_2d
from .median import _compute_zero_padding # TODO: Move to proper place
@@ -35,6 +32,7 @@ class BlurPool2D(nn.Module):
\text{kernel\_size}[1]}{\text{stride}[1]} + 1\right\rfloor
Examples:
+ >>> from kornia.filters.blur_pool import BlurPool2D
>>> input = torch.eye(5)[None, None]
>>> bp = BlurPool2D(kernel_size=3, stride=2)
>>> bp(input)
@@ -75,6 +73,8 @@ class MaxBlurPool2D(nn.Module):
torch.Tensor: the transformed tensor.
Examples:
+ >>> import torch.nn as nn
+ >>> from kornia.filters.blur_pool import BlurPool2D
>>> input = torch.eye(5)[None, None]
>>> mbp = MaxBlurPool2D(kernel_size=3, stride=2, max_pool_size=2, ceil_mode=False)
>>> mbp(input)
diff --git a/kornia/filters/filter.py b/kornia/filters/filter.py
index c21488928..b215381b0 100644
--- a/kornia/filters/filter.py
+++ b/kornia/filters/filter.py
@@ -1,7 +1,6 @@
-from typing import List, Tuple
+from typing import List
import torch
-import torch.nn as nn
import torch.nn.functional as F
from kornia.filters.__tmp__ import _deprecation_wrapper
diff --git a/kornia/filters/laplacian.py b/kornia/filters/laplacian.py
index ceb50f26c..f1560f041 100644
--- a/kornia/filters/laplacian.py
+++ b/kornia/filters/laplacian.py
@@ -1,5 +1,3 @@
-from typing import Tuple
-
import torch
import torch.nn as nn
diff --git a/kornia/filters/unsharp.py b/kornia/filters/unsharp.py
index 934209d3b..f63a5073c 100644
--- a/kornia/filters/unsharp.py
+++ b/kornia/filters/unsharp.py
@@ -3,7 +3,6 @@ from typing import Tuple
import torch
import torch.nn as nn
-import kornia
from kornia.filters import gaussian_blur2d
diff --git a/kornia/geometry/camera/perspective.py b/kornia/geometry/camera/perspective.py
index 2d8ffa190..d1b3ce9b0 100644
--- a/kornia/geometry/camera/perspective.py
+++ b/kornia/geometry/camera/perspective.py
@@ -1,10 +1,7 @@
-from typing import Optional
-
import torch
import torch.nn.functional as F
from kornia.geometry.conversions import convert_points_from_homogeneous, convert_points_to_homogeneous
-from kornia.geometry.linalg import transform_points
def project_points(point_3d: torch.Tensor, camera_matrix: torch.Tensor) -> torch.Tensor:
diff --git a/kornia/geometry/camera/pinhole.py b/kornia/geometry/camera/pinhole.py
index cd3d54134..97fe30631 100644
--- a/kornia/geometry/camera/pinhole.py
+++ b/kornia/geometry/camera/pinhole.py
@@ -1,8 +1,6 @@
-import warnings
-from typing import Iterable, Optional, Union
+from typing import Iterable, Optional
import torch
-import torch.nn as nn
from kornia.geometry.linalg import inverse_transformation, transform_points
diff --git a/kornia/geometry/conversions.py b/kornia/geometry/conversions.py
index 59f0fb6c4..667cdf798 100644
--- a/kornia/geometry/conversions.py
+++ b/kornia/geometry/conversions.py
@@ -3,7 +3,6 @@ import warnings
from typing import Tuple
import torch
-import torch.nn as nn
import torch.nn.functional as F
from kornia.constants import pi
diff --git a/kornia/geometry/linalg.py b/kornia/geometry/linalg.py
index f11f8877f..18262d91c 100644
--- a/kornia/geometry/linalg.py
+++ b/kornia/geometry/linalg.py
@@ -1,5 +1,3 @@
-from typing import Optional
-
import torch
import kornia
diff --git a/kornia/geometry/transform/affwarp.py b/kornia/geometry/transform/affwarp.py
index 08303329c..07f7c3a47 100644
--- a/kornia/geometry/transform/affwarp.py
+++ b/kornia/geometry/transform/affwarp.py
@@ -1,5 +1,3 @@
-from functools import wraps
-from math import ceil
from typing import Optional, Tuple, Union
import torch
diff --git a/kornia/geometry/transform/crop/crop2d.py b/kornia/geometry/transform/crop/crop2d.py
index b40295ec4..68a39ba36 100644
--- a/kornia/geometry/transform/crop/crop2d.py
+++ b/kornia/geometry/transform/crop/crop2d.py
@@ -1,8 +1,8 @@
-from typing import Optional, Tuple, Union
+from typing import Optional, Tuple
import torch
-from kornia.geometry.transform.imgwarp import get_perspective_transform, warp_affine, warp_perspective
+from kornia.geometry.transform.imgwarp import get_perspective_transform, warp_affine
__all__ = [
"crop_and_resize",
diff --git a/kornia/geometry/transform/elastic_transform.py b/kornia/geometry/transform/elastic_transform.py
index de168a0fb..e6d9f0d15 100644
--- a/kornia/geometry/transform/elastic_transform.py
+++ b/kornia/geometry/transform/elastic_transform.py
@@ -1,4 +1,4 @@
-from typing import Optional, Tuple
+from typing import Tuple
import torch
import torch.nn.functional as F
diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.py
index 720a53089..1427eb4bf 100644
--- a/kornia/geometry/transform/imgwarp.py
+++ b/kornia/geometry/transform/imgwarp.py
@@ -11,7 +11,7 @@ from kornia.geometry.conversions import (
normalize_pixel_coordinates,
)
from kornia.geometry.linalg import transform_points
-from kornia.geometry.transform.homography_warper import homography_warp, normalize_homography
+from kornia.geometry.transform.homography_warper import normalize_homography
from kornia.geometry.transform.projwarp import get_projective_transform
from kornia.utils import create_meshgrid
from kornia.utils.helpers import _torch_inverse_cast, _torch_solve_cast
diff --git a/kornia/geometry/warp/depth_warper.py b/kornia/geometry/warp/depth_warper.py
index 5f524186b..194ed27d2 100644
--- a/kornia/geometry/warp/depth_warper.py
+++ b/kornia/geometry/warp/depth_warper.py
@@ -1,9 +1,8 @@
import warnings
-from typing import Union
import torch
-from kornia.geometry.camera import cam2pixel, PinholeCamera, pixel2cam
+from kornia.geometry.camera import PinholeCamera
from kornia.geometry.depth import depth_warp as _depth_warp
from kornia.geometry.depth import DepthWarper as _DepthWarper
diff --git a/kornia/geometry/warp/homography_warper.py b/kornia/geometry/warp/homography_warper.py
index c4a24fc0b..87869e521 100644
--- a/kornia/geometry/warp/homography_warper.py
+++ b/kornia/geometry/warp/homography_warper.py
@@ -4,9 +4,6 @@ from typing import Optional, Tuple
import torch
import kornia.geometry.transform.homography_warper as HMW
-from kornia.geometry.linalg import transform_points
-from kornia.testing import check_is_tensor
-from kornia.utils import create_meshgrid, create_meshgrid3d
__all__ = [
"HomographyWarper",
diff --git a/kornia/losses/depth_smooth.py b/kornia/losses/depth_smooth.py
index b760dfbe4..e08c627f1 100644
--- a/kornia/losses/depth_smooth.py
+++ b/kornia/losses/depth_smooth.py
@@ -1,6 +1,5 @@
import torch
import torch.nn as nn
-import torch.nn.functional as F
# Based on
# https://github.com/tensorflow/models/blob/master/research/struct2depth/model.py#L625-L641
diff --git a/kornia/losses/dice.py b/kornia/losses/dice.py
index a8d183d84..a6782c47d 100644
--- a/kornia/losses/dice.py
+++ b/kornia/losses/dice.py
@@ -1,5 +1,3 @@
-from typing import Optional
-
import torch
import torch.nn as nn
import torch.nn.functional as F
diff --git a/kornia/losses/focal.py b/kornia/losses/focal.py
index 439362e27..0c31cff83 100644
--- a/kornia/losses/focal.py
+++ b/kornia/losses/focal.py
@@ -1,5 +1,3 @@
-from typing import Optional
-
import torch
import torch.nn as nn
import torch.nn.functional as F
diff --git a/kornia/losses/ssim.py b/kornia/losses/ssim.py
index 503971d94..1ffa95565 100644
--- a/kornia/losses/ssim.py
+++ b/kornia/losses/ssim.py
@@ -1,8 +1,5 @@
-from typing import Tuple
-
import torch
import torch.nn as nn
-import torch.nn.functional as F
from kornia.filters import filter2d, get_gaussian_kernel2d
diff --git a/kornia/losses/tversky.py b/kornia/losses/tversky.py
index f8cf1f5f1..6ab76f3e6 100644
--- a/kornia/losses/tversky.py
+++ b/kornia/losses/tversky.py
@@ -1,5 +1,3 @@
-from typing import Optional
-
import torch
import torch.nn as nn
import torch.nn.functional as F
diff --git a/kornia/utils/draw.py b/kornia/utils/draw.py
index 8d860f457..e4b613556 100644
--- a/kornia/utils/draw.py
+++ b/kornia/utils/draw.py
@@ -1,4 +1,4 @@
-from typing import Optional, Union
+from typing import Optional
import torch
diff --git a/kornia/utils/grid.py b/kornia/utils/grid.py
index 744326352..ce7f14469 100644
--- a/kornia/utils/grid.py
+++ b/kornia/utils/grid.py
@@ -1,9 +1,7 @@
-from typing import Optional, Union
+from typing import Optional
import torch
-import kornia as K
-
def create_meshgrid(
height: int,
diff --git a/kornia/utils/image.py b/kornia/utils/image.py
index 83e103818..2e4e5dd33 100644
--- a/kornia/utils/image.py
+++ b/kornia/utils/image.py
@@ -1,5 +1,4 @@
from functools import wraps
-from typing import Optional
import numpy as np
import torch
diff --git a/kornia/utils/memory.py b/kornia/utils/memory.py
index 87ece98c6..74bf606cf 100644
--- a/kornia/utils/memory.py
+++ b/kornia/utils/memory.py
@@ -1,5 +1,3 @@
-from typing import Optional, Union
-
import torch
import kornia
diff --git a/test/feature/test_mkd.py b/test/feature/test_mkd.py
index 766a3f387..bb20b4007 100644
--- a/test/feature/test_mkd.py
+++ b/test/feature/test_mkd.py
@@ -3,7 +3,6 @@ from torch.autograd import gradcheck
from torch.testing import assert_allclose
import kornia.testing as utils # test utils
-from kornia.constants import pi
from kornia.feature.mkd import *
diff --git a/test/integration/test_soft_argmax2d.py b/test/integration/test_soft_argmax2d.py
index 89af7f0c0..4a15db1dc 100644
--- a/test/integration/test_soft_argmax2d.py
+++ b/test/integration/test_soft_argmax2d.py
@@ -1,6 +1,5 @@
import logging
-import pytest
import torch
import torch.nn as nn
import torch.optim as optim
diff --git a/test/utils/test_memory.py b/test/utils/test_memory.py
index ee846f357..9afa0dc3e 100644
--- a/test/utils/test_memory.py
+++ b/test/utils/test_memory.py
@@ -1,4 +1,3 @@
-import pytest
import torch
from torch.autograd import gradcheck