ViT-B/16 (ImageNet-21k) fine-tuned on CIFAR-100
Vision Transformer (Dosovitskiy et al., 2021) implemented from scratch in PyTorch, with the official ViT-B/16 weights (Google, ImageNet-21k) loaded 1:1 into the implementation and fine-tuned on CIFAR-100.
| Architecture | ViT, D=768, 12 blocks, 12 heads, MLP 3072, patch 16, input 224px |
| Parameters | 85.9M |
| Dataset | CIFAR-100 |
| Test top-1 | 91.31% |
| Test top-5 | 99.00% |
Training
{
"variant": "B/16",
"img_size": 224,
"batch_size": 512,
"micro_batch": 32,
"steps": 500,
"lrs": [
0.03
],
"momentum": 0.9,
"warmup_steps": 25,
"grad_clip": 1.0,
"dropout": 0.0,
"log_every": 25,
"best_lr": 0.03
}
Usage
pip install git+https://github.com/AdrianKazi/ViT
import torch
from PIL import Image
from datasets import load_dataset_builder
from vit.data import finetune_transforms
from vit.hub import from_pretrained
model = from_pretrained("AdrianSK/vit-b16-in21k-cifar100").eval()
names = load_dataset_builder("uoft-cs/cifar100").info.features["fine_label"].names
_, tf = finetune_transforms(224)
img = Image.open("image.jpg").convert("RGB")
with torch.no_grad():
probs = model(tf(img)[None]).softmax(-1)[0]
for p, i in zip(*probs.topk(5)):
print(f"{names[i]:15s} {p:.3f}")
Inputs: RGB images resized to 224x224, pixels scaled to [-1, 1]. Classes: the 100 CIFAR-100 fine labels.