Views
No views yet
1from transformers import AutoImageProcessor, SuperPointForKeypointDetection
2import torch
3from PIL import Image
4import requests
5
6url = "http://images.cocodataset.org/val2017/000000039769.jpg"
7image = Image.open(requests.get(url, stream=True).raw)
8
9processor = AutoImageProcessor.from_pretrained("magic-leap-community/superpoint")
10model = SuperPointForKeypointDetection.from_pretrained("magic-leap-community/superpoint")
11
12inputs = processor(image, return_tensors="pt")
13outputs = model(**inputs)1from transformers import AutoImageProcessor, SuperPointForKeypointDetection
2import torch
3from PIL import Image
4import requests
5
6url_image_1 = "http://images.cocodataset.org/val2017/000000039769.jpg"
7image_1 = Image.open(requests.get(url_image_1, stream=True).raw)
8url_image_2 = "http://images.cocodataset.org/test-stuff2017/000000000568.jpg"
9image_2 = Image.open(requests.get(url_image_2, stream=True).raw)
10
11images = [image_1, image_2]
12
13processor = AutoImageProcessor.from_pretrained("magic-leap-community/superpoint")
14model = SuperPointForKeypointDetection.from_pretrained("magic-leap-community/superpoint")
15
16inputs = processor(images, return_tensors="pt")
17outputs = model(**inputs)1import matplotlib.pyplot as plt
2import torch
3
4for i in range(len(images)):
5 image = images[i]
6 image_width, image_height = image.size
7
8 image_mask = outputs.mask[i]
9 image_indices = torch.nonzero(image_mask).squeeze()
10
11 image_scores = outputs.scores[i][image_indices]
12 image_keypoints = outputs.keypoints[i][image_indices]
13
14 keypoints = image_keypoints.detach().numpy()
15 scores = image_scores.detach().numpy()
16
17 valid_keypoints = [
18 (kp, score) for kp, score in zip(keypoints, scores)
19 if 0 <= kp[0] < image_width and 0 <= kp[1] < image_height
20 ]
21
22 valid_keypoints, valid_scores = zip(*valid_keypoints)
23 valid_keypoints = torch.tensor(valid_keypoints)
24 valid_scores = torch.tensor(valid_scores)
25
26 print(valid_keypoints.shape)
27
28 plt.axis('off')
29 plt.imshow(image)
30 plt.scatter(
31 valid_keypoints[:, 0],
32 valid_keypoints[:, 1],
33 s=valid_scores * 100,
34 c='red'
35 )
36 plt.show()1@inproceedings{detone2018superpoint,
2 title={Superpoint: Self-supervised interest point detection and description},
3 author={DeTone, Daniel and Malisiewicz, Tomasz and Rabinovich, Andrew},
4 booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition workshops},
5 pages={224--236},
6 year={2018}
7}