🚀 視覺變換器(小型模型) - 使用DINOv2訓練
本項目是一個使用DINOv2方法訓練的視覺變換器(ViT)模型,可用於圖像分類等下游任務,為圖像識別領域提供了強大的特徵提取能力。
🚀 快速開始
本模型是使用DINOv2方法訓練的視覺變換器(ViT)模型。該方法由Oquab等人在論文 DINOv2: Learning Robust Visual Features without Supervision 中提出,並首次在 此倉庫 中發佈。
聲明:發佈DINOv2的團隊並未為此模型編寫模型卡片,此模型卡片由Hugging Face團隊編寫。
✨ 主要特性
- 基於自監督學習方式,在大量圖像上進行預訓練,學習到圖像的內在表示,可用於提取對下游任務有用的特徵。
- 不包含任何微調頭,用戶可根據自身需求在預訓練編碼器之上添加線性層,訓練標準分類器。
📚 詳細文檔
模型描述
視覺變換器(ViT)是一種基於Transformer編碼器的模型(類似BERT),以自監督的方式在大量圖像上進行預訓練。
圖像以固定大小的圖像塊序列形式輸入到模型中,這些圖像塊經過線性嵌入處理。同時,在序列開頭添加一個 [CLS] 標記,用於分類任務。在將序列輸入到Transformer編碼器的各層之前,還會添加絕對位置嵌入。
需要注意的是,此模型不包含任何微調頭。
通過對模型進行預訓練,它能夠學習到圖像的內在表示,這些表示可用於提取對下游任務有用的特徵。例如,如果您有一個帶標籤的圖像數據集,可以在預訓練編碼器之上添加一個線性層,訓練一個標準分類器。通常會在 [CLS] 標記之上添加線性層,因為該標記的最後隱藏狀態可視為整個圖像的表示。
預期用途和侷限性
您可以使用此模型對圖像進行分類,類別為 1000個ImageNet標籤 之一。您可以在 模型中心 查找其他針對您感興趣任務的微調版本。
💻 使用示例
基礎用法
from transformers import AutoImageProcessor, AutoModelForImageClassification
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('facebook/dinov2-small-imagenet1k-1-layer')
model = AutoModelForImageClassification.from_pretrained('facebook/dinov2-small-imagenet1k-1-layer')
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])
📄 許可證
本項目採用Apache-2.0許可證。
BibTeX引用
misc{oquab2023dinov2,
title={DINOv2: Learning Robust Visual Features without Supervision},
author={Maxime Oquab and Timothée Darcet and Théo Moutakanni and Huy Vo and Marc Szafraniec and Vasil Khalidov and Pierre Fernandez and Daniel Haziza and Francisco Massa and Alaaeldin El-Nouby and Mahmoud Assran and Nicolas Ballas and Wojciech Galuba and Russell Howes and Po-Yao Huang and Shang-Wen Li and Ishan Misra and Michael Rabbat and Vasu Sharma and Gabriel Synnaeve and Hu Xu and Hervé Jegou and Julien Mairal and Patrick Labatut and Armand Joulin and Piotr Bojanowski},
year={2023},
eprint={2304.07193},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
📦 信息表格