A deep learning–powered application to classify fruits as fresh or spoiled.
Model: ResNet-50 (Transfer Learning) | Framework: PyTorch | UI: Streamlit
This project demonstrates an end-to-end computer vision workflow — from data preparation and leakage-safe splitting to model training, evaluation, and deployment using Streamlit.
A practical deep learning project that classifies fruit images as fresh or spoiled using a pretrained ResNet-50 model.
The project emphasizes data integrity, correct evaluation, and production-ready deployment, rather than just high accuracy.
- Binary Classification: Predicts whether a fruit is fresh or spoiled
- Multi-Fruit Support: Trained on 8 different fruits
- Transfer Learning: Uses pretrained ResNet-50 for efficient learning
- Leakage-Safe Dataset Splitting: Fruit-aware and class-aware splits
- Minimal Hyperparameter Tuning: Lightweight Optuna demonstration
- Fast Inference: Backbone frozen for quick predictions
- Interactive UI: User-friendly Streamlit web app
Fruits_Freshness_Classifier/
│
├── README.md
├── .gitignore
└──streamlit_app/
│
├── artifacts/
├── harvest_classifier_notebook.ipynb
└── harvest_classifier_resnet50.ipynb
│
├── models/
└── fruits_classifier_resnet50_tl.pth
├── app.py
├── app_v2.py # ✅ Main Streamlit application (use this)
├── model_definition.py # Model architecture definition
├── model_helper.py # Model loading & inference utilities
├── requirements.txt
- Architecture: ResNet-50 (pretrained on ImageNet)
- Training Strategy:
- Transfer learning
- Backbone frozen
- Fully connected layer fine-tuned
- Classes:
0 → Fresh1 → Spoiled
- Input Size:
224 × 224 RGB - Loss Function: CrossEntropyLoss
- Optimizer: Adam / AdamW (with weight decay)
- Python 3.9+
- Git
git clone https://github.com/inv-fourier-transform/Fruits_Freshness_Classifier.git
cd Fruits_Freshness_Classifierpython -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate
pip install -r requirements.txt
streamlit run app_v2.py
- Upload a fruit image
- The model processes the image
- View the output, which includes:
- Prediction: Fresh / Spoiled
- Confidence Score
All experimentation and training logic is documented in the notebooks inside the artifacts/ directory.
Includes:
- From-scratch CNN experiments
- BatchNorm & Dropout analysis
- Data leakage diagnosis
- Transfer learning with ResNet-50
- Minimal Optuna-based tuning (demo only)
The trained model can be loaded independently:
import torch
model = torch.load("models/fruits_classifier_resnet50_tl.pth")Refer to model_helper.py for reusable inference utilities.
- Correct evaluation > inflated accuracy
- Data leakage prevention
- Minimal but meaningful regularization
- Clear separation of training and inference
- Production-ready deployment mindset
Contributions are welcome!
Please open an issue or submit a pull request for improvements or bug fixes.
This project is licensed under the MIT License.
Built with a focus on correctness, clarity, and real-world deployment.


