Our model uses a convolutional neural network and TensorFlow to infer if an image is a Pastel de Nata or not.
We took the Mobilenet V3 pre-trained network and trained a new layer on top of it with thousands of Portuguese egg custard tart (Pasteis de Nata) images and other non related images to get the "Nata or Not" classifier. The model was trained on a server with an NVIDIA A100 Tensor Core GPU. Check our Jupyter notebook for details and code, inspired by the "Retraining an Image Classifier" tutorial.
To get a reasonable training dataset, we simply used as many Creative Commons images as possible from Google Images using the "pastel de nata" keywords. We also added a few of our own; the Lisbon Office is quite a fan of the famous pastry.
Finally, we also searched for non-egg tart images, the kind we think would be the most common for people to try out, like other foods, furniture, pets, people, and, of course, hotdogs.
Get your dataset and use the following folder structure to place the pastel
and not-pastel
images.
nata-model
│ notebooks
└───data
| pastel
└───not-pastel
Setup your python environment using python 3.7.10:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Run the notebook:
cd notebooks
jupyter notebook
To perform an inference run this notebook notebooks/inference.ipynb. You can change the default image in the fpath
variable.
We did a little live demo using this TensorFlow model using Cloudflare Workers and a Cloudflare server which has an NVIDIA A100 Tensor Core GPU in it.
Check our blog post for more information.