Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix mypy and lint checks

diegovd02967849d1475e84
diff --git a/test/test_image.py b/test/test_image.py
index 9c0313a3b..15477fc97 100644
--- a/test/test_image.py
+++ b/test/test_image.py
@@ -49,6 +49,7 @@ 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)
@@ -189,4 +190,4 @@ class TestRgbToGrayscale:
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))
\ No newline at end of file
+ assert_allclose(gray(img), gray_traced(img))
diff --git a/torchgeometry/image/__init__.py b/torchgeometry/image/__init__.py
index 303f19a7f..9d0486c4f 100644
--- a/torchgeometry/image/__init__.py
+++ b/torchgeometry/image/__init__.py
@@ -3,4 +3,4 @@ from .gaussian import GaussianBlur, gaussian_blur
from .normalization import Normalize, normalize
from .laplacian import get_laplacian_kernel, get_laplacian_kernel2d
from .laplacian import Laplacian, laplacian
-from .color import rgb_to_grayscale, RgbToGrayscale
\ No newline at end of file
+from .color import rgb_to_grayscale, RgbToGrayscale
diff --git a/torchgeometry/image/normalization.py b/torchgeometry/image/normalization.py
index daadc1bb9..b8f173b32 100644
--- a/torchgeometry/image/normalization.py
+++ b/torchgeometry/image/normalization.py
@@ -24,7 +24,7 @@ class Normalize(nn.Module):
self.mean = mean
self.std = std
- def forward(self, input: torch.Tensor) -> torch.Tensor:
+ def forward(self, input: torch.Tensor) -> torch.Tensor: # type: ignore
return normalize(input, self.mean, self.std)
def __repr__(self):
@@ -55,10 +55,10 @@ def normalize(data: torch.Tensor, mean: torch.Tensor,
if not torch.is_tensor(std):
raise TypeError('std should be a tensor. Got {}'.format(type(std)))
- if len(mean) != data.shape[-3] and mean.shape[:2] != data.shape[:2]:
+ if mean.shape[0] != data.shape[-3] and mean.shape[:2] != data.shape[:2]:
raise ValueError('mean lenght and number of channels do not match')
- if len(std) != data.shape[-3] and std.shape[:2] != data.shape[:2]:
+ if std.shape[0] != data.shape[-3] and std.shape[:2] != data.shape[:2]:
raise ValueError('std lenght and number of channels do not match')
if std.shape != mean.shape:
@@ -67,8 +67,6 @@ def normalize(data: torch.Tensor, mean: torch.Tensor,
mean = mean[..., :, None, None].to(data.device)
std = std[..., :, None, None].to(data.device)
- out = data.sub(mean).div(std)
+ out = (data - mean) / std
return out
-
-# - denormalise