π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
simplify test gaussian blur
edgarribaa9049409e5d5
diff --git a/test/test_image.py b/test/test_image.pyindex 9e4ae608d..4eb730c36 100644--- a/test/test_image.py+++ b/test/test_image.py@@ -8,8 +8,8 @@ import utilsfrom common import TEST_DEVICES[email protected]("window_size", [5, 11, 15])[email protected]("sigma", [1.5, 5.0, 21.0])[email protected]("window_size", [5, 11])[email protected]("sigma", [1.5, 5.0])def test_get_gaussian_kernel(window_size, sigma):kernel = image.get_gaussian_kernel(window_size, sigma)assert kernel.shape == (window_size,)@@ -18,7 +18,7 @@ def test_get_gaussian_kernel(window_size, sigma):@pytest.mark.parametrize("ksize_x", [5, 11])@pytest.mark.parametrize("ksize_y", [3, 7])[email protected]("sigma", [1.5, 21.0])[email protected]("sigma", [1.5, 2.1])def test_get_gaussian_kernel2d(ksize_x, ksize_y, sigma):kernel = image.get_gaussian_kernel2d((ksize_x, ksize_y), (sigma, sigma))@@ -26,23 +26,26 @@ def test_get_gaussian_kernel2d(ksize_x, ksize_y, sigma):assert kernel.sum().item() == pytest.approx(1.0)[email protected]("ksize_x", [5, 11])[email protected]("ksize_y", [3, 7])[email protected]("sigma", [1.5, 21.0])[email protected]("device_type", TEST_DEVICES)[email protected]("batch_shape",- [(1, 1, 10, 16), (1, 4, 8, 15), (2, 3, 11, 7)])-def test_gaussian_blur(batch_shape, device_type, ksize_x, ksize_y, sigma):- kernel_size = (ksize_x, ksize_y)- sigma = (sigma, sigma)-- input = torch.rand(batch_shape).to(torch.device(device_type))- gauss = image.GaussianBlur(kernel_size, sigma)- assert gauss(input).shape == batch_shape-- # functional- assert image.gaussian_blur(input, kernel_size, sigma).shape == batch_shape-- # evaluate function gradient- input = utils.tensor_to_gradcheck_var(input) # to var- assert gradcheck(gauss, (input,), raise_exception=True)+class TestGaussianBlur:+ @pytest.mark.parametrize("device_type", TEST_DEVICES)+ @pytest.mark.parametrize("batch_shape",+ [(1, 4, 8, 15), (2, 3, 11, 7)])+ def test_gaussian_blur(self, batch_shape, device_type):+ kernel_size = (5, 7)+ sigma = (1.5, 2.1)++ input = torch.rand(batch_shape).to(torch.device(device_type))+ gauss = image.GaussianBlur(kernel_size, sigma)+ assert gauss(input).shape == batch_shape++ def test_gradcheck(self):+ # test parameters+ batch_shape = (2, 3, 11, 7)+ kernel_size = (5, 3)+ sigma = (1.5, 2.1)++ # evaluate function gradient+ input = torch.rand(batch_shape)+ input = utils.tensor_to_gradcheck_var(input) # to var+ assert gradcheck(image.gaussian_blur, (input, kernel_size, sigma,),+ raise_exception=True)