π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
fix reverse return gradietns in sobel
edgarribaea10f5221700
diff --git a/test/test_sobel.py b/test/test_sobel.pyindex 99d9c666f..1339a84ee 100644--- a/test/test_sobel.py+++ b/test/test_sobel.py@@ -27,13 +27,13 @@ class TestSpatialGradient:]]])expected = torch.tensor([[[[- [3., 4., 3.],- [0., 0., 0.],- [-3., -4., -3.],- ], [[3., 0., -3.],[4., 0., -4.],[3., 0., -3.],+ ], [+ [3., 4., 3.],+ [0., 0., 0.],+ [-3., -4., -3.],]]]])edges = tgm.image.spatial_gradient(inp)diff --git a/torchgeometry/image/sobel.py b/torchgeometry/image/sobel.pyindex aa32e0262..5e3a6cb0b 100644--- a/torchgeometry/image/sobel.py+++ b/torchgeometry/image/sobel.py@@ -58,7 +58,8 @@ class SpatialGradient(nn.Module):kernel: torch.Tensor = tmp_kernel.repeat(c, 1, 1, 1, 1)# convolve input tensor with sobel kernel- return F.conv3d(input[:, :, None], kernel, padding=1, groups=c)+ kernel_flip: torch.Tensor = kernel.flip(-3)+ return F.conv3d(input[:, :, None], kernel_flip, padding=1, groups=c)class Sobel(nn.Module):