stevenbucaille
commited on
Commit
•
0f62105
1
Parent(s):
1857f4b
Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,215 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
|
|
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
|
8 |
-
|
|
|
|
|
9 |
|
|
|
|
|
|
|
10 |
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
|
20 |
-
-
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
- **Repository:** [More Information Needed]
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
-
|
36 |
-
## Uses
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
### Direct Use
|
41 |
|
42 |
-
|
43 |
|
44 |
-
|
|
|
|
|
45 |
|
46 |
-
|
47 |
|
48 |
-
<!--
|
49 |
|
50 |
-
|
|
|
|
|
51 |
|
52 |
-
|
|
|
|
|
53 |
|
54 |
-
|
55 |
|
56 |
-
|
57 |
|
58 |
-
|
|
|
|
|
59 |
|
60 |
-
|
61 |
|
62 |
-
|
63 |
|
64 |
-
###
|
65 |
|
66 |
-
|
|
|
|
|
67 |
|
68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
|
70 |
## How to Get Started with the Model
|
71 |
|
72 |
-
Use the code below to get started with the model.
|
73 |
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
## Training Details
|
77 |
|
78 |
### Training Data
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
-
### Training Procedure
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
|
|
|
|
|
92 |
|
93 |
#### Training Hyperparameters
|
94 |
|
95 |
-
- **Training regime:**
|
96 |
-
|
97 |
-
#### Speeds, Sizes, Times [optional]
|
98 |
-
|
99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
-
|
103 |
-
## Evaluation
|
104 |
-
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
|
117 |
-
|
118 |
|
119 |
-
|
|
|
|
|
|
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
|
173 |
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
|
175 |
**BibTeX:**
|
176 |
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
|
197 |
-
## Model Card
|
198 |
|
199 |
-
[
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
inference: false
|
4 |
+
license: other
|
5 |
---
|
6 |
|
7 |
+
# SuperGlue
|
8 |
|
9 |
+
The SuperGlue model was proposed
|
10 |
+
in [SuperGlue: Learning Feature Matching with Graph Neural Networks](https://arxiv.org/abs/1911.11763) by Paul-Edouard Sarlin, Daniel
|
11 |
+
DeTone, Tomasz Malisiewicz and Andrew Rabinovich.
|
12 |
|
13 |
+
This model consists of matching two sets of interest points detected in an image. Paired with the
|
14 |
+
[SuperPoint model](https://huggingface.co/magic-leap-community/superpoint), it can be used to match two images and
|
15 |
+
estimate the pose between them. This model is useful for tasks such as image matching, homography estimation, etc.
|
16 |
|
17 |
+
The abstract from the paper is the following:
|
18 |
|
19 |
+
*This paper introduces SuperGlue, a neural network that matches two sets of local features by jointly finding correspondences
|
20 |
+
and rejecting non-matchable points. Assignments are estimated by solving a differentiable optimal transport problem, whose costs
|
21 |
+
are predicted by a graph neural network. We introduce a flexible context aggregation mechanism based on attention, enabling
|
22 |
+
SuperGlue to reason about the underlying 3D scene and feature assignments jointly. Compared to traditional, hand-designed heuristics,
|
23 |
+
our technique learns priors over geometric transformations and regularities of the 3D world through end-to-end training from image
|
24 |
+
pairs. SuperGlue outperforms other learned approaches and achieves state-of-the-art results on the task of pose estimation in
|
25 |
+
challenging real-world indoor and outdoor environments. The proposed method performs matching in real-time on a modern GPU and
|
26 |
+
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).*
|
27 |
|
28 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/2I8QDRNoMhQCuL236CvdN.png" alt="drawing" width="500"/>
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
<!-- ![image/png](https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/2I8QDRNoMhQCuL236CvdN.png) -->
|
31 |
|
32 |
+
This model was contributed by [stevenbucaille](https://huggingface.co/stevenbucaille).
|
33 |
+
The original code can be found [here](https://github.com/magicleap/SuperGluePretrainedNetwork).
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
## Model Details
|
|
|
|
|
36 |
|
37 |
+
### Model Description
|
38 |
|
39 |
+
SuperGlue is a neural network that matches two sets of local features by jointly finding correspondences and rejecting non-matchable points.
|
40 |
+
It introduces a flexible context aggregation mechanism based on attention, enabling it to reason about the underlying 3D scene and feature
|
41 |
+
assignments. The architecture consists of two main components: the Attentional Graph Neural Network and the Optimal Matching Layer.
|
42 |
|
43 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/zZGjSWQU2na5aPFRak5kp.png" alt="drawing" width="1000"/>
|
44 |
|
45 |
+
<!-- ![image/png](https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/zZGjSWQU2na5aPFRak5kp.png) -->
|
46 |
|
47 |
+
The Attentional Graph Neural Network uses a Keypoint Encoder to map keypoint positions and visual descriptors.
|
48 |
+
It employs self- and cross-attention layers to create powerful representations. The Optimal Matching Layer creates a
|
49 |
+
score matrix, augments it with dustbins, and finds the optimal partial assignment using the Sinkhorn algorithm.
|
50 |
|
51 |
+
- **Developed by:** MagicLeap
|
52 |
+
- **Model type:** Image Matching
|
53 |
+
- **License:** ACADEMIC OR NON-PROFIT ORGANIZATION NONCOMMERCIAL RESEARCH USE ONLY
|
54 |
|
55 |
+
### Model Sources
|
56 |
|
57 |
+
<!-- Provide the basic links for the model. -->
|
58 |
|
59 |
+
- **Repository:** https://github.com/magicleap/SuperGluePretrainedNetwork
|
60 |
+
- **Paper:** https://arxiv.org/pdf/1911.11763
|
61 |
+
- **Demo:** https://psarlin.com/superglue/
|
62 |
|
63 |
+
## Uses
|
64 |
|
65 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
66 |
|
67 |
+
### Direct Use
|
68 |
|
69 |
+
SuperGlue is designed for feature matching and pose estimation tasks in computer vision. It can be applied to a variety of multiple-view
|
70 |
+
geometry problems and can handle challenging real-world indoor and outdoor environments. However, it may not perform well on tasks that
|
71 |
+
require different types of visual understanding, such as object detection or image classification.
|
72 |
|
|
|
73 |
|
74 |
## How to Get Started with the Model
|
75 |
|
|
|
76 |
|
77 |
+
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:
|
78 |
+
|
79 |
+
```python
|
80 |
+
from transformers import AutoImageProcessor, AutoModel
|
81 |
+
import torch
|
82 |
+
from PIL import Image
|
83 |
+
import requests
|
84 |
+
url = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_98169888_3347710852.jpg"
|
85 |
+
im1 = Image.open(requests.get(url, stream=True).raw)
|
86 |
+
url = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_26757027_6717084061.jpg"
|
87 |
+
im2 = Image.open(requests.get(url, stream=True).raw)
|
88 |
+
images = [im1, im2]
|
89 |
+
processor = AutoImageProcessor.from_pretrained("stevenbucaille/superglue_outdoor")
|
90 |
+
model = AutoModel.from_pretrained("stevenbucaille/superglue_outdoor")
|
91 |
+
inputs = processor(images, return_tensors="pt")
|
92 |
+
outputs = model(**inputs)
|
93 |
+
```
|
94 |
+
|
95 |
+
The outputs contain the list of keypoints detected by the keypoint detector as well as the list of matches with their corresponding matching scores.
|
96 |
+
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:
|
97 |
+
|
98 |
+
```python
|
99 |
+
from transformers import AutoImageProcessor, AutoModel
|
100 |
+
import torch
|
101 |
+
from PIL import Image
|
102 |
+
import requests
|
103 |
+
url_image_1 = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_98169888_3347710852.jpg"
|
104 |
+
image_1 = Image.open(requests.get(url_image_1, stream=True).raw)
|
105 |
+
url_image_2 = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_26757027_6717084061.jpg"
|
106 |
+
image_2 = Image.open(requests.get(url_image_2, stream=True).raw)
|
107 |
+
images = [image_1, image_2]
|
108 |
+
processor = AutoImageProcessor.from_pretrained("stevenbucaille/superglue_indoor")
|
109 |
+
model = AutoModel.from_pretrained("stevenbucaille/superglue_indoor")
|
110 |
+
inputs = processor(images, return_tensors="pt")
|
111 |
+
with torch.no_grad():
|
112 |
+
outputs = model(**inputs)
|
113 |
+
# Get the respective image masks
|
114 |
+
image0_mask, image1_mask = outputs_mask[0]
|
115 |
+
image0_indices = torch.nonzero(image0_mask).squeeze()
|
116 |
+
image1_indices = torch.nonzero(image1_mask).squeeze()
|
117 |
+
image0_matches = outputs.matches[0, 0][image0_indices]
|
118 |
+
image1_matches = outputs.matches[0, 1][image1_indices]
|
119 |
+
image0_matching_scores = outputs.matching_scores[0, 0][image0_indices]
|
120 |
+
image1_matching_scores = outputs.matching_scores[0, 1][image1_indices]
|
121 |
+
```
|
122 |
+
|
123 |
+
You can use the `post_process_keypoint_matching` method from the `SuperGlueImageProcessor` to get the keypoints and matches in a more readable format:
|
124 |
+
```python
|
125 |
+
image_sizes = [(image.height, image.width) for image in images]
|
126 |
+
outputs = processor.post_process_keypoint_matching(outputs, image_sizes)
|
127 |
+
for i, output in enumerate(outputs):
|
128 |
+
print("For the image pair", i)
|
129 |
+
for keypoint0, keypoint1, matching_score in zip(output["keypoints0"], output["keypoints1"],
|
130 |
+
output["matching_scores"]):
|
131 |
+
print(
|
132 |
+
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}."
|
133 |
+
)
|
134 |
+
```
|
135 |
+
|
136 |
+
From the outputs, you can visualize the matches between the two images using the following code:
|
137 |
+
```python
|
138 |
+
import matplotlib.pyplot as plt
|
139 |
+
import numpy as np
|
140 |
+
# Create side by side image
|
141 |
+
merged_image = np.zeros((max(image1.height, image2.height), image1.width + image2.width, 3))
|
142 |
+
merged_image[: image1.height, : image1.width] = np.array(image1) / 255.0
|
143 |
+
merged_image[: image2.height, image1.width :] = np.array(image2) / 255.0
|
144 |
+
plt.imshow(merged_image)
|
145 |
+
plt.axis("off")
|
146 |
+
# Retrieve the keypoints and matches
|
147 |
+
output = outputs[0]
|
148 |
+
keypoints0 = output["keypoints0"]
|
149 |
+
keypoints1 = output["keypoints1"]
|
150 |
+
matching_scores = output["matching_scores"]
|
151 |
+
keypoints0_x, keypoints0_y = keypoints0[:, 0].numpy(), keypoints0[:, 1].numpy()
|
152 |
+
keypoints1_x, keypoints1_y = keypoints1[:, 0].numpy(), keypoints1[:, 1].numpy()
|
153 |
+
# Plot the matches
|
154 |
+
for keypoint0_x, keypoint0_y, keypoint1_x, keypoint1_y, matching_score in zip(
|
155 |
+
keypoints0_x, keypoints0_y, keypoints1_x, keypoints1_y, matching_scores
|
156 |
+
):
|
157 |
+
plt.plot(
|
158 |
+
[keypoint0_x, keypoint1_x + image1.width],
|
159 |
+
[keypoint0_y, keypoint1_y],
|
160 |
+
color=plt.get_cmap("RdYlGn")(matching_score.item()),
|
161 |
+
alpha=0.9,
|
162 |
+
linewidth=0.5,
|
163 |
+
)
|
164 |
+
plt.scatter(keypoint0_x, keypoint0_y, c="black", s=2)
|
165 |
+
plt.scatter(keypoint1_x + image1.width, keypoint1_y, c="black", s=2)
|
166 |
+
# Save the plot
|
167 |
+
plt.savefig("matched_image.png", dpi=300, bbox_inches='tight')
|
168 |
+
plt.close()
|
169 |
+
```
|
170 |
+
|
171 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/01ZYaLB1NL5XdA8u7yCo4.png)
|
172 |
+
|
173 |
|
174 |
## Training Details
|
175 |
|
176 |
### Training Data
|
177 |
|
178 |
+
SuperGlue is trained on large annotated datasets for pose estimation, enabling it to learn priors for pose estimation and reason about the 3D scene.
|
179 |
+
The training data consists of image pairs with ground truth correspondences and unmatched keypoints derived from ground truth poses and depth maps.
|
|
|
|
|
|
|
180 |
|
181 |
+
### Training Procedure
|
|
|
|
|
|
|
|
|
182 |
|
183 |
+
SuperGlue is trained in a supervised manner using ground truth matches and unmatched keypoints. The loss function maximizes
|
184 |
+
the negative log-likelihood of the assignment matrix, aiming to simultaneously maximize precision and recall.
|
185 |
|
186 |
#### Training Hyperparameters
|
187 |
|
188 |
+
- **Training regime:** fp32
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
+
#### Speeds, Sizes, Times
|
191 |
|
192 |
+
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.
|
193 |
+
The model has 12 million parameters, making it relatively compact compared to some other deep learning models.
|
194 |
+
The inference speed of SuperGlue is suitable for real-time applications and can be readily integrated into
|
195 |
+
modern Simultaneous Localization and Mapping (SLAM) or Structure-from-Motion (SfM) systems.
|
196 |
|
197 |
+
## Citation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
200 |
|
201 |
**BibTeX:**
|
202 |
|
203 |
+
```bibtex
|
204 |
+
@inproceedings{sarlin2020superglue,
|
205 |
+
title={Superglue: Learning feature matching with graph neural networks},
|
206 |
+
author={Sarlin, Paul-Edouard and DeTone, Daniel and Malisiewicz, Tomasz and Rabinovich, Andrew},
|
207 |
+
booktitle={Proceedings of the IEEE/CVF conference on computer vision and pattern recognition},
|
208 |
+
pages={4938--4947},
|
209 |
+
year={2020}
|
210 |
+
}
|
211 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
|
213 |
+
## Model Card Authors
|
214 |
|
215 |
+
[Steven Bucaille](https://github.com/sbucaille)
|