VGG
VGG 是一个卷积图像分类器,由一叠尺寸统一的 3x3 小卷积堆叠而成,而不是更大的滤波器。LibreYOLO 提供 16 层和 19 层两种尺寸,每种都有普通版和带批归一化(batch normalization)的版本,用于图像分类。
- 任务
- classify
- 尺寸
- 16, 19, 16bn, 19bn at 224 px
- 安装
pip install libreyolo- 支持层级
- 仅推理,自 v 起。仅支持预测、验证和导出。训练相关的功能不适用。
- 许可
- 代码采用 BSD-3-Clause,权重采用 BSD-3-Clause。商用
安装
VGG 不需要任何可选 extra。它导入的一切都在基础安装里。
pip install libreyolo预测
权重在首次使用时从 Hugging Face 下载,并缓存在本地。
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreVGG16-cls.pt")result = model(SAMPLE_IMAGE, save=True) probs = result.probsprint(probs.top1, probs.top1conf)print(probs.top5, probs.top5conf)libreyolo predict model=LibreVGG16-cls.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True分类器返回的是 result.probs 而不是 result.boxes:top1 和 top5 给出类别
索引,top1conf 和 top5conf 给出对应的置信度。预测固定以 224px 输入运行,传入
不同的 imgsz 会报错。数据源、流式处理和结果处理见预测。
变体
四种尺寸:16 层和 19 层卷积,每种各有一个普通版本和一个带批归一化的变体。随库 提供的权重来自 torchvision 后期从零开始的 ImageNet 训练,而不是牛津团队 2014 年 最初 Caffe 版本的转换结果。LibreYOLO 只以推理方式提供这个家族:预测、ImageNet 风格的 top-1/top-5 验证和导出都支持,微调没有实现。
验证
val() 在 ImageFolder 风格的划分上运行(一个带 train/ 和 val/ 子文件夹的
目录,每个类别一个文件夹),返回 top-1 和 top-5 精度。
from libreyolo import LibreYOLO model = LibreYOLO("LibreVGG16-cls.pt") # data 是一个根目录,下面是按类别分文件夹的 train/ 和 val/ 划分# (ImageFolder 布局),而不是数据集 YAMLmetrics = model.val(data="imagenet-1k/") print(metrics["metrics/accuracy_top1"])print(metrics["metrics/accuracy_top5"])libreyolo val model=LibreVGG16-cls.pt data=imagenet-1k/导出
| 任务 | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| classify | classify to ONNX:支持 | classify to TorchScript:支持 | classify to ExecuTorch:支持 | classify to TensorRT:支持 | classify to OpenVINO:支持 | classify to Paddle:不支持 | classify to MNN:不支持 | classify to RKNN:不支持 | classify to ncnn:支持 | classify to TFLite:不支持 | classify to CoreML:不支持 | classify to Core AI:不支持 |
导出的产物按文件后缀经由 LibreYOLO() 重新加载,所以一个 .onnx 或 .engine
文件的表现和检查点(checkpoint)一样,返回同样的 Results。导出列出了每种格式接受的参数,以及其中少数几种额外增加的参数。
from libreyolo import LibreYOLO model = LibreYOLO("LibreVGG16-cls.pt")model.export(format="onnx")model.export(format="tensorrt", half=True)libreyolo export model=LibreVGG16-cls.pt format=onnxlibreyolo export model=LibreVGG16-cls.pt format=tensorrt half=Truefrom libreyolo import LibreYOLO, SAMPLE_IMAGE # 工厂按文件后缀分发,所以导出的产物加载方式和任何检查点一样,# 返回的也是同一个 Results 对象model = LibreYOLO("LibreVGG16-cls.onnx")result = model(SAMPLE_IMAGE) print(result.probs.top1)检查点
这个家族已发布的全部权重文件。
| 文件 | 输入(px) | 权重许可 |
|---|---|---|
| classify | ||
| LibreVGG16-cls.pt | 224 | bsd-3-clause |
| LibreVGG19bn-cls.pt | 224 | bsd-3-clause |
| LibreVGG19-cls.pt | 224 | bsd-3-clause |
| LibreVGG16bn-cls.pt | 224 | bsd-3-clause |
上面的每个文件目前都在 LibreYOLO 组织中,并会在首次使用时下载。
许可证
请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。
这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。
- 原始工作
- VGG, Visual Geometry Group, University of Oxford
- 上游许可
- BSD-3-Clause
- LibreYOLO 代码
- MIT
- 权重
- 采用 BSD-3-Clause 许可,重新发布在 huggingface.co/LibreYOLO
- 解读
- BSD-3-Clause is a permissive license, so these weights can be used in commercial and closed-source products. It asks you to keep the copyright notice, the list of conditions and the disclaimer with any copy you redistribute, and it forbids using the contributors' names to endorse a derived product without permission; it carries no explicit patent grant. LibreYOLO's code and the four shipped checkpoints (16, 19, 16-BN, 19-BN) are both derived from torchvision, not from the Oxford group's original 2014 Caffe release, which is a separate model under Creative Commons Attribution and is not what LibreYOLO redistributes. Torchvision itself notes that BSD-3-Clause redistribution of a pretrained checkpoint is an implied basis rather than a grant written for that specific checkpoint, and that pretrained-model terms can depend on the data a model was trained on; LibreYOLO repeats that caveat on each hosted weights repository.