Cattle Breed Classifier
From cattle photos to breed predictions with Vision Transformer and Gated Attention.
5 cattle breeds 2026
Overview
Classification-cow is an image-based cattle breed classifier deployed on Hugging Face Spaces. It recognizes Ayrshire, Brown Swiss, Holstein Friesian, Jersey, and Red Dane. The application makes the thesis project accessible through a browser: upload a cattle photo, inspect the predicted breed, and compare probabilities across the five classes.
Images are converted to RGB, resized to 224 by 224 pixels, and normalized using ImageNet statistics. ViT-Base/16 produces token representations that pass through a residual Gated Attention block. The refined CLS token feeds a LayerNorm and five-class linear classifier. The project README reports approximately 94.02% test accuracy for its 80:20 split; this is the documented experiment result, not a guarantee for new field images.
PyTorch and Transformers power inference, with a FastAPI service behind a Streamlit interface. Detailed inference exposes real intermediate tensors, including gate activations, the refined CLS representation, and logits. Docker packages the interface, internal API, and trained checkpoint for deployment on Hugging Face Spaces.
Key features
Predictions with probabilities
Image uploads return the predicted breed, confidence, ranked alternatives, and probabilities for all five supported classes.
Inspect the model pipeline
Explore image patches, gate activations, feature values, and raw logits through visualizations, tables, and downloadable data.
Breed reference library
An illustrated breed encyclopedia provides reference information and photos alongside the classification workflow.
Research available online
A Docker-based Hugging Face Space serves the Streamlit interface, with FastAPI handling inference internally in the same container.