Making a Mask Identifier: Machine Learning in PictoBlox

Machine Learning with PictoBlox
About This Tutorial
In this tutorial learn what is machine learning and how can we use it to make mask identifiers in PictoBlox.
Tutorial Info

In today’s world of technology, Machine Learning is used in many fields i.e. surveillance,  healthcare, defense, gaming, and much more. Hence, in this tutorial, we will also make a script in PictoBlox based on the machine learning model that detects the face using the camera and reports whether the person has a face mask covering his nose and mouth or not.

Let’s begin.

Machine learning

First of all, let’s understand what Machine learning is and how it works.

Machine Learning is commonly used alongside AI but they are not the same thing.  It refers to systems that can learn by themselves, that get smarter and smarter over time without human intervention.

ML is a subset of AI.AI and ML comparison

Machine Learning Lifecycle

It consists of the following four major stages:

  1. Defining the objective
  2. Exploring and Acquiring the Training Data
  3. Training the Model
  4. Deploying the Model

Now, we know about Machine Learning is and its lifecycle. So, Let’s make a script in PictoBlox based on the machine learning model that detects the face using the camera and reports whether the person has a face mask covering his nose and mouth or not.

Before making a script make sure your device has connected to the Internet. Because we are going to use the Machine Learning extension of PictoBlox and it will work only if your device is connected to the internet.

Let’s Begin!

First of all, we will make and train a machine learning model using Teachable Machines and use it inside PictoBlox.

Teachable Machine is a tool that makes it fast and easy to create machine learning models for your projects. 


  • A PC/Laptop with a working camera/webcam
  • PictoBlox Software
  • Internet Connectivity
  • A face mask

Creating a Machine Learning Project

  • Go to
  • Click the Get Started button and a new page will open.
  • Click the Image Project tile.Choosing the Image Project
  • A new page will open where you can see the following flow of the ML project.ML Flow

Loading the Training Data

  • Next, we will edit Class which is a category in which the Machine Learning model classifies the images.Images-Class
  • Rename the Class 1 as Mask OFF.
  • Next, We will use the webcam to click the images of you without the mask, so, click on the Webcam button, and camera feed will start.
  • Now, click on the Hold to Record button, and webcam will start capturing the images. A set of 40-50 images will be good enough to start.
  • Next, Rename the Class 2 as Mask ON.
  • Wear the Face mask and record the 40-50 images with the face mask.

Your training data is ready as two classes: Mask OFF and Mask ON. Now we will see how to train the model. 

Let’s get started!

Training the Model

  • To train the model, click the Train Model button.Training Model Training Model
  • It will take a few minutes to train, so have some patience and don’t leave the page.

Testing the Model

  • Once trained, you can see the following Preview tile to test the model.Training Model
  • Just come in front of the webcam with and without wearing the mask, it will show output class with percentage of confidence.

Exporting the Model

  • To export the model so that you can import it in PictoBlox, click the Export Model button.  Exporting the Model
  • A popup will open. Click the Upload my model button.Exporting the Model
  • Once uploaded, the sharable link will appear. Copy it.Exporting the Model

That’s it. Next, we will make a script inside PictoBlox.

Importing the Model

  • Open PictoBlox and start a new project.
  • Select evive as your board from the Board Tab on the menu bar.
  • Click the Add Extension button and select the Machine Learning extension.  Machine Learning in PictoBlox
  • Click the Load Model button.Load Model
  • A pop-up will open. Paste the link that you copied from the Teachable machine and click the Load Model button.Load Model
  • The relevant blocks will appear in the Machine Learning palette when the model is loaded successfully.

Setting Up the Stage

  • Set the Tobi sprite’s standing position on stage and switch on the camera feed using the following script.  Wearing the Mask Script
  • Next, using the class identifier block, we will identify the class from the stage. If class returned by machine is Mask OFF, Tobi will say “Please wear a Mask!”.Wearing the Mask Script
  • Similarly, we detect another class i.e. Mask ON and the Tobi will say “Thank You!” accordingly.

The final script will look like this:Wearing the Mask Script You can download the code from here.

Your script is now complete. Click the green flag to start the script.Machine Learning with PictoBlox

Hope you enjoyed the tutorial, we also developed an online course on Artificial Intelligence covering all detailed concepts for smart kids like you. So for what you are what for? Enroll now and get yourself certified.

Share this Tutorial
Share on facebook
Share on twitter
Share on pinterest
Share on reddit
Share on print
Featured Projects

Leave a Reply