Bektur756/vit-cats-dogs-pandas
025
ViT Cats, Dogs and Pandas Classifier
Vision Transformer image classifier for three classes:
0: cats1: dogs2: panda
Base model
google/vit-base-patch16-224
The classifier uses the output representation of the first [CLS] token and a Linear(768, 3) classification head.
Dataset
Melisa13/Animals_dataset
Exact image duplicates between splits: 0.
Image preprocessing
- RGB input
- Resize and crop to
224×224 - Patch size:
16×16 - 196 image patches
- 197 tokens including
[CLS] - Normalization mean:
(0.5, 0.5, 0.5) - Normalization standard deviation:
(0.5, 0.5, 0.5)
Fine-tuning
The following components were trainable:
- Transformer blocks 10 and 11
- Final LayerNorm
Linear(768, 3)classifier
Results
Test classification report:
End-to-end latency
Latency includes image preprocessing and model inference with batch size 1.
Usage
from PIL import Image
import torch
from transformers import (
AutoImageProcessor,
AutoModelForImageClassification,
)
MODEL_NAME = "Bektur756/vit-cats-dogs-pandas"
processor = AutoImageProcessor.from_pretrained(
MODEL_NAME
)
model = AutoModelForImageClassification.from_pretrained(
MODEL_NAME
)
image = Image.open(
"animal.jpg"
).convert(
"RGB"
)
inputs = processor(
images=image,
return_tensors="pt",
)
with torch.inference_mode():
logits = model(
**inputs
).logits
probabilities = torch.softmax(
logits,
dim=-1,
)[0]
predicted_id = int(
probabilities.argmax()
)
print(
model.config.id2label[
predicted_id
]
)
print(
probabilities.tolist()
)
## Limitations
- The test split contains only 120 images.
- The dataset is small and relatively simple.
- Perfect test accuracy does not imply perfect performance on arbitrary images.
- CPU inference is substantially slower than GPU inference.
