Downloads · 30 days
9
5% of all-time downloads
vishnuamar/cattle-breed-classifier
cattle-breed-classifier is a image classification model from vishnuamar. Use it when you need a label for an image. The card lists the license as apache-2.0.
This model classifies cattle and buffalo breeds using computer vision. It's based on ResNet-50 architecture and trained to recognize 10 different breeds.
Downloads · 30 days
9
5% of all-time downloads
All-time downloads
170
Public
Repo size
95.3 MB
Likes
0
Public
Click a slice to open those files.
.onnx94 MB · 98%
From the Hugging Face model README
This model classifies cattle and buffalo breeds using computer vision. It's based on ResNet-50 architecture and trained to recognize 10 different breeds.
from huggingface_hub import hf_hub_download
import onnxruntime as ort
import numpy as np
import json
from PIL import Image
from torchvision import transforms
def setup_model():
print("📥 Downloading model from Hugging Face...")
model_path = hf_hub_download("vishnuamar/cattle-breed-classifier", "model.onnx")
prototypes_path = hf_hub_download("vishnuamar/cattle-breed-classifier", "prototypes.json")
session = ort.InferenceSession(model_path)
with open(prototypes_path, 'r') as f:
prototypes = json.load(f)
print("✅ Model ready!")
return session, prototypes
def predict_breed(session, prototypes, image_path):
image = Image.open(image_path).convert('RGB')
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
input_data = transform(image).unsqueeze(0).numpy()
features = session.run(None, {'input': input_data})[0][0]
similarities = {}
for breed, prototype in prototypes['prototypes'].items():
similarity = np.dot(features, np.array(prototype))
similarities[breed] = float(similarity)
predicted_breed = max(similarities, key=similarities.get)
confidence = similarities[predicted_breed]
buffalo_breeds = ['Bhadawari', 'Jaffarbadi', 'Mehsana', 'Murrah', 'Surti']
animal_type = 'Buffalo' if predicted_breed in buffalo_breeds else 'Cattle'
return {
'breed': predicted_breed,
'confidence': confidence,
'animal_type': animal_type,
'all_scores': similarities
}
if __name__ == "__main__":
session, prototypes = setup_model()
image_path = "path/to/your/image.jpg" # Change this to your test image
result = predict_breed(session, prototypes, image_path)
print(f"\n🐄 Animal: {result['animal_type']}")
print(f"Breed: {result['breed']}")
print(f"Confidence: {result['confidence']:.4f}")
// React Native example
import { ONNX } from 'onnxjs-react-native';
const model = new ONNX.InferenceSession();
await model.loadModel('path/to/model.onnx');
const prediction = await model.run([preprocessedImageTensor]);
// Process with prototypes for final classification
model.onnx: The trained ONNX modelprototypes.json: Breed prototype vectors for classificationconfig.json: Model configuration and metadatasample_images/: Example images for testingApache 2.0
If you use this model, please cite:
@misc{cattle-breed-classifier,
title={Cattle and Buffalo Breed Classification Model},
author={Your Name},
year={2025},
publisher={Hugging Face},
url={https://huggingface.co/your-username/cattle-breed-classifier}
}
For questions or issues, please open an issue in the model repository.