查看 Markdown

LW-DETR

一个纯 ViT 的检测 transformer,百度把它定位成 YOLO 检测器的实时替代方案。LibreYOLO 提供五种尺寸用于检测,仅支持推理。

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

安装

LW-DETR 不需要任何可选 extra。它导入的一切都在基础安装里。

bash
pip install libreyolo

预测

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

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

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

在 LibreYOLO 里 LW-DETR 只支持推理。上游用跨多个 query 组的 Group-DETR 一对多 监督和一个 IoU 感知的分类损失函数来训练;这套配方这里没有接上,所以 train() 会抛出 NotImplementedError

变体

五种尺寸,共用同一个纯 ViT 编码器、多尺度投影器和 deformable DETR 解码器,输入 分辨率也都相同。最小的两个共用一个编码器宽度,按 block 深度区分;接下来的两个 共用一个更宽的编码器,按有多少个投影器层级喂给解码器区分;最大的那个则换上最宽 的编码器。

验证

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

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreLWDETRt.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=LibreLWDETRt.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 文件的表现和检查点(checkpoint)一样,返回同样的 Results导出 列出了每种格式接受的参数。

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

检查点

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

文件输入(px)权重许可
Detection
LibreLWDETRt.pt640apache-2.0
LibreLWDETRs.pt640apache-2.0
LibreLWDETRm.pt640apache-2.0
LibreLWDETRl.pt640apache-2.0
LibreLWDETRx.pt640apache-2.0

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

许可证

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

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

原始工作
LW-DETR, Baidu
上游许可
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 published checkpoints are converted from the upstream Apache-2.0 Hugging Face release (xbsu/LW-DETR) and rehosted under the same license.

引用

@article{chen2024lw,
    title={LW-DETR: A Transformer Replacement to YOLO for Real-Time Detection},
    author={Chen, Qiang and Su, Xiangbo and Zhang, Xinyu and Wang, Jian and Chen, Jiahui and Shen, Yunpeng and Han, Chuchu and Chen, Ziliang and Xu, Weixiang and Li, Fanrong and others},
    journal={arXiv preprint arXiv:2406.03459},
    year={2024}
}

复制自作者在 github.com/Atten4Vis/LW-DETR#10-citation 上提供的引用块。

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