Table of Contents

when class () is predicted

Description

Scripts that wear this block will activate once the selected class is predicted either on the recognition window, stage or camera.

Example

The example shows how to use a audio classifier in PictoBlox to make the Bird Audio Classifier Bot.

Introduction

In this example project, we are going to create a machine learning model that can classify different audio messages of birds from the microphone feed of computer.

Audio Classifier in Machine Learning Environment

The Audio Classifier is the extension of the ML Environment used for classifying different birds voice.

Audio Classifier Workflow

Follow the steps below to create your own Audio Classifier Model:

  1. Open PictoBlox and create a new file.
  2. Select the Block coding environment as the appropriate Coding Environment.
  3. Select the “Open ML Environment” option under the “Files” tab to access the ML Environment.
  4. A new window will open. Type in an appropriate project name of your choice and select the “Audio Classifier” extension. Click the “Create Project” button to open the Audio Classifier Window.
  5. You shall see the Classifier workflow with two classes already made for you. Your environment is all set. Now it’s time to upload the data.
  6. As you can observe in the above image, we will add many classes for audio. We will be able to add audio samples with the help of the microphone.

Note: You can add more classes to the projects using the Add Class button.

Adding Data to Class

You can perform the following operations to manipulate the data into a class.

  1. Naming the Class: You can rename the class by clicking on the edit button.
  2. Adding Data to the Class: You can add the data using the Microphone.
  3. You will be able to add the audio sample in each class and make sure you add at least 20 samples for the model to run with good accuracy.

Training the Model

After data is added, it’s fit to be used in model training. To do this, we have to train the model. By training the model, we extract meaningful information from the hand pose, and that in turn updates the weights. Once these weights are saved, we can use our model to make predictions on data previously unseen.

The accuracy of the model should increase over time. The x-axis of the graph shows the epochs, and the y-axis represents the accuracy at the corresponding epoch. Remember, the higher the reading in the accuracy graph, the better the model. The range of accuracy is 0 to 1.

Testing the Model

To test the model simply, use the microphone directly and check the classes as shown in the below image:

You will be able to test the difference in audio samples recorded from the microphone as shown below:

Export in Block Coding

Click on the “Export Model” button on the top right of the Testing box, and PictoBlox will load your model into the Block Coding Environment if you have opened the ML Environment in the Block Coding.

Script

The idea is simple, we’ll add one image of  each class in the “costume” column by making one new sprite which will we display on the stage according to input from user. we’ll also change name of the image according to bird class type.

  1. Add one bird image as another sprite and upload at-least one image of all bird classes on costume.
  2. Now, come back to the coding tab and select the Tobi sprite.
  3. We’ll start by adding a when flag clicked block from the Events palette.
  4. Add the “open recognition window” block from the Machine Learning palette.
  5. Add an “when () is predicted” block from the Machine Learning palette. Select the appropriate class from the options.
  6. Add an “say () for () seconds” block from the Looks palette block. Write an appropriate statement in an empty place.
  7. Repeat the same code for other classes and make changes according to the class.
  8. For “BackNoise” class, don’t add any statement at place of empty space of “say () for () seconds” block
  9. Final code of “Tobi” sprite is
  10. Now click on another sprite and write code.
  11. We’ll start writing code for this sprite by adding a “when () is predicted” block from the Machine Learning palette.
  12. Add the “switch costume to ()” block from the Looks palette. Select the appropriate class from the options.
  13. Repeat the same code for other classes and make changes according to the class.
  14. Final code of another sprite is

Final Output

Read More
All articles loaded
No more articles to load