Tiny Sorter Tutorial
Tiny sorter is a project by Google whose aim is to show how Artificial Intelligence works. You can find this project here :
https://experiments.withgoogle.com/tiny-sorter/view
This little machine is capable of sorting object, provided that you train the device beforehand. You'll feed the sorter with two (or more) distinct objects and with the help of your webcam it will recognize the different objects and sort them accordingly, by dropping them to the left or to the right.
This experiment will go through some handcrafting, configuring an Arduino Leonardo, using a p5sketch that will control the Arduino and finally training and operating the tiny sorter via Teachable Machine.
Supplies
Electronics:
- Linux with a webcam and Google Chrome
- Arduino Leonardo with micro usb cable
- Micro Servo SG90
- 3 jumper wires
For the printout:
- A4 paper with the assembly instructions printed (~200g)
- Tape (electric tape recommended)
- Scissors
- Ruler
- Googley Eyes (to bring your device to life)
To sort:
You'll also need two objects to sort. The objects should be between 1-1.5cm. 5 to 10 of each should be enough to have some fun.
The shape doesn't matter too much as the tiny sorter will shake to make them go down one by one.
Some cereals can work very well as well as marbles, dices, small stones.
Take two bowls to collect your objects.
Download and Cut
You'll find the assembly PDF here:
https://experiments.withgoogle.com/tiny-sorter/view/assets/img/tiny_template.pdf
Use cardstock paper at home or in a print shop. The paper used should be around 200g or it may break easily.
Once printed, follow the instructions to cut and assemble the tiny sorter.
Use electric tape to tie the head and the servo motor for better results.
Setup the Arduino Leonardo
You need a computer with Arduino IDE installed
https://www.arduino.cc/en/software
Download the Arduino sketch and the WebUSB library here:
https://experiments.withgoogle.com/tiny-sorter/view/assets/img/sorter_sketch.zip
https://github.com/webusb/arduino/archive/gh-pages.zip
Open the file sorter_sketch.ino with Arduino IDE.
Now you need to add the WebUSB library for your Google Chrome browser to be able to connect to the Arduino.
On Arduino IDE go to Sketch -> Include Library -> Add Zip Library, and then browse to the WebUSB folder located in arduino-gh-pages/library that you just downloaded.
We need to fix the Usb version of Arduino from 2.0 to 2.1
- Open the terminal application
- type cd /usr/share/arduino
- type cd hardware/arduino/avr/cores/arduino
- type sudo nano USBCore.h
- find the line #define USB_VERSION 0x200
- change 0x200 by 0x210
- Press Ctrl + X to quit
- Press Y to save
Check in the Tools menu that you've selected the right type of board, also check that you have selected the correct port.
You can now upload the code to your Arduino by hitting the Upload button on the IDE.
Fix Usb Problem With Chrome
By default linux will block every usb connection toward your navigator and we need to allow it to be used by google chrome.
To do that follow these instructions:
- open the terminal
- type sudo usermod -a -G plugdev USERNAME (USERNAME being the name of your machine)
- type sudo nano /etc/udev/rules.d/50-leonardo.rules
- you are now in a text editor
- type SUBSYSTEM=="usb", ATTR{idVendor}=="2341", MODE="0664", GROUP="plugdev"
- Press Ctrl + X
- Press Y to save
- Finish
Open the P5 Sketch
Go to this link https://editor.p5js.org/gbose/present/2BN5HQYNK and click on Connect Arduino. If everything is ok and the servo motor is correctly wired, your tiny sorter will start shaking right and left!
If nothing happens, it is probable that you have to install drivers for your operating system or to allow your usb port to be exploited by Google Chrome.
You can now place your tiny sorter over your laptop's webcam. If your webcam is not able to see the content that's placed on the head of the tiny sorter, you should trim the paper a little.
Train Your Model
We will use Teachable Machine website to make a model for tiny sorter to learn what to recognize. Click here https://teachablemachine.withgoogle.com/train/image
Your Tiny Sorter should still be shaking for the training, so keep it connected on the p5 sketch. Now change your class name to "cereal" or whatever you want to sort. Then feed the sorter with a cereal, click on webcam and make around 30 snapshots by hitting the Hold to record button.
Do the same for the second object to sort, then add a third class and take some snapshots with no object to sort (it'll serve as comparison).
You should now have three class: Object 1, Object 2 and Empty
Now click on Train your model, it'll take a short while. Once done, click on Export Model.
Start Sorting
Click on Upload my model. This will create a link in the cloud for you to use in the p5 sketch. When the upload is finished, click on copy.
Go back to the p5 sketch, paste your model link and click Load Model. Your Tiny Sorter should be alive and you can feed it and start sorting objects!
Notes to the Futur Engineer
Above all, remember that the results of any machine learning model depend on the examples you provide. Feeding the machine with different examples is a core part of exploring machine learning. So, if it's not working as you intended, play around with different approaches and see if you achieve a better result.
This tutorial enables you to understand the basics of Machine Learning, hence also Artificial Intelligence. An important step in all Artificial intelligence applications consists in "Teaching" the machine for it to be able to work autonomously and perform the function it is meant for.
AI is currently one of the most vibrant fields in tech. Examples of AI that we deal with on a daily basis include the virtual assistant on e-commerce websites, devices that recognize body postures, animals, diseases, devices that play chess or go games... Although AI is still far from performing as efficiently as a human brain, this technology has already proven extremely useful in a variety of different fields.