DeiT

DeiT(Data-efficient image Transformer)是一个纯粹的 Vision Transformer 分类器,只在 ImageNet-1k 上训练,没有用额外的预训练数据。LibreYOLO 以冻结、仅推理的展品形式收录 tiny、small 和 base 三种 patch-16 尺寸。

任务
classify
尺寸
t, s, b at 224 px
安装
pip install libreyolo
支持层级
博物馆,自 v 起。一件冻结的展品。只修 bug。
上游
DeiT,由 Meta Research 发布,采用 Apache-2.0 许可。论文源码
许可
代码采用 Apache-2.0,权重采用 Apache-2.0。商用

安装

DeiT 在基础包之外不需要任何 extra。

bash
pip install libreyolo

预测

这个家族只提供推理:train() 会抛出 NotImplementedError,所以本页没有训练一节。 预测、验证和导出都支持。权重在首次使用时从 Hugging Face 下载,并缓存在本地。文件名 里的 -cls 后缀是必需的,它选择分类任务。

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreDeiTb-cls.pt")result = model(SAMPLE_IMAGE) print(result.probs.top1, result.probs.top1conf)print(result.probs.top5)
CLI
libreyolo predict model=LibreDeiTb-cls.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg

返回的 Results 对象带的是 probs 张量而不是 boxestop1top5 索引 ImageNet-1k 的 1,000 个类别,top1conf 是排在第一的那个预测的 softmax 分数。每种 尺寸都有一个由位置嵌入向量决定的固定输入分辨率:预处理会缩放并中心裁剪到这个分辨率, 传入不同的 imgsz 会直接报错,而不是悄悄重采样。数据源、流式处理和结果处理见 预测

验证

val() 返回一个带 top-1 和 top-5 精度的字典,在按惯例的 train/<class>/val/<class>/ 文件夹结构组织的数据集上测得。

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreDeiTb-cls.pt")metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/accuracy_top1"])print(metrics["metrics/accuracy_top5"])
CLI
libreyolo val model=LibreDeiTb-cls.pt data=my-dataset.yaml

导出

任务ONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
classifyclassify 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。在不装 LibreYOLO 的裸 运行时里跑这张计算图也是支持的,但那样预处理和后处理就得你自己写。

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

检查点

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

文件输入(px)权重许可
classify
LibreDeiTt-cls.pt224apache-2.0
LibreDeiTs-cls.pt224apache-2.0
LibreDeiTb-cls.pt224apache-2.0

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

许可证

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

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

原始工作
DeiT, Meta Research
上游许可
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. LibreYOLO ships the plain tiny, small and base patch-16 classifiers at fixed 224px only; the distillation-token, CaiT, DeiT III and 384px variants from the same repository are out of scope.

引用

@InProceedings{pmlr-v139-touvron21a,
  title =     {Training data-efficient image transformers & distillation through attention},
  author =    {Touvron, Hugo and Cord, Matthieu and Douze, Matthijs and Massa, Francisco and Sablayrolles, Alexandre and Jegou, Herve},
  booktitle = {International Conference on Machine Learning},
  pages =     {10347--10357},
  year =      {2021},
  volume =    {139},
  month =     {July}
}

复制自作者在 github.com/facebookresearch/deit#-model-zoo 上提供的引用块。

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