Creating Your First Segmentation Recipe
  • 15 Nov 2024
  • PDF

Creating Your First Segmentation Recipe

  • PDF

Article summary

Once you’ve followed the steps in Creating Your First Recipe to configure the Imaging Setup, Template Image and Alignment, and Inspection Setup, follow the steps below to train a Segmentation model.

Label and Train

In this section, you’ll capture several images of the object and label defects using the brush tool. You’ll need to capture and label at least 10 images.

  1. From the Inspection Setup page, use the breadcrumb menu to select Label and Train. Alternatively, select Label and Train from the Recipe Editor.

    Segmeneter Recipe Editor Breadcrumb Menu

    Note

    The preview pane (on the left-hand side) displays a live preview, until an image is captured or is selected using the Navigation menu.

  2. Under Inspection Types, click Edit to rename the default class (fail_[Inspection Type Name]) or add additional classes. Once you have all the classes you need the camera to identify, continue to the next step.

  3. With the object in the camera’s field of vision, select Capture.

  4. Use the Brush tool to highlight the defects on the object you want the camera to identify.

    Tip

    Use the Eraser tool to remove any unwanted highlights.

  5. If you’ve added other classes, select the applicable Brush Class from the drop-down menu.

  6. Click Save Annotations.

    Segmentation Annotation - keychain(1)

  7. Place another example of the same object in the camera’s field of vision and repeat steps 3-6 until you have added at least 10 labeled examples (or if you’ve added additional classes, at least five examples of each class).

    Tip

    The model will be more accurate if each image is different (do not repeat the same image).

    Double check that each capture is labeled correctly as this is what will be used to train the model.

  8. Continue to IO Block.

Note

For more information about the Label and Train page, see Label And Train (Segmentation).

IO Block

In this section, you’ll define the pass/fail logic for your Recipe using Node-RED logic.

  1. From the Label and Train page, use the breadcrumb menu to select IO Block. Alternatively, select Configure IO from the Recipe Editor.

    Segmeneter Recipe Editor Breadcrumb Menu

  2. Right-click on the Classification Block Logic node and select Delete Selection.

    Segmentation IO Block - keychain(1)

  3. Right-click and select Insert > Node > Function.

  4. Reconnect the nodes.

    Segmentation IO Block - keychain

  5. Double-click on the function 1 node.

  6. Copy and paste the desired example code from the code samples below into the On Message tab.

    Code sample: Pass if no pixels are detected

    Copy and paste the following logic:

    const allBlobs = msg.payload.segmentation.blobs; // Extract the blobs from the payload's segmentation data
    
    const results = allBlobs.length < 1; // Check if there are no blobs and store the result (true or false)
    
    msg.payload = results; // Set the payload to the result of the check
    
    return msg; // Return the modified message object

    Code sample: Pass if all blobs detected are smaller than the defined threshold

    Copy and paste the following logic:

    const threshold = 500; // Define the threshold value for pixel count
    
    const allBlobs = msg.payload.segmentation.blobs; // Extract the blobs from the payload's segmentation data
    
    const allUnderThreshold = allBlobs.every(blob => blob.pixel_count < threshold); // Check if all blobs have a pixel count less than the threshold
    
    msg.payload = allUnderThreshold; // Set the payload to the result of the check
    
    return msg; // Return the modified message object

    Code sample: Pass if the total number of pixels detected is less than the defined threshold

    Copy and paste the following logic:

    const threshold = 5000; // Define the threshold value for the total pixel count
    
    const allBlobs = msg.payload.segmentation.blobs; // Extract the blobs from the payload's segmentation data
    
    const totalArea = allBlobs.reduce((sum, blob) => sum + blob.pixel_count, 0); // Calculate the total pixel count of all blobs
    
    msg.payload = totalArea < threshold; // Set the payload to true if the total area is less than the threshold, otherwise false
    
    return msg; // Return the modified message object

  7. Click Done.

  8. Click Deploy.

  9. Continue to Train Segmentation Model.

Note

For more information about the IO Block page, see IO Block and Node-RED Logic.

Train Segmentation Model

In this section, you’ll train the model using the images labeled earlier.

  1. From the IO Block page, use the breadcrumb menu to select Label and Train. Alternatively, select Label and Train from the Recipe Editor.

    Segmeneter Recipe Editor Breadcrumb Menu

  2. Click Train Segmentation Model.

  3. Adjust the Number of Iterations using the arrows on the right-hand side of the field to set how many times the labeled images are shown to the model to help it learn.

    Note

    Increasing the number of iterations will improve the model’s accuracy, but will also take longer to train.


    creating-a-segmenter-image-d3t5mlho

  4. Click Start Training. A modal will display the progress of the training.

  5. Once the model is trained, use the Live Preview Mode or the HMI tab to verify the functionality of your Recipe. Place different examples of the object in the camera’s field of vision and verify the model classifies each example correctly.


Was this article helpful?

What's Next
ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence