Giter VIP home page Giter VIP logo

superglue_training's Introduction

SuperGlue - Reimplementation

This repository contains training and evaluation code for Superglue model with homography pairs generated from COCO dataset. The code is adapted from the inference only official implementation released by MagicLeap

Requirements

  • torch>=1.8.1
  • torch_scatter>=2.06
  • matplotlib>=3.1.3
  • opencv-python==4.1.2.30
  • numpy>=1.18.1
  • PyYAML>=5.4.1
  • wandb (If logging of checkpoints to cloud is need)
  • albumentations

Training data

COCO 2017 dataset is used for training. Random homographies are generated at every iteration and matches are computed using the know homography matrix. Download the 'train2017', 'val2017', and 'annotations' folder of COCO 2017 dataset and put that path in the config file used for training.

Training

All the parameters of training are provided in the coco_config.yaml in the configs folder. Change that file inplace and start the training. Or clone that file to make the changes and mention the custom config path in training command. Parameters of training are explained in comments in the coco_config.yaml file. To start the training run,

python3 train_superglue.py --config_path configs/coco_config.yaml

Incase of Multi-GPU training, distributed setting is used. So run the following command,

python3 -m torch.distributed.launch --nproc_per_node="NUM_GPUS" train_superglue.py --config_path configs/coco_config.yaml

Only singe-node training is supported as of now.

Checkpoints are saved at the end of every epoch, and best checkpoint is determined by weighted score of AUC at different thresholds, precision and recall computed on COCO 2017 val dataset using random homographies. Validation score is computed on fixed set of images and homographies for consistency across runs. Image and homography info used for validation is present at assets/coco_val_images_homo.txt

Evaluation

The official implementation has evaluation code for testing on small set of scannet scene pairs. Since our model in trained with random homographies, evaluating on scenes with random 3D camera movements doesn't perform well as pretrained indoor model. Instead we evaluate on test images of COCO, indoor and outdoor dataset(https://dimlrgbd.github.io/) with random homographies. Images are selected from the datasets and random homographies are generated for each of them. Based on matches given by the model, we determine the homography matrix using DLT and RANSAC implementation. As mentioned in paper, we report the AUC at 5, 10, 25 thresholds(for corner points), precision and recall. For evaluation run the following command,

python3 match_homography.py --eval --superglue coco_homo

Parameter --superglue determines the checkpoint used and should be one of the following,

  • Use coco_homo to run with the released coco homography model

  • Use PATH_TO_YOUR_.PT to run with your trained model

  • Use indoor to run with official indoor pretrained model

  • Use outdoor to run with official outdoor pretrained model

Add --viz flag to dump the matching info image to 'dump_homo_pairs' folder.

If you want to evaluate with scannet pairs, run the above command with match_pairs.py with same parameters

Evaluation Results

Following are the results on three different sets of COCO2017 test images, indoor images and outdoor images using randomly generated homographies at assets/coco_test_images_homo.txt, assets/indoor_test_images_homo.txt, assets/outdoor_test_images_homo.txt respectively.

Homography using RANSAC

Indoor test set (Mean over 144 pairs)

python3 match_homography.py --eval --superglue {indoor, outdoor, coco_homo, ckpt_path} --input_homography assets/indoor_test_images_homo.txt --input_dir assets/indoor_test_images
Models AUC@5 AUC@10 AUC@25 Prec Recall
Indoor 26.44 37.71 52.66 62.14 88.28
Outdoor 28.01 40.38 56.43 81.74 98.02
COCO_homo 28.41 42.45 57.90 68.70 87.56

Outdoor test set (Mean over 145 pairs)

python3 match_homography.py --eval --superglue {indoor, outdoor, coco_homo, ckpt_path} --input_homography assets/outdoor_test_images_homo.txt --input_dir assets/outdoor_test_images
Models AUC@5 AUC@10 AUC@25 Prec Recall
Indoor 23.41 35.08 46.82 54.07 79.70
Outdoor 23.92 33.26 47.57 76.44 96.07
COCO_homo 23.82 33.49 46.69 53.90 70.18

