Cattle & buffalo breed classifier
recognition of 16 Indian livestock breeds
2 min readupdated
The model identifies 8 Indian cattle breeds and 8 buffalo breeds from a photograph, and when confidence is low, it honestly outputs "unsure" and displays the most likely options. It is built on the compact convolutional architecture convnext_tiny.fb_in22k_ft_in1k (ConvNeXt-Tiny pre-trained on ImageNet-22k) by author thearyansingh. Unlike heavy models that require PyTorch, the weights are exported to the ONNX format (a cross-platform format for fast deployment of AI models without extra dependencies). This solution is useful for developers of agritech applications and farm monitoring services.
Key features
- Recognizes 16 specific breeds: 8 cattle breeds (Gir, Sahiwal, Ongole, Hallikar, Kankrej, Malnad Gidda, Rathi, Red Sindhi) and 8 buffalo breeds (Murrah, Jafarabadi, Nagpuri, Toda, Nili-Ravi, Bhadawari, Surti, Mehsana).
- Fallback mechanism: if the maximum class probability is below the 0.45 threshold, the model flags the image as "unsure" and shows the top guesses.
- Lightweight inference via
onnxruntime— running it does not require installing PyTorch. - Trained on a cleaned set of 3,383 photographs from two public Kaggle datasets with duplicate removal and label noise cleanup.
What you can do
- Integrate into a mobile application or Telegram bot for quick preliminary assessment of livestock breeds from photos on the farm.
- Use in web services for cataloging and automatically sorting animal photographs into databases.
Example
from gopalan_ml.breed import BreedClassifier
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))
Read more
DetailsMetrics on the test set (508 photos): Accuracy — 72.0%, Top-3 accuracy — 90.3%, Macro-F1 — 0.71.
At a confidence threshold of 0.45, the model answers 79% of images with an accuracy of 81.5%.
Input: RGB image 224×224 (resize shorter side to 256, center crop, ImageNet normalization).
Limitations: trained on internet photos, buffalo breeds are recognized worse than cattle (especially Surti and Bhadawari), crossbreeds and other breeds are not supported.










Comments