Skip to content

arpanpramanik2003/fruit-veg-classification

Repository files navigation

🍎πŸ₯• Fruits & Vegetables Classification System

Fruits & Vegetables Classification

Python TensorFlow Streamlit License: MIT

Dataset: Fruit and Vegetable Image Recognition


πŸ“Œ Project Overview

This project is a deep learning-based image classification system designed to accurately identify various types of fruits and vegetables from uploaded images. Built using TensorFlow/Keras and deployed with Streamlit, it leverages the power of EfficientNet, a state-of-the-art convolutional neural network architecture, to deliver high-accuracy predictions with an intuitive web interface.

The system processes user-uploaded images, performs real-time inference, and provides detailed classification results including confidence scores and visual probability distributions. This project demonstrates practical applications of transfer learning and deep learning in computer vision for food classification tasks.


✨ Key Features

🎯 Core Functionality

  • Multi-Class Classification: Identifies 36 different categories of fruits and vegetables
  • Real-Time Predictions: Instant classification with confidence scores
  • Interactive Web Interface: User-friendly Streamlit-based UI for seamless image uploads
  • Confidence Visualization: Bar chart representation of prediction probabilities
  • High Accuracy: Utilizes EfficientNet architecture for superior performance

πŸ”§ Technical Highlights

  • Transfer Learning: Pre-trained EfficientNet model fine-tuned for fruit/vegetable classification
  • Image Preprocessing: Automated resizing and normalization pipeline
  • Model Optimization: Trained with data augmentation for improved generalization
  • Lightweight Deployment: Streamlit Cloud-ready application
  • Extensible Architecture: Easy to add new categories and retrain

πŸ—οΈ Project Structure

fruit-veg-classification/
β”‚
β”œβ”€β”€ .github/
β”‚   └── workflows/           # CI/CD workflows
β”‚       └── python-app.yml
β”‚
β”œβ”€β”€ app.py                   # Main Streamlit application
β”œβ”€β”€ Computer_vision.py       # Model training and evaluation script
β”‚
β”œβ”€β”€ efficient_model.h5       # Pre-trained EfficientNet model (primary)
β”œβ”€β”€ cnn_model.h5            # Alternative CNN model
β”‚
β”œβ”€β”€ fruit-veg-detection.ipynb      # Initial model development notebook
β”œβ”€β”€ fruit-veg-detection-2.ipynb    # Advanced model experimentation
β”‚
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ .gitignore              # Git ignore rules
β”œβ”€β”€ LICENSE                 # MIT License
β”œβ”€β”€ README.md              # Project documentation
└── image.png              # Project banner image

πŸ“Š Dataset Information

Source: Kaggle - Fruit and Vegetable Image Recognition

Dataset Specifications

  • Total Categories: 36 classes (fruits and vegetables)
  • Image Format: RGB images of varying sizes
  • Data Split: Train, validation, and test sets
  • Preprocessing: Images resized to 224Γ—224 pixels for model input

Sample Categories Include:

  • Fruits: Apple, Banana, Orange, Mango, Grape, Watermelon, etc.
  • Vegetables: Carrot, Tomato, Potato, Cabbage, Cucumber, Broccoli, etc.

🧠 Model Architecture

EfficientNet Backbone

The project utilizes EfficientNet, a family of convolutional neural networks that uniformly scale network width, depth, and resolution using a compound coefficient. This approach delivers state-of-the-art accuracy with fewer parameters.

Architecture Highlights:

  • Base Model: EfficientNetB0 (pre-trained on ImageNet)
  • Transfer Learning: Fine-tuned top layers for fruit/vegetable classification
  • Input Shape: 224Γ—224Γ—3 (RGB images)
  • Output Layer: Softmax activation with 36 classes
  • Optimization: Adam optimizer with categorical cross-entropy loss

Model Performance:

  • High training accuracy achieved through data augmentation
  • Robust generalization on unseen test images
  • Fast inference time suitable for real-time applications

πŸš€ Installation & Setup

Prerequisites

  • Python 3.8 or higher
  • pip package manager
  • Git

Step 1: Clone the Repository

git clone https://github.com/arpanpramanik2003/fruit-veg-classification.git
cd fruit-veg-classification

Step 2: Create Virtual Environment (Recommended)

# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

Step 3: Install Dependencies

pip install -r requirements.txt

Key Dependencies:

  • TensorFlow 2.x
  • Streamlit
  • NumPy
  • Pillow (PIL)
  • Matplotlib

πŸ’» Usage

Running the Web Application

streamlit run app.py

The application will automatically open in your default web browser at http://localhost:8501

Using the Application

  1. Upload Image: Click on the file uploader to select an image of a fruit or vegetable
  2. View Prediction: The system will display the predicted class name
  3. Confidence Score: Check the confidence percentage for the prediction
  4. Probability Distribution: Examine the bar chart showing probabilities for all classes

