A Walkthrough of Classification Tasks with Brain Builder for AITRIOS

Brain Builder version used: v24.09.7

Mastering Classification with Brain Builder for AITRIOS: Raspberry Pi Board Quality Control

In the world of electronics manufacturing, quality control is critical, and vision AI can play a pivotal role in ensuring consistency and accuracy. With Brain Builder for AITRIOS, you can easily train a Classification AI model to identify and categorize Raspberry Pi boards as Good, Bad, Lack, Board, Empty, or Background. This process automates defect detection and improves efficiency in real-time applications.

In this blog post, we’ll walk you through the steps to set up and train a Classification AI model for Raspberry Pi board quality control.

Conveyor belt with Raspberry Pi AI Camera scanning single-board computers

What is a Classification Model?

A classification model analyzes an image or a specific region of an image and assigns it to one of several predefined categories. For this use case, we’ll classify Raspberry Pi boards into the following categories:

  • Good: Boards that meet all quality standards.
  • Bad: Boards with visible defects or issues.
  • Lack: Missing components or parts on the board.
  • Board: Blurred image of the board.
  • Empty: No board detected in the image.
  • Background: Images that include irrelevant areas of the scene.
Examples of images by predefined categories such as: good, bad, lack, board, empty, background

How to Use the Classification AI Model for Raspberry Pi Boards

Follow these steps to create and train your model:

1. Create a New Project

  • Log in to Brain Builder for AITRIOS and select New Project.
  • Name your project (e.g., “Solder Point Monitoring”) and provide a brief description.
Brain Builder UI view where you can create a new project

2. Create a New Dataset

  • Select the “Create Dataset” button.
  • In our case, we will use the “Classifier” data type.
Brain Builder UI view where you can create a new dataset
Brain Builder UI view where you can choose the AI model type you want to create a dataset

3. Upload Data

  • Balance your dataset: Ensure you have enough images for each category (at least 50–100 per class is a good starting point).
  • You can upload images by class or upload a ZIP file that contains the images with the labels as the top-level folder names. We will use a ZIP file in this format:
Format for ZIP file structure
Brain Builder UI view where you click to upload new data
Folder view of the images in the dataset
Brain Builder UI view where you choose how you want to upload your data

4. Train the Learning Classifier

  • Select “Start Upload” to start the training process. The learning classifier will:
    • Evaluate your dataset against multiple AI models.
    • Learn to classify Raspberry Pi boards into the predefined categories.
  • Depending on the size of your dataset and the specs of your machine this could take from a few minutes to a few hours.
  • Review the results of the Learning Classifier. The possible results are "Still Learning", "Low", "Good" or "Great". You want to aim for a “Great” score. If you get a lower score, try adding more images.
Brain Builder UI view where you can review the results of the Learning Classifier
Brain Builder UI view where you can check some of the images to make sure that they are classifier correctly by the Learning Classifier
Why Start with a Learning Classifier?

A Learning Classifier is a dynamic model that actively improves its predictions during training by testing against your dataset and refining itself. This step is crucial for several reasons:

  1. Model adaptation: The Learning Classifier tailors its predictions based on the nuances of your dataset, ensuring it understands specific features like soldering quality or missing components.
  2. Accuracy foundation: By starting with a Learning Classifier, you establish a baseline model that is well-optimized for your task. The Static Classifier then locks in this trained behavior.
  3. Customization: The Learning Classifier identifies and adjusts to variations in the dataset, such as lighting conditions, angles, or minor manufacturing inconsistencies.

Once the Learning Classifier has been fully trained and evaluated, the Static Classifier locks these results for consistent deployment, avoiding further changes or drifts in predictions.

