🚀 RT-DETRv2
RT-DETRv2是一個用於目標檢測的模型,它在RT-DETR的基礎上進行了改進,提升了靈活性和實用性,同時保持了即時性能,可廣泛應用於自動駕駛、監控系統等多個領域。
🚀 快速開始
本部分將介紹如何快速使用RT-DETRv2進行目標檢測。
import torch
import requests
from PIL import Image
from transformers import RTDetrV2ForObjectDetection, RTDetrImageProcessor
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)
image_processor = RTDetrImageProcessor.from_pretrained("PekingU/rtdetr_v2_r34vd")
model = RTDetrV2ForObjectDetection.from_pretrained("PekingU/rtdetr_v2_r34vd")
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.height, image.width)]), threshold=0.5)
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.97 [341.14, 25.11, 639.98, 372.89]
cat: 0.96 [12.78, 56.35, 317.67, 471.34]
remote: 0.95 [39.96, 73.12, 175.65, 117.44]
sofa: 0.86 [-0.11, 2.97, 639.89, 473.62]
sofa: 0.82 [-0.12, 1.78, 639.87, 473.52]
remote: 0.79 [333.65, 76.38, 370.69, 187.48]
✨ 主要特性
模型改進
RT-DETRv2由Wenyu Lv、Yian Zhao、Qinyao Chang、Kui Huang、Guanzhong Wang和Yi Liu在論文RT-DETRv2: Improved Baseline with Bag-of-Freebies for Real-Time Detection Transformer中提出。它通過引入選擇性多尺度特徵提取、離散採樣算子,以及改進動態數據增強和尺度自適應超參數等訓練策略,對RT-DETR進行了優化。這些改進在保持即時性能的同時,提高了模型的靈活性和實用性。
性能表現
RT-DETRv2在所有模型尺寸上都始終優於其前身,並且保持了相同的即時速度。

應用場景
RT-DETRv2非常適合用於各種即時目標檢測應用,如自動駕駛、監控系統、機器人技術和零售分析。其增強的靈活性和易於部署的設計使其適用於邊緣設備和大規模系統,同時確保在動態的現實環境中具有高精度和高速度。
🔧 技術細節
訓練數據
RT-DETRv2在COCO(Lin等人 [2014])的train2017數據集上進行訓練,並在COCO val2017數據集上進行驗證。
評估指標
該模型報告了標準的AP指標(在從0.50 - 0.95的均勻採樣IoU閾值上平均,步長為0.05),以及在實際場景中常用的APval50指標。
📄 許可證
本模型採用Apache-2.0許可證。
本模型由@jadechoghari在@cyrilvallez和@qubvel-hf的幫助下貢獻。