Live Demo

Access the deployed application: Fruit-Veg Classification App


πŸ”¬ Model Training & Customization

Training Your Own Model

If you want to retrain the model with custom data:

  1. Prepare Dataset: Organize images in folders by class name
  2. Run Training Script:
    python Computer_vision.py
  3. Explore Notebooks: Use the Jupyter notebooks for experimentation:
    • fruit-veg-detection.ipynb - Initial model development
    • fruit-veg-detection-2.ipynb - Advanced experiments

Customization Options

  • Add New Categories: Expand the dataset with additional fruit/vegetable classes
  • Model Architecture: Experiment with different EfficientNet variants (B1, B2, etc.)
  • Hyperparameter Tuning: Adjust learning rate, batch size, and epochs
  • Data Augmentation: Implement custom augmentation strategies

πŸ“· Model Inference Pipeline

  1. Image Upload: User uploads image through Streamlit interface
  2. Preprocessing:
    • Convert image to RGB format
    • Resize to 224Γ—224 pixels
    • Normalize pixel values
  3. Model Prediction: Feed preprocessed image to EfficientNet model
  4. Post-processing:
    • Extract class probabilities
    • Identify top prediction
    • Calculate confidence score
  5. Visualization: Display results with bar chart

πŸ“Š Results & Performance

Model Metrics

  • Architecture: EfficientNetB0
  • Input Resolution: 224Γ—224 pixels
  • Training Strategy: Transfer learning with fine-tuning
  • Performance: High accuracy on test dataset

Sample Predictions

The model successfully identifies various fruits and vegetables with high confidence, handling variations in:

  • Lighting conditions
  • Image angles and perspectives
  • Background complexity
  • Fruit/vegetable ripeness stages

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the Repository
  2. Create Feature Branch: git checkout -b feature/YourFeature
  3. Commit Changes: git commit -m 'Add YourFeature'
  4. Push to Branch: git push origin feature/YourFeature
  5. Open Pull Request

Contribution Ideas

  • Add support for new fruit/vegetable categories
  • Improve model accuracy with advanced architectures
  • Enhance UI/UX of the web application
  • Implement batch prediction functionality
  • Add multi-language support
  • Create mobile application version

πŸ—ΊοΈ Roadmap

Current Version (v1.0)

  • βœ… EfficientNet-based classification
  • βœ… Streamlit web interface
  • βœ… 36 fruit/vegetable categories
  • βœ… Confidence score visualization

Planned Features (v2.0)

  • πŸ”„ Enhanced model with Vision Transformers
  • πŸ”„ Real-time webcam classification
  • πŸ”„ Nutritional information display
  • πŸ”„ Multi-image batch processing
  • πŸ”„ Mobile app development (React Native/Flutter)
  • πŸ”„ API endpoint for integration
  • πŸ”„ Docker containerization
  • πŸ”„ Cloud deployment optimization

Future Enhancements (v3.0)

  • πŸ“… Object detection for multiple items
  • πŸ“… Freshness/quality assessment
  • πŸ“… Calorie estimation
  • πŸ“… Recipe recommendations
  • πŸ“… Multi-language support
  • πŸ“… Voice-activated interface

πŸ› οΈ Troubleshooting

Common Issues

Issue: Model file not found

  • Solution: Ensure efficient_model.h5 is in the project root directory

Issue: TensorFlow installation errors

  • Solution: Install TensorFlow 2.x compatible with your Python version

Issue: Image upload fails

  • Solution: Verify image format (JPG, PNG supported)

Issue: Streamlit app won't start

  • Solution: Check if port 8501 is available or specify different port

πŸ™ Acknowledgements

  • Dataset: Thanks to Kritik Seth for the Fruit and Vegetable Image Recognition dataset on Kaggle
  • EfficientNet: Implementation based on Google's EfficientNet paper
  • Streamlit: For providing an excellent framework for rapid ML app development
  • TensorFlow/Keras: For comprehensive deep learning tools
  • Open Source Community: For continuous inspiration and support

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2024 Arpan Pramanik

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

πŸ“§ Contact

Developer: Arpan Pramanik
Role: AI/ML Enthusiast πŸš€
GitHub: @arpanpramanik2003

For questions, suggestions, or collaboration opportunities, feel free to reach out!


⭐ Support

If you find this project helpful, please consider:

  • ⭐ Starring the repository
  • 🍴 Forking for your own experiments
  • πŸ“’ Sharing with others
  • πŸ› Reporting issues
  • πŸ’‘ Suggesting improvements

Made with ❀️ by Arpan Pramanik

Powered by TensorFlow β€’ Streamlit β€’ EfficientNet

About

This project is a deep learning-based image classification system that uses EfficientNet for accurate identification of fruits and vegetables from uploaded images. Built with TensorFlow and deployed using Streamlit, it provides a user-friendly interface, confidence scores, and visualization of predictions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors