A modern, AI-powered web application for classifying Indian cattle and buffalo breeds using deep learning. Built with FastAPI, TensorFlow, React, and MongoDB, featuring incremental learning and real-time analytics.
- 29 Indian cattle and buffalo breeds supported
- EfficientNet-B0 transfer learning model
- Grad-CAM visualization showing AI attention areas
- Real-time prediction with confidence scores
- Top-3 predictions with detailed breed information
- Continuous model improvement through user feedback
- Automatic retraining with new data
- Background processing for model updates
- Performance tracking and accuracy monitoring
- React + TypeScript frontend
- Tailwind CSS for beautiful, responsive design
- PWA support for mobile devices
- Real-time analytics dashboard
- Drag & drop image upload
- URL-based image processing
- Real-time statistics and performance metrics
- Breed distribution analysis
- Accuracy trends over time
- User feedback tracking
- Admin dashboard for system management
- Python 3.9+
- Node.js 18+
- MongoDB
- Docker (optional)
-
Clone the repository
git clone https://github.com/yourusername/cattle-breed-classifier.git cd cattle-breed-classifier -
Install Python dependencies
pip install -r requirements.txt
-
Install frontend dependencies
cd frontend npm install cd ..
-
Set up environment variables
cp .env.example .env # Edit .env with your configuration -
Start MongoDB
# Using Docker docker run -d -p 27017:27017 --name mongodb mongo:6.0 # Or install MongoDB locally # Follow MongoDB installation guide for your OS
-
Run the application
# Start backend python -m uvicorn backend.main:app --reload --port 8000 # In another terminal, start frontend cd frontend npm run dev
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
-
Start all services
docker-compose up -d
-
Access the application
- Application: http://localhost
- MongoDB: localhost:27017
-
Build the image
docker build -t cattle-classifier . -
Run the container
docker run -p 8000:8000 -e MONGODB_URL=mongodb://host.docker.internal:27017 cattle-classifier
- FastAPI for high-performance API
- TensorFlow 2.x for deep learning
- MongoDB for data storage
- Motor for async MongoDB operations
- Pydantic for data validation
- React 18 with hooks and context
- TypeScript for type safety
- Tailwind CSS for styling
- React Query for data fetching
- Framer Motion for animations
// Images collection
{
_id: ObjectId,
image_path: String,
predicted_breed: String,
corrected_breed: String,
confidence: Number,
is_reviewed: Boolean,
timestamp: Date,
grad_cam_heatmap: String
}
// Metrics collection
{
_id: ObjectId,
metric_type: String,
timestamp: Date,
accuracy: Number,
progress: Number
}POST /api/predict- Upload image or URL for breed predictionGET /api/breeds- Get list of supported breedsGET /api/breed/{name}- Get detailed breed information
POST /api/feedback- Submit prediction feedbackGET /api/feedback/pending- Get pending reviewsGET /api/feedback/stats- Get feedback statistics
GET /api/stats- Get system statisticsGET /api/stats/trends- Get accuracy trendsGET /api/stats/breed-distribution- Get breed distribution
POST /api/admin/retrain- Start model retrainingGET /api/admin/retrain/status- Get retraining statusGET /api/admin/dashboard- Get admin dashboard data
python train.py --data_dir /path/to/training/data --epochs 50 --fine_tune_epochs 20- Cows: Gir, Sahiwal, Red Sindhi, Tharparkar, Kankrej, Ongole, Rathi, Deoni, Dangi, Hallikar, Amritmahal, Bargur, Kangayam, Kasaragod, Kenkatha, Kherigarh, Malnad Gidda, Nagori, Nimari, Pulikulam, Umblachery, Alambadi
- Buffaloes: Murrah, Jaffarabadi, Mehsana, Nili Ravi, Nagpuri, Banni, Shurti
- Base Model: EfficientNet-B0 (ImageNet pretrained)
- Input Size: 224x224x3
- Output: 29 classes (softmax)
- Optimizer: Adam
- Loss: Categorical Crossentropy
- Offline support with service worker
- Installable on mobile devices
- Push notifications for retraining completion
- Background sync for feedback submission
MONGODB_URL=mongodb://localhost:27017
REDIS_URL=redis://localhost:6379
PORT=8000
PYTHONPATH=/app- Image preprocessing: Resize to 224x224, normalize
- Data augmentation: Rotation, flip, zoom, shear
- Transfer learning: EfficientNet-B0 → Custom head
- Fine-tuning: Unfreeze top layers, lower learning rate
- Model Accuracy: 85-95% (varies by breed)
- Inference Time: <2 seconds per image
- Top-3 Accuracy: 95-98%
- Model Size: ~50MB (TFLite: ~15MB)
- Connect GitHub repository
- Set environment variables
- Deploy automatically
- Create Heroku app
- Add MongoDB addon
- Deploy using Procfile
- Build and push Docker image
- Deploy to Cloud Run
- Configure MongoDB Atlas
- Use container services (ECS, GKE, AKS)
- Configure load balancers
- Set up managed databases
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- TensorFlow Team for the deep learning framework
- FastAPI Team for the excellent web framework
- React Team for the frontend library
- Indian Agriculture Community for breed information
- Open Source Community for various libraries and tools
- Documentation: Wiki
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@cattleclassifier.com
- Mobile app (React Native)
- Multi-language support
- Advanced analytics
- Integration with veterinary databases
- Real-time video classification
- Blockchain-based breed certification
- IoT sensor integration
- AR/VR visualization
Made with ❤️ for Indian Agriculture