ViT
The classic Vision Transformer: a pure transformer applied to fixed-size image patches, with a learned class token and no convolutions. LibreYOLO ships four AugReg-pretrained sizes for image classification.
- Tasks
- classify
- Sizes
- ti, s, b, l at 224 px
- Install
pip install libreyolo- Support tier
- Inference only, since v. Predict, validate and export only. Training features do not apply.
- Licenses
- Code Apache-2.0, weights Apache-2.0. Commercial use
Install
ViT needs no optional extra. Everything it imports is in the base install.
pip install libreyoloPredict
Weights download from Hugging Face on first use and are cached locally.
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreViTti-cls.pt")result = model(SAMPLE_IMAGE, save=True) probs = result.probsprint(probs.top1, probs.top1conf)print(probs.top5, probs.top5conf)libreyolo predict model=LibreViTti-cls.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=TrueA classifier returns result.probs instead of result.boxes: top1
and top5 give class indices, top1conf and top5conf give their
confidences. Preprocessing resizes and center-crops to a fixed 224px input,
using timm's AugReg evaluation recipe: bicubic interpolation at a 0.9 crop
fraction. See prediction for sources, streaming and result
handling.
Variants
Four sizes, tiny through large, sharing one fixed 224px, patch-16 graph and differing in embedding width and transformer depth. LibreYOLO ships this family inference-only: prediction, ImageNet-style top-1/top-5 validation and export are supported, and the AugReg fine-tuning recipe is not implemented.
Validate
val() runs against an ImageFolder-style split (a directory with train/ and
val/ subfolders, one folder per class) and returns top-1 and top-5 accuracy.
from libreyolo import LibreYOLO model = LibreYOLO("LibreViTti-cls.pt") # data is a directory root with train/ and val/ class-folder splits# (ImageFolder layout), not a dataset YAML.metrics = model.val(data="imagenet-1k/") print(metrics["metrics/accuracy_top1"])print(metrics["metrics/accuracy_top5"])libreyolo val model=LibreViTti-cls.pt data=imagenet-1k/Export
| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| classify | classify to ONNX: supported. | classify to TorchScript: supported. | classify to ExecuTorch: supported. | classify to TensorRT: supported. | classify to OpenVINO: supported. | classify to Paddle: not supported | classify to MNN: not supported | classify to RKNN: not supported | classify to ncnn: supported. | classify to TFLite: not supported | classify to CoreML: not supported | classify to Core AI: not supported |
An exported artifact loads back through LibreYOLO() on its file suffix, so a
.onnx or .engine file behaves like a checkpoint and returns the same
Results. Export lists the arguments every format accepts and
the extras a few of them add.
from libreyolo import LibreYOLO model = LibreYOLO("LibreViTti-cls.pt")model.export(format="onnx")model.export(format="tensorrt", half=True)libreyolo export model=LibreViTti-cls.pt format=onnxlibreyolo export model=LibreViTti-cls.pt format=tensorrt half=Truefrom libreyolo import LibreYOLO, SAMPLE_IMAGE # The factory routes on the file suffix, so an exported artifact loads# like any checkpoint and returns the same Results object.model = LibreYOLO("LibreViTti-cls.onnx")result = model(SAMPLE_IMAGE) print(result.probs.top1)Checkpoints
Every published weight file for this family.
| File | Input (px) | Weights license |
|---|---|---|
| classify | ||
| LibreViTti-cls.pt | 224 | apache-2.0 |
| LibreViTs-cls.pt | 224 | apache-2.0 |
| LibreViTb-cls.pt | 224 | apache-2.0 |
| LibreViTl-cls.pt | 224 | apache-2.0 |
Every file above exists in the LibreYOLO org today and downloads on first use.
Licensing
Check the license on the Hugging Face repository of the specific weights you download. Every checkpoint in the LibreYOLO org carries one, and they are not always the same across a family. That repository is the authoritative source; the summary below describes what applied when this page was last verified.
This is a description of the licenses involved, not legal advice. If the answer matters commercially, read the licenses yourself and take your own counsel.
- Original work
- ViT, Google Research
- Upstream license
- Apache-2.0
- Upstream source
- github.com/google-research/vision_transformer
- LibreYOLO code
- MIT
- Weights
- Apache-2.0, republished at huggingface.co/LibreYOLO
- Interpretation
- 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. LibreYOLO's runtime code for this family is a derived port of the Apache-2.0 timm Vision Transformer implementation (Ross Wightman, huggingface/pytorch-image-models), kept checkpoint-compatible with the shipped tensors. The four AugReg checkpoints themselves are timm's Apache-2.0 conversion of Google Research's own AugReg pretraining, so the code and the weights carry the same permissive terms end to end.
Citation
@article{dosovitskiy2020vit,
title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
author={Dosovitskiy, Alexey and Beyer, Lucas and Kolesnikov, Alexander and Weissenborn, Dirk and Zhai, Xiaohua and Unterthiner, Thomas and Dehghani, Mostafa and Minderer, Matthias and Heigold, Georg and Gelly, Sylvain and Uszkoreit, Jakob and Houlsby, Neil},
journal={ICLR},
year={2021}
}
@article{steiner2021augreg,
title={How to train your ViT? Data, Augmentation, and Regularization in Vision Transformers},
author={Steiner, Andreas and Kolesnikov, Alexander and and Zhai, Xiaohua and Wightman, Ross and Uszkoreit, Jakob and Beyer, Lucas},
journal={arXiv preprint arXiv:2106.10270},
year={2021}
}Copied from the authors' citation block at github.com/google-research/vision_transformer#bibtex.