5. Train the Static Classifier

  • Go to the Training tab and configure your training preferences:
    • Duration - Choose based on your needs*:
      • Quick: for rapid prototyping.
      • Balanced: for good results with moderate time.
      • Thorough: for maximum accuracy.
    • Performance - Select a priority*:
      • Highest Average Accuracy: for balanced results.
      • Highest Accuracy: prioritizes correct detections by relaxing criteria.
      • Lowest Occurrence Rate of False Positives: reduces false positives with stricter criteria.
  • Start the training process. Brain Builder will test multiple AI models and optimize the best one for your dataset.

*In most cases Balanced duration and Highest Average Accuracy will work. Depending on the size of your data training and the specs of your machine, training the Static Classifier could take a significant amount of time, especially if you pick the highest settings.

Brain Builder UI view where you can choose the settings to build the Static Classifier
Brain Builder UI view where you can find the evaluation score for the Static Classifier
Brain Builder UI view where you can check some of the images to make sure that they are classifier correctly by the Static Classifier

6. Test the Results

  • Review the evaluation metrics:
    • Accuracy: How well the model predicts each class.
    • Confusion Matrix: Check for common misclassifications (for example, confusing “Good” with “Bad” or “Background”).
  • Fine-tune your dataset, if necessary, by adding more images for underrepresented categories or re-labeling unclear samples.
Diagram on how you can finetune your dataset
Brain Builder UI view showing how you test your AI model with images that are not part of the dataset

7. Export the Model

  • Once everything looks good you are ready to export your model. This will be a ZIP file named after your project.
Brain Builder UI view of the Export Brain screen.
Diagram showing what files are needed for deploying the AI model to a Raspberry Pi AI Camera

8. Deploying to the Raspberry Pi AI Camera

Deploying a model to the Raspberry Pi AI Camera is simple with Brain Builder for AITRIOS. We will take the exported model and use the IMX500 build tools package to convert the trained model into a format that Raspberry Pi AI Camera can use.

1. Be sure that you have installed all the dependencies.

sudo apt install imx500-tools
sudo apt install python3-opencv python3-munkres python3-picamera2
git clone https://github.com/SonySemiconductorSolutions/aitrios-rpi-model-zoo.git

2. Copy your exported Brain to the Raspberry Pi, unzip the top-level file, and the dataset named file.

Folder and terminal screen view for deploying the model to the Raspberry Pi AI Camera

3. Open a terminal at your extracted dataset. That would be {Unzipped brainBuilderExport}/{Unzipped dataSetName} and run this command. It will create your network.rpk file.

imx500-package -i packerOut.zip -o .

4. Switch to the correct Model Zoo directory, in this example, the classification/brainbuilder directory. Copy your network.rpk and labels.txt files to this directory.

cd aitrios-rpi-model-zoo/models/classification/brainbuilder/
Folder view of where the network.rpk and labels.txt files that need to be copied can be found

5. Push to the Raspberry Pi

  • Run the below command.
python app.py --model network.rpk --labels labels.txt --fps 15

6. See it in Action

  • Watch as your Raspberry Pi AI Camera runs your model in real-time, performing tasks from object recognition to classification all completely on the camera freeing up your Raspberry Pi board.
View of the results on the Raspberry Pi AI Camera running your model in real-time

Tips for Success
  1. Diverse data: Include images of boards from different angles, lighting conditions, and conveyor belt positions.
  2. Handle ambiguities: Ensure clear labeling, especially for edge cases like partially defective boards.
  3. Iterative improvement: Use test results to refine your dataset and retrain the model for better accuracy.

Use Case Spotlight: Raspberry Pi Board Classification

Here’s how your trained Classification model can streamline quality control:

  1. Automated inspection: The model processes live images of Raspberry Pi boards on a conveyor belt.
  2. Real-time classification:
    • Marks boards as Good or Bad based on soldering quality or missing components.
    • Identifies empty slots as Empty or misaligned objects as Background.
    • Detects incomplete boards as Lack.
  3. Improved efficiency: Reduces human error and speeds up the inspection process.

Ready to Build?

With Brain Builder for AITRIOS, creating and deploying a Classification AI model is simple and efficient.

Start today and bring AI-powered quality control to your production line!

Try it now