Closed spagnoloG closed 11 months ago
I have encountered a similar problem with you. I replaced the data in the file I trained with the data in the official PTH and conducted several epochs of training. At the beginning of the training, the loss displayed was very high and quickly decreased (yes, the official weight training shows a high loss at the beginning). After testing, there were no matching points. After debugging, it was found that the mscores became very low, and the filter_threshold needs to be adjusted 0.001 so that it will have a certain matching effect.
May I ask if you have currently resolved this issue?
@Zhaoyibinn Nope the problem still persists :/. I loaded the local weights in the same manner as you did in the freshly opened issue https://github.com/cvg/glue-factory/issues/49 . Will let you know if I find out anything interesting (not before the weekend) . Thanks for your info! :)
Hello, I have resolved my issue ^ ^. You can refer to issue #49 for reference (although it may be different from the problem you encountered)
<3 <3 Thanks it works!
Here is the final conversion script :D
import torch
def extract_checkpoint(checkpoint_path, save_model_path, n_layers):
checkpoint = torch.load(checkpoint_path, map_location=torch.device('cpu'))
print("Checkpoint Contents:")
state_dict = checkpoint.get('model', {})
matcher_dict = {k.split('matcher.', 1)[1]: v for k, v in state_dict.items() if k.startswith('matcher')}
if matcher_dict:
for i in range(n_layers):
patterns = [
(f"transformers.{i}.self_attn", f"self_attn.{i}"),
(f"transformers.{i}.cross_attn", f"cross_attn.{i}")
]
for old_key, new_key in patterns:
matcher_dict = {k.replace(old_key, new_key) if old_key in k else k: v for k, v in matcher_dict.items()}
print(matcher_dict.keys())
torch.save(matcher_dict, save_model_path)
if __name__ == "__main__":
checkpoint_path = "checkpoint_best.tar"
save_model_path = "lg_finetuned_v7.pth"
n_layers = 9 # Just like in official repo
extract_checkpoint(checkpoint_path, save_model_path, n_layers)
<3 <3 谢谢它有效! 这是最终的转换脚本:D
import torch def extract_checkpoint(checkpoint_path, save_model_path, n_layers): checkpoint = torch.load(checkpoint_path, map_location=torch.device('cpu')) print("Checkpoint Contents:") state_dict = checkpoint.get('model', {}) matcher_dict = {k.split('matcher.', 1)[1]: v for k, v in state_dict.items() if k.startswith('matcher')} if matcher_dict: for i in range(n_layers): patterns = [ (f"transformers.{i}.self_attn", f"self_attn.{i}"), (f"transformers.{i}.cross_attn", f"cross_attn.{i}") ] for old_key, new_key in patterns: matcher_dict = {k.replace(old_key, new_key) if old_key in k else k: v for k, v in matcher_dict.items()} print(matcher_dict.keys()) torch.save(matcher_dict, save_model_path) if __name__ == "__main__": checkpoint_path = "checkpoint_best.tar" save_model_path = "lg_finetuned_v7.pth" n_layers = 9 # Just like in official repo extract_checkpoint(checkpoint_path, save_model_path, n_layers)
完成训练后,模型本身不会输出 .pth 文件。函数是获取 .pth 文件的唯一方法吗?完成训练后,我只有检查点.tar文件。
您好,tar文件包含了pth文件的内容,您可以直接读取,也可以将其读取之后重新保存为pth
Hello, can you share the official pre-training weights? Thank you very much
Hello, firstly i would express thanks for providing the training framework to the public! :)
Let me firstly explain what i did, and then what issue I am facing:
datasets/homgraphies.py
todatasets/custom.py
and modified it to load my custom data (checked that dataloading is cool)And finetuned it for mere 5 epochs.
Then I wrote a custom python script that converts the
best_checkpoint.tar
to the same structure as official checkpoint (yes I went and manually inspected the layers)After I loaded the converted checkpoint to the official Lightglue repository, it did not produce any matches (tested on 1k images), keypoints were succesfully extracted though.
I am a bit worried that I took the wrong direction somewhere, and would really appreciate your guidance!
thanks:)