Skip to content

salim359/Food-Image-Classifier-Calorie-Predictor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿด Food Image Classifier & Calorie Predictor

This project is a web application that classifies food images and predicts their calorie content using a deep learning model (CNN) and a food calorie dataset. The app is built with Streamlit and Keras for an easy interactive demo.


๐Ÿš€ Features

  • Food Image Classification: Upload a food image, and the app predicts its category using a trained CNN model.
  • Calorie Prediction: Based on the predicted food category, the app estimates calorie content from a curated dataset.
  • Interactive Web App: Simple UI built with Streamlit to make predictions in real time.

โš™๏ธ How It Works

  1. Upload an Image โ†’ User uploads a food image (.jpg, .jpeg, .png).
  2. Classification โ†’ The CNN model predicts the food category (20 predefined classes).
  3. Calorie Lookup โ†’ The predicted food is matched to the closest entry in a calorie dataset (food.csv), and the calorie value is displayed.

๐Ÿ“‚ Project Structure

๐Ÿ“ฆ food-calorie-predictor
 โ”ฃ ๐Ÿ“œ app.py                        # Streamlit app
 โ”ฃ ๐Ÿ“œ food.csv                      # Food names + calorie values
 โ”ฃ ๐Ÿ“‚ my_food_classifier_model/
 โ”— ๐Ÿ“œ README.md                     # Project documentation

๐Ÿ“Š Datasets

This project uses two datasets from Kaggle:

  1. Food Detection Dataset rusqi29/food-detection-dataset-for-calorie-measurement โ†’ Used for training the CNN model for food classification.

  2. Food Calories Dataset vaishnavivenkatesan/food-and-their-calories โ†’ Used for mapping food names to calorie values (food.csv).

๐Ÿ‘‰ Download both datasets and place the required files (food.csv, images, etc.) in the project directory as shown in the structure.


โš ๏ธ Setting the Dataset Path

Before running the notebook (Food.ipynb) or any code, make sure to set the correct path to your dataset. In the notebook, you will find a line like:

dataset_path = 'add the path here'

Replace 'add the path here' with the actual path to your dataset directory. For example:

dataset_path = '/home/user/data/FooDD'

This step is required for the code to access and process the images correctly.


๐Ÿง  Model Details

  • Architecture: CNN (Conv2D โ†’ MaxPooling โ†’ Flatten โ†’ Dense layers)
  • Input Size: 150 ร— 150 RGB images
  • Classes: 20 food categories (class_labels.json not included; generate by running the notebook)
  • Weights: Pre-trained weights stored in model.weights.h5 (not included in the repository)

Note: The model weights file (model.weights.h5) is not included in this repository due to size constraints. To build the weights yourself, use the provided Jupyter notebook (Food.ipynb) to train the model on the dataset. This notebook contains all the code needed for data loading, preprocessing, model training, and saving the weights.

Tip: After downloading the Kaggle datasets, make sure to import or load them at the top of the notebook (Food.ipynb). This ensures all data is available for training and generating required files like class_labels.json and model weights


๐ŸŽ Example Food Classes

Apple, Banana, Bean, Bread, Carrot, Cheese, Cucumber, Egg, Grape, Grape & Apple, Mixed, Net Images, Onion, Orange, Pasta, Pepper, Qiwi, Tomato, Watermelon, Sauce


๐ŸŽฏ Example Workflow

  1. Upload a food image โ†’ e.g., โ€œfried rice.jpgโ€
  2. Model predicts โ†’ Fried Rice
  3. Calorie dataset lookup โ†’ โ‰ˆ 250 kcal per serving
  4. Output shown in the Streamlit app

๐Ÿ”ฎ Future Improvements

  • Estimate portion size from images for better calorie accuracy.
  • Support more food categories by training on larger datasets.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published