Introduction: Making a Mask Identifier Using Machine Learning

About: STEMpedia is a place bringing project-making tools at one place- kits, online courses, coding platforms, controller app and tons of free learning resources.

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- a Scratch Based Graphical Programming Software based on Scratch Blocks using 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!

You can join the free webinar on Artificial Intelligence for Kids.

Supplies

Prerequisites are:

  1. A PC/Laptop with a Working camera/webcam
  2. PictoBlox Software
  3. Good Internet Connectivity
  4. Face Mask

Step 1: What Is Machine Learning?

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.

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.

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

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.

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

Step 2: Training the Model in Teachable Machine

Let's begin by training the model in Teachable Machine.

  1. Go to https://teachablemachine.withgoogle.com/
  2. Click the Get Started button and a new page will open.
  3. Click the Image Project tile. (Fig 1)
  4. A new page will open where you can see the following flow of the ML project. (Fig 2)
  5. Next, we will edit Class which is a category in which the Machine Learning model classifies the images. (Fig 3)
  6. Rename the Class 1 as Mask OFF.
  7. 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.
  8. 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.
  9. Next, Rename the Class 2 as Mask ON.
  10. 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.
  11. Next, let's train the model.
  12. Click the Train Model button. It will take a few minutes to train, so have some patience and don’t leave the page. (Fig 4 & 5)
  13. Testing the Model Once trained, you can see the following Preview tile to test the model. (Fig 6)
  14. Just come in front of the webcam with and without wearing the mask, it will show output class with a percentage of confidence.

Step 3: Exporting the Model

  1. To export the model so that you can import it in PictoBlox, click the Export Model button. (fig 1)
  2. A popup will open. Click the Upload my model button.
  3. Exporting the Model Once uploaded, the sharable link will appear. Copy it.That’s it. Next, we will make a script inside PictoBlox.

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

Step 4: Writing the Script in PictoBlox

  1. Open PictoBlox and start a new project.
  2. Select evive as your board from the Board Tab on the menu bar.
  3. Click the Add Extension button and select the Machine Learning extension. (fig 1)
  4. Click the Load Model button. (fig 2)
  5. A pop-up will open. Paste the link that you copied from the Teachable machine and click the Load Model button. (fig 3)
  6. The relevant blocks will appear in the Machine Learning palette when the model is loaded successfully.
  7. Set the Tobi sprite’s standing position on stage and switch on the camera feed using the go to x() y() block and the turn ON video on stage with 0% transparency block.

  8. 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. (fig 5)

You can join the free webinar on Artificial Intelligence for Kids.

Step 5: Conclusion

With this your mask-identifier is ready.