Giving your robot eyes: a tiny vision model
A camera and a tiny image classifier can tell your robot which way the path turns. Train one on small synthetic images and learn why real-world data matters.
In 60 seconds
Giving your robot eyes: a tiny vision model
A camera and a tiny image classifier can tell your robot which way the path turns. Train one on small synthetic images and learn why real-world data matters.
Where the camera and the model can live
| Setup | How it works | Keep in mind |
|---|---|---|
| Phone as camera | A phone on the robot, or held above, sends images to a laptop; the laptop runs the model and sends commands to the robot | Easiest to start; needs a reliable link (Wi-Fi, Bluetooth or a cable), and adds delay |
| Small computer with a camera | A Raspberry Pi (not the Pico) with a camera module runs a small model on the robot | More power-hungry and costly than a microcontroller; much more capable |
| Microcontroller camera board | Some ESP32 boards come with a small camera; very tiny models can run on the board | Very little memory: images must be small and models tiny |
How you build one
- 1
Decide the labels
Keep them few and clear: for example left, straight, right. - 2
Collect images
From the robot's own camera, in the real room, in different light, at different positions. - 3
Label them
Put each image in the right group. Mistakes here become mistakes in the model. - 4
Train and test
Train on most images; test on images the model has never seen. - 5
Shrink and deploy
Make the images and the model small enough for your device. - 6
Keep a safe fallback
If the model is unsure, slow down or stop. Keep the distance sensor as a safety layer.
Why synthetic images first?
- All images from one room, at one time of day
- Only perfect, centred examples
- Test images that are copies of training images
- Different rooms, lights, floors and times of day
- Off-centre, blurry and partly hidden examples too
- A separate test set collected on a different day
Watch and read more
Lab
A tiny classifier that tells from an 8 × 8 camera picture whether the path leans left, goes straight or leans right, with at least 85% accuracy on new images.
The problem
This runs in your browser. make_image makes a fake 8 × 8 grey camera picture of the floor: light floor, dark tape leaning left, straight or right, with noise and random brightness.
- Run the starter. It shows some example images and says there is no model yet.
- Train a classifier on
X_trainandy_trainand store it in a variable namedmodel. For exampleLogisticRegression(max_iter=1000)orKNeighborsClassifier()from scikit-learn. Each row ofX_trainis one image flattened to 64 numbers. - Print the accuracy on
X_test. Goal: at least 0.85 on new images (the check makes its own). - Make darker test images (change the brightness range in a copy of
make_image) and write what happens to the accuracy, and what you would do about it on a real robot.
Practice lab
Edit the code and run it. Python runs in your browser — nothing is sent to our server.
No output. Add print(...) to see values.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1Your classifier gets 99% on the synthetic test set. Why is that not a promise it will work on your robot's real camera?Reveal
The test images came from the same code as the training images, so they share the same "world": the same tape shape, noise and brightness range. A real camera adds shadows, reflections, blur, lens distortion and a different angle. The honest test is on real images from the robot, collected on a different day and place from the training images.
Q2The robot must decide 10 times a second, and your board has very little memory. What would you change about the model and the images?Reveal
Keep images tiny and in grey, as in the lab, and pick a small model: a linear classifier or a very small neural network. Fewer pixels and fewer model weights mean less memory and faster decisions. Then test that accuracy is still good enough. If it is not, move the model to a phone or laptop and accept the extra delay, with a local safety stop on the robot.
Questions people ask
Can I train a model without a powerful computer?
For tiny images and simple models like logistic regression, yes, a normal laptop or even the browser is enough. Larger vision models need more power, and many people use free online notebooks. Check the current limits and terms of any service you use.
How many images do I need?
It depends on how different the classes look and how varied the real world is. Start with some tens of images per class, test honestly on new images, and add more images of the cases where the model fails. More varied data usually helps more than more of the same.
Why not use a big vision-language model instead?
You can, for example on a laptop or through an online service, but it is slower, needs a network or a strong computer, and costs more. For a simple, fast decision like "left, straight or right", a tiny classifier is often better. Big models are useful for open questions, like "what is on the table?".
What does "the model is unsure" mean?
Many classifiers give a probability for each label. If the top label has a low probability, or two labels are close, the model is unsure. A robot can treat that as "slow down and look again" instead of acting on a guess.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.