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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
inference: false
|
| 4 |
+
license: other
|
| 5 |
+
tags:
|
| 6 |
+
- keypoint-matching
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
# SuperGlue
|
| 10 |
+
|
| 11 |
+
The SuperGlue model was proposed
|
| 12 |
+
in [SuperGlue: Learning Feature Matching with Graph Neural Networks](https://arxiv.org/abs/1911.11763) by Paul-Edouard Sarlin, Daniel
|
| 13 |
+
DeTone, Tomasz Malisiewicz and Andrew Rabinovich.
|
| 14 |
+
|
| 15 |
+
This model consists of matching two sets of interest points detected in an image. Paired with the
|
| 16 |
+
[SuperPoint model](https://huggingface.co/magic-leap-community/superpoint), it can be used to match two images and
|
| 17 |
+
estimate the pose between them. This model is useful for tasks such as image matching, homography estimation, etc.
|
| 18 |
+
|
| 19 |
+
The abstract from the paper is the following:
|
| 20 |
+
|
| 21 |
+
*This paper introduces SuperGlue, a neural network that matches two sets of local features by jointly finding correspondences
|
| 22 |
+
and rejecting non-matchable points. Assignments are estimated by solving a differentiable optimal transport problem, whose costs
|
| 23 |
+
are predicted by a graph neural network. We introduce a flexible context aggregation mechanism based on attention, enabling
|
| 24 |
+
SuperGlue to reason about the underlying 3D scene and feature assignments jointly. Compared to traditional, hand-designed heuristics,
|
| 25 |
+
our technique learns priors over geometric transformations and regularities of the 3D world through end-to-end training from image
|
| 26 |
+
pairs. SuperGlue outperforms other learned approaches and achieves state-of-the-art results on the task of pose estimation in
|
| 27 |
+
challenging real-world indoor and outdoor environments. The proposed method performs matching in real-time on a modern GPU and
|
| 28 |
+
can be readily integrated into modern SfM or SLAM systems. The code and trained weights are publicly available at this [URL](https://github.com/magicleap/SuperGluePretrainedNetwork).*
|
| 29 |
+
|
| 30 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/2I8QDRNoMhQCuL236CvdN.png" alt="drawing" width="500"/>
|
| 31 |
+
|
| 32 |
+
<!--  -->
|
| 33 |
+
|
| 34 |
+
This model was contributed by [stevenbucaille](https://huggingface.co/stevenbucaille).
|
| 35 |
+
The original code can be found [here](https://github.com/magicleap/SuperGluePretrainedNetwork).
|
| 36 |
+
|
| 37 |
+
## Demo notebook
|
| 38 |
+
|
| 39 |
+
A demo notebook showcasing inference + visualization with SuperGlue can be found [here](https://github.com/qubvel/transformers-notebooks/blob/main/notebooks/SuperGlue_inference.ipynb).
|
| 40 |
+
|
| 41 |
+
## Model Details
|
| 42 |
+
|
| 43 |
+
### Model Description
|
| 44 |
+
|
| 45 |
+
SuperGlue is a neural network that matches two sets of local features by jointly finding correspondences and rejecting non-matchable points.
|
| 46 |
+
It introduces a flexible context aggregation mechanism based on attention, enabling it to reason about the underlying 3D scene and feature
|
| 47 |
+
assignments. The architecture consists of two main components: the Attentional Graph Neural Network and the Optimal Matching Layer.
|
| 48 |
+
|
| 49 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/zZGjSWQU2na5aPFRak5kp.png" alt="drawing" width="1000"/>
|
| 50 |
+
|
| 51 |
+
<!--  -->
|
| 52 |
+
|
| 53 |
+
The Attentional Graph Neural Network uses a Keypoint Encoder to map keypoint positions and visual descriptors.
|
| 54 |
+
It employs self- and cross-attention layers to create powerful representations. The Optimal Matching Layer creates a
|
| 55 |
+
score matrix, augments it with dustbins, and finds the optimal partial assignment using the Sinkhorn algorithm.
|
| 56 |
+
|
| 57 |
+
- **Developed by:** MagicLeap
|
| 58 |
+
- **Model type:** Image Matching
|
| 59 |
+
- **License:** ACADEMIC OR NON-PROFIT ORGANIZATION NONCOMMERCIAL RESEARCH USE ONLY
|
| 60 |
+
|
| 61 |
+
### Model Sources
|
| 62 |
+
|
| 63 |
+
<!-- Provide the basic links for the model. -->
|
| 64 |
+
|
| 65 |
+
- **Repository:** https://github.com/magicleap/SuperGluePretrainedNetwork
|
| 66 |
+
- **Paper:** https://arxiv.org/pdf/1911.11763
|
| 67 |
+
- **Demo:** https://psarlin.com/superglue/
|
| 68 |
+
|
| 69 |
+
## Uses
|
| 70 |
+
|
| 71 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 72 |
+
|
| 73 |
+
### Direct Use
|
| 74 |
+
|
| 75 |
+
SuperGlue is designed for feature matching and pose estimation tasks in computer vision. It can be applied to a variety of multiple-view
|
| 76 |
+
geometry problems and can handle challenging real-world indoor and outdoor environments. However, it may not perform well on tasks that
|
| 77 |
+
require different types of visual understanding, such as object detection or image classification.
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
## How to Get Started with the Model
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
Here is a quick example of using the model. Since this model is an image matching model, it requires pairs of images to be matched:
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
from transformers import AutoImageProcessor, AutoModel
|
| 87 |
+
import torch
|
| 88 |
+
from PIL import Image
|
| 89 |
+
import requests
|
| 90 |
+
url = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_98169888_3347710852.jpg"
|
| 91 |
+
im1 = Image.open(requests.get(url, stream=True).raw)
|
| 92 |
+
url = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_26757027_6717084061.jpg"
|
| 93 |
+
im2 = Image.open(requests.get(url, stream=True).raw)
|
| 94 |
+
images = [im1, im2]
|
| 95 |
+
processor = AutoImageProcessor.from_pretrained("stevenbucaille/superglue_outdoor")
|
| 96 |
+
model = AutoModel.from_pretrained("stevenbucaille/superglue_outdoor")
|
| 97 |
+
inputs = processor(images, return_tensors="pt")
|
| 98 |
+
outputs = model(**inputs)
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
The outputs contain the list of keypoints detected by the keypoint detector as well as the list of matches with their corresponding matching scores.
|
| 102 |
+
Due to the nature of SuperGlue, to output a dynamic number of matches, you will need to use the mask attribute to retrieve the respective information:
|
| 103 |
+
|
| 104 |
+
```python
|
| 105 |
+
from transformers import AutoImageProcessor, AutoModel
|
| 106 |
+
import torch
|
| 107 |
+
from PIL import Image
|
| 108 |
+
import requests
|
| 109 |
+
url_image_1 = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_98169888_3347710852.jpg"
|
| 110 |
+
image_1 = Image.open(requests.get(url_image_1, stream=True).raw)
|
| 111 |
+
url_image_2 = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_26757027_6717084061.jpg"
|
| 112 |
+
image_2 = Image.open(requests.get(url_image_2, stream=True).raw)
|
| 113 |
+
images = [image_1, image_2]
|
| 114 |
+
processor = AutoImageProcessor.from_pretrained("stevenbucaille/superglue_indoor")
|
| 115 |
+
model = AutoModel.from_pretrained("stevenbucaille/superglue_indoor")
|
| 116 |
+
inputs = processor(images, return_tensors="pt")
|
| 117 |
+
with torch.no_grad():
|
| 118 |
+
outputs = model(**inputs)
|
| 119 |
+
# Get the respective image masks
|
| 120 |
+
image0_mask, image1_mask = outputs_mask[0]
|
| 121 |
+
image0_indices = torch.nonzero(image0_mask).squeeze()
|
| 122 |
+
image1_indices = torch.nonzero(image1_mask).squeeze()
|
| 123 |
+
image0_matches = outputs.matches[0, 0][image0_indices]
|
| 124 |
+
image1_matches = outputs.matches[0, 1][image1_indices]
|
| 125 |
+
image0_matching_scores = outputs.matching_scores[0, 0][image0_indices]
|
| 126 |
+
image1_matching_scores = outputs.matching_scores[0, 1][image1_indices]
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
You can use the `post_process_keypoint_matching` method from the `SuperGlueImageProcessor` to get the keypoints and matches in a more readable format:
|
| 130 |
+
```python
|
| 131 |
+
image_sizes = [(image.height, image.width) for image in images]
|
| 132 |
+
outputs = processor.post_process_keypoint_matching(outputs, image_sizes, threshold=0.2)
|
| 133 |
+
for i, output in enumerate(outputs):
|
| 134 |
+
print("For the image pair", i)
|
| 135 |
+
for keypoint0, keypoint1, matching_score in zip(output["keypoints0"], output["keypoints1"],
|
| 136 |
+
output["matching_scores"]):
|
| 137 |
+
print(
|
| 138 |
+
f"Keypoint at coordinate {keypoint0.numpy()} in the first image matches with keypoint at coordinate {keypoint1.numpy()} in the second image with a score of {matching_score}."
|
| 139 |
+
)
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
From the outputs, you can visualize the matches between the two images using the following code:
|
| 143 |
+
```python
|
| 144 |
+
import matplotlib.pyplot as plt
|
| 145 |
+
import numpy as np
|
| 146 |
+
# Create side by side image
|
| 147 |
+
merged_image = np.zeros((max(image1.height, image2.height), image1.width + image2.width, 3))
|
| 148 |
+
merged_image[: image1.height, : image1.width] = np.array(image1) / 255.0
|
| 149 |
+
merged_image[: image2.height, image1.width :] = np.array(image2) / 255.0
|
| 150 |
+
plt.imshow(merged_image)
|
| 151 |
+
plt.axis("off")
|
| 152 |
+
# Retrieve the keypoints and matches
|
| 153 |
+
output = outputs[0]
|
| 154 |
+
keypoints0 = output["keypoints0"]
|
| 155 |
+
keypoints1 = output["keypoints1"]
|
| 156 |
+
matching_scores = output["matching_scores"]
|
| 157 |
+
keypoints0_x, keypoints0_y = keypoints0[:, 0].numpy(), keypoints0[:, 1].numpy()
|
| 158 |
+
keypoints1_x, keypoints1_y = keypoints1[:, 0].numpy(), keypoints1[:, 1].numpy()
|
| 159 |
+
# Plot the matches
|
| 160 |
+
for keypoint0_x, keypoint0_y, keypoint1_x, keypoint1_y, matching_score in zip(
|
| 161 |
+
keypoints0_x, keypoints0_y, keypoints1_x, keypoints1_y, matching_scores
|
| 162 |
+
):
|
| 163 |
+
plt.plot(
|
| 164 |
+
[keypoint0_x, keypoint1_x + image1.width],
|
| 165 |
+
[keypoint0_y, keypoint1_y],
|
| 166 |
+
color=plt.get_cmap("RdYlGn")(matching_score.item()),
|
| 167 |
+
alpha=0.9,
|
| 168 |
+
linewidth=0.5,
|
| 169 |
+
)
|
| 170 |
+
plt.scatter(keypoint0_x, keypoint0_y, c="black", s=2)
|
| 171 |
+
plt.scatter(keypoint1_x + image1.width, keypoint1_y, c="black", s=2)
|
| 172 |
+
# Save the plot
|
| 173 |
+
plt.savefig("matched_image.png", dpi=300, bbox_inches='tight')
|
| 174 |
+
plt.close()
|
| 175 |
+
```
|
| 176 |
+
|
| 177 |
+

|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
## Training Details
|
| 181 |
+
|
| 182 |
+
### Training Data
|
| 183 |
+
|
| 184 |
+
SuperGlue is trained on large annotated datasets for pose estimation, enabling it to learn priors for pose estimation and reason about the 3D scene.
|
| 185 |
+
The training data consists of image pairs with ground truth correspondences and unmatched keypoints derived from ground truth poses and depth maps.
|
| 186 |
+
|
| 187 |
+
### Training Procedure
|
| 188 |
+
|
| 189 |
+
SuperGlue is trained in a supervised manner using ground truth matches and unmatched keypoints. The loss function maximizes
|
| 190 |
+
the negative log-likelihood of the assignment matrix, aiming to simultaneously maximize precision and recall.
|
| 191 |
+
|
| 192 |
+
#### Training Hyperparameters
|
| 193 |
+
|
| 194 |
+
- **Training regime:** fp32
|
| 195 |
+
|
| 196 |
+
#### Speeds, Sizes, Times
|
| 197 |
+
|
| 198 |
+
SuperGlue is designed to be efficient and runs in real-time on a modern GPU. A forward pass takes approximately 69 milliseconds (15 FPS) for an indoor image pair.
|
| 199 |
+
The model has 12 million parameters, making it relatively compact compared to some other deep learning models.
|
| 200 |
+
The inference speed of SuperGlue is suitable for real-time applications and can be readily integrated into
|
| 201 |
+
modern Simultaneous Localization and Mapping (SLAM) or Structure-from-Motion (SfM) systems.
|
| 202 |
+
|
| 203 |
+
## Citation
|
| 204 |
+
|
| 205 |
+
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 206 |
+
|
| 207 |
+
**BibTeX:**
|
| 208 |
+
|
| 209 |
+
```bibtex
|
| 210 |
+
@inproceedings{sarlin2020superglue,
|
| 211 |
+
title={Superglue: Learning feature matching with graph neural networks},
|
| 212 |
+
author={Sarlin, Paul-Edouard and DeTone, Daniel and Malisiewicz, Tomasz and Rabinovich, Andrew},
|
| 213 |
+
booktitle={Proceedings of the IEEE/CVF conference on computer vision and pattern recognition},
|
| 214 |
+
pages={4938--4947},
|
| 215 |
+
year={2020}
|
| 216 |
+
}
|
| 217 |
+
```
|
| 218 |
+
|
| 219 |
+
## Model Card Authors
|
| 220 |
+
|
| 221 |
+
[Steven Bucaille](https://github.com/sbucaille)
|
config.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "superglue",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"SuperGlueForKeypointMatching"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0,
|
| 7 |
+
"gnn_layers_types": [
|
| 8 |
+
"self",
|
| 9 |
+
"cross",
|
| 10 |
+
"self",
|
| 11 |
+
"cross",
|
| 12 |
+
"self",
|
| 13 |
+
"cross",
|
| 14 |
+
"self",
|
| 15 |
+
"cross",
|
| 16 |
+
"self",
|
| 17 |
+
"cross",
|
| 18 |
+
"self",
|
| 19 |
+
"cross",
|
| 20 |
+
"self",
|
| 21 |
+
"cross",
|
| 22 |
+
"self",
|
| 23 |
+
"cross",
|
| 24 |
+
"self",
|
| 25 |
+
"cross"
|
| 26 |
+
],
|
| 27 |
+
"hidden_size": 256,
|
| 28 |
+
"initializer_range": 0.02,
|
| 29 |
+
"keypoint_detector_config": {
|
| 30 |
+
"model_type": "superpoint"
|
| 31 |
+
},
|
| 32 |
+
"keypoint_encoder_sizes": [
|
| 33 |
+
32,
|
| 34 |
+
64,
|
| 35 |
+
128,
|
| 36 |
+
256
|
| 37 |
+
],
|
| 38 |
+
"matching_threshold": 0.0,
|
| 39 |
+
"model_type": "superglue",
|
| 40 |
+
"num_attention_heads": 4,
|
| 41 |
+
"sinkhorn_iterations": 100,
|
| 42 |
+
"torch_dtype": "float32",
|
| 43 |
+
"transformers_version": "4.47.0.dev0"
|
| 44 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9bf0577b46cd76feedbc1e6908f56e10b7d92212d33338086c9156d0287d6e38
|
| 3 |
+
size 53413232
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_grayscale": true,
|
| 3 |
+
"do_rescale": true,
|
| 4 |
+
"do_resize": true,
|
| 5 |
+
"image_processor_type": "SuperGlueImageProcessor",
|
| 6 |
+
"resample": 2,
|
| 7 |
+
"rescale_factor": 0.00392156862745098,
|
| 8 |
+
"size": {
|
| 9 |
+
"height": 480,
|
| 10 |
+
"width": 640
|
| 11 |
+
}
|
| 12 |
+
}
|