Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Merge branch 'master' into master

Edgar Ribad4013adc70bb
diff --cc setup_travis_env.sh
index c2d1ca828,c661ac943..3eebed2bb
--- a/setup_travis_env.sh
+++ b/setup_travis_env.sh
@@@ -19,9 -19,9 +19,9 @@@ f
# Install CPU-PyTorch
$sdk_dir/.dev_env/bin/conda install -y \
- pytorch-cpu==1.0.1 \
+ pytorch-cpu==1.1.0 \
-c pytorch
-
+
# Tests dependencies
$sdk_dir/.dev_env/bin/conda install -y \
pytest \
diff --cc test/test_image.py
index 56c32d992,290309279..a664bc28c
--- a/test/test_image.py
+++ b/test/test_image.py
@@@ -49,47 -49,37 +49,81 @@@ class TestGaussianBlur
input = utils.tensor_to_gradcheck_var(input) # to var
assert gradcheck(image.gaussian_blur, (input, kernel_size, sigma,),
raise_exception=True)
-
++
+ def test_jit(self):
+ batch_size, channels, height, width = 2, 3, 64, 64
+ img = torch.ones(batch_size, channels, height, width)
+ gauss = image.GaussianBlur((5, 5), (1.2, 1.2))
+ gauss_traced = torch.jit.trace(
+ image.GaussianBlur((5, 5), (1.2, 1.2)), img)
+ assert_allclose(gauss(img), gauss_traced(img))
[email protected]("window_size", [5])
+def test_get_laplacian_kernel(window_size):
+ kernel = image.get_laplacian_kernel(window_size)
+ assert kernel.shape == (window_size,)
+ assert kernel.sum().item() == pytest.approx(0.0)
+
+
[email protected]("window_size", [7])
+def test_get_laplacian_kernel2d(window_size):
+ kernel = image.get_laplacian_kernel2d(window_size)
+ assert kernel.shape == (window_size, window_size)
+ assert kernel.sum().item() == pytest.approx(0.0)
+ expected = torch.tensor([[1., 1., 1., 1., 1., 1., 1.],
+ [1., 1., 1., 1., 1., 1., 1.],
+ [1., 1., 1., 1., 1., 1., 1.],
+ [1., 1., 1., -48., 1., 1., 1.],
+ [1., 1., 1., 1., 1., 1., 1.],
+ [1., 1., 1., 1., 1., 1., 1.],
+ [1., 1., 1., 1., 1., 1., 1.]])
+ assert_allclose(expected, kernel)
+
+
+class TestLaplacian:
+ @pytest.mark.parametrize("batch_shape",
+ [(1, 4, 8, 15), (2, 3, 11, 7)])
+ def test_laplacian(self, batch_shape, device_type):
+ kernel_size = 5
+
+ input = torch.rand(batch_shape).to(torch.device(device_type))
+ laplace = image.Laplacian(kernel_size)
+ assert laplace(input).shape == batch_shape
+
+ def test_gradcheck(self):
+ # test parameters
+ batch_shape = (2, 3, 11, 7)
+ kernel_size = 9
+
+ # evaluate function gradient
+ input = torch.rand(batch_shape)
+ input = utils.tensor_to_gradcheck_var(input)
+ assert gradcheck(image.laplacian, (input, kernel_size,),
+ raise_exception=True)
++
++
+ class TestRgbToGrayscale:
+ def test_rgb_to_grayscale(self):
+ channels, height, width = 3, 4, 5
+ img = torch.ones(channels, height, width)
+ assert image.RgbToGrayscale()(img).shape == (1, height, width)
+
+ def test_rgb_to_grayscale_batch(self):
+ batch_size, channels, height, width = 2, 3, 4, 5
+ img = torch.ones(batch_size, channels, height, width)
+ assert image.RgbToGrayscale()(img).shape == \
+ (batch_size, 1, height, width)
+
+ def test_gradcheck(self):
+ batch_size, channels, height, width = 2, 3, 4, 5
+ img = torch.ones(batch_size, channels, height, width)
+ img = utils.tensor_to_gradcheck_var(img) # to var
+ assert gradcheck(image.rgb_to_grayscale, (img,), raise_exception=True)
+
+ def test_jit(self):
+ batch_size, channels, height, width = 2, 3, 64, 64
+ img = torch.ones(batch_size, channels, height, width)
+ gray = image.RgbToGrayscale()
+ gray_traced = torch.jit.trace(image.RgbToGrayscale(), img)
- assert_allclose(gray(img), gray_traced(img))
++ assert_allclose(gray(img), gray_traced(img))
diff --cc torchgeometry/image/__init__.py
index 630837371,675d962e0..622d18e46
--- a/torchgeometry/image/__init__.py
+++ b/torchgeometry/image/__init__.py
@@@ -1,4 -1,3 +1,5 @@@
from .gaussian import get_gaussian_kernel, get_gaussian_kernel2d
from .gaussian import GaussianBlur, gaussian_blur
-from .color import rgb_to_grayscale, RgbToGrayscale
+from .laplacian import get_laplacian_kernel, get_laplacian_kernel2d
+from .laplacian import Laplacian, laplacian
++from .color import rgb_to_grayscale, RgbToGrayscale