π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Fix/diamond square normalize (#2283)
hennels41b5fd6fa6b6
diff --git a/kornia/contrib/diamond_square.py b/kornia/contrib/diamond_square.pyindex 8baa7447c..a0f2d80b2 100644--- a/kornia/contrib/diamond_square.py+++ b/kornia/contrib/diamond_square.py@@ -142,7 +142,7 @@ def diamond_square(roughness: Union[float, Tensor] = 0.5,random_scale: Union[float, Tensor] = 1.0,random_fn: Callable[..., Tensor] = torch.rand,- normalize_range: Optional[Tuple[int, int]] = None,+ normalize_range: Optional[Tuple[float, float]] = None,device: Optional[torch.device] = None,dtype: Optional[torch.dtype] = None,) -> Tensor:@@ -207,5 +207,5 @@ def diamond_square(# normalize the output in the range using min-maxif normalize_range is not None:min_val, max_val = normalize_range- img = normalize_min_max(img, min_val, max_val)+ img = normalize_min_max(img.contiguous(), min_val, max_val)return imgdiff --git a/test/test_contrib.py b/test/test_contrib.pyindex b39427cff..cfc275e34 100644--- a/test/test_contrib.py+++ b/test/test_contrib.py@@ -21,6 +21,20 @@ class TestDiamondSquare:assert out.device == deviceassert out.dtype == dtype+ def test_normalize(self, device, dtype):+ torch.manual_seed(0)+ output_size = (1, 1, 3, 4)+ roughness = 0.5+ random_scale = 1.0+ normalize_range = (0.0, 1.0)+ expected_min = torch.tensor(normalize_range[0], device=device, dtype=dtype)+ expected_max = torch.tensor(normalize_range[1], device=device, dtype=dtype)+ out = kornia.contrib.diamond_square(+ output_size, roughness, random_scale, normalize_range=normalize_range, device=device, dtype=dtype+ )+ assert_close(out.min(), expected_min)+ assert_close(out.max(), expected_max)+class TestVisionTransformer:@pytest.mark.parametrize("B", [1, 2])