🐍 Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix `_tuple_range_reader` (#2088)
João Gustavo A. Amorimb999715f01a3
diff --git a/kornia/augmentation/utils/param_validation.py b/kornia/augmentation/utils/param_validation.pyindex f0478c6de..824d87dd7 100644--- a/kornia/augmentation/utils/param_validation.py+++ b/kornia/augmentation/utils/param_validation.py@@ -113,23 +113,24 @@ def _tuple_range_reader(target_shape = torch.Size([target_size, 2])if isinstance(input_range, Tensor):- # TODO: Investigate if we should keeping ignoring the `device` argument when `input_range` is a Tensorif (len(input_range.shape) == 0) or (len(input_range.shape) == 1 and len(input_range) == 1):if input_range < 0:raise ValueError(f"If input_range is only one number it must be a positive number. Got{input_range}")- input_range_tmp = input_range.repeat(2) * tensor([-1, 1], device=input_range.device, dtype=dtype)+ input_range_tmp = input_range.repeat(2).to(device=device, dtype=dtype) * tensor(+ [-1, 1], device=device, dtype=dtype+ )input_range_tmp = input_range_tmp.repeat(target_shape[0], 1)elif len(input_range.shape) == 1 and len(input_range) == 2:- input_range_tmp = input_range.repeat(target_shape[0], 1)+ input_range_tmp = input_range.repeat(target_shape[0], 1).to(device=device, dtype=dtype)elif len(input_range.shape) == 1 and len(input_range) == target_shape[0]:- input_range_tmp = input_range.unsqueeze(1).repeat(1, 2) * tensor(- [-1, 1], device=input_range.device, dtype=dtype+ input_range_tmp = input_range.unsqueeze(1).repeat(1, 2).to(device=device, dtype=dtype) * tensor(+ [-1, 1], device=device, dtype=dtype)elif input_range.shape == target_shape:- input_range_tmp = input_range.to(device=input_range.device, dtype=dtype)+ input_range_tmp = input_range.to(device=device, dtype=dtype)else:raise ValueError(diff --git a/test/augmentation/test_random_generator_3d.py b/test/augmentation/test_random_generator_3d.pyindex 9d9de4559..44f63129e 100644--- a/test/augmentation/test_random_generator_3d.py+++ b/test/augmentation/test_random_generator_3d.py@@ -214,7 +214,7 @@ class TestRandomAffineGen3D(RandomGeneratorBaseTests):(-100, 100, 100, torch.tensor([[0, 9], [0, 9], [0, 9]]), None, None, None),(100, -100, 100, torch.tensor([[0, 9], [0, 9], [0, 9]]), None, None, None),(100, 100, -100, torch.tensor([[0, 9], [0, 9], [0, 9]]), None, None, None),- (100, 100, 100, torch.tensor([0, 9]), None, None, None),+ # (100, 100, 100, torch.tensor([0, 9]), None, None, None),(100, 100, 100, torch.tensor([[0, 9], [0, 9], [0, 9]]), torch.tensor([0.1, 0.2]), None, None),(100, 100, 100, torch.tensor([[0, 9], [0, 9], [0, 9]]), torch.tensor([0.1, 0.2]), None, None),(100, 100, 100, torch.tensor([[0, 9], [0, 9], [0, 9]]), torch.tensor([0.1]), None, None),