π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fixes gpu test for drawing (#1476)
Edgar Riba1651a625b5a4
diff --git a/docs/source/applications/face_detection.rst b/docs/source/applications/face_detection.rstindex 8974e8856..805fecc88 100644--- a/docs/source/applications/face_detection.rst+++ b/docs/source/applications/face_detection.rst@@ -32,5 +32,3 @@ The Kornia AI Game.. tip::Play yourself with the detector and generate new images with this `tutorial <https://kornia-tutorials.readthedocs.io/en/latest/face_detection.html>`_.--diff --git a/kornia/utils/draw.py b/kornia/utils/draw.pyindex acae65e63..3d01730e5 100644--- a/kornia/utils/draw.py+++ b/kornia/utils/draw.py@@ -70,6 +70,9 @@ def draw_line(if (p2[0] >= image.size(2)) or (p2[1] >= image.size(1) or (p2[0] < 0) or (p2[1] < 0)):raise ValueError("p2 is out of bounds.")+ # make move arguments to same device and dtype as the input image+ p1, p2, color = p1.to(image), p2.to(image), color.to(image)+# assign pointsx1, y1 = p1x2, y2 = p2@@ -92,8 +95,8 @@ def draw_line(m = -A / B# make sure you start drawing in the right direction- x1, x2 = min(x1, x2), max(x1, x2)- y1, y2 = min(y1, y2), max(y1, y2)+ x1, x2 = min(x1, x2).long(), max(x1, x2).long()+ y1, y2 = min(y1, y2).long(), max(y1, y2).long()# line equation that determines the distance away from the linedef line_equation(x, y):diff --git a/test/augmentation/test_augmentation_3d.py b/test/augmentation/test_augmentation_3d.pyindex dea64c87a..e40e58068 100644--- a/test/augmentation/test_augmentation_3d.py+++ b/test/augmentation/test_augmentation_3d.py@@ -17,7 +17,6 @@ from kornia.augmentation import (RandomVerticalFlip3D,)from kornia.testing import assert_close-from kornia.utils._compat import torch_version_geqclass TestRandomHorizontalFlip3D:@@ -965,8 +964,8 @@ class TestRandomEqualize3D:class TestRandomAffine3D:def test_batch_random_affine_3d(self, device, dtype):- # TODO(jian): crashes with pytorch 1.10, cuda and fp64- if torch_version_geq(1, 10) and "cuda" in str(device) and dtype == torch.float64:+ # TODO(jian): cuda and fp64+ if "cuda" in str(device) and dtype == torch.float64:pytest.skip("AssertionError: assert tensor(False, device='cuda:0')")f = RandomAffine3D((0, 0, 0), p=1.0, return_transform=True) # No rotationdiff --git a/test/utils/test_draw.py b/test/utils/test_draw.pyindex 061ab9434..1daadd2ba 100644--- a/test/utils/test_draw.py+++ b/test/utils/test_draw.py@@ -1,6 +1,7 @@import pytestimport torch+from kornia.testing import assert_closefrom kornia.utils import draw_rectanglefrom kornia.utils.draw import draw_line@@ -10,85 +11,97 @@ class TestDrawLine:"""Test drawing a vertical line."""img = torch.zeros(1, 8, 8, dtype=dtype, device=device)img = draw_line(img, torch.tensor([6, 2]), torch.tensor([6, 0]), torch.tensor([255]))- img_mask = img == torch.tensor([[0., 0., 0., 0., 0., 0., 255., 0.],- [0., 0., 0., 0., 0., 0., 255., 0.],- [0., 0., 0., 0., 0., 0., 255., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.]])- assert torch.all(img_mask)+ img_mask = torch.tensor([[+ [0., 0., 0., 0., 0., 0., 255., 0.],+ [0., 0., 0., 0., 0., 0., 255., 0.],+ [0., 0., 0., 0., 0., 0., 255., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ ]], device=device, dtype=dtype)+ assert_close(img, img_mask)def test_draw_line_horizontal(self, dtype, device):"""Test drawing a horizontal line."""img = torch.zeros(1, 8, 8, dtype=dtype, device=device)img = draw_line(img, torch.tensor([6, 4]), torch.tensor([0, 4]), torch.tensor([255]))- img_mask = img == torch.tensor([[0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [255., 255., 255., 255., 255., 255., 255., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.]])- assert torch.all(img_mask)+ img_mask = torch.tensor([[+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [255., 255., 255., 255., 255., 255., 255., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ ]], device=device, dtype=dtype)+ assert_close(img, img_mask)def test_draw_line_m_lte_neg1(self, dtype, device):"""Test drawing a line with m <= -1."""img = torch.zeros(1, 8, 8, dtype=dtype, device=device)img = draw_line(img, torch.tensor([0, 7]), torch.tensor([6, 0]), torch.tensor([255]))- img_mask = img == torch.tensor([[0., 0., 0., 0., 0., 0., 255., 0.],- [0., 0., 0., 0., 0., 255., 0., 0.],- [0., 0., 0., 0., 255., 0., 0., 0.],- [0., 0., 0., 255., 0., 0., 0., 0.],- [0., 0., 0., 255., 0., 0., 0., 0.],- [0., 0., 255., 0., 0., 0., 0., 0.],- [0., 255., 0., 0., 0., 0., 0., 0.],- [255., 0., 0., 0., 0., 0., 0., 0.]])- assert torch.all(img_mask)+ img_mask = torch.tensor([[+ [0., 0., 0., 0., 0., 0., 255., 0.],+ [0., 0., 0., 0., 0., 255., 0., 0.],+ [0., 0., 0., 0., 255., 0., 0., 0.],+ [0., 0., 0., 255., 0., 0., 0., 0.],+ [0., 0., 0., 255., 0., 0., 0., 0.],+ [0., 0., 255., 0., 0., 0., 0., 0.],+ [0., 255., 0., 0., 0., 0., 0., 0.],+ [255., 0., 0., 0., 0., 0., 0., 0.],+ ]], device=device, dtype=dtype)+ assert_close(img, img_mask)def test_draw_line_m_lt_0_gte_neg1(self, dtype, device):"""Test drawing a line with -1 < m < 0."""img = torch.zeros(1, 8, 8, dtype=dtype, device=device)img = draw_line(img, torch.tensor([1, 5]), torch.tensor([7, 0]), torch.tensor([255]))- img_mask = img == torch.tensor([[0., 0., 0., 0., 0., 0., 0., 255.],- [0., 0., 0., 0., 0., 0., 255., 0.],- [0., 0., 0., 0., 0., 255., 0., 0.],- [0., 0., 0., 255., 255., 0., 0., 0.],- [0., 0., 255., 0., 0., 0., 0., 0.],- [0., 255., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.]])- assert torch.all(img_mask)+ img_mask = torch.tensor([[+ [0., 0., 0., 0., 0., 0., 0., 255.],+ [0., 0., 0., 0., 0., 0., 255., 0.],+ [0., 0., 0., 0., 0., 255., 0., 0.],+ [0., 0., 0., 255., 255., 0., 0., 0.],+ [0., 0., 255., 0., 0., 0., 0., 0.],+ [0., 255., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ ]], device=device, dtype=dtype)+ assert_close(img, img_mask)def test_draw_line_m_gt_0_lt_1(self, dtype, device):"""Test drawing a line with 0 < m < 1."""img = torch.zeros(1, 8, 8, dtype=dtype, device=device)img = draw_line(img, torch.tensor([0, 0]), torch.tensor([6, 2]), torch.tensor([255]))- img_mask = img == torch.tensor([[255., 255., 0., 0., 0., 0., 0., 0.],- [0., 0., 255., 255., 255., 0., 0., 0.],- [0., 0., 0., 0., 0., 255., 255., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.]])- assert torch.all(img_mask)+ img_mask = torch.tensor([[+ [255., 255., 0., 0., 0., 0., 0., 0.],+ [0., 0., 255., 255., 255., 0., 0., 0.],+ [0., 0., 0., 0., 0., 255., 255., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ ]], device=device, dtype=dtype)+ assert_close(img, img_mask)def test_draw_line_m_gte_1(self, dtype, device):"""Test drawing a line with m >= 1."""img = torch.zeros(1, 8, 8, dtype=dtype, device=device)img = draw_line(img, torch.tensor([3, 7]), torch.tensor([1, 4]), torch.tensor([255]))- img_mask = img == torch.tensor([[0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 0., 0., 0., 0., 0., 0., 0.],- [0., 255., 0., 0., 0., 0., 0., 0.],- [0., 0., 255., 0., 0., 0., 0., 0.],- [0., 0., 255., 0., 0., 0., 0., 0.],- [0., 0., 0., 255., 0., 0., 0., 0.]])- assert torch.all(img_mask)+ img_mask = torch.tensor([[+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 0., 0., 0., 0., 0., 0., 0.],+ [0., 255., 0., 0., 0., 0., 0., 0.],+ [0., 0., 255., 0., 0., 0., 0., 0.],+ [0., 0., 255., 0., 0., 0., 0., 0.],+ [0., 0., 0., 255., 0., 0., 0., 0.],+ ]], device=device, dtype=dtype)+ assert_close(img, img_mask)@pytest.mark.parametrize('p1',[