Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Added DogHardNet LightGlue (#2758)

Dmytro Mishkinba2b7d66f7f8
diff --git a/kornia/feature/integrated.py b/kornia/feature/integrated.py
index dead996b1..03ab204d3 100644
--- a/kornia/feature/integrated.py
+++ b/kornia/feature/integrated.py
@@ -415,6 +415,7 @@ class LightGlueMatcher(GeometryAwareDescriptorMatcher):
"aliked",
"keynet_affnet_hardnet",
"dog_affnet_hardnet",
+ "doghardnet",
"sift",
]
diff --git a/kornia/feature/lightglue.py b/kornia/feature/lightglue.py
index 1092a746e..aed295ea6 100644
--- a/kornia/feature/lightglue.py
+++ b/kornia/feature/lightglue.py
@@ -363,12 +363,20 @@ class LightGlue(Module):
"add_scale_ori": True,
},
"dog_affnet_hardnet": {
- "weights": "keynet_affnet_hardnet_lightglue",
+ "weights": "doghardnet",
"input_dim": 128,
"width_confidence": -1,
"depth_confidence": -1,
- "add_laf": True,
- "scale_coef": 0.1,
+ "add_scale_ori": True,
+ "scale_coef": 1.0 / 6.0,
+ },
+ "doghardnet": {
+ "weights": "doghardnet",
+ "input_dim": 128,
+ "width_confidence": -1,
+ "depth_confidence": -1,
+ "add_scale_ori": True,
+ "scale_coef": 1.0 / 6.0,
},
"keynet_affnet_hardnet": {
"weights": "keynet_affnet_hardnet_lightglue",
@@ -411,7 +419,9 @@ class LightGlue(Module):
state_dict = None
if features is not None:
fname = f"{conf.weights}_{self.version}.pth".replace(".", "-")
- if features in ["keynet_affnet_hardnet", "dog_affnet_hardnet"]:
+ if features == "dog_affnet_hardnet":
+ features = "doghardnet" # new dog model is better for affnet as well
+ if features in ["keynet_affnet_hardnet"]:
fname = "keynet_affnet_hardnet_lightlue.pth"
url = "http://cmp.felk.cvut.cz/~mishkdmy/models/keynet_affnet_hardnet_lightlue.pth"
else:
@@ -490,7 +500,12 @@ class LightGlue(Module):
KORNIA_CHECK(torch.all(kpts1 >= -1).item() and torch.all(kpts1 <= 1).item(), "") # type: ignore
if self.conf.add_scale_ori:
kpts0 = concatenate([kpts0] + [data0[k].unsqueeze(-1) for k in ("scales", "oris")], -1)
+ if self.conf.scale_coef != 1.0:
+ kpts0[..., -2] = kpts0[..., -2] * self.conf.scale_coef
kpts1 = concatenate([kpts1] + [data1[k].unsqueeze(-1) for k in ("scales", "oris")], -1)
+ if self.conf.scale_coef != 1.0:
+ kpts1[..., -2] = kpts1[..., -2] * self.conf.scale_coef
+
elif self.conf.add_laf:
laf0 = scale_laf(data0["lafs"], self.conf.scale_coef)
laf1 = scale_laf(data1["lafs"], self.conf.scale_coef)
@@ -605,6 +620,7 @@ class LightGlue(Module):
prune1 = ones_like(mscores1) * self.conf.n_layers
pred = {
+ "log_assignment": scores,
"matches0": m0,
"matches1": m1,
"matching_scores0": mscores0,
diff --git a/tests/feature/test_matching.py b/tests/feature/test_matching.py
index 3fd6d9bba..658fff29f 100644
--- a/tests/feature/test_matching.py
+++ b/tests/feature/test_matching.py
@@ -496,3 +496,8 @@ class TestLightGlueDISK(BaseTester):
torch.empty(0, 0, 2, 3, device=device, dtype=dtype),
data_dev["lafs2"],
)
+
+
+class TestLightGlueHardNet(BaseTester):
+ def test_smoke(self):
+ lg = LightGlueMatcher("doghardnet")