Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

remove numpy import (#1116)

Edgar Riba2b3dee5c9aaf
diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml
index 824ae899a..1df648127 100644
--- a/.github/workflows/format.yml
+++ b/.github/workflows/format.yml
@@ -23,6 +23,7 @@ jobs:
run: |
pip install torch --find-links https://download.pytorch.org/whl/cpu/torch_stable.html
pip install -r requirements-dev.txt
+ python setup.py develop --user
- name: Run linter
run: make lint
@@ -41,6 +42,7 @@ jobs:
run: |
pip install torch --find-links https://download.pytorch.org/whl/cpu/torch_stable.html
pip install -r requirements-dev.txt
+ python setup.py develop --user
- name: Run mypy
run: make mypy
@@ -59,6 +61,7 @@ jobs:
run: |
pip install torch --find-links https://download.pytorch.org/whl/cpu/torch_stable.html
pip install -r requirements-dev.txt
+ python setup.py develop --user
- name: Run doctest
run: make doctest
diff --git a/docs/generate_example_images.py b/docs/generate_example_images.py
index d10c7b6bd..7717a3f14 100644
--- a/docs/generate_example_images.py
+++ b/docs/generate_example_images.py
@@ -1,4 +1,5 @@
import importlib
+import os
from pathlib import Path
import cv2
diff --git a/kornia/testing/__init__.py b/kornia/testing/__init__.py
index 04039c570..0869e731c 100644
--- a/kornia/testing/__init__.py
+++ b/kornia/testing/__init__.py
@@ -6,7 +6,6 @@ from abc import ABC, abstractmethod
from copy import deepcopy
from itertools import product
-import numpy as np
import torch
__all__ = ['tensor_to_gradcheck_var', 'create_eye_batch', 'xla_is_available']
@@ -19,11 +18,6 @@ def xla_is_available() -> bool:
return False
-def create_checkerboard(h, w, nw):
- """Creates a synthetic checkered board of shape HxW and window size `nw`."""
- return np.kron([[1, 0] * nw, [0, 1] * nw] * nw, np.ones((h // (2 * nw), w // (2 * nw)))).astype(np.float32)
-
-
# TODO: Isn't this function duplicated with eye_like?
def create_eye_batch(batch_size, eye_size, device=None, dtype=None):
"""Creates a batch of identity matrices of shape Bx3x3"""
diff --git a/setup.cfg b/setup.cfg
index 9a0ea1251..0f0060e43 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -36,6 +36,9 @@ ignore =
exclude = docs/src
[mypy]
+files = kornia, test
+pretty = True
+show_error_codes = True
ignore_missing_imports = True
[pydocstyle]
diff --git a/test/geometry/transform/test_homography_warper.py b/test/geometry/transform/test_homography_warper.py
index 077dcc91d..ff24958da 100644
--- a/test/geometry/transform/test_homography_warper.py
+++ b/test/geometry/transform/test_homography_warper.py
@@ -186,14 +186,7 @@ class TestHomographyWarper:
height, width = 128, 64
eye_size = 3 # identity 3x3
- # create checkerboard
- board = utils.create_checkerboard(height, width, 4)
- patch_src = (
- torch.from_numpy(board)
- .to(device=device, dtype=dtype)
- .view(1, 1, height, width)
- .expand(batch_size, 1, height, width)
- )
+ patch_src = torch.ones(batch_size, 1, height, width, device=device, dtype=dtype)
# create base homography
dst_homo_src = utils.create_eye_batch(batch_size, eye_size, device=device, dtype=dtype)
@@ -256,14 +249,7 @@ class TestHomographyWarper:
height, width = 128, 64
eye_size = 3 # identity 3x3
- # create checkerboard
- board = utils.create_checkerboard(height, width, 4)
- patch_src = (
- torch.from_numpy(board)
- .to(device=device, dtype=dtype)
- .view(1, 1, height, width)
- .expand(batch_size, 1, height, width)
- )
+ patch_src = torch.rand(batch_size, 1, height, width, device=device, dtype=dtype)
# create base homography
dst_homo_src = utils.create_eye_batch(batch_size, eye_size, device=device, dtype=dtype)
diff --git a/test/morphology/test_bottom_hat.py b/test/morphology/test_bottom_hat.py
index 03dedd3e7..5bdffef40 100644
--- a/test/morphology/test_bottom_hat.py
+++ b/test/morphology/test_bottom_hat.py
@@ -39,8 +39,10 @@ class TestBottomHat:
None, None, :, :
]
assert_allclose(
- bottom_hat(tensor, torch.ones_like(structural_element), structuring_element=structural_element), expected,
- atol=1e-3, rtol=1e-3
+ bottom_hat(tensor, torch.ones_like(structural_element), structuring_element=structural_element),
+ expected,
+ atol=1e-3,
+ rtol=1e-3,
)
def test_exception(self, device, dtype):
diff --git a/test/morphology/test_closing.py b/test/morphology/test_closing.py
index d739d8f9e..529beab03 100644
--- a/test/morphology/test_closing.py
+++ b/test/morphology/test_closing.py
@@ -39,8 +39,10 @@ class TestClosing:
None, None, :, :
]
assert_allclose(
- closing(tensor, torch.ones_like(structural_element), structuring_element=structural_element), expected,
- atol=1e-4, rtol=1e-4
+ closing(tensor, torch.ones_like(structural_element), structuring_element=structural_element),
+ expected,
+ atol=1e-4,
+ rtol=1e-4,
)
def test_exception(self, device, dtype):
diff --git a/test/morphology/test_dilation.py b/test/morphology/test_dilation.py
index 6d57fffb9..5e6f092de 100644
--- a/test/morphology/test_dilation.py
+++ b/test/morphology/test_dilation.py
@@ -39,8 +39,10 @@ class TestDilate:
None, None, :, :
]
assert_allclose(
- dilation(tensor, torch.ones_like(structural_element), structuring_element=structural_element), expected,
- atol=1e-4, rtol=1e-4
+ dilation(tensor, torch.ones_like(structural_element), structuring_element=structural_element),
+ expected,
+ atol=1e-4,
+ rtol=1e-4,
)
def test_exception(self, device, dtype):
diff --git a/test/morphology/test_erosion.py b/test/morphology/test_erosion.py
index 0f50fc973..2c03e4dfe 100644
--- a/test/morphology/test_erosion.py
+++ b/test/morphology/test_erosion.py
@@ -39,8 +39,10 @@ class TestErode:
None, None, :, :
]
assert_allclose(
- erosion(tensor, torch.ones_like(structural_element), structuring_element=structural_element), expected,
- atol=1e-4, rtol=1e-4
+ erosion(tensor, torch.ones_like(structural_element), structuring_element=structural_element),
+ expected,
+ atol=1e-4,
+ rtol=1e-4,
)
def test_exception(self, device, dtype):
diff --git a/test/morphology/test_gradient.py b/test/morphology/test_gradient.py
index 6830e54af..3df74f07f 100644
--- a/test/morphology/test_gradient.py
+++ b/test/morphology/test_gradient.py
@@ -39,8 +39,10 @@ class TestGradient:
None, None, :, :
]
assert_allclose(
- gradient(tensor, torch.ones_like(structural_element), structuring_element=structural_element), expected,
- atol=1e-3, rtol=1e-3
+ gradient(tensor, torch.ones_like(structural_element), structuring_element=structural_element),
+ expected,
+ atol=1e-3,
+ rtol=1e-3,
)
def test_exception(self, device, dtype):
diff --git a/test/morphology/test_opening.py b/test/morphology/test_opening.py
index 75969ad9c..e4631f0db 100644
--- a/test/morphology/test_opening.py
+++ b/test/morphology/test_opening.py
@@ -39,8 +39,10 @@ class TestOpening:
None, None, :, :
]
assert_allclose(
- opening(tensor, torch.ones_like(structural_element), structuring_element=structural_element), expected,
- atol=1e-4, rtol=1e-4
+ opening(tensor, torch.ones_like(structural_element), structuring_element=structural_element),
+ expected,
+ atol=1e-4,
+ rtol=1e-4,
)
def test_exception(self, device, dtype):
diff --git a/test/morphology/test_top_hat.py b/test/morphology/test_top_hat.py
index 575d2be5b..8329e8376 100644
--- a/test/morphology/test_top_hat.py
+++ b/test/morphology/test_top_hat.py
@@ -39,8 +39,10 @@ class TestTopHat:
None, None, :, :
]
assert_allclose(
- top_hat(tensor, torch.ones_like(structural_element), structuring_element=structural_element), expected,
- atol=1e-3, rtol=1e-3
+ top_hat(tensor, torch.ones_like(structural_element), structuring_element=structural_element),
+ expected,
+ atol=1e-3,
+ rtol=1e-3,
)
def test_exception(self, device, dtype):