RetinaNet
RetinaNet 是一个用 focal 损失训练的单阶段检测器,focal 损失会压低简单负样本的权重,让一整片密集的锚框网格不再需要单独的候选框阶段也能保持精度。LibreYOLO 移植了 torchvision 的实现,用于检测。
- 任务
- detection
- 尺寸
- r50, r50v2 at 800 px
- 安装
pip install libreyolo- 支持层级
- 仅推理,自 v 起。仅支持预测、验证和导出。训练相关的功能不适用。
- 许可
- 代码采用 BSD-3-Clause,权重采用 BSD-3-Clause。商用
安装
RetinaNet 不需要任何可选 extra。它导入的一切都在基础安装里。
pip install libreyolo预测
权重在首次使用时从 Hugging Face 下载,并缓存在本地。
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreRetinaNetr50v2.pt")result = model(SAMPLE_IMAGE, save=True) for box in result.boxes: print(box.cls, box.conf, box.xyxy)libreyolo predict model=LibreRetinaNetr50v2.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True返回的 Results 对象就是每个家族都返回的那一个,所以换用另一个检测器只是一行
改动。conf 和 iou 设置置信度阈值和 NMS 阈值;RetinaNet 在它密集的锚框网格之
上保留了上游的 NMS 步骤。数据源、流式处理和结果处理见
预测。
变体
两种尺寸,都是 ResNet-50 配特征金字塔:r50 是原始的 head,r50v2 把它换成一
个 GroupNorm head,外加一个更宽的 P6 块,这个块的输入取自骨干的最后一个阶段,而
不是 FPN 的输出。
验证
val() 返回一个由 metrics/ 键组成的字典,涵盖查准率、查全率、mAP 50 和
mAP 50-95,在任何采用你训练时所用格式的数据集上测量。
from libreyolo import LibreYOLO model = LibreYOLO("LibreRetinaNetr50v2.pt")metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/mAP50-95"])print(metrics["metrics/mAP50"])libreyolo val model=LibreRetinaNetr50v2.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:不支持 |
RetinaNet 只能导出到 ONNX,批大小为 1。RetinaNet 会把输入缩放到一个可变的、保持
宽高比的尺寸,所以无论传入什么,LibreYOLO 都会强制 dynamic=True,好让计算图对
不同形状的数据源依然有效。导出的 .onnx 文件按文件后缀经由 LibreYOLO() 重新
加载,返回同样的 Results。
from libreyolo import LibreYOLO model = LibreYOLO("LibreRetinaNetr50v2.pt")model.export(format="onnx", imgsz=800)libreyolo export model=LibreRetinaNetr50v2.pt format=onnx imgsz=800from libreyolo import LibreYOLO, SAMPLE_IMAGE # 工厂按文件后缀分发,所以导出的产物加载方式和任何检查点一样,# 返回的也是同一个 Results 对象model = LibreYOLO("LibreRetinaNetr50v2.onnx")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)检查点
这个家族已发布的全部权重文件。
| 文件 | 输入(px) | 权重许可 |
|---|---|---|
| Detection | ||
| LibreRetinaNetr50.pt | 800 | bsd-3-clause |
| LibreRetinaNetr50v2.pt | 800 | bsd-3-clause |
上面的每个文件目前都在 LibreYOLO 组织中,并会在首次使用时下载。
许可证
请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。
这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。
- 原始工作
- RetinaNet, PyTorch
- 上游许可
- BSD-3-Clause
- LibreYOLO 代码
- MIT
- 权重
- 采用 BSD-3-Clause 许可,重新发布在 huggingface.co/LibreYOLO
- 解读
- BSD-3-Clause is a permissive license, so this code can be used in commercial and closed-source products with no obligation on your own application code. It asks only that you keep the copyright notice and disclaimer with any copy you redistribute, and it carries no patent grant. The two published checkpoints used for parity testing are not distributed in the LibreYOLO source tree: torchvision's own documentation notes that a pretrained model's terms may depend on its training data, so each Hugging Face mirror ships the BSD text on that implied basis and repeats the caveat rather than issuing an explicit checkpoint-specific grant.