Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Avoid 2N x 2N weight matrix allocation in find_homography_dlt (#3134)

Simon Larsen8149cbf0dcb9
diff --git a/kornia/geometry/homography.py b/kornia/geometry/homography.py
index fbc127cbd..5a5bc4597 100644
--- a/kornia/geometry/homography.py
+++ b/kornia/geometry/homography.py
@@ -186,8 +186,8 @@ def find_homography_dlt(
# We should use provided weights
if not (len(weights.shape) == 2 and weights.shape == points1.shape[:2]):
raise AssertionError(weights.shape)
- w_diag = torch.diag_embed(weights.unsqueeze(dim=-1).repeat(1, 1, 2).reshape(weights.shape[0], -1))
- A = A.transpose(-2, -1) @ w_diag @ A
+ w_full = weights.repeat_interleave(2, dim=1).unsqueeze(1)
+ A = (A.transpose(-2, -1) * w_full) @ A
if solver == "svd":
try: