π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
[Feat] improve testing framework (#560)
Edgar Ribab528a0d26abc
diff --git a/.circleci/config.yml b/.circleci/config.ymlindex 3657f24d3..e741538b3 100644--- a/.circleci/config.yml+++ b/.circleci/config.yml@@ -24,7 +24,7 @@ common: &commoncommand: make build-docs- run:name: unit tests- command: make test-cpu-cov+ command: make test-cpu- run:name: send coveragewhen: on_successdiff --git a/Makefile b/Makefileindex e298204e7..76e1937e1 100644--- a/Makefile+++ b/Makefile@@ -1,35 +1,39 @@-.PHONY: test test-cpu test-gpu lint mypy build-docs install uninstall FORCE+.PHONY: test test-cpu test-cuda lint mypy build-docs install uninstall FORCE-test: mypy lint test-cpu+test: mypy lint build-docs test-all-test-cpu: FORCE- pytest --typetest cpu -v+test-all: FORCE+ pytest -v --device cpu,cuda --dtype float16,float32,float64 --cov=kornia test/ --flake8 --mypy-test-cpu-cov: FORCE- pytest --typetest cpu -v --cov=kornia test+test-cpu: FORCE+ pytest -v --device cpu --dtype float32,float64 --cov=kornia test/ --flake8 --mypy-test-gpu: FORCE- pytest --typetest cuda -v+test-cuda: FORCE+ pytest -v --device cuda --dtype float16,float32,float64 --cov=kornia test/ --flake8 --mypylint: FORCE- python verify.py --check lint+ pytest -v --flake8 -m flake8++mypy: FORCE+ pytest -v --mypy -m mypy test/autopep8: FORCEautopep8 --in-place --aggressive --recursive kornia/ test/ examples/-mypy: FORCE- python verify.py --check mypy+docstyle: FORCE+ pydocstyle kornia/build-docs: FORCE- python verify.py --check build-docs+ cd docs; make clean htmlinstall: FORCEpython setup.py install-benchmark:+install-dev: FORCE+ python setup.py develop++benchmark: FORCEfor f in test/performance/*.py ; do python -utt $${f}; doneuninstall: FORCEpip uninstall kornia--FORCE:diff --git a/conftest.py b/conftest.pyindex 6f5a59314..77b844a8e 100644--- a/conftest.py+++ b/conftest.py@@ -1,6 +1,15 @@import pytest+def pytest_generate_tests(metafunc):+ if 'device_name' in metafunc.fixturenames:+ raw_value = metafunc.config.getoption('--device')+ metafunc.parametrize('device_name', raw_value.split(','))+ if 'dtype_name' in metafunc.fixturenames:+ raw_value = metafunc.config.getoption('--dtype')+ metafunc.parametrize('dtype_name', raw_value.split(','))++def pytest_addoption(parser):- parser.addoption('--typetest', action="store", default="cpu")- parser.addoption('--dtypetest', action="store", default="float32")+ parser.addoption('--device', action="store", default="cpu")+ parser.addoption('--dtype', action="store", default="float32")diff --git a/docs/requirements.txt b/docs/requirements.txtindex b22d0f585..d54f52b80 100644--- a/docs/requirements.txt+++ b/docs/requirements.txt@@ -9,5 +9,5 @@ nbconvert==5.5.0notebook==6.0.1matplotlib==3.1.1opencv-python==4.2.0.34-torch==1.4.0+cpu-torchvision==0.5+cpu+torch==1.5.0+cpu+torchvision==0.6+cpudiff --git a/docs/source/augmentation.rst b/docs/source/augmentation.rstindex 87afa533e..1a9055f5c 100644--- a/docs/source/augmentation.rst+++ b/docs/source/augmentation.rst@@ -16,43 +16,50 @@ For detailed comparision, please checkout the For detailed comparision, please cContainers-----------This is the base class for creating a new transform. The user only needs to overrive: `generate_parameters`, `apply_transformation` and optionally, `compute_transformation`.+This is the base class for creating a new transform. The user only needs to overrive: `generate_parameters`, `apply_transform` and optionally, `compute_transformation`... autoclass:: AugmentationBase- :members:+ :members: return_transform++ .. automethod:: generate_parameters+ .. automethod:: compute_transformation+ .. automethod:: apply_transformCreate your own transformation:.. code-block:: python- from kornia.augmentation import AugmentationBase--- class MyRandomTransform(AugmentationBase):- def __init__(self, return_transform: bool = False) -> None:- super(MyRandomTransform, self).__init__(return_transform)-- def generate_parameters(self, input_shape: torch.Size):- # generate the random parameters as you wish depending on your use case.- angles_rad torch.Tensor = torch.rand(batch_shape) * K.pi- angles_deg = kornia.rad2deg(angles_rad) * self.angle- return dict(angles=angles_deg)-- def compute_transformation(self, input, params):- # compute transformation- angles: torch.Tensor = params['angles'].type_as(input)- center = torch.tensor([[W / 2, H / 2]]).type_as(input)- transform = K.get_rotation_matrix2d(center, angles, torch.ones_like(angles))- return transform-- def apply_transformation(self, input, params):- # compute transformation- transform = self.compute_transform(input, params)- # apply transformation and return- output = K.warp_affine(input, transform, (H, W))-- return (output, transform)+ import torch+ import kornia as K++ from kornia.augmentation import AugmentationBase++ class MyRandomTransform(AugmentationBase):+ def __init__(self, return_transform: bool = False) -> None:+ super(MyRandomTransform, self).__init__(return_transform)++ def generate_parameters(self, input_shape: torch.Size):+ # generate the random parameters for your use case.+ angles_rad torch.Tensor = torch.rand(batch_shape) * K.pi+ angles_deg = kornia.rad2deg(angles_rad) * self.angle+ return dict(angles=angles_deg)++ def compute_transformation(self, input, params):+ # compute transformation+ angles: torch.Tensor = params['angles'].type_as(input)+ center = torch.tensor([[W / 2, H / 2]]).type_as(input)+ transform = K.get_rotation_matrix2d(+ center, angles, torch.ones_like(angles))+ return transform++ def apply_transform(self, input, params):+ # compute transformation+ transform = self.compute_transform(input, params)++ # apply transformation and return+ output = K.warp_affine(input, transform, (H, W))+ return (output, transform)Module------@@ -60,54 +67,59 @@ ModuleKornia augmentation implementations can be easily used in a TorchVision style using `nn.Sequential`... code-block:: python- import kornia.augmentation as K- import torch.nn as nn- transform = nn.Sequential(- K.RandomAffine(360),- K.ColorJitter(0.2, 0.3, 0.2, 0.3)- )+ import kornia.augmentation as K+ import torch.nn as nn++ transform = nn.Sequential(+ K.RandomAffine(360),+ K.ColorJitter(0.2, 0.3, 0.2, 0.3)+ )Kornia augmentation implementations have two additional parameters compare to TorchVision, `return_transform` and `same_on_batch`. The former provides the ability of undoing one geometry transformation while the latter can be used to control the randomness for a batched transformation. To enable those behaviour, you may simply set the flags to True... code-block:: python- import kornia.augmentation as K-- class MyAugmentationPipeline(nn.Module):- def __init__(self) -> None:- super(MyAugmentationPipeline, self).__init__()- self.aff = K.RandomAffine(360, return_transform=True, same_on_batch=True)- self.jit = K.ColorJitter(0.2, 0.3, 0.2, 0.3, same_on_batch=True)-- def forward(self, input):- input, transform = self.aff(input)- input, transform = self.jit((input, transform))- return input, transform+ import kornia.augmentation as K++ class MyAugmentationPipeline(nn.Module):+ def __init__(self) -> None:+ super(MyAugmentationPipeline, self).__init__()+ self.aff = K.RandomAffine(+ 360, return_transform=True, same_on_batch=True+ )+ self.jit = K.ColorJitter(0.2, 0.3, 0.2, 0.3, same_on_batch=True)++ def forward(self, input):+ input, transform = self.aff(input)+ input, transform = self.jit((input, transform))+ return input, transformExample for semantic segmentation using low-level randomness control:.. code-block:: python- import kornia.augmentation as K--- class MyAugmentationPipeline(nn.Module):- def __init__(self) -> None:- super(MyAugmentationPipeline, self).__init__()- self.aff = K.RandomAffine(360)- self.jit = K.ColorJitter(0.2, 0.3, 0.2, 0.3)-- def forward(self, input, mask):- assert input.shape == mask.shape,- f"Input shape should be consistent with mask shape, while got {input.shape}, {mask.shape}"- aff_params = self.aff.generate_parameters(input.shape)- input = self.aff(input, aff_params)- mask = self.aff(mask, aff_params)-- jit_params = self.jit.generate_parameters(input.shape)- input = self.jit(input, jit_params)- mask = self.jit(mask, jit_params)- return input, mask++ import kornia.augmentation as K++ class MyAugmentationPipeline(nn.Module):+ def __init__(self) -> None:+ super(MyAugmentationPipeline, self).__init__()+ self.aff = K.RandomAffine(360)+ self.jit = K.ColorJitter(0.2, 0.3, 0.2, 0.3)++ def forward(self, input, mask):+ assert input.shape == mask.shape,+ f"Input shape should be consistent with mask shape, "+ f"while got {input.shape}, {mask.shape}"++ aff_params = self.aff.generate_parameters(input.shape)+ input = self.aff(input, aff_params)+ mask = self.aff(mask, aff_params)++ jit_params = self.jit.generate_parameters(input.shape)+ input = self.jit(input, jit_params)+ mask = self.jit(mask, jit_params)+ return input, mask.. autoclass:: RandomHorizontalFlip.. autoclass:: RandomVerticalFlipdiff --git a/docs/source/conf.py b/docs/source/conf.pyindex 56d6b4266..a5ec0b849 100644--- a/docs/source/conf.py+++ b/docs/source/conf.py@@ -13,8 +13,6 @@ import sphinx_rtd_theme#current_path = os.path.abspath(os.path.join(__file__, "..", "..", ".."))sys.path.append(current_path)-#sys.path.append(os.path.join(root_path, "kornia"))-#sys.path.append(os.path.join(root_path, "examples"))# -- General configuration ------------------------------------------------@@ -67,7 +65,7 @@ copyright = u'2019, %s' % author# |version| and |release|, also used in various other places throughout the# built documents.-#version = 'master (' + kornia.__version__ + ' )'+# version = 'master (' + kornia.__version__ + ' )'version = ''if 'READTHEDOCS' not in os.environ:@@ -75,7 +73,7 @@ if 'READTHEDOCS' not in os.environ:from kornia import __version__ # noqaE402version = __version__-#release = 'master'+# release = 'master'release = version# The language for content autogenerated by Sphinx. Refer to documentation@@ -198,10 +196,10 @@ intersphinx_mapping = {examples_dir = os.path.join(current_path, "tutorials")sphinx_gallery_conf = {- 'doc_module': 'kornia',- 'examples_dirs': [examples_dir], # path to your example scripts- 'gallery_dirs': ['tutorials'], # path where to save gallery generated output- 'filename_pattern': './',+ 'doc_module': 'kornia',+ 'examples_dirs': [examples_dir], # path to your example scripts+ 'gallery_dirs': ['tutorials'], # path where to save gallery generated output+ 'filename_pattern': './',}diff --git a/kornia/color/normalize.py b/kornia/color/normalize.pyindex 872c2b9ea..612dae52b 100644--- a/kornia/color/normalize.py+++ b/kornia/color/normalize.py@@ -1,12 +1,15 @@+"""Module containing functionals for intensity normalisation."""++from typing import Union+import torchimport torch.nn as nn-from typing import Unionclass Normalize(nn.Module):- r"""Normalize a tensor image or a batch of tensor images- with mean and standard deviation. Input must be a tensor of shape (C, H, W)- or a batch of tensors :math:`(*, C, H, W)`.+ r"""Normalize a tensor image or a batch of tensor images with mean and standard deviation.++ Input must be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.Given mean: ``(M1,...,Mn)`` and std: ``(S1,..,Sn)`` for ``n`` channels,this transform will normalize each channel of the input ``torch.Tensor``@@ -15,8 +18,8 @@ class Normalize(nn.Module):Args:mean (torch.Tensor or float): Mean for each channel.std (torch.Tensor or float): Standard deviations for each channel.- """+ """def __init__(self, mean: Union[torch.Tensor, float], std: Union[torch.Tensor, float]) -> None:super(Normalize, self).__init__()@@ -25,6 +28,15 @@ class Normalize(nn.Module):self.std = stddef forward(self, input: torch.Tensor) -> torch.Tensor: # type: ignore+ """Normalises an input tensor by the mean and standard deviation.++ Args:+ input: image tensor of size (*, H, W).++ Returns:+ normalised tensor with same size as input (*, H, W).++ """return normalize(input, self.mean, self.std)def __repr__(self):@@ -44,10 +56,10 @@ def normalize(mean (torch.Tensor or float): Mean for each channel.std (torch.Tensor or float): Standard deviations for each channel.- Returns:- torch.Tensor: The normalised image tensor.- """+ Returns:+ torch.Tensor: The normalised image tensor.+ """if isinstance(mean, float):mean = torch.tensor([mean]) # prevent 0 sized tensors@@ -84,8 +96,9 @@ def normalize(class Denormalize(nn.Module):- r"""Denormalize a tensor image or a batch of tensor images- . Input must be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.+ r"""Denormalize a tensor image or a batch of tensor images.++ Input must be a tensor of shape (C, H, W) or a batch of tensors :math:`(*, C, H, W)`.Given mean: ``(M1,...,Mn)`` and std: ``(S1,..,Sn)`` for ``n`` channels,this transform will denormalize each channel of the input ``torch.Tensor``@@ -94,8 +107,8 @@ class Denormalize(nn.Module):Args:mean (torch.Tensor or float): Mean for each channel.std (torch.Tensor or float): Standard deviations for each channel.- """+ """def __init__(self, mean: Union[torch.Tensor, float], std: Union[torch.Tensor, float]) -> None:super(Denormalize, self).__init__()@@ -104,6 +117,15 @@ class Denormalize(nn.Module):self.std = stddef forward(self, input: torch.Tensor) -> torch.Tensor: # type: ignore+ """Denormalises an input tensor by the mean and standard deviation.++ Args:+ input: image tensor of size (*, H, W).++ Returns:+ normalised tensor with same size as input (*, H, W).++ """return denormalize(input, self.mean, self.std)def __repr__(self):@@ -123,10 +145,10 @@ def denormalize(mean (torch.Tensor or float): Mean for each channel.std (torch.Tensor or float): Standard deviations for each channel.- Returns:- torch.Tensor: The normalised image tensor.- """+ Returns:+ torch.Tensor: The normalised image tensor.+ """if isinstance(mean, float):mean = torch.tensor([mean]) # prevent 0 sized tensorsdiff --git a/mypy_files.txt b/mypy_files.txtdeleted file mode 100644index e22ca38a9..000000000--- a/mypy_files.txt+++ /dev/null@@ -1,35 +0,0 @@-kornia/color/gray.py-kornia/color/hsv.py-kornia/color/rgb.py-kornia/color/normalize.py-kornia/contrib/extract_patches.py-kornia/contrib/max_blur_pool.py-kornia/feature/nms.py-kornia/filters/blur.py-kornia/filters/gaussian.py-kornia/filters/laplacian.py-kornia/filters/median.py-kornia/filters/sobel.py-kornia/augmentation/augmentation.py-kornia/augmentation/functional.py-kornia/augmentation/random_generator.py-kornia/augmentation/utils.py-kornia/geometry/conversions.py-kornia/geometry/linalg.py-kornia/geometry/camera/pinhole.py-kornia/geometry/transform/affwarp.py-kornia/geometry/transform/imgwarp.py-kornia/geometry/transform/crop.py-kornia/geometry/transform/pyramid.py-kornia/geometry/warp/homography_warper.py-kornia/geometry/warp/depth_warper.py-kornia/losses/ssim.py-kornia/losses/dice.py-kornia/losses/focal.py-kornia/losses/tversky.py-kornia/losses/depth_smooth.py-kornia/utils/grid.py-kornia/utils/image.py-kornia/utils/one_hot.py-kornia/utils/metrics/confusion_matrix.py-kornia/utils/metrics/mean_iou.pydiff --git a/requirements.txt b/requirements.txtindex 62ee9ddc2..ac2d75cd4 100644--- a/requirements.txt+++ b/requirements.txt@@ -1,9 +1,6 @@# core dependenciespytorch==1.5.0-# package-setuptools>=41.4.0-# utilstorchvision==0.6.0opencv@@ -13,11 +10,11 @@ matplotlib# testpytest>=5.1.2+pytest-flake8pytest-cov-flake8+pytest-mypyautopep8-mypy-mypy_extensions+pydocstyle# docssphinxdiff --git a/setup.cfg b/setup.cfgindex 647758b10..20bf793c7 100644--- a/setup.cfg+++ b/setup.cfg@@ -7,14 +7,18 @@ universal=1[metadata]license_file = LICENSE-[pep8]-max-line-length = 120-[flake8]max-line-length = 120ignore = W504,E305,E402,E721,E722,E741,F401,F403,F405,F821,F841,F999,W605,F811exclude = docs/src+[mypy]+ignore_missing_imports = True++[pydocstyle]+match = .*\.py+ignore = D105,D107,D203,D204,D213,D406,D407+[coverage:report]exclude_lines =pragma: no coverdiff --git a/setup.py b/setup.pyindex dfe3c0c74..648898f71 100644--- a/setup.py+++ b/setup.py@@ -88,25 +88,25 @@ if __name__ == '__main__':write_version_file()setup(# Metadata- name=package_name,- version=version,- author='Edgar Riba',- author_email='[email protected]',- url='https://github.com/arraiyopensource/kornia',- description='Open Source Differentiable Computer Vision Library for PyTorch',- long_description=long_description,- license='Apache License 2.0',- python_requires='>=3.6',-- # Test- setup_requires=['pytest-runner'],- tests_require=['pytest'],-- # Package info- packages=find_packages(exclude=('docs', 'test', 'examples',)),-- zip_safe=True,- install_requires=requirements,+ name=package_name,+ version=version,+ author='Edgar Riba',+ author_email='[email protected]',+ url='https://github.com/kornia/kornia',+ description='Open Source Differentiable Computer Vision Library for PyTorch',+ long_description=long_description,+ license='Apache License 2.0',+ python_requires='>=3.6',++ # Test+ setup_requires=['pytest-runner'],+ tests_require=['pytest'],++ # Package info+ packages=find_packages(exclude=('docs', 'test', 'examples',)),++ zip_safe=True,+ install_requires=requirements,classifiers=['Intended Audience :: Developers','Intended Audience :: Education',@@ -116,5 +116,5 @@ if __name__ == '__main__':'License :: OSI Approved :: Apache Software License','Topic :: Scientific/Engineering :: Image Recognition','Topic :: Software Development :: Libraries',- ],+ ],)diff --git a/test/augmentation/test_augmentation.py b/test/augmentation/test_augmentation.pyindex d845e0723..60f6e2dcb 100644--- a/test/augmentation/test_augmentation.py+++ b/test/augmentation/test_augmentation.py@@ -1,3 +1,5 @@+from typing import Union, Tuple+import pytestimport torchimport torch.nn as nn@@ -131,7 +133,7 @@ class TestRandomHorizontalFlip:@pytest.mark.skip(reason="turn off all jit for a while")def test_jit(self, device):@torch.jit.script- def op_script(data: torch.Tensor) -> torch.Tensor:+ def op_script(data: torch.Tensor) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:return kornia.random_hflip(data)@@ -278,8 +280,7 @@ class TestRandomVerticalFlip:@pytest.mark.skip(reason="turn off all jit for a while")def test_jit(self, device):@torch.jit.script- def op_script(data: torch.Tensor) -> torch.Tensor:-+ def op_script(data: torch.Tensor) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:return kornia.random_vflip(data)input = torch.tensor([[0., 0., 0.],@@ -1216,8 +1217,7 @@ class TestRandomRotation:torch.manual_seed(0) # for random reproductibility@torch.jit.script- def op_script(data: torch.Tensor) -> torch.Tensor:-+ def op_script(data: torch.Tensor) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:return kornia.random_rotation(data, degrees=45.0)input = torch.tensor([[1., 0., 0., 2.],diff --git a/test/color/test_normalize.py b/test/color/test_normalize.pyindex 94fa6d4d3..83bfa0829 100644--- a/test/color/test_normalize.py+++ b/test/color/test_normalize.py@@ -86,7 +86,7 @@ class TestNormalize:std = torch.tensor([2.0, 2.0, 2.0]).repeat(2, 1).to(device)actual = op_script(data, mean, std)- expected = image.normalize(data, mean, std)+ expected = kornia.normalize(data, mean, std)assert_allclose(actual, expected)def test_gradcheck(self, device):diff --git a/test/color/test_yuv.py b/test/color/test_yuv.pyindex 46309e32f..291872207 100644--- a/test/color/test_yuv.py+++ b/test/color/test_yuv.py@@ -71,12 +71,12 @@ class TestRgbYuvConversion:out = kornia.yuv_to_rgb(1)@pytest.mark.parametrize("bad_input_shapes", [([2, 2],), ([3, 3, 3, 3, 3],), ([2, 2, 2],), ([2, 2, 2, 2],)])- def test_rgb_to_yuv_shape(self, bad_input_shapes):+ def test_rgb_to_yuv_shape_bad(self, bad_input_shapes):with pytest.raises(ValueError):out = kornia.rgb_to_yuv(torch.ones(*bad_input_shapes))@pytest.mark.parametrize("bad_input_shapes", [([2, 2],), ([3, 3, 3, 3, 3],), ([2, 2, 2],), ([2, 2, 2, 2],)])- def test_yuv_to_rbg_shape(self, bad_input_shapes):+ def test_yuv_to_rbg_shape_bad(self, bad_input_shapes):with pytest.raises(ValueError):out = kornia.yuv_to_rgb(torch.ones(*bad_input_shapes))diff --git a/test/common.py b/test/common.pyindex 832f2a150..17c72ff2a 100644--- a/test/common.py+++ b/test/common.py@@ -38,12 +38,14 @@ TEST_DTYPES: Dict[str, torch.dtype] = get_test_dtypes()@pytest.fixture()-def device(request) -> torch.device:- _device_type: str = request.config.getoption('--typetest')- return TEST_DEVICES[_device_type]+def device(device_name) -> torch.device:+ if device_name not in TEST_DEVICES:+ pytest.skip(f"Unsupported device type: {device_name}")+ return TEST_DEVICES[device_name]@pytest.fixture()-def dtype(request) -> torch.dtype:- _dtype_name: str = request.config.getoption('--dtypetest')- return TEST_DTYPES[_dtype_name]+def dtype(device, dtype_name) -> torch.dtype:+ if device.type == 'cpu' and dtype_name == 'float16':+ pytest.skip(f"Unsupported device cpu and dtype float16.")+ return TEST_DTYPES[dtype_name]diff --git a/test/geometry/test_depth.py b/test/geometry/test_depth.pyindex 62b495750..a6fd0ce8c 100644--- a/test/geometry/test_depth.py+++ b/test/geometry/test_depth.py@@ -33,7 +33,7 @@ class TestDepthTo3d:points3d = kornia.depth_to_3d(depth, camera_matrix)assert points3d.shape == (batch_size, 3, 3, 4)- def test_unproject_normalized(self, device):+ def test_unproject_denormalized(self, device):# this is for default normalize_points=Falsedepth = 2 * torch.tensor([[[[1., 1., 1.],diff --git a/test/geometry/transform/test_crop.py b/test/geometry/transform/test_crop.pyindex 8add481bf..396cb18f0 100644--- a/test/geometry/transform/test_crop.py+++ b/test/geometry/transform/test_crop.py@@ -284,7 +284,7 @@ class TestCenterCrop:def test_jit_trace(self, device):@torch.jit.scriptdef op_script(input: torch.Tensor,- size: Tuple[torch.Tensor, torch.Tensor]) -> torch.Tensor:+ size: Tuple[int, int]) -> torch.Tensor:return kornia.center_crop(input, size)# 1. Trace opbatch_size, channels, height, width = 1, 2, 5, 4diff --git a/test/performance/test_imgwarp_speed.py b/test/performance/test_imgwarp_speed.pyindex 584fb2c84..ae1e9570e 100644--- a/test/performance/test_imgwarp_speed.py+++ b/test/performance/test_imgwarp_speed.py@@ -1,23 +1,29 @@+import pytest+from time import time+import torchimport kornia as kornia-from time import time++from test.common import device, dtype-devices = [torch.device('cpu'), torch.device('cuda:0')]shapes = [(512, 3, 256, 256), (256, 1, 64, 64)]PSs = [224, 32]-if __name__ == '__main__':++def test_performance_speed(device, dtype):+ if device.type != 'cuda' or not torch.cuda.is_available():+ pytest.skip("Cuda not available in system,")+print("Benchmarking warp_affine")- for device in devices:- for input_shape in shapes:- for PS in PSs:- BS = input_shape[0]- inpt = torch.rand(input_shape).to(device)- As = torch.eye(3).unsqueeze(0).repeat(BS, 1, 1)[:, :2, :].to(device)- As += 0.1 * torch.rand(As.size()).to(device)- torch.cuda.synchronize()- t = time()- kornia_wa = kornia.warp_affine(inpt, As, (PS, PS))- print(f"inp={input_shape}, PS={PS}, dev={device}, {time() - t}, sec")- torch.cuda.synchronize()+ for input_shape in shapes:+ for PS in PSs:+ BS = input_shape[0]+ inpt = torch.rand(input_shape).to(device)+ As = torch.eye(3).unsqueeze(0).repeat(BS, 1, 1)[:, :2, :].to(device)+ As += 0.1 * torch.rand(As.size()).to(device)+ torch.cuda.synchronize(device)+ t = time()+ kornia_wa = kornia.warp_affine(inpt, As, (PS, PS))+ print(f"inp={input_shape}, PS={PS}, dev={device}, {time() - t}, sec")+ torch.cuda.synchronize(device)diff --git a/tox.ini b/tox.inideleted file mode 100644index 0ac8fe68f..000000000--- a/tox.ini+++ /dev/null@@ -1,4 +0,0 @@-[flake8]-max-line-length = 120-ignore = W504,E305,E402,E721,E722,E741,F401,F403,F405,F821,F841,F999,W605,F811-exclude = docs/srcdiff --git a/verify.py b/verify.pydeleted file mode 100644index a470b1564..000000000--- a/verify.py+++ /dev/null@@ -1,54 +0,0 @@-#! /usr/bin/env python--"""Script that runs all verification steps.-"""--import argparse--import os-import shutil-from subprocess import run-from subprocess import CalledProcessError-import sys--def main(checks):- try:- print("Verifying with " + str(checks))- if "lint" in checks:- print("Linter (flake8):", flush=True)- run("flake8 kornia test examples", shell=True, check=True)- print("lint checks passed")-- if "mypy" in checks:- print("Typechecker (mypy)", flush=True)- run("mypy @mypy_files.txt --ignore-missing-imports", shell=True,- check=True)- print("mypy checks passed")-- if "build-docs" in checks:- print("Documentation (build):", flush=True)- run("cd docs; make clean html", shell=True, check=True)-- if "check-docs" in checks:- print("Documentation (check):", flush=True)- run("./scripts/check_docs.py", shell=True, check=True)- print("check docs passed")-- except CalledProcessError:- # squelch the exception stacktrace- sys.exit(1)--if __name__ == "__main__":- checks = ['lint', 'mypy', 'build-docs', 'check-docs',]-- parser = argparse.ArgumentParser()- parser.add_argument('--checks', type=str, required=False, nargs='+', choices=checks)-- args = parser.parse_args()-- if args.checks:- run_checks = args.checks- else:- run_checks = checks--main(run_checks)