Machine Learning powered app to decide whether a photo is food or not.

Overview

Food Not Food dot app ( πŸ” 🚫 πŸ” )

Code for building a machine Learning powered app to decide whether a photo is of food or not.

See it working live at: https://foodnotfood.app

Yes, that's all it does.

It's not perfect.

But think about it.

How do you decide what's food or not?

Inspiration

Remember hotdog not hotdog?

That's what this repo builds, excepts for food or not.

It's arguably harder to do food or not.

Because there's so many options for what a "food" is versus what "not food" is.

Whereas with hotdog not hotdog, you've only got one option: is it a hotdog or not?

Video and notes

I built this app during a 10-hour livestream to celebrate 100,000 YouTube Subscribers (thank you thank you thank you).

The full stream replay is available to watch on YouTube.

The code has changed since the stream.

I made it cleaner and more reproducible.

My notes are on Notion.

Steps to reproduce

Note: If this doesn't work, please leave an issue.

To reproduce, the following steps are best run in order.

You will require and installation of Conda, I'd recommend Miniconda.

Clone the repo

git clone https://github.com/mrdbourke/food-not-food
cd food-not-food

Environment creation

I use Conda for my environments. You could do similar with venv and pip but I prefer Conda.

This code works with Python 3.8.

conda create --prefix ./env python=3.8 -y
conda activate ./env
conda install pip

Installing requirements

Getting TensorFlow + GPU to work

Follow the install instructions for running TensorFlow on the GPU.

This will be required for model_building/train_model.py.

Note: Another option here to skip the installation of TensorFlow is to use your global installation of TensorFlow and just install the requirements.txt file below.

Other requirements

If you're using your global installation of TensorFlow, you might be able to just run pip install requirements.txt in your environment.

Or if you're running in another dedicated environment, you should also be able to just run pip install -r requirements.txt.

pip install -r requirements.txt

Getting the data

  1. Download Food101 data (101,000 images of food).
python data_download/download_food101.py
  1. Download a subset of Open Images data. Use the -n flag to indicate how many images from each set (train/valid/test) to randomly download.

For example, running python data_download/download_open_images.py -n=100 downloads 100 images from the training, validation and test sets of Open Images (300 images in total).

The downloading for Open Images data is powered by FiftyOne.

python data_download/download_open_images.py -n=100

Processing the data

  1. Extract the Food101 data into a "food" directory, use the -n flag to set how many images of food to extract, for example -n=10000 extracts 10,000 random food images from Food101.
python data_processing/extract_food101.py -n=10000
  1. Extract the Open Images images into open_images_extracted directory.

The data_processing/extract_open_images.py script uses the Open Images labels plus a list of foods and not foods (see data/food_list.txt and data/non_food_list.txt) to separate the downloaded Open Images.

