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.
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.
Machine Learning Lifecycle
It consists of the following four major stages:
- Defining the objective
- Exploring and Acquiring the Training Data
- Training the Model
- 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.
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 https://teachablemachine.withgoogle.com/
- Click the Get Started button and a new page will open.
- Click the Image Project tile.
- A new page will open where you can see the following flow of the ML project.
Loading the Training Data
- Next, we will edit Class which is a category in which the Machine Learning model classifies the images.
- 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.
- 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.
- 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.
- A popup will open. Click the Upload my model button.
- Once uploaded, the sharable link will appear. Copy it.
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.
- Click the Load Model button.
- A pop-up will open. Paste the link that you copied from the Teachable machine and click the Load Model button.
- 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.
- 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!”.
- Similarly, we detect another class i.e. Mask ON and the Tobi will say “Thank You!” accordingly.
The final script will look like this: You can download the code from here.
Your script is now complete. Click the green flag to start the script.
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.