查看 Markdown

DINO-DETR

DINO-DETR 由 IDEA Research 以 DINO 之名发布,在 Deformable DETR 的稀疏注意力之上,把对比式去噪训练和混合 query 选择结合在一起。LibreYOLO 提供三种尺寸用于检测,仅支持推理。

任务
detection
尺寸
r50, r50s5, swinl at 800 px
安装
pip install libreyolo
支持层级
仅推理,自 v 起。仅支持预测、验证和导出。训练相关的功能不适用。
上游
DINO-DETR,由 IDEA Research 发布,采用 Apache-2.0 许可。论文源码
许可
代码采用 Apache-2.0,权重采用 Apache-2.0。商用

安装

DINO-DETR 不需要任何可选 extra。它导入的一切都在基础安装里,用的是和 LibreYOLO 的 Deformable DETR 家族相同的纯 PyTorch 多尺度可变形注意力核心。

bash
pip install libreyolo

安装 libreyolo[hub-kernels] 是可选的。一旦 kernels 包存在,LibreYOLO 会在 运行时从 Hugging Face Hub 拉取一个编译好的多尺度可变形注意力 kernel,用它替代 纯 PyTorch 核心;LIBREYOLO_HUB_KERNELS=0 可以把它再关掉。

预测

权重在首次使用时从 Hugging Face 下载,并缓存在本地。

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreDINODETRr50.pt")result = model(SAMPLE_IMAGE, save=True) for box in result.boxes:    print(box.cls, box.conf, box.xyxy)
CLI
libreyolo predict model=LibreDINODETRr50.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True

返回的 Results 对象和每个家族返回的都是同一个,所以换成另一个检测器只是一行 的改动。confmax_det 过滤 query 的选择;iou 为了 API 一致性会被接受, 但没有任何作用,因为解码器是一个集合预测器,没有 NMS 步骤。数据源、流式处理和 结果处理见预测

在 LibreYOLO 里 DINO-DETR 只支持推理。上游用对比式去噪和匈牙利匹配来训练;这套 配方这里没有实现,所以 train() 会抛出 NotImplementedError

变体

三个检查点(checkpoint),输入分辨率都相同。r50r50s5 共用一个 ResNet-50 骨干,区别在于有多少个特征图尺度送进解码器,四个对五个。swinl 把骨干换成 Swin-L,同样采样五个尺度。

验证

val() 返回一个由 metrics/ 键组成的字典,涵盖查准率、查全率、mAP 50 和 mAP 50-95,在任何符合你训练所用格式的数据集上测量。

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreDINODETRr50.pt") # val() 返回的是一个普通 dict,不是对象metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/mAP50-95"])print(metrics["metrics/mAP50"])print(metrics["metrics/precision"], metrics["metrics/recall"])
CLI
libreyolo val model=LibreDINODETRr50.pt data=my-dataset.yaml

导出

任务ONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
DetectionDetection to ONNX:支持Detection to TorchScript:支持Detection to ExecuTorch:支持Detection to TensorRT:支持Detection to OpenVINO:支持Detection to Paddle:不支持Detection to MNN:不支持Detection to RKNN:不支持Detection to ncnn:不支持Detection to TFLite:不支持Detection to CoreML:不支持Detection to Core AI:不支持

导出的产物按文件后缀经由 LibreYOLO() 重新加载,所以一个 .onnx.engine 文件的表现和检查点一样,返回同样的 Results导出列出了每种 格式接受的参数。

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreDINODETRr50.pt")model.export(format="onnx", imgsz=800)model.export(format="tensorrt", imgsz=800, half=True)
CLI
libreyolo export model=LibreDINODETRr50.pt format=onnx imgsz=800libreyolo export model=LibreDINODETRr50.pt format=tensorrt imgsz=800 half=True
使用导出的文件
from libreyolo import LibreYOLO, SAMPLE_IMAGE # 工厂按文件后缀分发,所以导出的产物加载方式和任何检查点一样,# 返回的也是同一个 Results 对象model = LibreYOLO("LibreDINODETRr50.onnx")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)

检查点

这个家族已发布的全部权重文件。

文件输入(px)权重许可
Detection
LibreDINODETRr50.pt800apache-2.0
LibreDINODETRr50s5.pt800apache-2.0
LibreDINODETRswinl.pt800apache-2.0

上面的每个文件目前都在 LibreYOLO 组织中,并会在首次使用时下载。

许可证

请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。

这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。

原始工作
DINO-DETR, IDEA Research
上游许可
Apache-2.0
LibreYOLO 代码
MIT
权重
采用 Apache-2.0 许可,重新发布在 huggingface.co/LibreYOLO
解读
Apache-2.0 is a permissive license, so these weights can be used in commercial and closed-source products. It asks you to keep its license text and attribution notices with any copy of the weights you redistribute, and it grants a patent license. It places no obligation on your own application code, and weights you train yourself on your own data are yours. The three checkpoints come from the authors' Google Drive release rather than a Hugging Face model card, and the upstream repository does not attach a license to the checkpoint files individually, so the redistribution basis is the repository-level Apache-2.0 declaration rather than a checkpoint-specific grant.

三个官方检查点来自作者的 Google Drive 发布文件夹,而不是 Hugging Face 模型卡。 上游仓库在仓库层面声明了 Apache-2.0,但没有给检查点本身附上许可证文件或许可证 元数据,所以再分发的依据是那条仓库层面的声明,而不是针对检查点的单独许可。每个 LibreYOLO 镜像都随附上游 Apache-2.0 许可证原文,以及一份解释这一点的说明。

引用

@misc{zhang2022dino,
      title={DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection}, 
      author={Hao Zhang and Feng Li and Shilong Liu and Lei Zhang and Hang Su and Jun Zhu and Lionel M. Ni and Heung-Yeung Shum},
      year={2022},
      eprint={2203.03605},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

@inproceedings{li2022dn,
      title={Dn-detr: Accelerate detr training by introducing query denoising},
      author={Li, Feng and Zhang, Hao and Liu, Shilong and Guo, Jian and Ni, Lionel M and Zhang, Lei},
      booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
      pages={13619--13627},
      year={2022}
}

@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}
}

复制自作者在 github.com/IDEA-Research/DINO#bibtex 上提供的引用块。

已针对 LibreYOLO v1.5.0 验证。本页的支持表、检查点和基准测试数据由已发布的库和权重生成,并非手工编写。