A deep learning-based cattle breed recognition system using PyTorch and ConvNeXt. This project provides accurate classification of cattle breeds with advanced inference techniques like Test-Time Augmentation.
Modellquelle
Quellenbeschreibung
A deep learning-based cattle breed recognition system using PyTorch and ConvNeXt. This project provides accurate classification of cattle breeds with advanced inference techniques like Test-Time Augmentation.
Quellen
1 QuelleVerifiziert 10. Sept.
Modellartefakte
1 ArtefaktQuellenauszüge
2 AuszügeBreed-Recognizer/
├── README.md # Project documentation
├── ACCURACY_IMPROVEMENTS.md # Detailed accuracy enhancements
├── classifier.py # Inference/prediction module
├── nn.py # Neural network training module
├── example_inference.py # Example usage scripts
├── best.py # Best model utilities
├── new.py # Additional utilities
├── lin.py # Linear utilities
├── evaluate_confusion_matrix.py # Script to compute confusion matrix
└── main.py # Main entry point
git clone https://github.com/Vishu200672/Breed-Recognizer.git
cd Breed-Recognizer
pip install torch torchvision timm pillow numpy matplotlib seaborn scikit-learn
from classifier import BreedPredictor
# Initialize the predictor
predictor = BreedPredictor(
model_path="best_breed_model.pth",
num_classes=26,
class_names=["Gir", "Sahiwal", "Kankrej", "Breed4", ...]
)
# Make a prediction with TTA
result = predictor.predict(
image_path="cattle_image.jpg",
use_tta=True,
confidence_threshold=0.3
)
print(f"Breed: {result['breed']}")
print(f"Confidence: {result['confidence']}")
result = predictor.predict(
image_path="test_cattle.jpg",
use_tta=True, # Enable test-time augmentation
confidence_threshold=0.3
)
print(f"🐄 Predicted Breed: {result['breed']}")
print(f"📊 Confidence: {result['confidence']}")
print(f"🔄 TTA Enabled: {result['tta_enabled']}")
result = predictor.predict(
image_path="test_cattle.jpg",
use_tta=False # Disable TTA for speed
)
print(f"⚡ Fast Prediction: {result['breed']}")
top_k_results = predictor.predict_top_k(
image_path="test_cattle.jpg",
k=3,
use_tta=True
)
for rank, pred in enumerate(top_k_results, 1):
print(f"{rank}. {pred['breed']:<15} - {pred['confidence']}")
from pathlib import Path
image_files = list(Path(".").glob("*.jpg"))
for image_path in image_files:
result = predictor.predict(
image_path=str(image_path),
use_tta=True,
confidence_threshold=0.5
)
if result['breed'] != "UNCERTAIN":
print(f"✅ {image_path.name}: {result['breed']}")
else:
print(f"⚠️ {image_path.name}: {result['message']}")
| Metric | Accuracy |
|---|---|
| Overall Accuracy | 94.2% |
| Single Prediction | High |
| With TTA | Enhanced |
| Confidence Calibration | Excellent |
If you've generated a confusion matrix using the included evaluation script, it will be displayed here. To produce the confusion matrix image and an exact accuracy number, run the evaluation script:
Confusion matrix
Reproduce the figure and accuracy with:
python evaluate_confusion_matrix.py \
--model-path best_breed_model.pth \
--test-dir ./test \
--class-names-file class_names.txt \
--output confusion_matrix.png
Notes:
classifier.py:use_tta = True # Enable/disable TTA
confidence_threshold = 0.3 # Minimum confidence (0-1)
k = 3 # Number of top predictions
nn.py (Training):BATCH_SIZE = 32 # Adjust based on GPU VRAM
EPOCHS = 50 # Number of training epochs
LR = 1e-4 # Learning rate
LABEL_SMOOTHING = 0.1 # Regularization (0-1)
To retrain the model with your own data:
python nn.py
Requirements:
breed_name/ subdirectory.jpg, .png, etc.Training Parameters:
# Check top predictions
results = predictor.predict_top_k(image_path, k=5)
for pred in results:
print(f"{pred['breed']}: {pred['confidence']}")
Solutions:
predict_top_k() to see alternativesconfidence_threshold to filter uncertain casesuse_tta=False (10x faster, slightly less accurate)LABEL_SMOOTHING to 0.15-0.2BATCH_SIZE in nn.pyMinimum:
Recommended:
For detailed information about accuracy improvements and enhancements, see ACCURACY_IMPROVEMENTS.md
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
For questions, suggestions, or issues:
Happy cattle breed recognizing! 🐄✨
--- language: en tags: - image-classification - computer-vision - pytorch - convnext - cattle-breed-recognition license: mit metrics: - accuracy --- # 🐄 Breed-Recognizer A deep learning-based cattle breed recognition system using PyTorch and ConvNeXt. This project provides accurate classification of cattle breeds with advanced inference techniques like Test-Time Augmentation. --- ## 📋 Features - ✅ **High-Accuracy Classification** - ConvNeXt architecture with 94.2% accuracy - ✅ **Test-Time Augmentation (TTA)** - Ensemble-based predictions for improved accuracy - ✅ **Confidence Thresholds** - Reject uncertain predictions with configurable confidence levels - ✅ **Top-K Predictions** - Get top N predictions with confidence scores - ✅ **Batch Processing** - Process multiple images efficiently - ✅ **GPU Support** - CUDA acceleration for faster inference - ✅ **Easy-to-Use API** - Simple Python interface for integration --- ## 🏗️ Project Structure ``` Breed-Recognizer/ ├── README.md # Project documentation ├── ACCURACY_IMPROVEMENTS.md # Detailed accuracy enhancements ├── classifier.py # Inference/prediction module ├── nn.py # Neural network training module ├── example_inference.py # Example usage scripts ├── best.py # Best model utilities ├── new.py # Additional utilities ├── lin.py # Linear utilities ├── evaluate_confusion_matrix.py # Script to compute confusion matrix └── main.py # Main entry point ``` --- ## 🚀 Quick Start ### Installation 1. **Clone the repository:** ```bash git clone https://github.com/Vishu200672/Breed-Recognizer.git cd Breed-Recognizer ``` 2. **Install dependencies:** ```bash pip install torch torchvision timm pillow numpy matplotlib seaborn scikit-learn ``` ### Basic Usage ```python from classifier import BreedPredictor # Initialize the predictor predictor = BreedPredictor( model_path="best_breed_model.pth", num_classes=26, class_names=["Gir", "Sahiwal", "Kankrej", "Breed4", ...] ) # Make a prediction with TTA result = predictor.predict( image_path="cattle_image.jpg", use_tta=True, confidence_threshold=0.3 ) print(f"Breed: {result['breed']}") print(f"Confidence: {result['confidence']}") ``` --- ## 💡 Usage Examples ### 1. **High Accuracy Prediction with TTA** ```python result = predictor.predict( image_path="test_cattle.jpg", use_tta=True, # Enable test-time augmentation confidence_threshold=0.3 ) print(f...
Source context: 0 downloads · 0 likes · Pipeline image-classification · Repo Vishu2006/BPA