A collection of two deep learning computer vision projects for practical applications: Coffee Bean Classification and Meat Quality Detection. Both projects utilize transfer learning with ResNet architectures and feature user-friendly GUI applications for real-time predictions.
An intelligent system that automatically classifies coffee bean roast levels into 4 categories:
- Dark Roast: Deep brown color, oily surface
- Green Beans: Raw, unroasted coffee beans
- Light Roast: Light brown color, dry surface
- Medium Roast: Medium brown color, even roasting
An AI-powered system that classifies meat quality as Fresh or Spoiled using deep learning, helping ensure food safety and quality control.
- Python: 3.8 or higher (3.9+ recommended)
- Operating System: Windows 10/11, Linux, or macOS
- RAM: Minimum 8GB (16GB recommended)
- GPU: Optional but recommended for faster training (NVIDIA GPU with CUDA support)
-
Clone the repository
git clone <repository-url> cd KT27-AI_Vision_Further_Applications-main
-
Install dependencies
For Coffee Bean project:
cd "Coffee Bean" pip install -r requirements.txt
For Meat Quality project:
cd "Meat Quality" pip install -r requirements.txt
Or install for both projects from root:
pip install -r "Coffee Bean/requirements.txt" pip install -r "Meat Quality/requirements.txt"
-
Optional: GPU Support (if you have NVIDIA GPU)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Coffee Bean/
├── train_coffee_bean.py # Training script with advanced features
├── gui_coffee_bean.py # GUI application for predictions
├── requirements.txt # Python dependencies
├── README.md # Detailed project documentation
└── data_analysis.png # Dataset analysis visualization
Training Features:
- ✅ Transfer learning with pretrained ResNet50
- ✅ Advanced data preprocessing and analysis
- ✅ Multiple data augmentation strengths (light/medium/strong)
- ✅ Early stopping mechanism
- ✅ Cross-validation support (5-fold)
- ✅ Test-time augmentation (TTA)
- ✅ Gradient clipping
- ✅ Adaptive learning rate scheduling
- ✅ Automatic checkpoint saving
- ✅ Rich visualizations (training curves, confusion matrix, etc.)
GUI Features:
- 📁 Upload Image: Select local image for prediction
- 🎲 Random Test: Randomly select image from training or test set
- 📷 Camera Prediction: Real-time camera prediction
- 🎯 Start Prediction: Classify current image
- 📊 Detailed Results: Display predicted class, confidence, timestamp, and full probability distribution
1. Train the Model
cd "Coffee Bean"
python train_coffee_bean.pyAfter training, the following files will be generated:
coffee_bean_classifier.pth- Trained model filebest_model_checkpoint.pth- Best model checkpointdata_analysis.png- Dataset analysis charttraining_history.png- Training history chartconfusion_matrix.png- Confusion matrix chart
2. Run the GUI Application
python gui_coffee_bean.py- Training Accuracy: 95%+
- Validation Accuracy: 90%+
- Test Accuracy: 85%+
- Backbone: ResNet50 (pretrained)
- Classifier: Two fully connected layers + Dropout
- Input Size: 224×224×3
- Output Classes: 4 classes
Meat Quality/
├── train_meat_quality.py # Standard training script
├── train_meat_quality_optimized.py # CPU-optimized training
├── train_resnet_transfer_learning.py # Advanced training with enhanced features
├── train_meat_quality_cv.py # Cross-validation training
├── quick_train.py # Quick start training script
├── meat_quality_gui.py # GUI application
├── requirements.txt # Python dependencies
├── setup_environment.bat # Windows setup script
├── setup_environment.sh # Linux/Mac setup script
├── README.md # Detailed project documentation
└── README_TRAINING.md # Detailed training guide
Training Scripts:
train_meat_quality.py: Standard training with ResNet variants (18, 34, 50, 101)train_meat_quality_optimized.py: CPU-optimized training with lightweight ResNet-18train_resnet_transfer_learning.py: Advanced training with enhanced featurestrain_meat_quality_cv.py: Cross-validation training for robust evaluationquick_train.py: Quick start training script for beginners
GUI Features:
- 📁 Single Image Prediction: Upload and analyze individual images
- 📂 Batch Processing: Process multiple images simultaneously
- 📹 Real-time Camera Detection: Live analysis using webcam
- 💾 Results Export: Save predictions in CSV/JSON format
- 📊 Statistical Analysis: Visual charts and prediction history
- 🎨 Modern UI: Professional dark theme interface
Your dataset should be organized as follows:
meat_quality/
├── Fresh/
│ ├── image1.jpg
│ ├── image2.jpg
│ └── ... (948 images)
└── Spoiled/
├── image1.jpg
├── image2.jpg
└── ... (948 images)
1. Quick Training (Recommended for beginners)
cd "Meat Quality"
python quick_train.py2. Standard Training
python train_meat_quality.py --epochs 50 --batch_size 32 --learning_rate 0.0013. Advanced Training
python train_resnet_transfer_learning.py --model_name resnet50 --epochs 504. Run the GUI Application
python meat_quality_gui.py- Training Accuracy: 90-95%
- Validation Accuracy: 85-92%
- Training Time: 30-60 minutes (depending on hardware)
Input Image (224x224x3)
↓
ResNet Backbone (pre-trained)
↓
Global Average Pooling
↓
Fully Connected (2048 → 512)
↓
ReLU + Dropout (0.3)
↓
Fully Connected (512 → 2)
↓
Output: [Fresh, Spoiled]
Both projects share similar technical foundations:
- Deep Learning Framework: PyTorch 2.0+
- Computer Vision: torchvision, OpenCV
- Image Processing: PIL/Pillow
- Data Science: NumPy, Pandas, scikit-learn
- Visualization: Matplotlib, Seaborn
- GUI Framework: CustomTkinter (Coffee Bean), Tkinter (Meat Quality)
- Transfer Learning: Leverage pretrained ResNet models on ImageNet
- Data Augmentation: Random crops, flips, rotations, color jitter
- Two-Phase Training:
- Phase 1: Transfer learning with frozen early layers
- Phase 2: Fine-tuning with all layers unfrozen
- Optimization: Adam optimizer with learning rate scheduling
- Validation: 20% of data used for validation
- Accuracy: Overall classification accuracy
- Precision: True positives / (True positives + False positives)
- Recall: True positives / (True positives + False negatives)
- F1-Score: Harmonic mean of precision and recall
Each project has its own detailed README:
- Coffee Bean: See
Coffee Bean/README.md - Meat Quality: See
Meat Quality/README.md - Meat Quality Training Guide: See
Meat Quality/README_TRAINING.md
1. Model file not found
Solution: Run the training script first to train the model
2. CUDA out of memory
Solution: Reduce batch size (e.g., --batch_size 16 or --batch_size 8)
3. Camera not working
Solution:
1. Check camera permissions
2. Ensure no other applications are using the camera
3. Try different camera index (modify cv2.VideoCapture(0) to cv2.VideoCapture(1))
4. Dependency conflicts
Solution: Use virtual environment and reinstall dependencies
- GPU Usage: Ensure CUDA is properly installed for GPU acceleration
- Data Quality: Use high-quality, well-lit images for best results
- Batch Size: Increase batch size if you have sufficient GPU memory
- Training Time: Use ResNet-18 for faster training, ResNet-50/101 for better accuracy
| Feature | Coffee Bean | Meat Quality |
|---|---|---|
| Classes | 4 (Dark, Green, Light, Medium) | 2 (Fresh, Spoiled) |
| Model | ResNet50 | ResNet18/34/50/101 |
| Input Size | 224×224 | 224×224 (112×112 for optimized) |
| GUI Framework | CustomTkinter | Tkinter |
| Batch Processing | ❌ | ✅ |
| Results Export | ❌ | ✅ |
| Training Scripts | 1 | 5 |
Contributions are welcome! To improve the projects:
- Collect more diverse training data
- Experiment with different architectures
- Implement additional data augmentation techniques
- Add more detailed quality classifications
- Develop mobile/web applications
- Deploy as web services
This project is for educational and research purposes. Make sure to comply with any dataset licensing requirements.
If you encounter issues:
- Check the console output for error messages
- Verify all dependencies are installed correctly
- Ensure your dataset follows the required structure
- Try running with default parameters first
- Check the individual project README files for detailed troubleshooting
Possible improvements for both projects:
- 🔄 Add more classification categories
- 🎨 Add image quality detection
- 📱 Develop mobile applications
- 🌐 Deploy as web services
- 📊 Add batch processing (for Coffee Bean)
- 🔍 Implement explainable AI features
- 📈 Add model performance monitoring
Version: 2.0
Last Updated: December 2024
Author: AI Assistant
Happy Coding! 🎉