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
Shai-Hulud - A qtile configuration for the (spice) masses

Shai-Hulud - A qtile configuration for the (spice) masses Installation Notes These dotfiles are set up to use GNU stow for installation. To install, f

16 Dec 30, 2022
A python script to decrypt media files encrypted using the Android application 'Secret Calculator Photo Vault'. Supports brute force of PIN also.

A python script to decrypt media files encrypted using the Android application 'Secret Calculator Photo Vault'. Supports brute force of PIN also.

3 May 01, 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
Desenvolvendo as habilidades básicas de programação visando a construção de aplicativos por meio de bibliotecas apropriadas à Ciência de Dados.

Algoritmos e Introdução à Computação Ementa: Conceitos básicos sobre algoritmos e métodos para sua construção. Tipos de dados e variáveis. Estruturas

Dyanna Cruz 1 Jan 06, 2022
ERPNext Easy Letterhead

ERPNext Easy Letterhead Intro Quality letterheads are a problem for non-technical users. So we've built (really hacked together) a slightly easier sol

Bantoo 3 Jan 02, 2023
Collie is for uncovering RDMA NIC performance anomalies

Collie is for uncovering RDMA NIC performance anomalies. Overview Prerequ

Bytedance Inc. 34 Dec 11, 2022
Identify unused production dependencies and avoid a bloated virtual environment.

creosote Identify unused production dependencies and avoid a bloated virtual environment. Quickstart # Install creosote in separate virtual environmen

Fredrik Averpil 7 Dec 29, 2022
📙 Super lightweight function registries for your library

catalogue: Super lightweight function registries for your library catalogue is a tiny, zero-dependencies library that makes it easy to add function (o

Explosion 139 Jan 02, 2023
🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.

Boltons boltons should be builtins. Boltons is a set of over 230 BSD-licensed, pure-Python utilities in the same spirit as — and yet conspicuously mis

Mahmoud Hashemi 6k Jan 06, 2023
hey, this repo is the backend of the sociio project

sociio backend Hey, this repository is a part of sociio project , In this repo we are working to create an independent server for everything you can i

2 Jun 09, 2022
Woltcheck - Python script to check if a wolt restaurant is ready to deliver to your location

woltcheck Python script to check if a wolt restaurant is ready to deliver to you

30 Sep 13, 2022
apysc is the Python frontend library to create html and js file, that has ActionScript 3 (as3)-like interface.

apysc apysc is the Python frontend library to create HTML and js files, that has ActionScript 3 (as3)-like interface. Notes: Currently developing and

simonritchie 17 Dec 14, 2022
Robotic hamster to give you financial advice

hampp Robotic hamster to give you financial advice. I am not liable for any advice that the hamster gives. Follow at your own peril. Description Hampp

1 Nov 17, 2021
The Official Jaseci Code Repository

Jaseci Release Notes Version 1.2.2 Updates Added new built-ins for nodes and edges (context, info, and details) Fixed dot output Added reset command t

136 Dec 20, 2022
A compilation of useful scripts to automate common tasks

Scripts-To-Automate-This A compilation of useful scripts for common tasks Name What it does Type Add file extensions Adds ".png" to a list of file nam

0 Nov 05, 2021
This library attempts to abstract the handling of Sigma rules in Python

This library attempts to abstract the handling of Sigma rules in Python. The rules are parsed using a schema defined with pydantic, and can be easily loaded from YAML files into a structured Python o

Caleb Stewart 44 Oct 29, 2022
A Linux webcam plugin for BGMv2 as used in our demos.

The goal of this repository is to supplement the main Real-Time High Resolution Background Matting repo with a working demo of a videoconferencing plu

Andrey Ryabtsev 144 Dec 27, 2022
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
Machine Learning powered app to decide whether a photo is food or not.

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 a

Daniel Bourke 48 Dec 28, 2022
My custom Fedora ostree build with sway/wayland.

Ramblurr's Sway Desktop This is an rpm-ostree based minimal Fedora developer desktop with the sway window manager and podman/toolbox for doing develop

Casey Link 1 Nov 28, 2021