license: other
tags:
- 视觉
- 图像匹配
inference: false
pipeline_tag: 关键点检测
SuperPoint
概述
SuperPoint模型由Daniel DeTone、Tomasz Malisiewicz和Andrew Rabinovich在论文《SuperPoint: Self-Supervised Interest Point Detection and Description》中提出。
该模型是通过自监督训练的全卷积网络,用于兴趣点检测和描述。模型能够检测在单应变换下可重复的兴趣点,并为每个点提供描述符。单独使用该模型的功能有限,但它可以作为特征提取器用于其他任务,如单应性估计、图像匹配等。
论文摘要如下:
本文提出了一种自监督框架,用于训练适用于计算机视觉中大量多视图几何问题的兴趣点检测器和描述符。与基于块的神经网络不同,我们的全卷积模型在全尺寸图像上运行,并在一次前向传递中联合计算像素级兴趣点位置和相关描述符。我们引入了单应性适应(Homographic Adaptation),这是一种多尺度、多单应性的方法,用于提升兴趣点检测的可重复性并执行跨域适应(例如,从合成到真实)。我们的模型在MS-COCO通用图像数据集上使用单应性适应进行训练后,能够比初始未适应的深度模型和任何其他传统角点检测器重复检测到更丰富的兴趣点集。最终系统在HPatches上与LIFT、SIFT和ORB相比,实现了最先进的单应性估计结果。
演示笔记本
展示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的特性,为了输出动态数量的关键点,你需要使用mask属性来检索相应的信息:
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}
}