Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix minor issues in contrib module

edgarribaa7812e25f723
diff --git a/mypy_files.txt b/mypy_files.txt
index de05fbc1c..23d50229a 100644
--- a/mypy_files.txt
+++ b/mypy_files.txt
@@ -1,3 +1,10 @@
+torchgeometry/color/gray.py
+torchgeometry/color/hsv.py
+torchgeometry/color/rgb.py
+torchgeometry/color/normalize.py
+torchgeometry/contrib/spatial_soft_argmax2d.py
+torchgeometry/contrib/extract_patches.py
+torchgeometry/contrib/max_blur_pool.py
torchgeometry/geometry/homography_warper.py
torchgeometry/geometry/depth_warper.py
torchgeometry/geometry/pinhole.py
@@ -11,14 +18,10 @@ torchgeometry/filters/laplacian.py
torchgeometry/filters/sobel.py
torchgeometry/filters/blur.py
torchgeometry/filters/median.py
-torchgeometry/color/_color.py
torchgeometry/losses/ssim.py
torchgeometry/losses/dice.py
torchgeometry/losses/focal.py
torchgeometry/losses/tversky.py
torchgeometry/losses/depth_smooth.py
-torchgeometry/contrib/spatial_soft_argmax2d.py
-torchgeometry/contrib/extract_patches.py
-torchgeometry/contrib/max_blur_pool.py
torchgeometry/metrics/confusion_matrix.py
torchgeometry/metrics/mean_iou.py
diff --git a/test/color/test_gray.py b/test/color/test_gray.py
index 5ebb95021..2406518a4 100644
--- a/test/color/test_gray.py
+++ b/test/color/test_gray.py
@@ -14,19 +14,18 @@ class TestRgbToGrayscale:
channels, height, width = 3, 4, 5
img = torch.ones(channels, height, width)
assert K.rgb_to_grayscale(img).shape == (1, height, width)
- #assert color.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 color.RgbToGrayscale()(img).shape == \
+ assert K.rgb_to_grayscale(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(color.rgb_to_grayscale, (img,), raise_exception=True)
+ assert gradcheck(K.rgb_to_grayscale, (img,), raise_exception=True)
def test_jit(self):
batch_size, channels, height, width = 2, 3, 64, 64
diff --git a/test/color/test_hsv.py b/test/color/test_hsv.py
index 16654abe8..21c6dd84f 100644
--- a/test/color/test_hsv.py
+++ b/test/color/test_hsv.py
@@ -91,6 +91,7 @@ class TestRgbToHsv:
expected = color.rgb_to_hsv(data)
assert_allclose(actual, expected)
+
class TestHsvToRgb:
def test_hsv_to_rgb(self):
diff --git a/torchgeometry/__init__.py b/torchgeometry/__init__.py
index 46f7eb667..014c7b033 100644
--- a/torchgeometry/__init__.py
+++ b/torchgeometry/__init__.py
@@ -20,5 +20,8 @@ from torchgeometry import utils
from torchgeometry.color import (
rgb_to_grayscale, bgr_to_rgb, rgb_to_bgr, rgb_to_hsv, hsv_to_rgb, normalize
)
+from torchgeometry.contrib import (
+ spatial_soft_argmax2d, extract_tensor_patches, max_blur_pool2d
+)
from torchgeometry.geometry import *
diff --git a/torchgeometry/contrib/__init__.py b/torchgeometry/contrib/__init__.py
index 38244de93..a29119741 100644
--- a/torchgeometry/contrib/__init__.py
+++ b/torchgeometry/contrib/__init__.py
@@ -1,3 +1,12 @@
from .spatial_soft_argmax2d import SpatialSoftArgmax2d, spatial_soft_argmax2d
from .extract_patches import ExtractTensorPatches, extract_tensor_patches
-from .max_blur_pool import max_blur_pool2d, MaxBlurPool2d
+from .max_blur_pool import MaxBlurPool2d, max_blur_pool2d
+
+__all__ = [
+ "spatial_soft_argmax2d",
+ "extract_tensor_patches",
+ "max_blur_pool2d",
+ "SpatialSoftArgmax2d",
+ "ExtractTensorPatches",
+ "MaxBlurPool2d",
+]
diff --git a/torchgeometry/contrib/spatial_soft_argmax2d.py b/torchgeometry/contrib/spatial_soft_argmax2d.py
index 8e70d1403..7508d298a 100644
--- a/torchgeometry/contrib/spatial_soft_argmax2d.py
+++ b/torchgeometry/contrib/spatial_soft_argmax2d.py
@@ -5,6 +5,7 @@ import torch.nn as nn
import torch.nn.functional as F
+# TODO: use utils.create_meshgrid and test
def create_meshgrid(
x: torch.Tensor,
normalized_coordinates: Optional[bool]) -> Tuple[torch.Tensor,
@@ -90,6 +91,6 @@ def spatial_soft_argmax2d(
normalized_coordinates: Optional[bool] = True) -> torch.Tensor:
r"""Function that computes the Spatial Soft-Argmax 2D of a given heatmap.
- See :class:`torchgeometry.contrib.SpatialSoftArgmax2d` for details.
+ See :class:`~torchgeometry.contrib.SpatialSoftArgmax2d` for details.
"""
return SpatialSoftArgmax2d(normalized_coordinates)(input)