
Machine learning (ML) models, (like Google’s Teachable Machine) are trained to recognize categories of information called classes.
This ML model has been trained on two classes: apples and bananas. That means, that everything is either an apple, or a banana.
ML models don’t “see” images. They look for colour values of pixels in a picture, and compare that to images it was trained on. For example, an apple has many red pixels, in a circular shape.
Even if you’re not holding up an apple or banana to your camera, the ML model will look at objects in the background of your screen, your facial features, or clothes. Try “tricking” the program to find out when it works the best! Can you get an apple emoji when you hold up a red piece of paper? What other objects are often attributed as bananas?
How do you train an ML model to be more effective?
Programmers use experiments like “tricking” their ML model to learn how to make it better at correctly recognizing objects. Training the model using more images, including the object in different different lighting conditions, or on different backgrounds, are all ways to make your ML model recognize a class more effectively.
When creating your own ML model, you can also try creating a neutral class, so your AI program knows what it looks like when there is no apple or banana. Neutral classes should be trained to know that a person, your furniture, or any other background images look like.
Test an ML Model!

To test this activity, you’ll need a working webcam, and a printed copy of an apple, and banana. Once you have your materials, follow the steps below to test your model.
- Start the Code: Click on the apple & banana, and select “allow camera” when prompted by your browser.
- Show Apple & Banana Icon: One at a time, hold up the picture of your apple, then your banana. The AI model will react with the emoji of that fruit!
- Experiment: Try testing the model in different conditions, like the ones below:
- Black & white icon: How well can the AI recognize the shapes of the apples and bananas, without the colour?
- Real apple & banana: How well can the AI recognize a real red apple or banana?
- Apple & banana at the same time: Does the AI recognize an apple, or banana when it sees both at the same time?
About the Tools in This Activity
This challenge features a hands on activity created using Google’s Teachable Machine, and an open source community platform, p5.js. To use this activity, you must have a working webcam.
Your camera data is not collected by p5.js or Teachable Machine. Read more about the tools used in this activity below.
Teachable Machine is a web-based tool created by Google, that makes creating machine learning models fast, easy, and accessible to everyone.
Do I HAVE to train a model using a webcam?
Nope! Teachable Machine is a flexible tool, with several ways to train your data. For example, the model featured in this Digital2030 Challenge uses public-use, creative commons images of apples and bananas, rather than images captured from a computer’s webcam.
Who can access my samples?
Your samples aren’t sent to any servers, unless you save your project to Google Drive — and even then, it’s in your Google Drive, so that sample data is still yours. When you train the model, it trains in your browser tab without sending anything to any servers.
Where is my model published when I click “upload my model”?
Your model is published to Google servers, but the examples you used to make the model are not. Just your model — the mathematical program that predicts which class you’re showing it.
Who can use my model once it’s published?
If you choose to publish your model online (like the one we created in this Digital2030 Challenge), Teachable Machine will generate a URL where your model is hosted. You can share that link with anyone if you’d like them to use your model—anyone who has that link can use your model in their projects.
If you make a website that calls the url of your model, and someone looks at your code and finds that url, they could copy it and use it in their project — just like any image or video file you host online. However, they cannot change your model.
Learn more about this AI powered tool on Teachable Machine’s website.
p5.js is an open-source JavaScript library designed to make coding visual arts and creative technology accessible and inclusive for artists, designers, and educators.
How does the p5.js webcam feature work?
When users grant camera access to a p5.js program, the video data is handled through the browser’s MediaStream API. By default, p5.js does not upload or store your video data on any server. The video is processed entirely within your computer’s local memory (RAM) and rendered on your screen via the browser.
Learn More: p5.js Video Capture, p5.js Privacy Policy