stevenbucaille
commited on
Commit
•
29fa269
1
Parent(s):
7dc7f80
Update README.md
Browse files
README.md
CHANGED
@@ -1,37 +1,64 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
tags: []
|
|
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
|
8 |
-
|
|
|
|
|
9 |
|
|
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
## Model Details
|
13 |
|
14 |
### Model Description
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
-
|
22 |
-
|
23 |
-
|
24 |
-
- **
|
25 |
-
- **
|
26 |
-
- **
|
27 |
|
28 |
### Model Sources [optional]
|
29 |
|
30 |
<!-- Provide the basic links for the model. -->
|
31 |
|
32 |
-
- **Repository:**
|
33 |
-
- **Paper
|
34 |
-
- **Demo
|
35 |
|
36 |
## Uses
|
37 |
|
@@ -39,134 +66,127 @@ This is the model card of a 🤗 transformers model that has been pushed on the
|
|
39 |
|
40 |
### Direct Use
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
### Downstream Use [optional]
|
47 |
-
|
48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
49 |
-
|
50 |
-
[More Information Needed]
|
51 |
-
|
52 |
-
### Out-of-Scope Use
|
53 |
-
|
54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
55 |
-
|
56 |
-
[More Information Needed]
|
57 |
-
|
58 |
-
## Bias, Risks, and Limitations
|
59 |
-
|
60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
61 |
-
|
62 |
-
[More Information Needed]
|
63 |
-
|
64 |
-
### Recommendations
|
65 |
-
|
66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
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 |
|
@@ -174,28 +194,18 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
|
|
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 |
-
[
|
200 |
|
201 |
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
tags: []
|
4 |
+
inference: false
|
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 [optional]
|
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 |
|
|
|
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 |
## How to Get Started with the Model
|
74 |
|
|
|
75 |
|
76 |
+
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:
|
77 |
+
|
78 |
+
```python
|
79 |
+
from transformers import AutoImageProcessor, AutoModel
|
80 |
+
import torch
|
81 |
+
from PIL import Image
|
82 |
+
import requests
|
83 |
+
|
84 |
+
url = "https://github.com/magicleap/SuperGluePretrainedNetwork/blob/master/assets/phototourism_sample_images/london_bridge_78916675_4568141288.jpg?raw=true"
|
85 |
+
im1 = Image.open(requests.get(url, stream=True).raw)
|
86 |
+
url = "https://github.com/magicleap/SuperGluePretrainedNetwork/blob/master/assets/phototourism_sample_images/london_bridge_19481797_2295892421.jpg?raw=true"
|
87 |
+
im2 = Image.open(requests.get(url, stream=True).raw)
|
88 |
+
images = [im1, im2]
|
89 |
+
|
90 |
+
processor = AutoImageProcessor.from_pretrained("stevenbucaille/superglue_indoor")
|
91 |
+
model = AutoModel.from_pretrained("stevenbucaille/superglue_indoor")
|
92 |
+
|
93 |
+
inputs = processor(images, return_tensors="pt")
|
94 |
+
outputs = model(**inputs)
|
95 |
+
```
|
96 |
+
|
97 |
+
The outputs contain the list of keypoints detected by the keypoint detector as well as the list of matches with their corresponding matching scores.
|
98 |
+
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:
|
99 |
+
|
100 |
+
```python
|
101 |
+
from transformers import AutoImageProcessor, AutoModel
|
102 |
+
import torch
|
103 |
+
from PIL import Image
|
104 |
+
import requests
|
105 |
+
|
106 |
+
url_image_1 = "https://github.com/cvg/LightGlue/blob/main/assets/sacre_coeur1.jpg?raw=true"
|
107 |
+
image_1 = Image.open(requests.get(url_image_1, stream=True).raw)
|
108 |
+
url_image_2 = "https://github.com/cvg/LightGlue/blob/main/assets/sacre_coeur2.jpg?raw=true"
|
109 |
+
image_2 = Image.open(requests.get(url_image_2, stream=True).raw)
|
110 |
+
|
111 |
+
images = [image_1, image_2]
|
112 |
+
|
113 |
+
processor = AutoImageProcessor.from_pretrained("stevenbucaille/superglue_indoor")
|
114 |
+
model = AutoModel.from_pretrained("stevenbucaille/superglue_indoor")
|
115 |
+
|
116 |
+
inputs = processor(images, return_tensors="pt")
|
117 |
+
with torch.no_grad():
|
118 |
+
outputs = model(**inputs)
|
119 |
+
|
120 |
+
# Get the respective image masks
|
121 |
+
image0_mask, image1_mask = outputs_mask[0]
|
122 |
+
|
123 |
+
image0_indices = torch.nonzero(image0_mask).squeeze()
|
124 |
+
image1_indices = torch.nonzero(image1_mask).squeeze()
|
125 |
+
|
126 |
+
image0_matches = outputs.matches[0, 0][image0_indices]
|
127 |
+
image1_matches = outputs.matches[0, 1][image1_indices]
|
128 |
+
|
129 |
+
image0_matching_scores = outputs.matching_scores[0, 0][image0_indices]
|
130 |
+
image1_matching_scores = outputs.matching_scores[0, 1][image1_indices]
|
131 |
+
```
|
132 |
+
|
133 |
+
You can then print the matched keypoints on a side-by-side image to visualize the result :
|
134 |
+
```python
|
135 |
+
import cv2
|
136 |
+
import numpy as np
|
137 |
+
|
138 |
+
# Create side by side image
|
139 |
+
input_data = inputs['pixel_values']
|
140 |
+
height, width = input_data.shape[-2:]
|
141 |
+
matched_image = np.zeros((height, width * 2, 3))
|
142 |
+
matched_image[:, :width] = input_data.squeeze()[0].permute(1, 2, 0).cpu().numpy()
|
143 |
+
matched_image[:, width:] = input_data.squeeze()[1].permute(1, 2, 0).cpu().numpy()
|
144 |
+
matched_image = (matched_image * 255).astype(np.uint8)
|
145 |
+
|
146 |
+
# Retrieve matches by looking at which keypoints in image0 actually matched with keypoints in image1
|
147 |
+
image0_mask = outputs.mask[0, 0]
|
148 |
+
image0_indices = torch.nonzero(image0_mask).squeeze()
|
149 |
+
image0_matches_indices = torch.nonzero(outputs.matches[0, 0][image0_indices] != -1).squeeze()
|
150 |
+
image0_keypoints = outputs.keypoints[0, 0][image0_matches_indices]
|
151 |
+
image0_matches = outputs.matches[0, 0][image0_matches_indices]
|
152 |
+
image0_matching_scores = outputs.matching_scores[0, 0][image0_matches_indices]
|
153 |
+
# Retrieve matches from image1
|
154 |
+
image1_mask = outputs.mask[0, 1]
|
155 |
+
image1_indices = torch.nonzero(image1_mask).squeeze()
|
156 |
+
image1_keypoints = outputs.keypoints[0, 1][image0_matches]
|
157 |
+
|
158 |
+
# Draw matches
|
159 |
+
for (keypoint0, keypoint1, score) in zip(image0_keypoints, image1_keypoints, image0_matching_scores):
|
160 |
+
keypoint0_x, keypoint0_y = int(keypoint0[0].item()), int(keypoint0[1].item())
|
161 |
+
keypoint1_x, keypoint1_y = int(keypoint1[0].item() + width), int(keypoint1[1].item())
|
162 |
+
color = tuple([int(score.item() * 255)] * 3)
|
163 |
+
matched_image = cv2.line(matched_image, (keypoint0_x, keypoint0_y), (keypoint1_x, keypoint1_y), color)
|
164 |
+
cv2.imwrite(f"matched_image.png", matched_image)
|
165 |
+
```
|
166 |
+
|
167 |
|
168 |
## Training Details
|
169 |
|
170 |
### Training Data
|
171 |
|
172 |
+
SuperGlue is trained on large annotated datasets for pose estimation, enabling it to learn priors for pose estimation and reason about the 3D scene.
|
173 |
+
The training data consists of image pairs with ground truth correspondences and unmatched keypoints derived from ground truth poses and depth maps.
|
|
|
174 |
|
175 |
### Training Procedure
|
176 |
|
177 |
+
SuperGlue is trained in a supervised manner using ground truth matches and unmatched keypoints. The loss function maximizes
|
178 |
+
the negative log-likelihood of the assignment matrix, aiming to simultaneously maximize precision and recall.
|
|
|
|
|
|
|
|
|
179 |
|
180 |
#### Training Hyperparameters
|
181 |
|
182 |
+
- **Training regime:** fp32
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
|
184 |
+
#### Speeds, Sizes, Times
|
185 |
|
186 |
+
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.
|
187 |
+
The model has 12 million parameters, making it relatively compact compared to some other deep learning models.
|
188 |
+
The inference speed of SuperGlue is suitable for real-time applications and can be readily integrated into
|
189 |
+
modern Simultaneous Localization and Mapping (SLAM) or Structure-from-Motion (SfM) systems.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
## Citation [optional]
|
192 |
|
|
|
194 |
|
195 |
**BibTeX:**
|
196 |
|
197 |
+
```bibtex
|
198 |
+
@inproceedings{sarlin2020superglue,
|
199 |
+
title={Superglue: Learning feature matching with graph neural networks},
|
200 |
+
author={Sarlin, Paul-Edouard and DeTone, Daniel and Malisiewicz, Tomasz and Rabinovich, Andrew},
|
201 |
+
booktitle={Proceedings of the IEEE/CVF conference on computer vision and pattern recognition},
|
202 |
+
pages={4938--4947},
|
203 |
+
year={2020}
|
204 |
+
}
|
205 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
|
207 |
+
## Model Card Authors
|
208 |
|
209 |
+
[Steven Bucaille](https://github.com/sbucaille)
|
210 |
|
211 |
|