Views
No views yet
google/vit-base-patch16-224 (Vision Transformer, base, patch size 16, 224×224 input). Single self-contained .onnx file, no external weights.pixel_values, shape (batch, 3, 224, 224), float32, normalized with mean/std (0.5, 0.5, 0.5)logits, shape (batch, 1000), float32float32). No quantization or pruning has been applied.onnxruntime, numpy, Pillow, and requests are required — no transformers / PyTorch needed.1import io, json, requests, numpy as np, onnxruntime as ort
2from PIL import Image
3
4sess = ort.InferenceSession("vit-base-patch16-224.onnx", providers=["CPUExecutionProvider"])
5
6# 1) Load image
7url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png"
8image = Image.open(io.BytesIO(requests.get(url, timeout=30).content)).convert("RGB")
9
10# 2) Preprocess: resize to 224x224, scale to [0,1], normalize with mean=std=0.5, CHW, add batch
11image = image.resize((224, 224), Image.BILINEAR)
12arr = np.asarray(image, dtype=np.float32) / 255.0
13arr = (arr - 0.5) / 0.5
14pixel_values = arr.transpose(2, 0, 1)[None] # shape (1, 3, 224, 224)
15
16# 3) Run
17logits = sess.run(None, {"pixel_values": pixel_values})[0] # (1, 1000)
18pred = int(logits.argmax(-1)[0])
19
20# 4) (Optional) map index -> ImageNet-1k class name
21labels = requests.get(
22 "https://huggingface.co/datasets/huggingface/label-files/raw/main/imagenet-1k-id2label.json",
23 timeout=30,
24).json()
25print(pred, "->", labels[str(pred)])google/vit-base-patch16-224 (PyTorch safetensors)torch.onnx.export (PyTorch 2.11, dynamo path)pixel_values and logitsViTForImageClassification module is wrapped to return only logits (the HF ImageClassifierOutput is dropped) so the ONNX graph has a single named output.onnx file (≈330 MB)| Tensor | max abs err | max rel err | cosine sim |
|---|---|---|---|
| logits | 1.34e-05 | 8.00e-04 | 1.0000000000 |
| softmax probs | 1.19e-07 | 1.52e-05 | 1.0000000000 |