Vegetable Image Classifier Web App

Introduction
This web application allows users to upload images of vegetables and instantly receive a classification prediction with confidence scores. Built using deep learning and deployed with Streamlit, this project demonstrates the power of AI in agriculture and food sorting solutions.
Problem Statement
Inconsistent and manual vegetable sorting methods can lead to inefficiencies in food processing units. The goal was to automate vegetable recognition using a deep learning model that can be integrated into simple applications for educational, industrial, or consumer use.
Objective
- To build a CNN model capable of classifying 15 vegetable types with high accuracy.
- To deploy the model as a lightweight, accessible web app using Streamlit.
- To ensure the app works seamlessly with user-uploaded image files and provides visual output and confidence scores.
Data Overview
The dataset consists of high-resolution images from 15 vegetable categories. Images were resized, normalized, and augmented to improve model generalization. The data was split into training (80%) and validation (20%) sets.
Model Architecture
The model is built on top of MobileNetV2, a lightweight and efficient convolutional neural network architecture designed for mobile and embedded vision applications. Its pre-trained weights on ImageNet were leveraged for transfer learning, significantly improving training efficiency and accuracy while reducing computational cost.
- Base Model: MobileNetV2 (without top layers)
- Fine-Tuning: Added custom dense layers with ReLU activation
- Output Layer: Softmax activation with 15 neurons (for 15 classes)
- Regularization: Dropout and data augmentation for overfitting control
- Optimizer: Adam (learning rate: 0.0001)
Technologies Used
- Python
- TensorFlow & Keras
- Streamlit
- Pandas, NumPy
- gdown (for Google Drive integration)
Vegetable Classes
Beetroot, Bitter Gourd, Bottle Gourd, Brinjal, Broccoli, Cabbage, Capsicum, Carrot, Cauliflower, Cucumber, Papaya, Potato, Pumpkin, Radish, Tomato
Key Features
- Upload `.jpg`, `.jpeg`, `.png` images of vegetables
- Live preview of uploaded image
- Model prediction with top label and confidence percentage
- Simple, responsive UI with Streamlit
- Model file dynamically downloaded using gdown
Model Performance
The model was evaluated using training and validation datasets with a balanced number of images across all vegetable classes. Key performance metrics include:
- Training Accuracy: 97.2%
- Validation Accuracy: 95.8%
- Model Size: ~16MB (.keras format)
Future Improvements
- Expand dataset with more vegetables and image diversity
- Add real-time camera support
- Deploy app to Hugging Face or Streamlit Cloud for public access
Author
Developed by Afzal Mohamed, a data science enthusiast with a passion for solving real-world problems using machine learning and automation.
If you want to explore the deployed model, you can try it out on my Streamlit Web app.
View DeploymentTake a look at my other projects to see how I address real-world problems using data.