This is necessary because some of the images from Open Images contain foods (we don't want these in our not_food class).

python data_processing/extract_open_images.py
  1. Move the extracted images into "food" and "not_food" directories.

This is necessary because our model training file will be searching for class names by the title of our directories (food and not_food).

python data_processing/move_images.py 
  1. Split the data into training and test sets.

This creates a training and test split of food and not_food images.

This is so we can verify the performance of our model before deploying it.

It'll create the structure:

train/
    food/
        image1.jpeg
        image2.jpeg
        ...
    not_food/
        image100.jpeg
        image101.jpeg
        ...
test/
    food/
        image201.jpeg
        image202.jpeg
        ...
    not_food/
        image301.jpeg
        image302.jpeg
        ...

To do this, run:

python data_processing/data_splitting.py

Modeling the data

Note: This will require a working install of TensorFlow.

Running the model training file will produce a TensorFlow Lite model (this is small enough to be deployed in a browser) saved to the models directory.

The script will look for the train and test directories and will create training and testing datasets on each respectively.

It'll print out the progress at each epoch and then evaluate and save the model.

python model_building/train_model.py

What data is used?

The current deployed model uses about 40,000 images of food and 25,000 images of not food.

Owner
Daniel Bourke
Machine Learning Engineer live on YouTube.
Daniel Bourke
This is a python package to get wards, districts,cities and provinces in Zimbabwe

Zim-Places Features This is a python package that allows you to search for cities, provinces, and districts in Zimbabwe.Zimbabwe is split into eight p

RONALD KANYEPI 2 Mar 01, 2022
Python program that generates random user from API

RandomUserPy Author kirito sate #modules used requests, json, tkinter, PIL, urllib, io, install requests and PIL modules from pypi pip install Pillow

kiritosate 1 Jan 05, 2022
A demo of a data science project using Kedro

iris Overview This is your new Kedro project, which was generated using Kedro 0.17.4. Take a look at the Kedro documentation to get started. Rules and

Khuyen Tran 14 Oct 14, 2022
A webapp for taking fast notes, designed for business, school, and collaboration with groups.

JOTS Journal of the Session A webapp for taking fast notes, designed for business, school, and collaboration with groups.

Zebadiah S. Taylor 2 Jun 10, 2022
A python package for bitclout.

BitClout.py A python package for bitclout. Developed by ItsAditya Run pip install bitclout to install the module! Examples of How To Use BitClout.py G

ItsAditya 9 Dec 31, 2021
lets learn Python language with basic examples. highly recommended for beginners who just start coding.

Lets Learn Python 🐍 Learn python from basic programs. learn python from scratch. 1.Online python compiler: https://www.onlinegdb.com/online_python_co

Subhranshu Choudhury 1 Jan 18, 2022
Acesse seus investimentos da NuInvest pelo Python (Experimental)

Acesse seus investimentos da NuInvest pelo Python (Experimental)

AndrΓ© Roggeri Campos 5 Dec 06, 2022
Run CodeServer on Google Colab using Inlets in less than 60 secs using your own domain.

Inlets Colab Run CodeServer on Colab using Inlets in less than 60 secs using your own domain. Features Optimized for Inlets/InletsPro Use your own Cus

2 Dec 30, 2021
Tips that improve your life in one way or another

Tips that improve your life in one way or another. This software downloads life tips from reddit.com/r/LifeProTips and tweet the most upvoted tips on Twitter.

Burak Tokman 2 Aug 04, 2022
What Do Deep Nets Learn? Class-wise Patterns Revealed in the Input Space

What Do Deep Nets Learn? Class-wise Patterns Revealed in the Input Space Introduction: Environment: Python3.6.5, PyTorch1.5.0 Dataset: CIFAR-10, Image

8 Mar 23, 2022
Static bytecode simulator

SEA Static bytecode simulator for creating dependency/dependant based experimental bytecode format for CPython. Example a = random() if a = 5.0:

Batuhan Taskaya 23 Jun 10, 2022
Pixelarticons - Pixel Art Icons made simple for Flutter, powered by pixelarticons and fontify

Pixelarticons - Pixel Art Icons made simple for Flutter, powered by pixelarticons and fontify

lask 16 Dec 12, 2022
validation for pre-commit.ci configuration

pre-commit-ci-config validation for pre-commit.ci configuration installation pip install pre-commit-ci-config api pre_commit_ci_config.SCHEMA a cfgv s

pre-commit.ci 17 Jul 11, 2022
Taichi is a parallel programming language for high-performance numerical computations.

Taichi is a parallel programming language for high-performance numerical computations.

Taichi Developers 22k Jan 04, 2023
GEGVL: Google Earth Based Geoscience Video Library

Google Earth Based Geoscience Video Library is transforming to Server Based. The

3 Feb 11, 2022
With Christmas and New Year ahead, it is time for some festive coding. Here is a Christmas Card for you all!

Christmas Card With Christmas and New Year ahead, it is time for some festive coding! Here is a Christmas Card for you all! NOTE: I have not made this

CodeMaster7000 1 Dec 25, 2021
My Analysis of the VC4 Assembly Code from the RPI4

My Analysis of the VC4 Assembly Code from the RPI4

Nicholas Starke 31 Jul 13, 2022
A novel dual model approach for categorization of unbalanced skin lesion image classes (Presented technical paper πŸ“ƒ)

A novel dual model approach for categorization of unbalanced skin lesion image classes (Presented technical paper πŸ“ƒ)

1 Jan 19, 2022
Combines power of torch, numerical methods to conquer and solve ALL {O,P}DEs

torch_DE_solver Combines power of torch, numerical methods and math overall to conquer and solve ALL {O,P}DEs There are three examples to provide a li

Natural Systems Simulation Lab 28 Dec 12, 2022
Example teacher bot for deployment to Chai app.

Create and share your own chatbot Here is the code for uploading the popular "Ms Harris (Teacher)" chatbot to the Chai app. You can tweak the config t

Chai 1 Jan 10, 2022