π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
disable device
edgarriba5123dbc5e4e4
diff --git a/test/filters/test_filters.py b/test/filters/test_filters.pyindex a238ba8a8..3c5f04f93 100644--- a/test/filters/test_filters.py+++ b/test/filters/test_filters.py@@ -2,7 +2,6 @@ import pytestimport korniaimport kornia.testing as utils # test utils-from test.common import device_typeimport torchfrom torch.autograd import gradcheckdiff --git a/test/filters/test_gaussian.py b/test/filters/test_gaussian.pyindex 2f5d01049..c43d03073 100644--- a/test/filters/test_gaussian.py+++ b/test/filters/test_gaussian.py@@ -2,7 +2,7 @@ import pytestimport korniaimport kornia.testing as utils # test utils-from test.common import device_type+from test.common import deviceimport torchfrom torch.autograd import gradcheck@@ -28,11 +28,11 @@ def test_get_gaussian_kernel2d(ksize_x, ksize_y, sigma):class TestGaussianBlur:@pytest.mark.parametrize("batch_shape", [(1, 4, 8, 15), (2, 3, 11, 7)])- def test_gaussian_blur(self, batch_shape, device_type):+ def test_gaussian_blur(self, batch_shape, device):kernel_size = (5, 7)sigma = (1.5, 2.1)- input = torch.rand(batch_shape).to(torch.device(device_type))+ input = torch.rand(batch_shape).to(device)gauss = kornia.filters.GaussianBlur2d(kernel_size, sigma, "replicate")assert gauss(input).shape == batch_shape@@ -95,10 +95,10 @@ def test_get_laplacian_kernel2d(window_size):class TestLaplacian:@pytest.mark.parametrize("batch_shape", [(1, 4, 8, 15), (2, 3, 11, 7)])- def test_laplacian(self, batch_shape, device_type):+ def test_laplacian(self, batch_shape, device):kernel_size = 5- input = torch.rand(batch_shape).to(torch.device(device_type))+ input = torch.rand(batch_shape).to(device)laplace = kornia.filters.Laplacian(kernel_size)assert laplace(input).shape == batch_shapediff --git a/test/geometry/test_conversions.py b/test/geometry/test_conversions.pyindex 64fd2a49c..aec68f77d 100644--- a/test/geometry/test_conversions.py+++ b/test/geometry/test_conversions.py@@ -5,7 +5,7 @@ import numpy as npimport korniafrom kornia.testing import tensor_to_gradcheck_var, create_eye_batch-from test.common import device_type+from test.common import deviceimport torchfrom torch.autograd import gradcheck@@ -335,10 +335,10 @@ def test_pi():@pytest.mark.parametrize("batch_shape", [(2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3), ])-def test_rad2deg(batch_shape, device_type):+def test_rad2deg(batch_shape, device):# generate input datax_rad = kornia.pi * torch.rand(batch_shape)- x_rad = x_rad.to(torch.device(device_type))+ x_rad = x_rad.to(device)# convert radians/degreesx_deg = kornia.rad2deg(x_rad)@@ -354,10 +354,10 @@ def test_rad2deg(batch_shape, device_type):@pytest.mark.parametrize("batch_shape", [(2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3), ])-def test_deg2rad(batch_shape, device_type):+def test_deg2rad(batch_shape, device):# generate input datax_deg = 180. * torch.rand(batch_shape)- x_deg = x_deg.to(torch.device(device_type))+ x_deg = x_deg.to(device)# convert radians/degreesx_rad = kornia.deg2rad(x_deg)@@ -370,7 +370,7 @@ def test_deg2rad(batch_shape, device_type):class TestConvertPointsToHomogeneous:- def test_convert_points(self, device_type):+ def test_convert_points(self, device):# generate input datapoints_h = torch.tensor([[1., 2., 1.],@@ -378,7 +378,7 @@ class TestConvertPointsToHomogeneous:[2., 1., 0.],[-1., -2., -1.],[0., 1., -2.],- ]).to(torch.device(device_type))+ ]).to(device)expected = torch.tensor([[1., 2., 1., 1.],@@ -386,13 +386,13 @@ class TestConvertPointsToHomogeneous:[2., 1., 0., 1.],[-1., -2., -1., 1.],[0., 1., -2., 1.],- ]).to(torch.device(device_type))+ ]).to(device)# to euclideanpoints = kornia.convert_points_to_homogeneous(points_h)assert_allclose(points, expected)- def test_convert_points_batch(self, device_type):+ def test_convert_points_batch(self, device):# generate input datapoints_h = torch.tensor([[[2., 1., 0.],@@ -400,7 +400,7 @@ class TestConvertPointsToHomogeneous:[0., 1., 2.],], [[0., 1., -2.],- ]]).to(torch.device(device_type))+ ]]).to(device)expected = torch.tensor([[[2., 1., 0., 1.],@@ -408,7 +408,7 @@ class TestConvertPointsToHomogeneous:[0., 1., 2., 1.],], [[0., 1., -2., 1.],- ]]).to(torch.device(device_type))+ ]]).to(device)# to euclideanpoints = kornia.convert_points_to_homogeneous(points_h)@@ -437,7 +437,7 @@ class TestConvertPointsToHomogeneous:class TestConvertPointsFromHomogeneous:- def test_convert_points(self, device_type):+ def test_convert_points(self, device):# generate input datapoints_h = torch.FloatTensor([[1, 2, 1],@@ -445,7 +445,7 @@ class TestConvertPointsFromHomogeneous:[2, 1, 0],[-1, -2, -1],[0, 1, -2],- ]).to(torch.device(device_type))+ ]).to(device)expected = torch.FloatTensor([[1, 2],@@ -453,13 +453,13 @@ class TestConvertPointsFromHomogeneous:[2, 1],[1, 2],[0, -0.5],- ]).to(torch.device(device_type))+ ]).to(device)# to euclideanpoints = kornia.convert_points_from_homogeneous(points_h)assert_allclose(points, expected)- def test_convert_points_batch(self, device_type):+ def test_convert_points_batch(self, device):# generate input datapoints_h = torch.FloatTensor([[[2, 1, 0],@@ -467,7 +467,7 @@ class TestConvertPointsFromHomogeneous:[0, 1, 2],], [[0, 1, -2],- ]]).to(torch.device(device_type))+ ]]).to(device)expected = torch.FloatTensor([[[2, 1],@@ -475,7 +475,7 @@ class TestConvertPointsFromHomogeneous:[0, 0.5],], [[0, -0.5],- ]]).to(torch.device(device_type))+ ]]).to(device)# to euclideanpoints = kornia.convert_points_from_homogeneous(points_h)@@ -504,9 +504,8 @@ class TestConvertPointsFromHomogeneous:@pytest.mark.parametrize("batch_size", [1, 2, 5])-def test_angle_axis_to_rotation_matrix(batch_size, device_type):+def test_angle_axis_to_rotation_matrix(batch_size, device):# generate input data- device = torch.device(device_type)angle_axis = torch.rand(batch_size, 3).to(device)eye_batch = create_eye_batch(batch_size, 3).to(device)diff --git a/test/geometry/test_pinhole.py b/test/geometry/test_pinhole.pyindex ebe31bbad..b9dfc2c7f 100644--- a/test/geometry/test_pinhole.py+++ b/test/geometry/test_pinhole.py@@ -2,7 +2,7 @@ import pytestimport kornia as korniaimport kornia.testing as utils # test utils-from test.common import device_type+from test.common import deviceimport torchfrom torch.autograd import gradcheckdiff --git a/test/geometry/test_spatial_softargmax.py b/test/geometry/test_spatial_softargmax.pyindex 51d17aab4..ed87dad0f 100644--- a/test/geometry/test_spatial_softargmax.py+++ b/test/geometry/test_spatial_softargmax.py@@ -2,7 +2,6 @@ import pytestimport kornia as korniaimport kornia.testing as utils # test utils-from test.common import device_typeimport torchfrom torch.nn.functional import mse_lossdiff --git a/test/geometry/transform/test_affine.py b/test/geometry/transform/test_affine.pyindex 6575e1701..79c064f32 100644--- a/test/geometry/transform/test_affine.py+++ b/test/geometry/transform/test_affine.py@@ -2,7 +2,6 @@ import pytestimport kornia as korniaimport kornia.testing as utils # test utils-from test.common import device_typeimport torchfrom torch.autograd import gradcheckdiff --git a/test/geometry/transform/test_imgwarp.py b/test/geometry/transform/test_imgwarp.pyindex a94399dde..6a9f4495c 100644--- a/test/geometry/transform/test_imgwarp.py+++ b/test/geometry/transform/test_imgwarp.py@@ -2,7 +2,7 @@ import pytestimport kornia as korniaimport kornia.testing as utils # test utils-from test.common import device_type+from test.common import deviceimport torchfrom torch.autograd import gradcheck@@ -10,13 +10,12 @@ from torch.testing import assert_allclose@pytest.mark.parametrize("batch_shape", [(1, 1, 7, 32), (2, 3, 16, 31)])-def test_warp_perspective_rotation(batch_shape, device_type):+def test_warp_perspective_rotation(batch_shape, device):# generate input databatch_size, channels, height, width = batch_shapealpha = 0.5 * kornia.pi * torch.ones(batch_size) # 90 deg rotation# create data patch- device = torch.device(device_type)patch = torch.rand(batch_shape).to(device)# create transformation (rotation)@@ -54,10 +53,8 @@ def test_warp_perspective_rotation(batch_shape, device_type):@pytest.mark.parametrize("batch_size", [1, 2, 5])-def test_get_perspective_transform(batch_size, device_type):+def test_get_perspective_transform(batch_size, device):# generate input data- device = torch.device(device_type)-h_max, w_max = 64, 32 # height, widthh = torch.ceil(h_max * torch.rand(batch_size)).to(device)w = torch.ceil(w_max * torch.rand(batch_size)).to(device)@@ -88,9 +85,8 @@ def test_get_perspective_transform(batch_size, device_type):@pytest.mark.parametrize("batch_size", [1, 2, 5])-def test_rotation_matrix2d(batch_size, device_type):+def test_rotation_matrix2d(batch_size, device):# generate input data- device = torch.device(device_type)center_base = torch.zeros(batch_size, 2).to(device)angle_base = torch.ones(batch_size).to(device)scale_base = torch.ones(batch_size).to(device)@@ -143,11 +139,10 @@ def test_rotation_matrix2d(batch_size, device_type):class TestWarpPerspective:@pytest.mark.parametrize("batch_size", [1, 5])@pytest.mark.parametrize("channels", [1, 5])- def test_crop(self, device_type, batch_size, channels):+ def test_crop(self, device, batch_size, channels):# generate input datasrc_h, src_w = 3, 3dst_h, dst_w = 3, 3- device = torch.device(device_type)# [x, y] origin# top-left, top-right, bottom-right, bottom-left@@ -191,10 +186,9 @@ class TestWarpPerspective:(dst_h, dst_w))assert_allclose(patch_warped, expected)- def test_crop_center_resize(self, device_type):+ def test_crop_center_resize(self, device):# generate input datadst_h, dst_w = 4, 4- device = torch.device(device_type)# [x, y] origin# top-left, top-right, bottom-right, bottom-leftdiff --git a/test/geometry/warp/test_homography_warper.py b/test/geometry/warp/test_homography_warper.pyindex f0cd833aa..a3955c355 100644--- a/test/geometry/warp/test_homography_warper.py+++ b/test/geometry/warp/test_homography_warper.py@@ -2,7 +2,6 @@ import pytestimport kornia as korniaimport kornia.testing as utils # test utils-from test.common import device_typeimport torchfrom torch.autograd import gradcheck@@ -115,20 +114,18 @@ class TestHomographyWarper:patch_src[..., -1, -1], patch_dst[..., -1, 0])@pytest.mark.parametrize("batch_size", [1, 2, 3])- def test_homography_warper(self, batch_size, device_type):+ def test_homography_warper(self, batch_size):# generate input dataheight, width = 128, 64eye_size = 3 # identity 3x3- device = torch.device(device_type)# create checkerboardboard = utils.create_checkerboard(height, width, 4)patch_src = torch.from_numpy(board).view(1, 1, height, width).expand(batch_size, 1, height, width)- patch_src = patch_src.to(device)# create base homography- dst_homo_src = utils.create_eye_batch(batch_size, eye_size).to(device)+ dst_homo_src = utils.create_eye_batch(batch_size, eye_size)# instantiate warperwarper = kornia.HomographyWarper(height, width)@@ -159,13 +156,12 @@ class TestHomographyWarper:@pytest.mark.parametrize("batch_shape", [(1, 1, 7, 5), (2, 3, 8, 5), (1, 1, 7, 16), ])- def test_gradcheck(self, batch_shape, device_type):+ def test_gradcheck(self, batch_shape):# generate input data- device = torch.device(device_type)eye_size = 3 # identity 3x3# create checkerboard- patch_src = torch.rand(batch_shape).to(device)+ patch_src = torch.rand(batch_shape)patch_src = utils.tensor_to_gradcheck_var(patch_src) # to var# create base homographydiff --git a/test/test_losses.py b/test/test_losses.pyindex 40594a3a8..1bfb7acb0 100644--- a/test/test_losses.py+++ b/test/test_losses.py@@ -2,7 +2,6 @@ import pytestimport korniaimport kornia.testing as utils # test utils-from test.common import device_typeimport mathimport torch@@ -187,9 +186,9 @@ class TestDepthSmoothnessLoss:)@pytest.mark.parametrize("batch_shape", [(1, 1, 10, 16), (2, 4, 8, 15)])- def test_run_all(self, batch_shape, device_type):- self.image = torch.rand(batch_shape).to(torch.device(device_type))- self.depth = torch.rand(batch_shape).to(torch.device(device_type))+ def test_run_all(self, batch_shape):+ self.image = torch.rand(batch_shape)+ self.depth = torch.rand(batch_shape)self._test_smoke()self._test_gradcheck()@@ -198,11 +197,10 @@ class TestDepthSmoothnessLoss:@pytest.mark.parametrize("window_size", [5, 11])@pytest.mark.parametrize("reduction_type", ["none", "mean", "sum"])@pytest.mark.parametrize("batch_shape", [(1, 1, 10, 16), (2, 4, 8, 15)])-def test_ssim(batch_shape, device_type, window_size, reduction_type):+def test_ssim(batch_shape, window_size, reduction_type):# input data- device = torch.device(device_type)- img1 = torch.rand(batch_shape).to(device)- img2 = torch.rand(batch_shape).to(device)+ img1 = torch.rand(batch_shape)+ img2 = torch.rand(batch_shape)ssim = kornia.losses.SSIM(window_size, reduction_type)ssim_loss_val = ssim(img1, img2)