Your first artificial intelligence without programming: Teachable Machine
It's time to make your first model! The tool Teachable Machine works in a web browser: you record examples with the camera, click “Train” and in less than a minute the model recognizes your objects. Without a single line of code and without opening an account.
What you need
- a computer with a web browser (Chrome, Edge or Firefox) and a camera (a laptop's built-in camera is fine);
- 2–3 objects that are easy to tell apart (for example a pencil, an eraser, a mug) – or a hand showing “rock, paper, scissors”;
- the address: teachablemachine.withgoogle.com (a tool by Google).
Step 1: a new project
- Open the website and click Get Started.
- Choose Image Project, then Standard image model.
- On the screen you see three parts: on the left the classes (groups of examples), in the middle the button Train (learning), on the right Preview (testing).
Step 2: classes and examples
- Click the name Class 1 and rename it, for example to pencil. Rename Class 2 to eraser.
- Add a third class (Add a class) and name it nothing – record an empty desk or just the background in it. This way the model also knows when there is nothing in front of the camera.
- In each class click Webcam, then hold the button Hold to Record while moving the object: turn it, bring it closer, move it away. Record 50–100 images per class.
These are your training data, and the class names are the labels – just like in the previous lesson.
Step 3: training and testing
- Click Train Model and wait (don't close the tab). The computer is now adjusting the model – this is training.
- When it finishes, show the objects to the camera in the Preview part. The bars show how “sure” the model is for each class (for example pencil 95%).
- Also try objects it hasn't seen – another pencil, a pencil of a different color. This is your test.
Experiments: how to “break” and fix the model
| Experiment | What to do | What you will probably notice |
|---|---|---|
| few examples | make a new model with only 5 images per class | the model makes mistakes more often and “jumps” between classes |
| a change of light | turn the light on or off, move to the window | success drops if you recorded everything in the same light |
| a biased background | record the pencil only on a white surface and the eraser only on a blue one; then swap the surfaces | the model “holds on” to the background color, not the object – and makes a mistake |
| a new class | add an object the model has never seen | the model still puts it into one of the existing classes – it can't say “I don't know” unless we taught it that |
The background experiment is very important: it shows how a model can learn the wrong thing that happens to match the label. The same happens to large models – that is why varied data is so important.
Other kinds of projects
- Audio Project – the model recognizes sounds: clapping, whistling, the spoken words “left” and “right”. Be sure to also record the class Background Noise (silence in the room).
- Pose Project – the model recognizes body positions (hands up, squat). Good for a game in the gym.
- You can save the model (Export Model) and later use it in your own program – more about this in the programming module.
Activity: rock, paper, scissors
- Make four classes: rock, paper, scissors and nothing.
- Record 80 images of your hand for each sign, from different angles, with both your left and your right hand.
- Train the model and play with a friend: the model is the referee that recognizes the signs.
- Write down how many times out of 20 tries the model recognized the sign correctly – calculate the accuracy.
The first 10 minutes: a shared example on the projector. Then groups make their own models (20 min) and do the background experiment (10 min). At the end, each group reports its accuracy and one thing that “broke” the model.
Common misconceptions
- “The model sees the object as we do” – the model looks at the colors and shapes of pixels; it is easily confused by the background or the light.
- “If the model is 99% sure, it must be right” – “sureness” is just a number the model calculates; it can be very sure and wrong.
Practice tasks
Try it yourself first, and only then open the solution.
- Why is it good to add the class “nothing” (just the background)?
- A model learned to tell bananas from apples, but all the bananas were photographed on a wooden table and the apples on white paper. What will happen if you put an apple on the wooden table?
- In 20 tries the model recognized the sign correctly 17 times. What is the accuracy? How would you increase it?
Solution 1: answer
Without it the model always has to choose one of the objects, so even when there is nothing in front of the camera it “sees” a pencil or an eraser. The class “nothing” teaches it this case too.
Solution 2: explanation
The model will probably say “banana”, because it learned that a wooden background means banana. This is bias in the data – the solution is to photograph both fruits on different surfaces.
Solution 3: answer
17 / 20 · 100% = 85%. It can be increased with more and more varied images (different light, angle, both hands, different people) and the class “nothing”.
Check your knowledge
Open the quiz
Quiz: Teachable Machine
1. What are “classes” in Teachable Machine?
2. What does the button Train Model do?
3. The pencils were recorded only on a white surface and the erasers only on a blue one. What will the model probably learn?
4. Why is the class “nothing” added?
