FruitQ-GradeX is an advanced deep learning system that simultaneously classifies fruit type (Apple, Banana, Guava, Orange) and quality condition (Good/Bad) using a custom multi-headed Convolutional Neural Network architecture. The system integrates Grad-CAM visualization for model interpretability and features a user-friendly Streamlit interface for real-time predictions.
- Enable automated fruit quality assessment for agricultural and retail applications
- Provide explainable AI insights through visual heatmaps
- Support both batch processing and real-time inference
- Bridge the gap between deep learning research and practical deployment
- 🔄 Dual Prediction System: Simultaneous fruit type and quality classification
- 🔍 Explainable AI: Grad-CAM visualizations for both prediction heads
- 📱 Interactive Interface: Clean Streamlit web app with real-time predictions
- 📊 Confidence Scoring: Probability distributions for all predictions
- 🎛️ Custom Data Pipeline: Automated data preprocessing and augmentation
- 📸 Multiple Input Methods: Upload images or use live webcam capture
- 🎨 Visual Feedback: Heatmap overlays highlighting decision-relevant regions
- 📈 Performance Metrics: Comprehensive evaluation with accuracy and F1-scores
- 🔧 Modular Architecture: Easy to extend for additional fruit types
Source: FruitNet - Indian Fruits Dataset with Quality Labels
| Fruit Type | Good Quality | Bad Quality | Total |
|---|---|---|---|
| 🍎 Apple | 1,149 | 1,141 | 2,290 |
| 🍌 Banana | 1,113 | 1,087 | 2,200 |
| 🥭 Guava | 1,152 | 1,129 | 2,281 |
| 🍊 Orange | 1,216 | 1,159 | 2,375 |
| Total | 4,630 | 4,516 | 9,146 |
- 📦 Total Images: 9,146
- 🏷️ Classes: 8 (4 fruit types × 2 quality conditions)
- 📏 Image Resolution: Variable (preprocessed to 224×224)
- 🎨 Color Space: RGB
- 📂 Format: JPEG/PNG
| Metric | Training | Validation | Test |
|---|---|---|---|
| Fruit Type Accuracy | 97.75% | 97.71% | 96.8% |
| Quality Accuracy | 98.21% | 99.18% | 98.5% |
| Fruit F1-Score | 0.978 | 0.976 | 0.972 |
| Quality F1-Score | 0.991 | 0.992 | 0.989 |
| Combined Loss | 0.2969 | 0.2435 | 0.2890 |
- ✅ High Accuracy: >97% for both classification tasks
- ✅ Excellent Generalization: Minimal overfitting observed
- ✅ Balanced Performance: Consistent across all fruit categories
- ✅ Multi-label Support: Robust dual-head architecture
- 🧠 Deep Learning Framework: TensorFlow 2.x + Keras
- 🏗️ Model Architecture: Custom Multi-Head CNN
- 🔍 Explainability: Grad-CAM (Gradient-weighted Class Activation Mapping)
- 🌐 Web Interface: Streamlit
- 📸 Computer Vision: OpenCV
- 📊 Data Processing: NumPy, Pandas
- 📈 Visualization: Matplotlib, Seaborn
- 🐍 Python: 3.8+
- 💾 Version Control: Git
- 📝 Development: Jupyter Notebooks
- 🔧 Package Management: pip/conda
# Python 3.8 or higher
python --versiongit clone https://github.com/arpanpramanik2003/FruitQ-GradeX.git
cd FruitQ-GradeX# Using venv
python -m venv fruitq_env
# Activate environment
# Windows
fruitq_env\Scripts\activate
# Linux/Mac
source fruitq_env/bin/activatepip install -r requirements.txt# Create data directory
mkdir data
# Place your fruit images in:
# data/
# ├── Apple_Good/
# ├── Apple_Bad/
# ├── Banana_Good/
# ├── Banana_Bad/
# ├── Guava_Good/
# ├── Guava_Bad/
# ├── Orange_Good/
# └── Orange_Bad/python -c "import tensorflow as tf; print('TensorFlow version:', tf.__version__)"# Launch the web interface
streamlit run app.py# Train from scratch
python train_model.py
# Resume training from checkpoint
python train_model.py --resume --checkpoint model_checkpoint.h5from fruit_classifier import FruitClassifier
# Initialize model
classifier = FruitClassifier('models/best_model.h5')
# Predict single image
result = classifier.predict_image('path/to/fruit_image.jpg')
print(f"Fruit: {result['fruit']} ({result['fruit_confidence']:.2%})")
print(f"Quality: {result['quality']} ({result['quality_confidence']:.2%})")
# Get Grad-CAM visualization
heatmap = classifier.generate_gradcam('path/to/fruit_image.jpg')- 📤 Upload Images: Drag & drop or browse for fruit images
- 📹 Live Camera: Real-time webcam capture and prediction
- 🎯 Predictions: View fruit type and quality classifications
- 📊 Confidence Scores: Probability distributions for all classes
- 🔍 Grad-CAM Heatmaps: Visual explanations of model decisions
- 📈 Batch Processing: Upload multiple images for bulk analysis
📤 Input: apple_sample.jpg
🍎 Predicted Fruit: Apple (Confidence: 94.2%)
❌ Predicted Quality: Bad (Confidence: 87.6%)
🔍 Grad-CAM: Highlighting brown spots and texture irregularities
Input Layer (224, 224, 3)
↓
Conv2D Blocks (Feature Extraction)
↓
Global Average Pooling
↓
├── Fruit Head (Dense → Softmax)
└── Quality Head (Dense → Sigmoid)
- 🏗️ Backbone: Custom CNN with residual connections
- 🎯 Dual Heads: Separate classification branches for fruit type and quality
- 🔄 Data Augmentation: Rotation, zoom, brightness, horizontal flip
- ⚖️ Loss Function: Combined categorical crossentropy and binary crossentropy
- 📈 Optimizer: Adam with learning rate scheduling
We welcome contributions! Here's how you can help:
-
🍴 Fork the Repository
git fork https://github.com/arpanpramanik2003/FruitQ-GradeX.git
-
🌿 Create Feature Branch
git checkout -b feature/amazing-feature
-
💻 Make Changes
- Follow PEP 8 style guidelines
- Add docstrings to functions
- Include unit tests for new features
-
✅ Test Your Changes
python -m pytest tests/
-
📝 Commit and Push
git commit -m "Add amazing feature" git push origin feature/amazing-feature -
🔄 Create Pull Request
- 🆕 Adding new fruit categories
- 🔧 Improving model architecture
- 🎨 Enhancing UI/UX design
- 📊 Adding more evaluation metrics
- 📚 Improving documentation
- 🐛 Bug fixes and optimizations
- 📧 Email: arpanpramanik2003@gmail.com
- 💼 LinkedIn: linkedin.com/in/arpan-pramanik
- 🐱 GitHub: @arpanpramanik2003
- 📧 Email: chandasujata01@gmail.com
- 🐱 GitHub: @chandadiya2004
- Arpan Pramanik – Model Architecture Design, Training Pipeline, Explainable AI (Grad-CAM), Deployment
- Diya Chanda – Dataset Curation, Experimental Analysis, Performance Evaluation, Documentation
MIT License
Copyright (c) 2025
Arpan Pramanik, Diya Chanda
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
⭐ Star this repository if you found it helpful! ⭐
Built with ❤️ by Arpan Pramanik & Diya Chanda