Deformable DETR
Deformable DETR 把 DETR 的稠密交叉注意力换成了围绕每个参考点的稀疏、多尺度采样,正是这一点让 transformer 检测器的训练变得可行。LibreYOLO 提供五种尺寸用于检测,仅支持推理。
- 任务
- detection
- 尺寸
- r50ss, r50ssdc5, r50, r50refine, r50twostage at 800 px
- 安装
pip install libreyolo- 支持层级
- 仅推理,自 v 起。仅支持预测、验证和导出。训练相关的功能不适用。
- 许可
- 代码采用 Apache-2.0,权重采用 Apache-2.0。商用
安装
Deformable DETR 不需要任何可选 extra。它导入的一切都在基础安装里,用的是纯 PyTorch 的多尺度可变形注意力核心。
pip install libreyolo安装 libreyolo[hub-kernels] 是可选的。一旦 kernels 包存在,LibreYOLO 会在
运行时从 Hugging Face Hub 拉取一个编译好的多尺度可变形注意力 kernel,用它替代
纯 PyTorch 核心;LIBREYOLO_HUB_KERNELS=0 可以把它再关掉。
预测
权重在首次使用时从 Hugging Face 下载,并缓存在本地。
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreDeformableDETRr50.pt")result = model(SAMPLE_IMAGE, save=True) for box in result.boxes: print(box.cls, box.conf, box.xyxy)libreyolo predict model=LibreDeformableDETRr50.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True返回的 Results 对象和每个家族返回的都是同一个,所以换成另一个检测器只是一行
的改动。conf 和 max_det 过滤 query 的选择;iou 为了 API 一致性会被接受,
但没有任何作用,因为解码器是一个集合预测器,没有 NMS 步骤。数据源、流式处理和
结果处理见预测。
在 LibreYOLO 里 Deformable DETR 只支持推理。上游用匈牙利匹配和 focal 分类损失
函数来训练;这套配方这里没有实现,所以 train() 会抛出 NotImplementedError。
变体
五个检查点(checkpoint)覆盖了已发布的各种配置,输入分辨率都相同。r50ss 把
注意力限制在单一特征尺度上;r50ssdc5 在此基础上再加一个空洞 C5 骨干阶段。
r50 是默认的多尺度配置,在四个特征图层级上采样。r50refine 在各个解码器层
之间加入迭代式的检测框精修,r50twostage 则从编码器输出而不是学习得到的 query
生成初始的区域候选。
验证
val() 返回一个由 metrics/ 键组成的字典,涵盖查准率、查全率、mAP 50 和
mAP 50-95,在任何符合你训练所用格式的数据集上测量。
from libreyolo import LibreYOLO model = LibreYOLO("LibreDeformableDETRr50.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"])libreyolo val model=LibreDeformableDETRr50.pt data=my-dataset.yaml导出
| 任务 | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Detection | Detection 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。导出列出了每种
格式接受的参数。
from libreyolo import LibreYOLO model = LibreYOLO("LibreDeformableDETRr50.pt")model.export(format="onnx", imgsz=800)model.export(format="tensorrt", imgsz=800, half=True)libreyolo export model=LibreDeformableDETRr50.pt format=onnx imgsz=800libreyolo export model=LibreDeformableDETRr50.pt format=tensorrt imgsz=800 half=Truefrom libreyolo import LibreYOLO, SAMPLE_IMAGE # 工厂按文件后缀分发,所以导出的产物加载方式和任何检查点一样,# 返回的也是同一个 Results 对象model = LibreYOLO("LibreDeformableDETRr50.onnx")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)检查点
这个家族已发布的全部权重文件。
| 文件 | 输入(px) | 权重许可 |
|---|---|---|
| Detection | ||
| LibreDeformableDETRr50ss.pt | 800 | apache-2.0 |
| LibreDeformableDETRr50ssdc5.pt | 800 | apache-2.0 |
| LibreDeformableDETRr50.pt | 800 | apache-2.0 |
| LibreDeformableDETRr50twostage.pt | 800 | apache-2.0 |
| LibreDeformableDETRr50refine.pt | 800 | apache-2.0 |
上面的每个文件目前都在 LibreYOLO 组织中,并会在首次使用时下载。
许可证
请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。
这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。
- 原始工作
- Deformable DETR, SenseTime
- 上游许可
- 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 five checkpoints are converted from SenseTime's own Hugging Face mirrors, each of which declares apache-2.0 in its model card; that declaration, not the original repository's Google Drive release links, is the redistribution basis.
引用
@article{zhu2020deformable,
title={Deformable DETR: Deformable Transformers for End-to-End Object Detection},
author={Zhu, Xizhou and Su, Weijie and Lu, Lewei and Li, Bin and Wang, Xiaogang and Dai, Jifeng},
journal={arXiv preprint arXiv:2010.04159},
year={2020}
}复制自作者在 github.com/fundamentalvision/Deformable-DETR#citing-deformable-detr 上提供的引用块。