🚀 SuperPoint
SuperPoint是一個用於關鍵點檢測和描述的模型。它通過自監督訓練全卷積網絡得到,能檢測在單應性變換下可重複的興趣點,併為每個點提供描述符,可作為特徵提取器用於單應性估計、圖像匹配等任務。
🚀 快速開始
模型概述
SuperPoint模型由Daniel DeTone、Tomasz Malisiewicz和Andrew Rabinovich在論文 SuperPoint: Self-Supervised Interest Point Detection and Description 中提出。該模型是全卷積網絡進行自監督訓練以實現興趣點檢測和描述的成果。它能夠檢測在單應性變換下可重複的興趣點,併為每個點提供描述符。雖然該模型單獨使用時存在一定侷限性,但可作為特徵提取器用於其他任務,如單應性估計、圖像匹配等。
論文摘要如下:
本文提出了一個自監督框架,用於訓練適用於計算機視覺中大量多視圖幾何問題的興趣點檢測器和描述符。與基於補丁的神經網絡不同,我們的全卷積模型可處理全尺寸圖像,並在一次前向傳播中聯合計算像素級興趣點位置和相關描述符。我們引入了單應性自適應(Homographic Adaptation),這是一種多尺度、多單應性的方法,用於提高興趣點檢測的可重複性,並進行跨領域自適應(例如,從合成數據到真實數據)。當我們使用單應性自適應在MS - COCO通用圖像數據集上訓練模型時,與初始的預自適應深度模型和任何其他傳統角點檢測器相比,該模型能夠重複檢測到更豐富的興趣點集。與LIFT、SIFT和ORB相比,最終系統在HPatches上的單應性估計結果達到了當前最優水平。
演示筆記本
展示SuperPoint推理和可視化的演示筆記本可在 這裡 找到。
💻 使用示例
基礎用法
以下是使用該模型檢測圖像中興趣點的快速示例:
from transformers import AutoImageProcessor, SuperPointForKeypointDetection
import torch
from PIL import Image
import requests
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
processor = AutoImageProcessor.from_pretrained("magic-leap-community/superpoint")
model = SuperPointForKeypointDetection.from_pretrained("magic-leap-community/superpoint")
inputs = processor(image, return_tensors="pt")
outputs = model(**inputs)
輸出包含關鍵點座標列表及其相應的分數和描述符(一個256維的向量)。
高級用法
你還可以向模型輸入多個圖像。由於SuperPoint的特性,要輸出動態數量的關鍵點,你需要使用掩碼屬性來獲取相應信息:
from transformers import AutoImageProcessor, SuperPointForKeypointDetection
import torch
from PIL import Image
import requests
url_image_1 = "http://images.cocodataset.org/val2017/000000039769.jpg"
image_1 = Image.open(requests.get(url_image_1, stream=True).raw)
url_image_2 = "http://images.cocodataset.org/test-stuff2017/000000000568.jpg"
image_2 = Image.open(requests.get(url_image_2, stream=True).raw)
images = [image_1, image_2]
processor = AutoImageProcessor.from_pretrained("magic-leap-community/superpoint")
model = SuperPointForKeypointDetection.from_pretrained("magic-leap-community/superpoint")
inputs = processor(images, return_tensors="pt")
outputs = model(**inputs)
我們現在可以可視化這些關鍵點:
import matplotlib.pyplot as plt
import torch
for i in range(len(images)):
image = images[i]
image_width, image_height = image.size
image_mask = outputs.mask[i]
image_indices = torch.nonzero(image_mask).squeeze()
image_scores = outputs.scores[i][image_indices]
image_keypoints = outputs.keypoints[i][image_indices]
keypoints = image_keypoints.detach().numpy()
scores = image_scores.detach().numpy()
valid_keypoints = [
(kp, score) for kp, score in zip(keypoints, scores)
if 0 <= kp[0] < image_width and 0 <= kp[1] < image_height
]
valid_keypoints, valid_scores = zip(*valid_keypoints)
valid_keypoints = torch.tensor(valid_keypoints)
valid_scores = torch.tensor(valid_scores)
print(valid_keypoints.shape)
plt.axis('off')
plt.imshow(image)
plt.scatter(
valid_keypoints[:, 0],
valid_keypoints[:, 1],
s=valid_scores * 100,
c='red'
)
plt.show()
📄 許可證
本模型使用其他許可證。
此模型由 stevenbucaille 貢獻。原始代碼可在 這裡 找到。
@inproceedings{detone2018superpoint,
title={Superpoint: Self-supervised interest point detection and description},
author={DeTone, Daniel and Malisiewicz, Tomasz and Rabinovich, Andrew},
booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition workshops},
pages={224--236},
year={2018}
}