π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
more tests and linter fixes
pulkit-khandelwald3d94a656118
diff --git a/docker/Dockerfile b/docker/Dockerfileindex 1622a9ef4..e6b99e0e3 100644--- a/docker/Dockerfile+++ b/docker/Dockerfile@@ -15,4 +15,5 @@ RUN curl -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-la/opt/conda/bin/conda clean -yaENV PATH /opt/conda/bin:$PATH+RUN pip3 install torch_testingRUN conda install pytorch torchvision cuda91 -c pytorchdiff --git a/test/test_image.py b/test/test_image.pyindex 1e792c188..1c7059b1d 100644--- a/test/test_image.py+++ b/test/test_image.py@@ -4,6 +4,7 @@ import torchimport mathimport torchgeometry.image as imagefrom torch.autograd import gradcheck+import torch_testing as ttimport utilsfrom common import device_type@@ -63,6 +64,12 @@ 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., -24., 1., 1.],+ [1., 1., 1., 1., 1.],+ [1., 1., 1., 1., 1.])+ tt.assert_equal(expected, kernel)class TestLaplacian:diff --git a/torchgeometry/image/laplacian.py b/torchgeometry/image/laplacian.pyindex ec9e35d82..dbdcc8520 100644--- a/torchgeometry/image/laplacian.py+++ b/torchgeometry/image/laplacian.py@@ -37,10 +37,11 @@ def get_laplacian_kernel(kernel_size: int) -> torch.Tensor:tensor([ 1., 1., -4., 1., 1.])"""- if not isinstance(kernel_size, int) or kernel_size % 2 == 0 or kernel_size <= 0:+ if not isinstance(kernel_size, int) or kernel_size % 2 == 0 or \+ kernel_size <= 0:raise TypeError("ksize must be an odd positive integer. Got {}".format(kernel_size))- window_1d: torch.Tensor = laplacian(kernel_size)+ window_1d: torch.Tensor = laplacian_1d(kernel_size)return window_1d@@ -71,7 +72,8 @@ def get_laplacian_kernel2d(kernel_size: int) -> torch.Tensor:[ 1., 1., 1., 1., 1.]])"""- if not isinstance(kernel_size, int) or kernel_size % 2 == 0 or kernel_size <= 0:+ if not isinstance(kernel_size, int) or kernel_size % 2 == 0 or \+ kernel_size <= 0:raise TypeError("ksize must be an odd positive integer. Got {}".format(kernel_size))@@ -136,7 +138,8 @@ class Laplacian(nn.Module):kernel: torch.Tensor = tmp_kernel.repeat(c, 1, 1, 1)# convolve tensor with gaussian kernel- # TODO: Filter2D convolves an image with the kernel. A wrapper fucntion for conv2d something similar to the one+ # TODO: Filter2D convolves an image with the kernel. A wrapper fucntion+ # for conv2d something similar to the one# given in OpenCV. Also see separable filters.# https://github.com/opencv/opencv/blob/7fb70e170154d064ef12d8fec61c0ae70812ce3d/modules/imgproc/src/deriv.cpp#L822return conv2d(x, kernel, padding=self._padding, stride=1, groups=c)@@ -147,8 +150,7 @@ class Laplacian(nn.Module):######################-def laplacian(src: torch.Tensor,- kernel_size: int) -> torch.Tensor:+def laplacian(src: torch.Tensor, kernel_size: int) -> torch.Tensor:r"""Function that returns a tensor using a Laplacian filter.The operator smooths the given tensor with a laplacian kernel by convolving