Cattle & buffalo breed classifier (16 Indian breeds)
Recognises 8 Indian cattle and 8 buffalo breeds from a photo, and says "unsure" with its top guesses when its confidence is low.
- Architecture:
convnext_tiny.fb_in22k_ft_in1k(ConvNeXt-Tiny, ImageNet-22k pretrained, fine-tuned) - Format: ONNX (runs with
onnxruntime, no PyTorch needed) - Input: RGB, 224Γ224, resize shorter side to 256 (bicubic), centre crop, ImageNet mean/std (see
labels.json) - Output: logits for 16 classes, in the order of
labels.jsonβclasses - "Unsure" threshold: 0.45 (top probability below this β unsure)
Results (held-out test set, 508 photos)
| Metric | Value |
|---|---|
| Accuracy | 72.0% |
| Top-3 accuracy | 90.3% |
| Macro-F1 | 0.71 |
| Answered at the "unsure" threshold | 79% of photos (threshold chosen on the validation set) |
| Correct when it answers | 81.5% |
| Breed | Type | Precision | Recall | F1 | Test photos |
|---|---|---|---|---|---|
| Ongole | cow | 0.90 | 0.93 | 0.91 | 28 |
| Hallikar | cow | 0.93 | 0.89 | 0.91 | 28 |
| Kankrej | cow | 0.92 | 0.89 | 0.90 | 26 |
| Gir | cow | 0.77 | 0.96 | 0.85 | 48 |
| Malnad Gidda | cow | 0.82 | 0.88 | 0.85 | 16 |
| Toda | buffalo | 0.80 | 0.90 | 0.85 | 31 |
| Rathi | cow | 0.82 | 0.82 | 0.82 | 22 |
| Sahiwal | cow | 0.90 | 0.72 | 0.80 | 61 |
| Jafarabadi | buffalo | 0.75 | 0.71 | 0.73 | 55 |
| Mehsana | buffalo | 0.89 | 0.61 | 0.73 | 13 |
| Nagpuri | buffalo | 0.72 | 0.55 | 0.63 | 38 |
| Red Sindhi | cow | 0.60 | 0.55 | 0.57 | 22 |
| Murrah | buffalo | 0.50 | 0.65 | 0.57 | 49 |
| Nili-Ravi | buffalo | 0.60 | 0.50 | 0.55 | 30 |
| Bhadawari | buffalo | 0.46 | 0.29 | 0.35 | 21 |
| Surti | buffalo | 0.28 | 0.45 | 0.35 | 20 |
Training data
3383 images after cleaning, from two CC0 (public domain) Kaggle datasets:
lukex9442/indian-bovine-breeds and atharvadarpude/indian-buffalo-dataset.
Cleaning: files checked by content, tiny files and GIFs removed, near-duplicates
removed across both datasets with a difference hash, and photos filed under
different breeds dropped as label noise (548 images). Split 70/15/15 per
breed after de-duplication.
Limitations
- Trained on web photos; accuracy on real farm photos has not been measured yet.
- Buffalo breeds are weaker than cattle breeds (the source folders contain heavy label noise). Common mix-ups: Murrah β Surti, Jafarabadi β Murrah, Sahiwal β Red Sindhi / Gir.
- Only the 16 listed breeds; crossbreeds and other breeds will be forced into one of them or reported as "unsure".
- Not a substitute for expert breed certification.
Usage
from gopalan_ml.breed import BreedClassifier # from the project repository
from huggingface_hub import hf_hub_download
clf = BreedClassifier(hf_hub_download("thearyansingh/cattle-breed-classifier", "breed_classifier.onnx"),
hf_hub_download("thearyansingh/cattle-breed-classifier", "labels.json"))
print(clf.predict(rgb_image_array))
