Activity 2: Animal Classifier in PictoBlox
Now we will see how to train the model. Let’s get started!
Training Settings
Click the Advanced button to see advanced settings.
You can change the following parameters to train the ML model:
- Epoch: The number of epochs is a parameter that defines the number of times that the learning algorithm will work through the entire training dataset. One epoch means that each sample in the training datasets has had a single opportunity to update the internal model parameters.
- Batch Size: It is the total number of training examples present in a single batch.
- Learning Rate: The learning rate is a tuning parameter in an optimization algorithm that determines the step size of each iteration while moving toward the optimization of the parameter.
For now, we will keep the default values. We will learn about the effect of parameters on the model in later lessons.
Training the Model
To train the model, click the Train Model button.
Testing the Model
Once trained, you can see the following Preview tile to test the model:
To test the image by uploading the testing files, click the Upload setting as shown in the image above. Now, upload the files and see how the model performs.
Exporting the Model
- To export the model so that you can import it in PictoBlox, click the Export button.
- A popup will open. Click the Upload my model button.
Once uploaded, the shareable link will appear. Copy it.
Let us see how to import a model in PictoBlox.
Importing the Model
- Open PictoBlox and start a new project.
- Click the Add Extension button and select the Machine Learning extension.
- Click the Load Model button.
- A model will open. Paste the link and click the Upload button.
- The relevant blocks will appear in the palette when the model is loaded successfully.
Understanding the Machine Learning Blocks
1. open recognition window
The Open recognition window block opens the recognition window with the camera feed the same as the AI extension and shows the predicted class based on the camera feed.
2. () block
The () block reports the label of the selected class.
3. identify class from ()
The identify class from () block reports the identified class from the selected feed – web camera, stage, or costume.
4. is identified class from () is ()?
The is identified class from () is () block reports true if the detected class from the selected feed is the selected class, else false.
5. get confidence of class () from ()
The get confidence of class () from () block reports the confidence of the selected class from the selected feed.

Tobi – The Classifier
Tobi will do us the honor of telling the result of the classification. Let us write the script for the same:
- Add the test images to the project by clicking the Upload Backdrop button. Select all 10 test images.
- Once uploaded, click the Backdrop tab and delete the white backdrop.
- Select Tobi. Switch to the sound tab and add the following two sounds from the library:
- Meow for cat
- Dog2 for dog
- Meow for cat
- Switch back to the Code tab.
- Add the when flag clicked block and the forever block into the scripting area and snap them together.
- Drag and drop the switch backdrop to () block inside forever block. From the drop-down, select random backdrop.
- Drag and drop the say () for () seconds block into the scripting area. In the first space, add the identify class from () block from the Machine Learning extension.
- Choose backdrop as the feed from the drop-down.
- Drag and drop the if block below the say block. Then, add the is identified class from () is ()? block in condition space. Select backdrop as the feed.
- From the Sound palette, add a play sound () until done block inside if block. From the drop-down, select Meow.
- Duplicate the if block and snap it below the first if block. Select the class as a dog in the second is identified class from () is () ? block.
- Change the sound in the second play sound () until done block to dog2.
Below is the complete script:
Click the green flag to run the script.
Yay! You have made your first Machine Learning project!

Assignment
Before moving on to the next lesson, a small assignment awaits you!
You must upload the video of the activity you created to the website. Submitting the assignment is a must to receive the certificate after completing the course.
[wpuf_form id=”18059″]