DETR
DETR 是最初的 detection transformer,它用经过匈牙利匹配(Hungarian matching)的 transformer 解码器预测一组固定数量的目标,而不是用锚框或稠密网格。LibreYOLO 提供四种尺寸,用于目标检测,只支持推理。
- 任务
- detection
- 尺寸
- r50, r50dc5, r101, r101dc5 at 800 px
- 安装
pip install libreyolo- 支持层级
- 仅推理,自 v 起。仅支持预测、验证和导出。训练相关的功能不适用。
- 许可
- 代码采用 Apache-2.0,权重采用 Apache-2.0。商用
安装
DETR 不需要任何可选 extra。它导入的一切都在基础安装里。
pip install libreyolo预测
权重在首次使用时从 Hugging Face 下载,并缓存在本地。
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreDETRr50.pt")result = model(SAMPLE_IMAGE, save=True) for box in result.boxes: print(box.cls, box.conf, box.xyxy)libreyolo predict model=LibreDETRr50.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True返回的 Results 对象就是每个家族都返回的那一个,所以换用另一个检测器只是一行
改动。conf 和 max_det 过滤查询(query)的选择;iou 为了 API 一致性会被接受,
但不起作用,因为解码器是一个集合预测器,没有 NMS 步骤。数据源、流式处理和结果
处理见预测。
在 LibreYOLO 里 DETR 只支持推理。上游用匈牙利匹配训练 500 轮;那套配方这里没有
实现,所以 train() 会抛出 NotImplementedError。
变体
四个检查点(checkpoint)由两种骨干深度(ResNet-50 或 ResNet-101)和一个可选的 空洞 C5 阶段组合而成:DC5 变体把骨干的最后一个阶段保持在全分辨率,不再继续下 采样,所以解码器在相同的输入尺寸下读到更精细的特征图。四个变体都用 100 个学习 得到的目标查询和一个六层 transformer 编码器-解码器,输入分辨率也都相同。
验证
val() 返回一个由 metrics/ 键组成的字典,涵盖查准率、查全率、mAP 50 和
mAP 50-95,在任何符合你训练所用格式的数据集上测量。
from libreyolo import LibreYOLO model = LibreYOLO("LibreDETRr50.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=LibreDETRr50.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("LibreDETRr50.pt")model.export(format="onnx", imgsz=800)model.export(format="tensorrt", imgsz=800, half=True)libreyolo export model=LibreDETRr50.pt format=onnx imgsz=800libreyolo export model=LibreDETRr50.pt format=tensorrt imgsz=800 half=Truefrom libreyolo import LibreYOLO, SAMPLE_IMAGE # 工厂按文件后缀分发,所以导出的产物加载方式和任何检查点一样,# 返回的也是同一个 Results 对象model = LibreYOLO("LibreDETRr50.onnx")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)检查点
这个家族已发布的全部权重文件。
| 文件 | 输入(px) | 权重许可 |
|---|---|---|
| Detection | ||
| LibreDETRr50dc5.pt | 800 | apache-2.0 |
| LibreDETRr50.pt | 800 | apache-2.0 |
| LibreDETRr101dc5.pt | 800 | apache-2.0 |
| LibreDETRr101.pt | 800 | apache-2.0 |
上面的每个文件目前都在 LibreYOLO 组织中,并会在首次使用时下载。
许可证
请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。
这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。
- 原始工作
- DETR, Meta AI (FAIR)
- 上游许可
- 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 four checkpoints are the official releases linked from the Apache-2.0 repository's model zoo, and the official Hugging Face DETR card independently declares the same license.