Faster R-CNN
Faster R-CNN 用一个区域建议网络(region proposal network)喂给两阶段分类器来检测目标,正是这个架构让区域建议成为同一个训练网络的一部分,而不再是单独的一步。LibreYOLO 移植了 torchvision 的实现,用于目标检测。
- 任务
- detection
- 尺寸
- n, s, m, l at 320 to 800 px
- 安装
pip install libreyolo- 支持层级
- 仅推理,自 v 起。仅支持预测、验证和导出。训练相关的功能不适用。
- 许可
- 代码采用 BSD-3-Clause,权重采用 BSD-3-Clause。商用
安装
Faster R-CNN 不需要任何可选 extra。它导入的一切都在基础安装里。
pip install libreyolo预测
权重在首次使用时从 Hugging Face 下载,并缓存在本地。
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreFasterRCNNl.pt")result = model(SAMPLE_IMAGE, save=True) for box in result.boxes: print(box.cls, box.conf, box.xyxy)libreyolo predict model=LibreFasterRCNNl.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True返回的 Results 对象就是每个家族都返回的那一个,所以换用另一个检测器只是一行
改动。conf 和 iou 设置置信度阈值和 NMS 阈值;和基于查询的检测器不同,
Faster R-CNN 保留了它上游的 NMS 步骤。数据源、流式处理和结果处理见
预测。
变体
四种尺寸,每一种都是不同的 torchvision 配置,而不是同一个配置按比例缩放的版本:
n 是 MobileNetV3-Large 配 320 px 输入,s 是同样的骨干配 800 px,m 是
ResNet-50 加一个特征金字塔,l 是 v2 修订版,用更深的区域建议 head 和一个四层
卷积的检测框 head 取代了 m 的那一套。n 和 s 用精度换来更轻的骨干。
验证
val() 返回一个由 metrics/ 键组成的字典,涵盖查准率、查全率、mAP 50 和
mAP 50-95,在任何符合你训练所用格式的数据集上测量。
from libreyolo import LibreYOLO model = LibreYOLO("LibreFasterRCNNl.pt")metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/mAP50-95"])print(metrics["metrics/mAP50"])libreyolo val model=LibreFasterRCNNl.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:不支持 |
Faster R-CNN 只能导出到 ONNX,批大小为 1。导出的计算图把上游的缩放步骤保留在
内部,所以无论传入什么,LibreYOLO 都会强制 dynamic=True,好让计算图对非正方形
的数据源依然有效。导出的 .onnx 文件按文件后缀经由 LibreYOLO() 重新加载,返回
同样的 Results。
from libreyolo import LibreYOLO model = LibreYOLO("LibreFasterRCNNl.pt")model.export(format="onnx", imgsz=800)libreyolo export model=LibreFasterRCNNl.pt format=onnx imgsz=800from libreyolo import LibreYOLO, SAMPLE_IMAGE # 工厂按文件后缀分发,所以导出的产物加载方式和任何检查点一样,# 返回的也是同一个 Results 对象model = LibreYOLO("LibreFasterRCNNl.onnx")result = model(SAMPLE_IMAGE) print(result.boxes.xyxy)检查点
这个家族已发布的全部权重文件。
| 文件 | 输入(px) | 权重许可 |
|---|---|---|
| Detection | ||
| LibreFasterRCNNn.pt | 320 | bsd-3-clause |
| LibreFasterRCNNs.pt | 800 | bsd-3-clause |
| LibreFasterRCNNm.pt | 800 | bsd-3-clause |
| LibreFasterRCNNl.pt | 800 | bsd-3-clause |
上面的每个文件目前都在 LibreYOLO 组织中,并会在首次使用时下载。
许可证
请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。
这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。
- 原始工作
- Faster R-CNN, 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 four 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.
引用
@inproceedings{renNIPS15fasterrcnn,
Author = {Shaoqing Ren and Kaiming He and Ross Girshick and Jian Sun},
Title = {Faster {R-CNN}: Towards Real-Time Object Detection
with Region Proposal Networks},
Booktitle = {Advances in Neural Information Processing Systems ({NIPS})},
Year = {2015}
}复制自作者在 github.com/rbgirshick/py-faster-rcnn#citing-faster-r-cnn 上提供的引用块。