COCO2017 test set (Mean over 199 pairs)

python3 match_homography.py --eval --superglue {indoor, outdoor, coco_homo, ckpt_path} --input_homography assets/coco_test_images_homo.txt --input_dir assets/coco_test_images
Models AUC@5 AUC@10 AUC@25 Prec Recall
Indoor 28.55 47.18 69.04 75.31 95.71
Outdoor 32.40 50.20 71.10 88.61 99.71
COCO_homo 34.06 52.33 73.03 80.87 96.22

Homography using DLT(Most confident 4 matches)

Indoor test set(Mean over 144 pairs)

Models AUC@5 AUC@10 AUC@25 Prec Recall
Indoor 0.57 1.07 3.43 62.14 88.28
Outdoor 0.38 1.17 4.45 81.74 98.02
COCO_homo 1.13 3.13 7.95 68.70 87.56

Outdoor test set (Mean over 145 pairs)

Models AUC@5 AUC@10 AUC@25 Prec Recall
Indoor 0.89 2.27 4.36 54.07 79.70
Outdoor 0.77 2.17 6.38 76.44 96.06
COCO_homo 0.45 1.89 5.60 53.90 70.18

COCO2017 test set (Mean over 199 pairs)

Models AUC@5 AUC@10 AUC@25 Prec Recall
Indoor 0.31 1.01 3.05 75.31 95.71
Outdoor 0.29 1.41 8.10 88.61 99.71
COCO_homo 1.28 4.65 10.62 80.87 96.22

Output of COCO_homo model on few of COCO2017 test images

Creating you own homography test set

Incase you want to generate your own test set with random homographies that is compatible with match_homography.py run the command python3 get_perspective.py.

All the parameters regarding the random homography range, input and output folder are mentioned in the file itself. While running the match_homography.py you should mention the additional parameters --input_homography and --input_dir that points to the generated homography text file and images directory respectively.

Credits

superglue_training's People

Contributors

gouthamvgk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

superglue_training's Issues

Error when training superglue

Hi!

I have 4 2080TI GPUs and want to use them to train the superglue model.
I try to run the following command:
python3 -m torch.distributed.launch --nproc_per_node=4 train_superglue.py --config_path configs/coco_config.yaml

But I get errors:

Traceback (most recent call last):
  File "train_superglue.py", line 252, in <module>
    train(config, opt.local_rank)
  File "train_superglue.py", line 165, in train
    total_loss, pos_loss, neg_loss = superglue_model.forward_train(superglue_input)
  File "/home/zhy/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 772, in __getattr__
    type(self).__name__, name))
torch.nn.modules.module.ModuleAttributeError: 'DistributedDataParallel' object has no attribute 'forward_train'

How to fix this problem?

Creating Custom Dataset on COCO Format for Training

Hello. I'm trying to annotate my custom dataset (images only) on COCO format so I can use your script for training SuperGlue. My dataset consists RGB images and I want to extract keypoints from both viewpoints to perform image matching.
My main goal is to annotate keypoints only. But I'm stuck on what to include in my annotations file. I understand that I need to focus on the Keypoint Detection task of COCO dataset. This is the description of the annotations for keypoint detection i could find: "A keypoint annotation contains all the data of the object annotation (including id, bbox, etc.) and two additional fields.
For Object Detection:
annotation{"id" : int, "image_id" : int, "category_id" : int, "segmentation" : RLE or [polygon], "area" : float, "bbox" : [x,y,width,height], "iscrowd" : 0 or 1,} categories[{ "id" : int, "name" : str, "supercategory" : str, }]

Additional fields for keypoint detection:
annotation{ "keypoints" : [x1,y1,v1,...], "num_keypoints" : int, "[cloned]" : ..., } categories[{ "keypoints" : [str], "skeleton" : [edge], "[cloned]" : ...,}]"

My primary concerns are:
i. What categories and supercategories should i define?
ii. What do i include in 'bbox', 'segmentation', 'num_keypoints' and 'skeleton'?

