Skip to content

Added macronutrients for 100 foods

Latest
Compare
Choose a tag to compare
@mrdbourke mrdbourke released this 14 Mar 07:09
· 60 commits to main since this release

Nutrify now displays macronutrient information for ~100 foods

When you upload a photo to Nutrify, it now predicts what class of food is in the image and then displays information about that foods macronutrients.

This happens via:

image upload -> computer vision model -> returns class -> class index used to index on a database (hosted on Supabase) -> information from Supabase displayed on homepage

This took a while to happen but I had to learn all about databases (Supabase uses pure PostgreSQL).

The good thing is the app is still fast.

A prediction + query to the database is done in ~0.2-0.5 seconds.

That'll be the peak time I'd like to let it happen in, any longer and the experience won't be as fun.

See the database code in the various JavaScript scripts (I'm new to JS so these are rough):

  • Constants for different food names/food data central IDs (fdc_id) live in constants.js
  • The database query and HTML update for macronutrients happen via get_data.js
  • The image upload and image classification happens via script.js
  • The connection to Supabase happens via supabaseClient.js - this uses an anon API key, that's apparently "safe to use in public", though I'm not sure what this means
  • Utility functions (all one of them) are located in utils.js

Is this how JS projects get laid out?

I have no idea.

It seems to work though.

Issues

No nutrition information for some foods

You might find that ~3/100 foods (like "egg tart") don't show nutrition information.

This is because they don't exist (at least what I've found) in the Food-Central USDA Database (where the rest of the nutrition information comes from).

Data loading is likely not optimal

I'm a newbie to databases.

The speed is how it is now because all of the database rows are loaded when you go to nutrify.app and then they are cached and queried when a prediction is made.

This may not be best practice... but it works.

Ideally, the database would be queried per image classification.

However, I tried this and it takes 1-2 seconds per query (from where I live in Australia because the Supabase database is hosted in the US), this kind of time delay is not acceptable.

Again, queries should happen within a maximum of 0.5 seconds.

The model still does not predict whether there is a food present or not

Future updates will include a food/not food model to see if there's food present in the image or not.

Next

  • Add food/not food model + a message about "no food detected, please upload a photo of food"
  • Make app design nicer
  • Add a way to toggle different nutrients to view
  • Add a way to adjust the different amount of macronutrients per food (e.g. 100g -> 50g -> 250g)
  • Add logging? Logging for different predictions/images etc
  • Clean up the GitHub repo... seriously, what's going on here now? Perhaps it's time for an organization?