Activity 1: Image Recognition
Train and Test the Image Classifier
Decide how many categories, or classes, you want and name them. Then use the webcam to take pictures for each class. For example, you might take pictures of you and your partner, or you with and without a stuffed animal. Aim for about 300 pictures for each class (this only takes a few seconds) and try to move around slightly so the camera gets a variety of angles.
The training will take about a minute. Make sure to leave the tab open while the model is training, even if your browser pops up a warning that the window is unresponsive.
When the training is complete, you will be able to test your model in the Preview panel. Make sure that your model works the way that you want it to before moving on. If it doesn’t, you may need to add more image samples for each class and train again. When you are happy with your model, click Export Model.
It is a good idea to save your model in case you want to reference or change it later. To do this, click on the Teachable Machine menu and either download the file or save it to your Google drive.
Using the Image Classifier in Snap!
Press the spacebar to see your classifier make predictions in Snap!. It will take up to a minute for the classification to start the first time you run the script. When it starts, the Snap! stage will show you an image of what the webcam sees and a table of prediction information. The table lists each classification class and the probability that the current image on the webcam belongs to that class. A probability close to 1 tells you that the image probably belongs to that class, while a probability close to 0 tells you that the image probably doesn’t belong to that class. For example, in this picture, the probability of “Darth Vader” is greater than 0.99, while the probabilities of all other classes are very small. Note that the probability of “None” appears to be greater than one; that is only because extremely small values are shown in scientific notation.
Challenge: Modify the program to make the Finch respond to each of your images. For example, this video shows the Finch responding to three Star Wars characters (turn your sound on). As you test your program, notice what happens if the webcam sees an image that is not similar to something in your training data.