An AI-powered web application that classifies fruit freshness using deep learning. Upload an image of an apple, banana, or orange, and the model will determine whether it's fresh or rotten with confidence scores and detailed visualizations.
- Real-time Fruit Classification: Instantly classify fruits as fresh or rotten
- Multiple Input Methods: Upload images or use camera for live capture
- Interactive Visualizations: Confidence gauges and probability charts using Plotly
- 6 Fruit Categories: Fresh & rotten apples, bananas, and oranges
- Transfer Learning: Built on MobileNetV2 for optimal performance
- Class Imbalance Handling: Weighted training for balanced predictions
- User-friendly Interface: Streamlit-powered responsive web app
- Deep Learning: TensorFlow 2.13+, Keras
- Computer Vision: OpenCV, PIL
- Web Framework: Streamlit
- Data Science: NumPy, Pandas, Scikit-learn
- Visualizations: Plotly, Matplotlib, Seaborn
- Model Architecture: MobileNetV2 + Transfer Learning
- Python 3.8 or higher
- pip package manager
- Virtual environment (recommended)
git clone https://github.com/yourusername/fruit-freshness-classifier.git
cd fruit-freshness-classifierpython -m venv venv
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activatepip install -r requirements.txtstreamlit run streamlit_app.pyThe app will open in your browser at http://localhost:8501
fruit-freshness-classifier/
β
βββ streamlit_app.py # Main Streamlit application
βββ Fruit_Freshness_Classifier.ipynb # Training notebook
βββ requirements.txt # Python dependencies
βββ fruit_freshness_model.h5 # Trained model (download separately)
βββ README.md # Project documentation
β
βββ dataset/ # Dataset directory
β βββ train/ # Training images
β β βββ freshapples/
β β βββ freshbanana/
β β βββ freshoranges/
β β βββ rottenapples/
β β βββ rottenbanana/
β β βββ rottenoranges/
β βββ test/ # Test images
β βββ [same structure as train]
β
βββ screenshots/ # App screenshots
βββ app_interface.png
βββ prediction_results.png
The classifier uses MobileNetV2 as the base model with transfer learning:
- Base Model: MobileNetV2 (pre-trained on ImageNet)
- Input Size: 224Γ224Γ3 RGB images
- Classes: 6 categories (3 fruits Γ 2 conditions)
- Training Strategy: Two-phase training with fine-tuning
- Optimization: Class weight balancing for imbalanced datasets
- Test Accuracy: 85%+ (varies by dataset)
- Training Time: ~30 minutes on GPU
- Model Size: ~14MB (optimized for deployment)
The model was trained on a curated dataset of fruit images:
- Total Images: 6,000+ images
- Categories: Fresh and rotten apples, bananas, oranges
- Preprocessing: Data augmentation, normalization, resizing
- Split: 80% training, 20% validation
Note: The dataset is not included in the repository due to size. Train your own model using the provided notebook.
- Open the Streamlit app
- Upload an image or use camera
- Click "Analyze Fruit"
- View results with confidence scores
- See detailed probability breakdown
Run the Jupyter notebook Fruit_Freshness_Classifier.ipynb to:
- Analyze dataset distribution
- Train the model with your data
- Evaluate performance metrics
- Generate visualizations
import tensorflow as tf
from PIL import Image
import numpy as np
# Load model
model = tf.keras.models.load_model('fruit_freshness_model.h5')
# Preprocess image
image = Image.open('fruit_image.jpg')
img_array = np.array(image.resize((224, 224))) / 255.0
img_batch = np.expand_dims(img_array, axis=0)
# Predict
predictions = model.predict(img_batch)
class_names = ['freshapples', 'freshbanana', 'freshoranges',
'rottenapples', 'rottenbanana', 'rottenoranges']
predicted_class = class_names[np.argmax(predictions)]The training script automatically detects and handles class imbalance using:
- Computed class weights
- Balanced sampling strategies
- Performance metrics per class
- Confidence Gauge: Radial gauge showing prediction confidence
- Probability Chart: Horizontal bar chart of all class probabilities
- Color Coding: Green for fresh, red for rotten fruits
The training pipeline includes:
- Confusion matrix generation
- Misclassification analysis
- Per-class performance metrics
- Fork this repository
- Connect to Streamlit Cloud
- Deploy directly from GitHub
- Share your app URL!
streamlit run streamlit_app.py --server.port 8501FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8501
CMD ["streamlit", "run", "streamlit_app.py"]Contributions are welcome! Please feel free to submit a Pull Request. For major changes:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Support for more fruit types (strawberries, grapes, etc.)
- Mobile app version using Flutter/React Native
- Batch processing for multiple images
- REST API endpoints
- Model quantization for edge deployment
- Real-time webcam integration
- Freshness timeline prediction
- Model performs best with clear, well-lit images
- Very dark or blurry images may reduce accuracy
- Background objects can sometimes affect predictions
This project is licensed under the MIT License - see the LICENSE file for details.
Your Name
- GitHub: isthatlak
- LinkedIn: Lakshay Bhandari
- Email: lakshaybofficial@gmail.com
- TensorFlow team for the excellent deep learning framework
- Streamlit for the amazing web app framework
- MobileNetV2 architecture by Google
- Open source community for inspiration and resources
- MobileNetV2: Inverted Residuals and Linear Bottlenecks
- Transfer Learning with TensorFlow
- Streamlit Documentation
β Star this repo if you found it helpful! β