I would be very grateful if you can usher me in the right direction.

Evaluation recall can't reach 96.22 on COCO2017 test set

The recall of the model I trained with the default yaml file is 10% lower than COCO_homo, are you using any pretrained weights for training COCO_homo? How to reach the recall of COCO_homo? Thanks.

Homography using RANSAC
Indoor test set (Mean over 144 pairs)

AUC@5 AUC@10 AUC@25 Prec Recall
28.79 43.65 58.84 70.98 78.67

Outdoor test set (Mean over 145 pairs)

AUC@5 AUC@10 AUC@25 Prec Recall
27.33 36.92 50.58 54.14 63.94

COCO2017 test set (Mean over 199 pairs)

AUC@5 AUC@10 AUC@25 Prec Recall
34.30 51.15 70.66 83.28 87.83

Error while training the SuperGlue

Hi.
I have been following the code that has been shared in the respective github repository. But on executing the code I am ending with an error as follow:

Traceback (most recent call last):
  File "/home/shuhulh/SuperGlue_training/train_superglue.py", line 252, in <module>
    train(config, opt.local_rank)
  File "/home/shuhulh/SuperGlue_training/train_superglue.py", line 139, in train
    superpoint_results = superpoint_model.forward_train({'homography': homographies, 'image': orig_warped})
  File "/home/shuhulh/SuperGlue_training/models/superpoint.py", line 260, in forward_train
    results.append(remove_borders_projected(k, s, self.config['remove_borders'], h*8, w*8, homo_matrix))
  File "/home/shuhulh/SuperGlue_training/models/superpoint.py", line 73, in remove_borders_projected
    projected_keypoints = warp_keypoints(keypoints, torch.inverse(homo_matrix))
  File "/home/shuhulh/SuperGlue_training/models/superpoint.py", line 103, in warp_keypoints
    dest /= dest[:, 2:3]
RuntimeError: unsupported operation: some elements of the input tensor and the written-to tensor refer to a single memory location. Please clone() the tensor before performing the operation.

How to overcome this error?

About pose estimation.

First, thank you for open code engineering. I want to test the code on other data sets, but I find that Homography Estimation is mainly included in the project. There is no pose estimation. Can I test the code as provided by Superglue official? Meanwhile, I found that your code can load indoor. pth and outdoor. pth provided by the official code, but the official code cannot load the training model of your code? Thanks for your reply.

Project integrity

May I ask whether this project can carry out a complete training and testing process?

What `coco_val_images_homo.txt` consists of?

I have tried training the model for my own custom dataset, but the problem that I facing is that in class COCO_valloader it is calling a file coco_val_images_homo.txt which I don't actually understand what is it consisting of. Can you help me out how this file is being generated or what does the file consists of so that I can generate one for my own custom dataset?

torch

torch>=1.8.1 ?? the lastest is 1.8.0

Training with different descriptions

Hi, I am trying to train superglue using hfnet keypoints instead of superpoint.

Can you please point me to the code that I need to change for this? Where is superpoint run?

Thanks!

Evaluate results

First, thank you for open code engineering. But there is a big gap between my final result and your result.Evaluation results of your model (coco_homo) : accuracy(80.87), recall(96.22). I used your model (models/weights/superglue_cocohomo.pt) to get the final result : acc(81.43),recall(96.25).The results are very good.But I got the final result(acc : 76.70 recall : 89.20)when I trained the superglue with your superpoint model(models/weights/superpoint_v1.pth).This is a lot worse than your results.

I used the coco(2017) dataset and the other parameters have not changed , but I used DDP to train. Why is there a discrepancy in the evaluation results? I look forward to your response.

Rare condiiton executed

When I am training the SuperGlue model with a custom dataset, following is the warning (or maybe an error, I guess) that pops up after every epoch
Rare condition executed
What does this error/warning indicates? Should I be worried regarding the same as I observe that my loss value is decreasing as usual (not much but still it does).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.