Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 46 additions & 175 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,194 +1,65 @@
# FoodSnap AI - Hackathon Project
# FoodSnap AI

🎉 **Welcome to the FoodSnap AI Hackathon!** 🎉
**FOODSNAP-AI**

Get ready to combine your coding skills with the fascinating world of artificial intelligence and nutrition! We're excited to see what innovative solutions you come up with.
FoodSnap AI is an advanced AI-powered tool designed to revolutionize the way users track their nutrition.This smart calorie calculator uses image recognition to instantly identify multiple food items in a single image and provide precise calorie estimates per 100 grams—just by snapping a picture!

**The Challenge:**
Your mission, should you choose to accept it, is to develop a solution that can estimate the caloric content (and ideally, macronutrient breakdown – protein, carbs, fats) of a food item from an input image.

## Table of Contents

1. [Project Overview](#project-overview)
2. [Why This Project?](#why-this-project)
3. [Scope & Implementation Freedom](#project-scope--implementation-freedom)
4. [Key Objectives / Potential Features](#key-objectives--potential-features)
5. [Helpful Resources & APIs](#helpful-resources--apis)
* [Food Image Datasets](#food-image-datasets)
* [Nutrition Information Databases & APIs](#nutrition-information-databases--apis)
* [Machine Learning / AI Tools](#machine-learning--ai-tools)
6. [Getting Started: Git & Submission Workflow](#getting-started-git--submission-workflow)
* [1. Fork the Repository](#1-fork-the-repository)
* [2. Clone Your Forked Repository](#2-clone-your-forked-repository)
* [3. Create a New Branch](#3-create-a-new-branch)
* [4. Develop Your Project](#4-develop-your-project)
* [5. Push Your Branch to Your Fork](#5-push-your-branch-to-your-fork)
* [6. Submit Your Project (Create a Pull Request)](#6-submit-your-project-create-a-pull-request)
7. [What to Include in Your Submission](#what-to-include-in-your-submission)
8. [Judging Criteria (General Pointers)](#judging-criteria-general-pointers)

1. [Features](#Features)
2. [Working](#Working)
2. [Installation](#Installation)
3. [Results](#Results)

---

## Project Overview
## Features

**Project Name:** FoodSnap AI
- ### AI-Powered Food Identification:
Recognizes variety of food items.
- ### Calorie & Nutrient Breakdown:
Instantly estimates calories, protein, fat, carbohydrates, dietary fibre and sugar.
- ### Multiple food detection:
Detects and identifies multiple food items present with in a single image.

**The Challenge:**
Develop a solution that can estimate the caloric content (and ideally, macronutrient breakdown – protein, carbs, fats) of a food item from an input image.
## Working

## Why This Project?
- ### Snap a Photo:
Capture an image of your meal using your smartphone.
- ### AI Recognition:
Our advanced model detects and identifies food items.
- ### Instant Calorie Analysis:
Get an estimated calorie count along with macronutrient details.

Understanding calorie intake is crucial for health and fitness. Manually logging food can be tedious. FoodSnap AI aims to simplify this process, making nutritional awareness more accessible to everyone. Imagine snapping a photo of your meal and instantly getting its nutritional information!

## Project Scope & Implementation Freedom

You have complete freedom in how you bring FoodSnap AI to life!

* **Platform:** Mobile App (iOS, Android, cross-platform), Web App, Website, or even a Command Line Interface (CLI) tool.
* **Technology Stack:** Use any programming languages, frameworks, libraries, or APIs you prefer. Python, JavaScript, Java, Swift, Kotlin, Ruby, Go – the choice is yours!
* **Approach:** You can use pre-trained machine learning models, train your own, leverage existing food recognition APIs, or come up with a completely novel approach.

## Key Objectives / Potential Features

1. **Image Input:** The system must accept an image of food as input.
2. **Food Identification (Implicit or Explicit):** The system needs to identify the food item(s) in the image. This could be a direct output or an internal step.
3. **Calorie Estimation:** Based on the identified food, estimate its total calories.
4. **Macronutrient Breakdown (Bonus):** If possible, also estimate protein, carbohydrates, and fats.
5. **Portion Size Consideration (Advanced Bonus):** Accurately estimating portion size from an image is challenging but would be a significant enhancement.
6. **User Interface (for non-CLI):** If you're building an app or website, make it user-friendly and intuitive.
7. **Multiple Food Items (Advanced Bonus):** Can your solution handle an image with multiple food items on a plate?

## Helpful Resources & APIs

To get you started, here are some resources that might be useful. You are **not limited** to these and are encouraged to explore!

### Food Image Datasets
*(For training/inspiration if you go the custom ML route)*

* **Food-101:** [https://data.vision.ee.ethz.ch/cvl/datasets_extra/food-101/](https://data.vision.ee.ethz.ch/cvl/datasets_extra/food-101/) (101 food categories, 101,000 images)
* **UECFood-100 / UECFood-256:** [http://foodcam.mobi/dataset.html](http://foodcam.mobi/dataset.html) (Japanese food primarily, good for object detection)
* **Recipe1M+:** [http://pic2recipe.csail.mit.edu/](http://pic2recipe.csail.mit.edu/) (Images and recipes)
* **Google Images / Flickr:** Can be used for scraping specific food images (be mindful of terms of service).

### Nutrition Information Databases & APIs
*(For calorie/macro lookup)*

* **USDA FoodData Central API:** [https://fdc.nal.usda.gov/api-guide.html](https://fdc.nal.usda.gov/api-guide.html) (Comprehensive US food composition database)
* **Edamam Food Database API:** [https://developer.edamam.com/food-database-api](https://developer.edamam.com/food-database-api) (Offers free tier for recipe analysis and food database lookup)
* **Spoonacular API:** [https://spoonacular.com/food-api](https://spoonacular.com/food-api) (Nutrition, recipes, food products, free tier available)
* **MyFitnessPal / CalorieKing / FatSecret:** While direct API access might be limited or paid, these websites are excellent sources for manual data collection or understanding how nutritional information is presented. Web scraping *could* be an option, but always respect `robots.txt` and terms of service.
* **Open Food Facts:** [https://world.openfoodfacts.org/](https://world.openfoodfacts.org/) (A collaborative, free, and open database of food products from around the world. They have an API.)

### Machine Learning / AI Tools

* **TensorFlow / Keras:** For building and training custom models.
* **PyTorch:** Another popular deep learning framework.
* **OpenCV:** For image processing tasks.
* **Pre-trained Image Recognition Models:** (e.g., MobileNet, ResNet, InceptionV3 available via TensorFlow Hub, PyTorch Hub, etc.) These can often be fine-tuned for food recognition.
* **Cloud AI Services:** Google Cloud Vision AI, AWS Rekognition, Azure Computer Vision (these often have free tiers for experimentation and can perform object/food recognition out-of-the-box).

## Getting Started: Git & Submission Workflow

We will be using GitHub for version control and submission. Please follow these steps carefully.

**This Repository (Main Project):** `https://github.com/WeCode-Community-Dev/foodsnap-ai`

### 1. Fork the Repository
* Go to the main project repository: `https://github.com/WeCode-Community-Dev/foodsnap-ai`
* In the top-right corner of the page, click the "**Fork**" button.
* This will create a copy of the repository under your own GitHub account (e.g., `https://github.com/YOUR_USERNAME/foodsnap-ai`). This is *your* personal remote copy.

### 2. Clone Your Forked Repository
* On your GitHub page for *your forked repository* (`https://github.com/YOUR_USERNAME/foodsnap-ai`), click the green "**Code**" button.
* Copy the HTTPS or SSH URL.
* Open your terminal or Git client and run:
```bash
git clone https://github.com/YOUR_USERNAME/foodsnap-ai.git
cd foodsnap-ai
```
(Replace `YOUR_USERNAME` with your actual GitHub username.)

### 3. Create a New Branch
* It's crucial to work on a new branch rather than directly on `main` or `master`.
* Choose a descriptive branch name, for example, `feature/your-team-name` or `solution-john-doe`.
* In your terminal, inside the `foodsnap-ai` directory, run:
```bash
git checkout -b feature/your-team-name
```
(e.g., `git checkout -b feature/awesome-coders` or `git checkout -b solution-jane-doe`)
* You are now on your new branch. Verify by running `git branch`.

### 4. Develop Your Project
* Start coding! Add your files, write your logic, and build your FoodSnap AI solution.
* Commit your changes frequently with clear commit messages:
```bash
# Stage all new and modified files
git add .
# Or stage specific files
# git add path/to/your/file.py path/to/another/file.js

# Commit your changes
git commit -m "feat: Implement image upload functionality"
# Example commit types: feat, fix, docs, style, refactor, test, chore
```

### 5. Push Your Branch to Your Fork
* When you're ready to save your progress to *your remote fork on GitHub*, push your branch:
```bash
git push origin feature/your-team-name
```
(Replace `feature/your-team-name` with your actual branch name.)
* If it's the first time pushing this branch, Git might suggest a command like `git push --set-upstream origin feature/your-team-name`. Use that command.

### 6. Submit Your Project (Create a Pull Request)
* Once your project is complete (or at a submittable stage), go to *your* forked repository on GitHub (`https://github.com/YOUR_USERNAME/foodsnap-ai`).
* You should see a prompt saying "`feature/your-team-name` had recent pushes". Click the "**Compare & pull request**" button.
* If you don't see the prompt, go to the "**Pull requests**" tab and click "**New pull request**".
* **Crucially, ensure the settings are:**
* **Base repository:** `WeCode-Community-Dev/foodsnap-ai`
* **Base branch:** `main` (or `master`, whichever is the default for this repository)
* **Head repository:** `YOUR_USERNAME/foodsnap-ai`
* **Compare branch:** `feature/your-team-name` (your development branch)
* Write a clear title and a detailed description for your Pull Request (PR). Include:
* A brief overview of your solution.
* Technologies used.
* How to run/test your project (setup, commands, etc.).
* Any known issues or limitations.
* A link to a live demo if applicable (e.g., Heroku, Netlify, GitHub Pages).
* Screenshots or a short video showcasing your project can be very helpful!
* Click "**Create pull request**".

## What to Include in Your Submission
*(In your project's directory, pushed to your branch and included in the PR)*

* **Source Code:** All the code for your project.
* **`README.md` (Your Project's README):** This is very important! Your project's `README.md` (different from this main hackathon `README.md`) should include:
* Project Title & Team Name/Members (if applicable).
* A brief description of your FoodSnap AI solution.
* What features you implemented.
* Tech stack used.
* **Clear instructions on how to set up and run *your specific project* locally.** This includes dependencies, environment variables, build steps, and run commands.
* Any API keys or environment variables needed (explain how to get them, but **DO NOT COMMIT ACTUAL KEYS** to the repository). Use a `.env.example` file to show what's needed.
* Link to a live demo (if any).
* **(Optional but Recommended)** A short demo video or presentation slides (you can link these in your PR description or in your project's README).

## Judging Criteria (General Pointers)

While specific criteria might be announced, generally projects are evaluated on:

* **Functionality:** Does it work as intended? Does it achieve the core goal of calorie estimation from an image?
* **Accuracy:** How close are the calorie/macro estimations? (We understand this is complex!)
* **Innovation & Creativity:** Did you come up with a unique approach or an interesting feature?
* **Technical Implementation:** Quality of code, choice of technology, and complexity handled.
* **User Experience (UX/UI):** If applicable, is the application easy and pleasant to use?
* **Presentation/Demo:** How well you explain and showcase your project.
* **Adherence to Submission Guidelines:** Including a good project `README.md` and following the Git workflow.
## Installation

Follow these steps to set up the project on your local machine:

---
### Steps

1. Clone the repository:
```bash
https://github.com/Muhammad-anzil-pm/foodsnap-ai.git
```

2. Install dependencies
```bash
pip install -r requirement.txt
```

3. Run the project:
```bash
python main.py
```
## Results

### Detected Food Items Preview

![Detected Items](results/Food_detection.png)

Good luck, innovators! We can't wait to see your FoodSnap AI creations. Remember to have fun, learn, and collaborate!
### Terminal Output

**Happy Hacking!**
The WeCode Community Dev Team
![Terminal Output](results/Terminal_output.png)
5 changes: 5 additions & 0 deletions data/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
train: \data\train\images
val: \data\valid\images

nc: 5
names: ['apple','banana','grapes','mango','strawberry']
6 changes: 6 additions & 0 deletions data/nutrition.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name,calories,protein,fat,carbohydrates,dietary fibre,sugar
apple,52 kcal,0.26 g,0.17 g,13.81 g,2.4 g,10.39 g
banana,89 kcal,1.1 g,0.3 g,23 g,2.6 g,12 g
grapes,83 kcal,0.9 g,0.2 g,19 g,0.9 g,17 g
mango,60 kcal,0.8 g,0.4 g,15 g,1.6 g,14 g
strawberry,32 kcal,0.7 g,0.3 g,7.7 g,2 g,4.9 g
Binary file added data/sample_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import cv2
import pandas as pd
import yaml

from ultralytics import YOLO

model = YOLO('weights/best.pt')
while True:

img_path = input("Enter the path of your image : ")
img = cv2.imread(img_path)

results = model.predict(img, conf = 0.6)

result = results[0].boxes.cls

#to list of tensors
item = result.tolist()
items = set()

with open("data/data.yaml", 'r') as classes:
out = yaml.safe_load(classes)
for i in item:
i = int(i)
items.add(out['names'][i])

df = pd.read_csv('data/nutrition.csv')
df.set_index('name', inplace=True)

try:
for i in items:
print(i)
print(df.loc[i])
print('\n')
except:
print("food not found...")

results[0].show()
4 changes: 4 additions & 0 deletions requirement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ultralytics
opencv-python
pandas
yaml
Binary file added results/Food_detection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added results/Terminal_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/F1_curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/PR_curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/P_curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/R_curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added runs/confusion_matrix_normalized.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weights/best.pt
Binary file not shown.