• Place the tiny sorter over your webcam so the camera can see into the bucket.
  • To create a new image project on Teachable Machine click here.

Time to grab some cereal and train some models!

Train the cereal class

Fill your first class with pictures of cereal captured from your webcam. The sorter will be shaking while training. Hint: the shaking mechanism allows the cereal to flow down the chute and into the bucket for the camera to see.

You can un-attach the pin A1 cable from the CPX in between training models to stop the sorter from shaking.

Train the marshmallow class

  • Next, fill your second class with pictures of marshmallows also captured from your webcam.
Q: How many pictures do I need to train each class?

A: Try to get somewhere between 75 - 150 pictures per class. But experiment with it! Remember the more accurate data your model has the better it will be.

Train the "nothing" class

  • Then train a third class with nothing inside the bucket. This class lets the sorter know when there is nothing in the bucket thus it should continue to shake until there is something identifiable.

Make sure to name each class corresponding to the object it represents.

To edit class names, click the pencil icon at the top of each class. 

  • Next, hit "train model" and that's it! You've trained a model.

  • Try testing out how well your model works by placing items in the bucket. The model will try to classify the items on the bottom right of the site.
  • If your model isn't recognizing very accurately, try adding more pictures to the classes that seem weak.
  • Next click "export model" and then  "upload my model" to upload to the cloud.

Load the model in the p5 sketch

  • After uploading the model, copy the sharable link to your clipboard.
  • Back on the p5 sketch site, paste in the link and hit "load model".

Test it Out.

Label a couple of bowls or cups and place next to each other accordingly under the sorter.

Drop in some cereal and see how well you've trained your model. Does it go into the right bucket?


Problem: The sorter is not accurately identifying the cereal.

Solution 1: Make sure the tiny sorter is aligned with your webcam for good classification.

Solution 2: Try adding more pictures to the "nothing" class in your model. Add some pictures of the background that your webcam sees when the sorter tilts one way or the other. This will help the model know when to keep wigglin' away! (eg. it may see the colors in your room or on your shirt and think it's a marshmallow)

Problem: The cereal is getting stuck or is moving too slowly down the ramp.

Solution: Tilt your computer screen up or down to make the ramp steeper or shallower.

You can always feel free to refer to the original guide which has videos and more.

Going further

Make this project your own! Classify whatever you can think up and train new and exciting models.

Other ideas include:

Wanna try this out with other boards?

You're in luck because Web USB and the code from this guide is now supported by any board with SAMD chip. This means you will be able to use the code from this project with the following boards:

  • PyPortal
  • Metro Express
  • Gemma M0
  • Itsy Bitsy M0 express
  • Feather M0
  • So many more!

Check out more tools and resources on machine learning from Teachable Machine.

Good luck modeling!

This guide was first published on Jan 27, 2020. It was last updated on Jan 27, 2020.

This page (Train the Model) was last updated on Jan 07, 2020.

Text editor powered by tinymce.