Teachable Machine Tutorial: Bananameter
Hi! This is a tutorial for Teachable Machine, a web-based tool that makes creating machine learning models fast, easy, and accessible to everyone.
In this tutorial, I’m going to walk you through making a machine learning model to detect how ripe a banana is using images. You don’t have to use bananas for this — you can use any fruit that changes color, or really, any three different objects — but we had bananas handy.
There are also two other tutorials — one making a machine learning model using audio, and one using poses.
So to get started, I’ll go to Teachable Machine and open up an image project.
HOW TO TRAIN IT
To start training the machine, we first have to create different categories, or classes, to teach it with. I’m going to make four classes here — one for bananas that are too early, one for bananas that are ripe, and one for bananas that are too late — plus one for images where there’s no banana at all.
Now that I have my classes, I’m going to give each class samples to learn from. In this case, those will just be images of the banana — so let’s start with a banana that’s “Too Early.”
Then, we’ll do the same with a ripe banana:
And a banana that’s a little past its prime:
And finally, an image with no banana at all. Notice that I’m also showing it my hand without a banana, so that it doesn’t only see hands in the classes with bananas and make a correlation that an image has to include a hand to be classified as ripe/etc.
Now that I have all of my classes ready, I can click train…
And, over on the right, preview if the model works!
THINGS TO TRY
Ok, now that it’s working, you can test out how it works — and even more fun, see where it doesn’t work. Try to find the edges of where the model works — machine learning has limits!
Remember that to the computer, images are just numbers & patterns of pixels.
So you haven’t truly taught it what a banana is… we taught it that THIS — a yellow shape against a background, is labelled a ripe banana — it’s just pixels to the computer.
And because of this, there are lots of ways it can get confused. So, let’s look at a few:
For example, if you hold up two bananas at the same time, the model never saw samples that looked like that while it was training, so it might be confused.
Different Backgrounds & Lighting
Or try evaluating your bananas on a different background, like a different color wall — does it still work?
On this new background, it gets some of the classes a little confused…
…so I’m going to add more samples to each class with the banana on the new background.
You can add more images of your bananas in different environments to make your model more robust, so that it can work on different backgrounds. I’ve added some more samples of my bananas on these backgrounds, so it’s a little better at recognizing now:
You could also try uploading a bunch of photos of bananas from the internet to get a more robust set of banana images, or collaborate on a dataset with folks in different places
Try to trick it!
Hold up a photo of a banana! Or a drawing of a banana! Or a toy that looks like a banana! See how the model responds to different images, and if you can figure out a way to train it so that it doesn’t get confused.
OTHER FUN FRUIT-RELATED CHALLENGES
Of course, you don’t need to use bananas to use Teachable Machine. You could make models with different types of apples, gourds, pumpkins, etc.
WHAT CAN YOU DO WITH THIS?
You can actually export your model to make things with it if you like!
For example, I exported this model and made this website that tells how ripe a banana is on Glitch. You can try out if you like, but your results may vary.
And one of our friends made this game that you can control with an image model from Teachable Machine.
You can learn more about using your models in the Teachable Machine FAQ here.
If you’re interested in peeking behind the scenes, you can open this project to see all the samples and try it out.
If you want to try making your own model, get started at Teachable Machine.