--- 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 ```python 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}") ``` ### Integration with Mobile Apps ```javascript // 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 model - `prototypes.json`: Breed prototype vectors for classification - `config.json`: Model configuration and metadata - `sample_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.