HuggingFace镜像/yolos-tiny
模型介绍文件和版本分析
下载使用量0

YOLOS(微型尺寸)模型

YOLOS 模型在 COCO 2017 目标检测数据集(包含 118k 张带标注图像)上进行了微调。该模型由 Fang 等人在论文《You Only Look at One Sequence: Rethinking Transformer in Vision through Object Detection》中提出,并首次在 此仓库 发布。

免责声明:发布 YOLOS 的团队未为此模型撰写模型卡片,因此本模型卡片由 Hugging Face 团队编写。

模型描述

YOLOS 是一种使用 DETR 损失进行训练的视觉Transformer(ViT)。尽管结构简单,基础尺寸的 YOLOS 模型在 COCO 2017 验证集上能够达到 42 AP(与 DETR 以及 Faster R-CNN 等更复杂的框架性能相当)。

该模型使用“ bipartite matching loss ”进行训练:将 N = 100 个目标查询的预测类别和边界框与 ground truth 标注进行比较,标注会被填充至相同长度 N(因此,如果一张图像仅包含 4 个目标,那么 96 个标注的类别将为“无目标”,边界框为“无边界框”)。匈牙利匹配算法用于在 N 个查询和 N 个标注之间创建最优的一对一映射。接下来,使用标准的交叉熵(针对类别)以及 L1 损失和广义 IoU 损失的线性组合(针对边界框)来优化模型参数。

预期用途与局限性

您可以将原始模型用于目标检测。请参阅 模型中心 以查找所有可用的 YOLOS 模型。

如何使用

以下是使用此模型的方法:

from transformers import YolosImageProcessor, YolosForObjectDetection
from PIL import Image
import torch
import requests

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)

model = YolosForObjectDetection.from_pretrained('hustvl/yolos-tiny')
image_processor = YolosImageProcessor.from_pretrained("hustvl/yolos-tiny")

inputs = image_processor(images=image, return_tensors="pt")
outputs = model(**inputs)

# model predicts bounding boxes and corresponding COCO classes
logits = outputs.logits
bboxes = outputs.pred_boxes


# print results
target_sizes = torch.tensor([image.size[::-1]])
results = image_processor.post_process_object_detection(outputs, threshold=0.9, target_sizes=target_sizes)[0]
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
    box = [round(i, 2) for i in box.tolist()]
    print(
        f"Detected {model.config.id2label[label.item()]} with confidence "
        f"{round(score.item(), 3)} at location {box}"
    )

目前,特征提取器和模型均支持 PyTorch。

训练数据

YOLOS 模型在 ImageNet-1k 上进行预训练,并在 COCO 2017 目标检测 数据集上进行微调。该数据集包含 118k 张训练图像和 5k 张验证图像,均带有标注。

训练过程

模型在 ImageNet-1k 上预训练了 300 个 epoch,在 COCO 上微调了 300 个 epoch。

评估结果

该模型在 COCO 2017 验证集上的平均精度(AP)达到 28.7。有关评估结果的更多详细信息,请参考原始论文。

BibTeX 条目和引用信息

@article{DBLP:journals/corr/abs-2106-00666,
  author    = {Yuxin Fang and
               Bencheng Liao and
               Xinggang Wang and
               Jiemin Fang and
               Jiyang Qi and
               Rui Wu and
               Jianwei Niu and
               Wenyu Liu},
  title     = {You Only Look at One Sequence: Rethinking Transformer in Vision through
               Object Detection},
  journal   = {CoRR},
  volume    = {abs/2106.00666},
  year      = {2021},
  url       = {https://arxiv.org/abs/2106.00666},
  eprinttype = {arXiv},
  eprint    = {2106.00666},
  timestamp = {Fri, 29 Apr 2022 19:49:16 +0200},
  biburl    = {https://dblp.org/rec/journals/corr/abs-2106-00666.bib},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}