Dataset: Fruit and Vegetable Image Recognition
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.
- 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
- 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
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
Source: Kaggle - Fruit and Vegetable Image Recognition
- 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
- Fruits: Apple, Banana, Orange, Mango, Grape, Watermelon, etc.
- Vegetables: Carrot, Tomato, Potato, Cabbage, Cucumber, Broccoli, etc.
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
- Python 3.8 or higher
- pip package manager
- Git
git clone https://github.com/arpanpramanik2003/fruit-veg-classification.git
cd fruit-veg-classification# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activatepip install -r requirements.txtKey Dependencies:
- TensorFlow 2.x
- Streamlit
- NumPy
- Pillow (PIL)
- Matplotlib
streamlit run app.pyThe application will automatically open in your default web browser at http://localhost:8501
- Upload Image: Click on the file uploader to select an image of a fruit or vegetable
- View Prediction: The system will display the predicted class name
- Confidence Score: Check the confidence percentage for the prediction
- Probability Distribution: Examine the bar chart showing probabilities for all classes
Access the deployed application: Fruit-Veg Classification App
If you want to retrain the model with custom data:
- Prepare Dataset: Organize images in folders by class name
- Run Training Script:
python Computer_vision.py
- Explore Notebooks: Use the Jupyter notebooks for experimentation:
fruit-veg-detection.ipynb- Initial model developmentfruit-veg-detection-2.ipynb- Advanced experiments
- 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
- Image Upload: User uploads image through Streamlit interface
- Preprocessing:
- Convert image to RGB format
- Resize to 224Γ224 pixels
- Normalize pixel values
- Model Prediction: Feed preprocessed image to EfficientNet model
- Post-processing:
- Extract class probabilities
- Identify top prediction
- Calculate confidence score
- Visualization: Display results with bar chart
- Architecture: EfficientNetB0
- Input Resolution: 224Γ224 pixels
- Training Strategy: Transfer learning with fine-tuning
- Performance: High accuracy on test dataset
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
Contributions are welcome! Here's how you can help:
- Fork the Repository
- Create Feature Branch:
git checkout -b feature/YourFeature - Commit Changes:
git commit -m 'Add YourFeature' - Push to Branch:
git push origin feature/YourFeature - Open Pull Request
- 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
- β EfficientNet-based classification
- β Streamlit web interface
- β 36 fruit/vegetable categories
- β Confidence score visualization
- π 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
- π Object detection for multiple items
- π Freshness/quality assessment
- π Calorie estimation
- π Recipe recommendations
- π Multi-language support
- π Voice-activated interface
Issue: Model file not found
- Solution: Ensure
efficient_model.h5is 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
- 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
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.
Developer: Arpan Pramanik
Role: AI/ML Enthusiast π
GitHub: @arpanpramanik2003
For questions, suggestions, or collaboration opportunities, feel free to reach out!
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
