metadata
license: apache-2.0
tags:
- cattle-breed-classification
- buffalo-breed-classification
- livestock-recognition
- agriculture
- computer-vision
- onnx
- resnet50
pipeline_tag: image-classification
base_model: microsoft/resnet-50
Cattle & Buffalo Breed Classification Model
This model classifies cattle and buffalo breeds using computer vision. It's based on ResNet-50 architecture and trained to recognize 10 different breeds.
Model Description
- Model Type: Feature extraction + similarity matching
- Architecture: ResNet-50 backbone with L2 normalization
- Format: ONNX (89.6MB)
- Input: RGB images (224x224)
- Output: 2048-dimensional feature vectors
- Classification: Cosine similarity with breed prototypes
Supported Breeds
Buffalo Breeds (5)
- Bhadawari
- Jaffarbadi
- Mehsana
- Murrah
- Surti
Cattle Breeds (5)
- Gir
- Kankrej
- Ongole
- Sahiwal
- Tharparkar
Usage
Using ONNX Runtime
import onnxruntime as ort
import numpy as np
from PIL import Image
import json
# Load model
session = ort.InferenceSession('model.onnx')
# Load breed prototypes
with open('prototypes.json', 'r') as f:
prototypes = json.load(f)
# Preprocess image
def preprocess_image(image_path):
from torchvision import transforms
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]
)
])
image = Image.open(image_path).convert('RGB')
tensor = transform(image).unsqueeze(0)
return tensor.numpy()
# Predict breed
def predict_breed(image_path):
# Get features
input_data = preprocess_image(image_path)
features = session.run(None, {'input': input_data})[0][0]
# Calculate similarities
similarities = {}
for breed, prototype in prototypes['prototypes'].items():
similarity = np.dot(features, prototype)
similarities[breed] = float(similarity)
# Get top prediction
predicted_breed = max(similarities, key=similarities.get)
confidence = similarities[predicted_breed]
return predicted_breed, confidence, similarities
# Example usage
breed, confidence, all_scores = predict_breed('path/to/image.jpg')
print(f"Predicted breed: {breed}")
print(f"Confidence: {confidence:.4f}")
Integration with Mobile Apps
// 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 Performance
- Inference Time: ~45-50ms (CPU)
- Model Size: 89.6MB
- Accuracy: Optimized for livestock breed recognition
- Platforms: Cross-platform (ONNX Runtime support)
Files Included
model.onnx: The trained ONNX modelprototypes.json: Breed prototype vectors for classificationconfig.json: Model configuration and metadatasample_images/: Example images for testing
Technical Details
- Feature Extraction: ResNet-50 backbone → 2048-dim features
- Normalization: L2 normalization applied to features
- Classification: Cosine similarity with pre-computed breed prototypes
- Preprocessing: ImageNet-style normalization (mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
License
Apache 2.0
Citation
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}
}
Contact
For questions or issues, please open an issue in the model repository.