TinyViT-5M β INT8 ONNX, 80.5% ImageNet in 9.2 MB
This is TinyViT-5M (timm/tiny_vit_5m_224.dist_in22k_ft_in1k, Apache-2.0), quantized to INT8 with Kenosis, Core Epoch's post-training quantizer, using 128 calibration images, a per-model configuration, and no retraining. It holds 80.53% top-1 on ImageNet-1K in a 9.2 MB single file that runs on both ONNX Runtime and OpenVINO, with no GPU required.
Measured accuracy
ImageNet-1K validation, 49,872 images. Calibration and evaluation images are disjoint, and every row was evaluated on identical inputs.
| model | top-1 | Ξ vs FP32 | file size |
|---|---|---|---|
| FP32 baseline | 80.87% | β | 22.1 MB |
| this artifact | 80.53% | β0.34 | 9.23 MB |
| ONNX Runtime static quantization at default calibration, same model, same calibration data | 3.12% | β77.8 | 7.6 MB |
Run it
pip install onnxruntime numpy pillow huggingface_hub
from huggingface_hub import hf_hub_download
import numpy as np
import onnxruntime as ort
from PIL import Image
path = hf_hub_download("CoreEpoch/tinyvit-5m-int8-imagenet", "tinyvit_5m_224_int8.onnx")
sess = ort.InferenceSession(path, providers=["CPUExecutionProvider"])
img = Image.open("your_image.jpg").convert("RGB")
scale = 236 / min(img.size) # shorter side to 236 (224/0.95 crop fraction), then center crop β the measured transform
img = img.resize((round(img.width * scale), round(img.height * scale)), Image.BICUBIC)
l, t = (img.width - 224) // 2, (img.height - 224) // 2
img = img.crop((l, t, l + 224, t + 224))
x = (np.asarray(img, np.float32) / 255.0 - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225]
logits = sess.run(None, {"input": x.transpose(2, 0, 1)[None].astype(np.float32)})[0]
print(int(np.argmax(logits)))
Input: 1x3x224x224, RGB, /255, ImageNet mean/std. Output: logits [1,1000]
in standard sorted-synset class order. run_classify.py and eval_imagenet.py
in this repo reproduce the demo and the full measurement against a local
ImageNet validation copy.
Integrity
tinyvit_5m_224_int8.onnx (9,228,639 bytes). SHA-256:
EC8176F32AEB73B157CEEC792ECA2E7A30C7492D5BDAB97BFD7D5EA57610C75B.
Credits
Base architecture:
@inproceedings{wu2022tinyvit,
title={TinyViT: Fast Pretraining Distillation for Small Vision Transformers},
author={Wu, Kan and Zhang, Jinnian and Peng, Houwen and Liu, Mengchen and Xiao, Bin and Fu, Jianlong and Yuan, Lu},
booktitle={European Conference on Computer Vision (ECCV)},
year={2022}
}
About
Quantized with Kenosis, Core Epoch's post-training quantizer (patent pending). To apply this to your own models: coreepoch.dev Β· core@coreepoch.dev
Model tree for CoreEpoch/tinyvit-5m-int8-imagenet
Base model
timm/tiny_vit_5m_224.dist_in22k_ft_in1k