File size: 5,573 Bytes
3a65321 8e5bbaf 3a65321 8e5bbaf 3a65321 bd81886 3a65321 bd81886 3a65321 8e5bbaf 3a65321 8e5bbaf 3a65321 8e5bbaf 3a65321 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | ---
license: bsd-3-clause
tags:
- vision
- image-classification
- transformer
datasets:
- imagenet-1k
---
<div align="center">
# ViT for TI EdgeAI
### Pure Transformer for Image Classification at Scale
[](https://opensource.org/licenses/BSD-3-Clause)
[](https://onnx.ai/)
[](https://github.com/TexasInstruments/edgeai)
[](http://www.image-net.org/)
</div>
---
## Overview
**ViT** (Vision Transformer) applies the standard Transformer architecture directly to sequences of non-overlapping image patches — no convolutions. Introduced in [*An Image is Worth 16x16 Words*](https://arxiv.org/abs/2010.11929) (Dosovitskiy et al., ICLR 2021), ViT demonstrates that a pure transformer pre-trained on large data transfers strongly to standard image recognition benchmarks.
Pretrained weights are sourced from **torchvision** (BSD-3-Clause), trained on ImageNet-1K using a DeiT-style recipe. Each exported ONNX model is a single-input classification graph that outputs 1000-class ImageNet logits `[1, 1000]`.
---
## Model Variants
| Model | Architecture | Params | Top-1 Acc | Validated Devices | Config |
|-------|-------------|--------|-----------|--------------------|--------|
| `vit_b_16` | ViT-Base/16 | 86.6M | 81.1% | TDA4VH | [vit_b_16_config.yaml](vit_b_16_config.yaml) |
| `vit_b_32` | ViT-Base/32 | 88.2M | 75.9% | TDA4VH | [vit_b_32_config.yaml](vit_b_32_config.yaml) |
| `vit_l_16` | ViT-Large/16 | 304.3M | 79.7% | TDA4VH | [vit_l_16_config.yaml](vit_l_16_config.yaml) |
| `vit_l_32` | ViT-Large/32 | 306.5M | 77.0% | TDA4VH | [vit_l_32_config.yaml](vit_l_32_config.yaml) |
**Recommended for edge deployment:** `vit_b_16` (best accuracy/compute trade-off)
---
## Quick Start
### Prerequisites
```bash
pip install torch torchvision onnx>=1.22.0 onnxruntime>=1.23.2
# Optional but recommended for model optimization:
pip install onnx-simplifier
```
### Export the Model
```bash
# Export the default model (vit_b_16)
python prepare_model.py
# Export a specific model variant
python prepare_model.py --model vit_b_32
# Export all supported models
python prepare_model.py --model all
# List all available variants
python prepare_model.py --list-models
```
The script automatically:
- Downloads pretrained ImageNet-1K weights from torchvision (first run only)
- Exports the model to ONNX (opset 17) with static input shape `[1, 3, 224, 224]`
- Runs ONNX shape inference
- Optionally simplifies the graph with onnx-simplifier
### Compile and Infer uing edgeai-tidlrunner
> **Note:** Run the commands below from inside the `tidlrunner` directory (the cloned [edgeai-tidlrunner](https://github.com/TexasInstruments/edgeai-tidlrunner) repository), with `--config_path` pointing to this model's config file.
**Compile using edgeai-tidlrunner - on PC**
```bash
cd /path/to/edgeai-tidlrunner
tidlrunner-cli compile --target_device J784S4 \
--config_path /path/to/vit_b_16_config.yaml
```
**Run Inference Benchmark - on device**
```bash
cd /path/to/edgeai-tidlrunner
tidlrunner-cli infer --target_device J784S4 \
--config_path /path/to/vit_b_16_config.yaml
```
### Compile and Infer using edgeai-tidl-tools (Advanced):
Follow the instructions at https://github.com/TexasInstruments/edgeai-tidl-tools
### Deploy using edgeai-tidl-tools:
Deplyment can be done using **[edgeai-tidl-tools](https://github.com/TexasInstruments/edgeai-tidl-tools)**. For ONNX models, onnxruntime-tidl with TIDL acceleration can be used. Consult the documentation of edgeai-tidl-tools for more details.
---
## Citation
```bibtex
@inproceedings{dosovitskiy2021image,
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},
booktitle = {International Conference on Learning Representations (ICLR)},
year = {2021},
url = {https://arxiv.org/abs/2010.11929}
}
```
---
## 🔗 Resources
| Resource | Link |
|----------|------|
| **Paper** | [arXiv:2010.11929](https://arxiv.org/abs/2010.11929) |
| **Source Code** | [pytorch/vision](https://github.com/pytorch/vision) |
| **Torchvision Docs** | [VisionTransformer](https://docs.pytorch.org/vision/main/models/vision_transformer.html) |
| **edgeai-tidl-tools** | [GitHub](https://github.com/TexasInstruments/edgeai-tidl-tools) |
| **edgeai-tidlrunner** | [GitHub](https://github.com/TexasInstruments/edgeai-tidlrunner) |
| **EdgeAI SDK** | [Documentation](https://github.com/TexasInstruments/edgeai/blob/main/edgeai-mpu/readme_sdk.md) |
---
## Related Models
<table>
<tr>
<td align="center">
**DINOv2**
Self-supervised ViT
Higher accuracy
</td>
<td align="center">
**DINO**
Self-supervised ViT
Linear classification head
</td>
<td align="center">
**ResNet**
CNN baseline
Lower compute
</td>
<td align="center">
**MobileNetV3**
Lightweight CNN
Built for edge
</td>
</tr>
</table>
---
<div align="center">
**Maintained by:** Texas Instruments EdgeAI Team
**Last Updated:** August 2026
</div>
|