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
Grammar of Scalable Linked Interactive Nucleotide Graphics

Gosling.js Gosling.js is a declarative grammar for interactive (epi)genomics visualization on the Web. ⚠️ Please be aware that the grammar of Gosling.

Gosling 126 Nov 29, 2022
A script where you execute a script that generates a base project for your gdextension

GDExtension Project Creator this is a script (currently only for linux) where you execute a script that generates a base project for your gdextension,

Unknown 11 Nov 17, 2022
Code for Crowd counting via unsupervised cross-domain feature adaptation.

CDFA-pytorch Code for Unsupervised crowd counting via cross-domain feature adaptation. Pre-trained models Google Drive Baidu Cloud : t4qc Environment

Guanchen Ding 6 Dec 11, 2022
DD监控室第一版

DD监控室 运行指南

执明神君 1.2k Dec 31, 2022
Data Poisoning based on Adversarial Attacks using Non-Robust Features

Data Poisoning based on Adversarial Attacks using Non-Robust Features Usage python main.py [-h] [--gpu | -g GPU] [--eps |-e EPSILON] [--pert | -p PER

Jonathan E. 1 Nov 02, 2021
This repository containing cross-section cut and fill calculations using Python programming language.

cross-section This repository is containing cut and fill calculations for cross-section using Python programming language. This codes is made to calcu

3 Jun 15, 2022
A tool to help calculate how to split conveyors in Satisfactory into specific ratios.

Satisfactory Splitter Calculator A tool to help calculate how to split conveyors in Satisfactory into specific ratios. Dependencies Python 3.9 PyYAML

RobotiCat 5 Dec 22, 2022
Fork of pathlib aiming to support the full stdlib Python API.

pathlib2 Fork of pathlib aiming to support the full stdlib Python API. The old pathlib module on bitbucket is in bugfix-only mode. The goal of pathlib

Jazzband 73 Dec 23, 2022
Meaningful and minimalist release notes for developers

Managing manual release notes is hard. Therefore, everyone tends to generate release notes from commit messages. But, you won't get a meaningful release note at the end.

codezri 31 Dec 30, 2022
A simple website-based resource monitor for slurm system.

Slurm Web A simple website-based resource monitor for slurm system. Screenshot Required python packages flask, colored, humanize, humanfriendly, beart

Tengda Han 17 Nov 29, 2022
Python language from the beginning.

Python For Beginners Python Programming Language ♦️ Python is a very powerful and user friendly programming language. ❄️ ♦️ There are some basic sytax

Randula Yashasmith Mawaththa 6 Sep 18, 2022
BlackIP-Rep is a tool designed to gather the reputation and information of Bulk IP's.

BlackIP-Rep is a tool designed to gather the reputation and information of Bulk IP's. Focused on increasing the workflow of Security Operations(SOC) team during investigation.

0LiVEr 6 Dec 12, 2022
Here You will Find CodeChef Challenge Solutions

Here You will Find CodeChef Challenge Solutions

kanishk kashyap 1 Sep 03, 2022
A topology optimization framework written in Taichi programming language, which is embedded in Python.

Taichi TopOpt (Under Active Development) Intro A topology optimization framework written in Taichi programming language, which is embedded in Python.

Li Zhehao 41 Nov 17, 2022
The docker-based Open edX distribution designed for peace of mind

Tutor: the docker-based Open edX distribution designed for peace of mind Tutor is a docker-based Open edX distribution, both for production and local

Overhang.IO 696 Dec 31, 2022
Block the annoying Token Grabbers on your discord

General We have seen that in the last time many discord servers are infected by fake discord nitro links we want to put an end to this and have develo

BadTiger Network 2 Jul 16, 2022
You can change your mac address with this program.

1 - Warning! You can use this program with Kali Linux. Therefore if you don't install the Kali Linux. Firstly you need to install Kali Linux. 2 - Star

Mustafa Bahadır Doğrusöz 1 Jun 10, 2022
A numbers check python package

A numbers check python package

Fayas Noushad 3 Nov 28, 2021
HPomb Is Socail Engineering Tool , Used For Bombing , Spoofing and Anonymity Available For Linux And Android(Termux)

HPomb v2020.02 Coming Soon Created By Secanonm HPomb Is Socail Engineering Tool , Used For Bombing , Spoofing and Anonymity Available For Linux And An

Secanonm 10 Jul 25, 2022
A minimal configuration for a dockerized kafka project.

Docker Kafka Quickstart A minimal configuration for a dockerized kafka project. Usage: Run this command to build kafka and zookeeper containers, and c

Nouamane Tazi 5 Jan 12, 2022