模型概述
模型特點
模型能力
使用案例
🚀 模型ID的模型卡片
本模型卡片介紹了一個用於目標檢測的 🤗 Transformers 模型,它基於動態錨框的新型查詢公式,解決了 DETR 訓練收斂慢的問題,在 MS - COCO 基準測試中表現出色。
🚀 快速開始
使用以下代碼開始使用該模型:
import torch
import requests
from PIL import Image
from transformers import AutoModelForObjectDetection, AutoImageProcessor
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)
image_processor = AutoImageProcessor.from_pretrained("IDEA-Research/dab-detr-resnet-50")
model = AutoModelForObjectDetection.from_pretrained("IDEA-Research/dab-detr-resnet-50")
inputs = image_processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
results = image_processor.post_process_object_detection(outputs, target_sizes=torch.tensor([image.size[::-1]]), threshold=0.3)
for result in results:
for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
score, label = score.item(), label_id.item()
box = [round(i, 2) for i in box.tolist()]
print(f"{model.config.id2label[label]}: {score:.2f} {box}")
這段代碼的輸出結果如下:
cat: 0.87 [14.7, 49.39, 320.52, 469.28]
remote: 0.86 [41.08, 72.37, 173.39, 117.2]
cat: 0.86 [344.45, 19.43, 639.85, 367.86]
remote: 0.61 [334.27, 75.93, 367.92, 188.81]
couch: 0.59 [-0.04, 1.34, 639.9, 477.09]
✨ 主要特性
- 提出了一種用於 DETR(DEtection TRansformer)的新型查詢公式,使用動態錨框,對 DETR 中查詢的作用有了更深入的理解。
- 直接使用框座標作為 Transformer 解碼器中的查詢,並逐層動態更新。
- 利用框座標有助於使用顯式位置先驗來提高查詢與特徵的相似度,消除 DETR 中訓練收斂慢的問題。
- 允許使用框的寬度和高度信息來調製位置注意力圖。
- 在相同設置下,在 MS - COCO 基準測試中,在類似 DETR 的檢測模型中取得了最佳性能。
📦 安裝指南
文檔未提及安裝步驟,故跳過此章節。
💻 使用示例
基礎用法
import torch
import requests
from PIL import Image
from transformers import AutoModelForObjectDetection, AutoImageProcessor
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)
image_processor = AutoImageProcessor.from_pretrained("IDEA-Research/dab-detr-resnet-50")
model = AutoModelForObjectDetection.from_pretrained("IDEA-Research/dab-detr-resnet-50")
inputs = image_processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
results = image_processor.post_process_object_detection(outputs, target_sizes=torch.tensor([image.size[::-1]]), threshold=0.3)
for result in results:
for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
score, label = score.item(), label_id.item()
box = [round(i, 2) for i in box.tolist()]
print(f"{model.config.id2label[label]}: {score:.2f} {box}")
📚 詳細文檔
模型詳情
本文提出了一種用於 DETR(DEtection TRansformer)的新型查詢公式,使用動態錨框,並對 DETR 中查詢的作用有了更深入的理解。這種新公式直接使用框座標作為 Transformer 解碼器中的查詢,並逐層動態更新。使用框座標不僅有助於使用顯式位置先驗來提高查詢與特徵的相似度,消除 DETR 中訓練收斂慢的問題,還允許我們使用框的寬度和高度信息來調製位置注意力圖。這種設計明確了 DETR 中的查詢可以實現為以級聯方式逐層執行軟 ROI 池化。因此,在相同設置下,在 MS - COCO 基準測試中,它在類似 DETR 的檢測模型中取得了最佳性能,例如,使用 ResNet50 - DC5 作為骨幹網絡,在 50 個 epoch 內訓練得到的 AP 為 45.7%。我們還進行了廣泛的實驗來證實我們的分析並驗證我們方法的有效性。
模型描述
這是一個已發佈在 Hub 上的 🤗 Transformers 模型的卡片,該模型卡片是自動生成的。
屬性 | 詳情 |
---|---|
開發者 | Shilong Liu、Feng Li、Hao Zhang、Xiao Yang、Xianbiao Qi、Hang Su、Jun Zhu、Lei Zhang |
資助方 | IDEA - Research |
分享者 | David Hajdu |
模型類型 | DAB - DETR |
許可證 | Apache - 2.0 |
模型來源
- 倉庫:https://github.com/IDEA-Research/DAB-DETR
- 論文:https://arxiv.org/abs/2201.12329
訓練詳情
訓練數據
DAB - DETR 模型在 COCO 2017 目標檢測 數據集上進行訓練,該數據集分別包含 118k 張訓練圖像和 5k 張驗證圖像。
訓練過程
遵循 Deformable DETR 和 Conditional DETR 的方法,我們使用 300 個錨框作為查詢。我們還選擇具有最大分類對數的 300 個預測框和標籤進行評估。我們使用 α = 0.25、γ = 2 的焦點損失(Lin 等人,2020)進行分類。在二分圖匹配和最終損失計算中使用相同的損失項,但係數不同。在二分圖匹配中使用係數為 2.0 的分類損失,而在最終損失中使用係數為 1.0 的分類損失。係數為 5.0 的 L1 損失和係數為 2.0 的 GIOU 損失(Rezatofighi 等人,2019)在匹配和最終損失計算過程中保持一致。所有模型在 16 個 GPU 上進行訓練,每個 GPU 處理 1 張圖像,並使用 AdamW(Loshchilov & Hutter,2018)進行訓練,權重衰減為 10−4。骨幹網絡和其他模塊的學習率分別設置為 10−5 和 10−4。我們訓練模型 50 個 epoch,並在 40 個 epoch 後將學習率降低 0.1。所有模型都在 Nvidia A100 GPU 上進行訓練。我們使用批量大小為 64 搜索超參數,論文中的所有結果均報告為批量大小為 16。
預處理
圖像被調整大小/縮放,使得最短邊至少為 480 像素,最多為 800 像素,最長邊最多為 1333 像素,並使用 ImageNet 均值(0.485, 0.456, 0.406)和標準差(0.229, 0.224, 0.225)在 RGB 通道上進行歸一化。
訓練超參數
參數 | 值 |
---|---|
activation_dropout | 0.0 |
activation_function | prelu |
attention_dropout | 0.0 |
auxiliary_loss | false |
backbone | resnet50 |
bbox_cost | 5 |
bbox_loss_coefficient | 5 |
class_cost | 2 |
cls_loss_coefficient | 2 |
decoder_attention_heads | 8 |
decoder_ffn_dim | 2048 |
decoder_layers | 6 |
dropout | 0.1 |
encoder_attention_heads | 8 |
encoder_ffn_dim | 2048 |
encoder_layers | 6 |
focal_alpha | 0.25 |
giou_cost | 2 |
giou_loss_coefficient | 2 |
hidden_size | 256 |
init_std | 0.02 |
init_xavier_std | 1.0 |
initializer_bias_prior_prob | null |
keep_query_pos | false |
normalize_before | false |
num_hidden_layers | 6 |
num_patterns | 0 |
num_queries | 300 |
query_dim | 4 |
random_refpoints_xy | false |
sine_position_embedding_scale | null |
temperature_height | 20 |
temperature_width | 20 |
評估
模型架構和目標
DAB - DETR 概述。我們使用 CNN 骨幹網絡提取圖像空間特徵,然後使用 Transformer 編碼器對 CNN 特徵進行細化。然後,將包括位置查詢(錨框)和內容查詢(解碼器嵌入)的雙查詢輸入到解碼器中,以探測與錨框對應的對象,並與內容查詢具有相似的模式。雙查詢逐層更新,以逐漸接近目標真實對象。最終解碼器層的輸出用於通過預測頭預測帶有標籤和框的對象,然後進行二分圖匹配以計算損失,如 DETR 中所示。
🔧 技術細節
文檔中關於技術細節的描述已在前面詳細文檔部分體現,故此處不再重複。
📄 許可證
本模型使用 Apache - 2.0 許可證。
📚 引用
BibTeX:
@inproceedings{
liu2022dabdetr,
title={{DAB}-{DETR}: Dynamic Anchor Boxes are Better Queries for {DETR}},
author={Shilong Liu and Feng Li and Hao Zhang and Xiao Yang and Xianbiao Qi and Hang Su and Jun Zhu and Lei Zhang},
booktitle={International Conference on Learning Representations},
year={2022},
url={https://openreview.net/forum?id=oMI9PjOb9Jl}
}
模型卡片作者











