
Overview
Food classification is an exciting application of machine learning and deep learning. This project demonstrates how to classify food items using images, leveraging Convolutional Neural Networks (CNNs). The implemented model can predict the type of food in an uploaded image or an image captured through a live camera with an accuracy of 88%. Pre-trained models have been used to improve classification performance and achieve better results.
Features
- User-Friendly Interface: Interactive UI with attractive animations and styles.
- Multiple Input Options:
- File Upload
- Live Camera Input
- Pre-Trained CNN Model: Uses transfer learning for better accuracy.
- Model Accuracy: Achieved an accuracy of 88% on the test dataset.
- Dataset: Contains 16 food categories with numerous images for training and validation.
- Visualization: Displays the uploaded/captured image and provides the classification result.
- Audio Support: Includes an audio introduction feature for better user engagement.
- Model Predictions: Displays pre-computed predictions for various food items.
Technologies and Libraries Used
- Programming Language: Python
- Libraries:
Streamlit
: For creating the web application.
Pillow (PIL)
: For image processing.
TensorFlow
and TensorFlow Hub
: For loading the pre-trained CNN model.
Matplotlib
: For image visualization.
NumPy
: For numerical computations.
Streamlit-Lottie
: For adding animations.
Requests
: For fetching Lottie animations.
h5py
: For loading .h5
model files.
Model Details
- Model Architecture: Convolutional Neural Network (CNN) with pre-trained layers for feature extraction.
- Input Shape: Images resized to
(228, 228, 3)
.
- Output Classes:
- Burger, Chapathi, Dosa, Fried Rice, Idli, Jalebi, Kulfi, Noodles, Paani Poori, Paneer, Parota, Pizza, Poori, Samosa, Soup, Tea.
- Loss Function: Categorical Cross-Entropy.
- Activation Function: Softmax for multi-class classification.
Dataset

Application Functionality
1. Interface Design
- Custom Background: Attractive gradient image background.
- Centered Layout: Content is aligned centrally for better user focus.
- Header Design: Uses a professional font style with gradient colors.
- Animations: Lottie animations to enhance interactivity.
2. Input Options
File Upload
- Users can upload an image in
.jpg
, .jpeg
, or .png
formats.
- The image is resized and pre-processed before being fed into the CNN model.
- Predicted class is displayed along with the image.
Live Camera Input
- Captures images using the live camera option.
- The captured image is processed and classified using the CNN model.
3. Model Predictions
- Displays pre-computed predictions for various food items as reference images.
4. Audio Feature
- An optional audio introduction (
Intro.mp3
) provides an overview of the application.
User Workflow
- Select an input option:
- File Uploader
- Live Camera Input
- Model Predictions
- Upload or capture an image.
- View the uploaded image with the classification result.
- Explore sample predictions or listen to the audio introduction for more insights.
Code Structure
.
├── app.py # Main application file
├── Icon.png # Application icon
├── FC_Model.h5 # Trained CNN model file
├── Intro.mp3 # Audio introduction
├── Predictions/ # Directory containing pre-computed prediction images
└── requirements.txt # Required Python libraries
Project Use Cases
- Personalized Meal Recommendations
- Restaurant Automation
- Food Delivery Applications
- Food Safety and Quality Control
- Dietary Monitoring
- Nutritional Analysis
Accuracy

Loss


Functionality Spotlight

















File Uploader
def main():
file_uploader = st.file_uploader("Choose the file", type=['jpg', 'jpeg', 'png'])
if file_uploader is not None:
image = Image.open(file_uploader)
result = predict_class(image)
st.success(result)
Prediction Function
def predict_class(image):
classifier_model = tf.keras.models.load_model("FC_Model.h5")
shape = ((228, 228, 3))
test_image = image.resize((228, 228))
test_image = preprocessing.image.img_to_array(test_image) / 255.0
test_image = np.expand_dims(test_image, axis=0)
predictions = classifier_model.predict(test_image)
class_names = [...]
scores = tf.nn.softmax(predictions[0])
image_class = class_names[np.argmax(scores)]
return f"Prediction of the uploaded image is: {image_class}"
How to Run the Application
- Install the required dependencies:
pip install -r requirements.txt
- Run the application
streamlit run app.py
- Open the application in your browser
http://localhost:8501
Future Enhancements
- Extend the dataset to include more food categories.
- Improve model accuracy using advanced architectures like EfficientNet or ResNet.
- Integrate real-time feedback for incorrect predictions.
- Deploy the application on cloud platforms for public access.
Acknowledgments
- Dataset: Food dataset with 16 categories.
- Frameworks: TensorFlow, Streamlit.
- Animations: LottieFiles.