Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

reorder HomographyWarper paramaters WxH -> HxW, and fix tests

edgarriba339d38ac231b
diff --git a/test/test_homography_warper.py b/test/test_homography_warper.py
index 05ecdfde6..884cb50dc 100644
--- a/test/test_homography_warper.py
+++ b/test/test_homography_warper.py
@@ -14,7 +14,7 @@ class Tester(unittest.TestCase):
def test_homography_warper(self):
# generate input data
batch_size = 1
- height, width = 128, 128
+ height, width = 128, 64
eye_size = 3 # identity 3x3
# create checkerboard
@@ -26,7 +26,7 @@ class Tester(unittest.TestCase):
dst_homo_src = utils.create_eye_batch(batch_size, eye_size)
# instantiate warper
- warper = dgm.HomographyWarper(width, height)
+ warper = dgm.HomographyWarper(height, width)
for i in range(self.num_tests):
# generate homography noise
@@ -49,7 +49,7 @@ class Tester(unittest.TestCase):
def test_homography_warper_gradcheck(self):
# generate input data
batch_size = 1
- height, width = 16, 16 # small patch, otherwise the test takes forever
+ height, width = 16, 32 # small patch, otherwise the test takes forever
eye_size = 3 # identity 3x3
# create checkerboard
@@ -64,7 +64,7 @@ class Tester(unittest.TestCase):
dst_homo_src, requires_grad=False) # to var
# instantiate warper
- warper = dgm.HomographyWarper(width, height)
+ warper = dgm.HomographyWarper(height, width)
# evaluate function gradient
res = gradcheck(warper, (patch_src, dst_homo_src,),
diff --git a/test/utils.py b/test/utils.py
index 89698d579..e90bbb7a8 100644
--- a/test/utils.py
+++ b/test/utils.py
@@ -5,7 +5,7 @@ import numpy as np
# test utilites
-def create_checkerboard(w, h, nw):
+def create_checkerboard(h, w, nw):
"""Creates a synthetic checkerd board of shape HxW and window size `nw`.
"""
return np.kron([[1, 0] * nw, [0, 1] * nw] * nw,
diff --git a/torchgeometry/homography_warper.py b/torchgeometry/homography_warper.py
index 6ba593f72..005e3b494 100644
--- a/torchgeometry/homography_warper.py
+++ b/torchgeometry/homography_warper.py
@@ -5,7 +5,7 @@ import torch.nn.functional as F
from .functional import transform_points
-def create_meshgrid(width, height, normalized_coordinates=True):
+def create_meshgrid(height, width, normalized_coordinates=True):
'''Generates a coordinate grid for an image of width(cols), height(rows).
This is normalized to be in the range [-1,1] to be consistent with the
pytorch function grid_sample.
@@ -18,7 +18,7 @@ def create_meshgrid(width, height, normalized_coordinates=True):
else:
xs = torch.linspace(0, width - 1, width)
ys = torch.linspace(0, height - 1, height)
- return torch.stack(torch.meshgrid([xs, ys])).view(1, 2, -1)
+ return torch.stack(torch.meshgrid([ys, xs])).view(1, 2, -1)
class HomographyWarper(nn.Module):
@@ -26,7 +26,7 @@ class HomographyWarper(nn.Module):
Warps patches by homographies.
height, width '''
- def __init__(self, width, height, points=None):
+ def __init__(self, height, width, points=None):
'''
:param width: The width of the image to warp.
:param height: The height of the image to warp.