Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix create_meshgrid indexing and refactor tensor_to_image

edgarriba12469a74e99e
diff --git a/torchgeometry/homography_warper.py b/torchgeometry/homography_warper.py
index 005e3b494..9907e1482 100644
--- a/torchgeometry/homography_warper.py
+++ b/torchgeometry/homography_warper.py
@@ -18,7 +18,7 @@ def create_meshgrid(height, width, normalized_coordinates=True):
else:
xs = torch.linspace(0, width - 1, width)
ys = torch.linspace(0, height - 1, height)
- return torch.stack(torch.meshgrid([ys, xs])).view(1, 2, -1)
+ return torch.stack(torch.meshgrid([ys, xs])).view(1, 2, -1)[:, (1, 0), :]
class HomographyWarper(nn.Module):
diff --git a/torchgeometry/utils/functional.py b/torchgeometry/utils/functional.py
index 352d4c0e3..b901b3bd3 100644
--- a/torchgeometry/utils/functional.py
+++ b/torchgeometry/utils/functional.py
@@ -16,7 +16,7 @@ def tensor_to_image(tensor):
in the GPU, it will be copied back to CPU.
"""
# TODO: add asserts and type checkings
+ tensor = torch.squeeze(tensor)
if len(tensor.shape) == 2:
tensor = torch.unsqueeze(tensor, dim=0)
- tensor = tensor.permute(1, 2, 0).contiguous()
- return torch.squeeze(tensor).cpu().numpy()
+ return tensor.permute(1, 2, 0).contiguous().cpu().detach().numpy()