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.
- 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.
- Upload an Image โ User uploads a food image (
.jpg,.jpeg,.png). - Classification โ The CNN model predicts the food category (20 predefined classes).
- Calorie Lookup โ The predicted food is matched to the closest entry in a calorie dataset (
food.csv), and the calorie value is displayed.
๐ฆ food-calorie-predictor
โฃ ๐ app.py # Streamlit app
โฃ ๐ food.csv # Food names + calorie values
โฃ ๐ my_food_classifier_model/
โ ๐ README.md # Project documentation
This project uses two datasets from Kaggle:
-
Food Detection Dataset rusqi29/food-detection-dataset-for-calorie-measurement โ Used for training the CNN model for food classification.
-
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.
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.
- Architecture: CNN (Conv2D โ MaxPooling โ Flatten โ Dense layers)
- Input Size: 150 ร 150 RGB images
- Classes: 20 food categories (
class_labels.jsonnot 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 likeclass_labels.jsonand model weights
Apple, Banana, Bean, Bread, Carrot, Cheese, Cucumber, Egg, Grape, Grape & Apple, Mixed, Net Images, Onion, Orange, Pasta, Pepper, Qiwi, Tomato, Watermelon, Sauce
- Upload a food image โ e.g., โfried rice.jpgโ
- Model predicts โ Fried Rice
- Calorie dataset lookup โ โ 250 kcal per serving
- Output shown in the Streamlit app
- Estimate portion size from images for better calorie accuracy.
- Support more food categories by training on larger datasets.