Skip to content

Model Training: Find Foreign Objects on a Board

Overview

In this tutorial, you will set up all necessary components and train an anomaly detection model.
For this use case, an empty board is considered OK, while any object on the board is treated as an anomaly (NOK).

Estimated time

30 minutes (if you have already completed the OD training tutorial).

What you'll learn

  • Add and manage datasets and annotations for anomaly detection tasks.
  • Configure a model training workspace and experiment.
  • Train a two different anomaly detection models using predefined architectures.

What you'll build

By the end of this tutorial, you will have a trained anomaly detection model capable of:

  • Identifying whether a board is empty (OK) or loaded (NOK).
  • Producing a localization heatmap highlighting anomalies.
Example of a foreign object on a board, with a heatmap localizing the anomaly and a high score indicating an NOK situation.
Example of a foreign object on a board, with a heatmap localizing the anomaly and a high score indicating an NOK situation.

Prerequisites

To complete this tutorial, you will need:

To complete this tutorial, you need the platformadmin role. If you don't have this role, you cannot access model training.

Step 1: Create Training and Validation Datasets

In the Hub, go to the Dataset tab and create two image datasets using the files from the prerequisites section. Name the first dataset Board Train (empty-boards-train.zip) and the second dataset Board Val (empty-boards-val.zip). If you don't know how to create a dataset, go to Create an Image Dataset and then come back.

Step 2: Add Annotations

The training dataset must contain only OK images, therefore, no annotations are required for training data. However, the validation dataset requires annotations:

  1. Open the Board Val dataset.
  2. Upload the validation annotations file (empty-boards-val-annotations.xml).
  3. Select Classification as the Annotation type.

For detailed instructions, see:
Add Annotations to Your Datasets

Step 3: Create a Model Training Workspace

Follow the same workflow as in the object detection tutorial until you open an experiment.

Reference:
Create Training Workspace

Step 4: Configure Training

Use the stepper interface and follow these settings:

  1. Basic configuration
  • Name: Empty Board Anomaly.
  • Problem Type: Anomaly Detection.
  • Model Architecture: FastFlow.
Stepper 1.
Stepper 1.
  1. Datasets and annotations
  • Training dataset: uploaded training dataset.
  • Validation dataset: uploaded validation dataset.
  • Validation annotations: uploaded validation annotations.
  • Anomalous Classes: NOK (represents defective or non-empty boards).
Stepper 2.
Stepper 2.
  1. Preprocessing
  • Set image resolution to 480x288 to reduce computational load and speed up training.
  • Click the link icon between W and H to unlock the aspect ratio.
Stepper 3.
Stepper 3.
  1. Data augmentation
  • Click Next to skip this step
  1. Training configuration

    • Open Anomaly detection training configuration.
    • Set Number of epochs to 10.
    • Leave all other settings as default.
Stepper 5.
Stepper 5.
  1. Start training
  • Click Start Training.
  • Monitor live training metrics.
Final FastFlow metrics graph. The best model is from the first epoch. This can happen when the task is easy for the model. The model is able to perfectly separate anomalous classes (both AUROC and F1Max are 1).
Final FastFlow metrics graph. The best model is from the first epoch. This can happen when the task is easy for the model. The model is able to perfectly separate anomalous classes (both AUROC and F1Max are 1).

⚠️ Training results may vary.

Training is not fully deterministic due to data ordering, augmentation, and slight variations in numeric operations. This can change exact mAP values, but overall results remain consistent.

Optional: Try PatchCore

You can compare another architecture:

  1. Click Duplicate (top left).
  2. This creates a new experiment with the same configuration.
Duplicate Button.
Duplicate Button.

Configure PatchCore

  1. Change Model Architecture to PatchCore.
  2. Click through all steps using Next.
  3. Click Start Training.
PatchCore warning message (informational only).
PatchCore warning message (informational only).

Notes on PatchCore

  • PatchCore is a non-iterative architecture.
  • Some training parameters are ignored (you’ll see a warning, this is expected).
  • You will not see a training curve, but a single metric point.
Final PatchCore metrics (single point). The model achieves perfect separation of anomalous classes (both AUROC and F1Max are 1). This indicates that the anomaly detection task is not challenging in this case. Overall, both FastFlow and PatchCore perform equally well on this task.
Final PatchCore metrics (single point). The model achieves perfect separation of anomalous classes (both AUROC and F1Max are 1). This indicates that the anomaly detection task is not challenging in this case. Overall, both FastFlow and PatchCore perform equally well on this task.

Conclusion

You have successfully:

  • Trained an anomaly detection model using FastFlow.
  • Compared it with PatchCore.
  • Learned how anomaly detection differs from object detection workflows.

Your model can now detect whether a board is empty or contains foreign objects and highlight anomalies using a heatmap.

Next steps

Now that you've completed this tutorial, you can learn how to: