Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configuration parameters setting #114

Open
thetashall opened this issue Dec 2, 2024 · 0 comments
Open

configuration parameters setting #114

thetashall opened this issue Dec 2, 2024 · 0 comments

Comments

@thetashall
Copy link

Thank you for sharing. I tried to write a show demo based on the official .pth file. However, its performance is much worse compared to the lightglue project(https://github.com/cvg/LightGlue/blob/main/demo.ipynb). Specifically, they perform well on images like boat1.png and boat2.png, but the performance significantly deteriorates on more challenging datasets . If you need test images, I will send them to you privately.
It is possible that certain configuration parameters are set incorrectly, Could you please advise on what parameter settings might be incorrect?

import torch
from gluefactory.utils.image import ImagePreprocessor
from gluefactory.visualization.viz2d import plot_images, plot_keypoints, plot_matches
#from lightglue import LightGlue, SuperPoint, DISK, SIFT, ALIKED, DoGHardNet

from gluefactory.models.extractors.superpoint_open import SuperPoint
from gluefactory.models.matchers.lightglue_pretrained import LightGlue
import matplotlib.pyplot as plt
from kornia import image_to_tensor
from gluefactory.utils.tensor import map_tensor
from torch import Tensor

improc = ImagePreprocessor({})
im0 = improc.load_image('assets/2.jpg')['image']
im1 = improc.load_image('assets/69.jpg')['image']

device = "cuda" if torch.cuda.is_available() else "cpu"
data = {"view0": improc(im0), "view1": improc(im1)}
data = map_tensor(
data,
lambda t: (
t[None].to(device)
if isinstance(t, Tensor)
else torch.from_numpy(t)[None].to(device)
),
)
#print(data)

#sp = SuperPoint({'nms_radius': 4}).cuda().eval()
sp = SuperPoint({'max_num_keypoints': 2048,"descriptor_dim": 256,
"nms_radius": 4,
"max_num_keypoints": None,
"detection_threshold": 0.0005,
"remove_borders": 4,"resize": 1024}).cuda().eval()

with torch.no_grad():
pred0 = sp({'image': im0.cuda()[None]})
pred1 = sp({'image': im1.cuda()[None]})

pts0, pts1 = [p['keypoints'].squeeze(0).cpu() for p in (pred0, pred1)]
plot_images([im.permute(1,2,0) for im in (im0, im1)],
titles=[f'{len(p)} keypoints' for p in (pts0, pts1)])
plot_keypoints([pts0, pts1])

#print(pred0)
#print({"keypoints0":pred0['keypoints'], "keypoints1":pred1['keypoints'],'descriptors0': pred0['descriptors'], 'descriptors1': pred1['descriptors'],"view0":data['view0'],"view1":data['view1']}.update(data))
#matcher = LightGlue({'input_dim': 256, 'add_scale_ori': False, 'descriptor_dim': 256, 'n_layers': 9, 'num_heads': 4, 'flash': False, 'mp': False, 'depth_confidence': -1, 'width_confidence': -1, 'filter_threshold': 0.1, 'checkpointed': True, 'weights': 'superpoint_lightglue_v0-1_arxiv.pth', 'weights_from_version': 'v0.1_arxiv'}).to(device)
matcher = LightGlue({'weights': 'superpoint_lightglue_v0-1_arxiv.pth', 'weights_from_version': 'v0.1_arxiv','width_confidence': 0.99,'filter_threshold':0.01}).to(device)
matches = matcher({**{"keypoints0":pred0['keypoints'], "keypoints1":pred1['keypoints'],'descriptors0': pred0['descriptors'], 'descriptors1': pred1['descriptors'],"view0":data['view0'],"view1":data['view1']},**data})['matches0'].squeeze(0)
#print(matches)
#for i in matches:

print(i)

plot_images([im.permute(1,2,0) for im in (im0, im1)])
plot_matches(pts0[matches.cpu()!=-1], pts1[matches[matches!=-1].cpu()], a=0.5, lw=1)
plt.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant