mhassanch commited on
Commit
0cf703d
·
1 Parent(s): 7be7bd0

fine tuned on sar

Browse files
Files changed (4) hide show
  1. README.md +219 -0
  2. config.json +44 -0
  3. model.safetensors +3 -0
  4. preprocessor_config.json +12 -0
README.md ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ## Demo notebook
36
+
37
+ A demo notebook showcasing inference + visualization with SuperGlue can be found [here](https://github.com/qubvel/transformers-notebooks/blob/main/notebooks/SuperGlue_inference.ipynb).
38
+
39
+ ## Model Details
40
+
41
+ ### Model Description
42
+
43
+ SuperGlue is a neural network that matches two sets of local features by jointly finding correspondences and rejecting non-matchable points.
44
+ It introduces a flexible context aggregation mechanism based on attention, enabling it to reason about the underlying 3D scene and feature
45
+ assignments. The architecture consists of two main components: the Attentional Graph Neural Network and the Optimal Matching Layer.
46
+
47
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/zZGjSWQU2na5aPFRak5kp.png" alt="drawing" width="1000"/>
48
+
49
+ <!-- ![image/png](https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/zZGjSWQU2na5aPFRak5kp.png) -->
50
+
51
+ The Attentional Graph Neural Network uses a Keypoint Encoder to map keypoint positions and visual descriptors.
52
+ It employs self- and cross-attention layers to create powerful representations. The Optimal Matching Layer creates a
53
+ score matrix, augments it with dustbins, and finds the optimal partial assignment using the Sinkhorn algorithm.
54
+
55
+ - **Developed by:** MagicLeap
56
+ - **Model type:** Image Matching
57
+ - **License:** ACADEMIC OR NON-PROFIT ORGANIZATION NONCOMMERCIAL RESEARCH USE ONLY
58
+
59
+ ### Model Sources
60
+
61
+ <!-- Provide the basic links for the model. -->
62
+
63
+ - **Repository:** https://github.com/magicleap/SuperGluePretrainedNetwork
64
+ - **Paper:** https://arxiv.org/pdf/1911.11763
65
+ - **Demo:** https://psarlin.com/superglue/
66
+
67
+ ## Uses
68
+
69
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
70
+
71
+ ### Direct Use
72
+
73
+ SuperGlue is designed for feature matching and pose estimation tasks in computer vision. It can be applied to a variety of multiple-view
74
+ geometry problems and can handle challenging real-world indoor and outdoor environments. However, it may not perform well on tasks that
75
+ require different types of visual understanding, such as object detection or image classification.
76
+
77
+
78
+ ## How to Get Started with the Model
79
+
80
+
81
+ 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:
82
+
83
+ ```python
84
+ from transformers import AutoImageProcessor, AutoModel
85
+ import torch
86
+ from PIL import Image
87
+ import requests
88
+ url = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_98169888_3347710852.jpg"
89
+ im1 = Image.open(requests.get(url, stream=True).raw)
90
+ url = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_26757027_6717084061.jpg"
91
+ im2 = Image.open(requests.get(url, stream=True).raw)
92
+ images = [im1, im2]
93
+ processor = AutoImageProcessor.from_pretrained("stevenbucaille/superglue_outdoor")
94
+ model = AutoModel.from_pretrained("stevenbucaille/superglue_outdoor")
95
+ inputs = processor(images, return_tensors="pt")
96
+ outputs = model(**inputs)
97
+ ```
98
+
99
+ The outputs contain the list of keypoints detected by the keypoint detector as well as the list of matches with their corresponding matching scores.
100
+ 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:
101
+
102
+ ```python
103
+ from transformers import AutoImageProcessor, AutoModel
104
+ import torch
105
+ from PIL import Image
106
+ import requests
107
+ url_image_1 = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_98169888_3347710852.jpg"
108
+ image_1 = Image.open(requests.get(url_image_1, stream=True).raw)
109
+ url_image_2 = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_26757027_6717084061.jpg"
110
+ image_2 = Image.open(requests.get(url_image_2, stream=True).raw)
111
+ images = [image_1, image_2]
112
+ processor = AutoImageProcessor.from_pretrained("stevenbucaille/superglue_indoor")
113
+ model = AutoModel.from_pretrained("stevenbucaille/superglue_indoor")
114
+ inputs = processor(images, return_tensors="pt")
115
+ with torch.no_grad():
116
+ outputs = model(**inputs)
117
+ # Get the respective image masks
118
+ image0_mask, image1_mask = outputs_mask[0]
119
+ image0_indices = torch.nonzero(image0_mask).squeeze()
120
+ image1_indices = torch.nonzero(image1_mask).squeeze()
121
+ image0_matches = outputs.matches[0, 0][image0_indices]
122
+ image1_matches = outputs.matches[0, 1][image1_indices]
123
+ image0_matching_scores = outputs.matching_scores[0, 0][image0_indices]
124
+ image1_matching_scores = outputs.matching_scores[0, 1][image1_indices]
125
+ ```
126
+
127
+ You can use the `post_process_keypoint_matching` method from the `SuperGlueImageProcessor` to get the keypoints and matches in a more readable format:
128
+ ```python
129
+ image_sizes = [(image.height, image.width) for image in images]
130
+ outputs = processor.post_process_keypoint_matching(outputs, image_sizes, threshold=0.2)
131
+ for i, output in enumerate(outputs):
132
+ print("For the image pair", i)
133
+ for keypoint0, keypoint1, matching_score in zip(output["keypoints0"], output["keypoints1"],
134
+ output["matching_scores"]):
135
+ print(
136
+ 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}."
137
+ )
138
+ ```
139
+
140
+ From the outputs, you can visualize the matches between the two images using the following code:
141
+ ```python
142
+ import matplotlib.pyplot as plt
143
+ import numpy as np
144
+ # Create side by side image
145
+ merged_image = np.zeros((max(image1.height, image2.height), image1.width + image2.width, 3))
146
+ merged_image[: image1.height, : image1.width] = np.array(image1) / 255.0
147
+ merged_image[: image2.height, image1.width :] = np.array(image2) / 255.0
148
+ plt.imshow(merged_image)
149
+ plt.axis("off")
150
+ # Retrieve the keypoints and matches
151
+ output = outputs[0]
152
+ keypoints0 = output["keypoints0"]
153
+ keypoints1 = output["keypoints1"]
154
+ matching_scores = output["matching_scores"]
155
+ keypoints0_x, keypoints0_y = keypoints0[:, 0].numpy(), keypoints0[:, 1].numpy()
156
+ keypoints1_x, keypoints1_y = keypoints1[:, 0].numpy(), keypoints1[:, 1].numpy()
157
+ # Plot the matches
158
+ for keypoint0_x, keypoint0_y, keypoint1_x, keypoint1_y, matching_score in zip(
159
+ keypoints0_x, keypoints0_y, keypoints1_x, keypoints1_y, matching_scores
160
+ ):
161
+ plt.plot(
162
+ [keypoint0_x, keypoint1_x + image1.width],
163
+ [keypoint0_y, keypoint1_y],
164
+ color=plt.get_cmap("RdYlGn")(matching_score.item()),
165
+ alpha=0.9,
166
+ linewidth=0.5,
167
+ )
168
+ plt.scatter(keypoint0_x, keypoint0_y, c="black", s=2)
169
+ plt.scatter(keypoint1_x + image1.width, keypoint1_y, c="black", s=2)
170
+ # Save the plot
171
+ plt.savefig("matched_image.png", dpi=300, bbox_inches='tight')
172
+ plt.close()
173
+ ```
174
+
175
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/_2a_V28C1eEMY_Wy6sRZa.png)
176
+
177
+
178
+ ## Training Details
179
+
180
+ ### Training Data
181
+
182
+ SuperGlue is trained on large annotated datasets for pose estimation, enabling it to learn priors for pose estimation and reason about the 3D scene.
183
+ The training data consists of image pairs with ground truth correspondences and unmatched keypoints derived from ground truth poses and depth maps.
184
+
185
+ ### Training Procedure
186
+
187
+ SuperGlue is trained in a supervised manner using ground truth matches and unmatched keypoints. The loss function maximizes
188
+ the negative log-likelihood of the assignment matrix, aiming to simultaneously maximize precision and recall.
189
+
190
+ #### Training Hyperparameters
191
+
192
+ - **Training regime:** fp32
193
+
194
+ #### Speeds, Sizes, Times
195
+
196
+ 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.
197
+ The model has 12 million parameters, making it relatively compact compared to some other deep learning models.
198
+ The inference speed of SuperGlue is suitable for real-time applications and can be readily integrated into
199
+ modern Simultaneous Localization and Mapping (SLAM) or Structure-from-Motion (SfM) systems.
200
+
201
+ ## Citation
202
+
203
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
204
+
205
+ **BibTeX:**
206
+
207
+ ```bibtex
208
+ @inproceedings{sarlin2020superglue,
209
+ title={Superglue: Learning feature matching with graph neural networks},
210
+ author={Sarlin, Paul-Edouard and DeTone, Daniel and Malisiewicz, Tomasz and Rabinovich, Andrew},
211
+ booktitle={Proceedings of the IEEE/CVF conference on computer vision and pattern recognition},
212
+ pages={4938--4947},
213
+ year={2020}
214
+ }
215
+ ```
216
+
217
+ ## Model Card Authors
218
+
219
+ [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:78d08cfb9d7523014b30eaca760461b82a7219c9e49c1dcb6de69238c648bdd5
3
+ size 48203748
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
+ }