Cookie Consent by PrivacyPolicies.com
Quality Automation with AI and Relimetrics

Knowledge Hub

Explore & Learn ReliVision with Proven Use Cases

Detection and Classification of Defects on Metal Nuts

This playbook demonstrates how to detect and classify defects in metal nuts using ReliVision. A defect detector identifies defective parts, followed by a three-class classifier that categorizes defects as bent, color, or scratch. Both models are combined into a single inspection pipeline.

The dataset

The dataset contains 70 defective (NOK) and 22 normal (OK) metal nut images. The three defect types are annotated in LabelMe format, as shown below.

Sample metal nut images showing bent, color and scratch defects.
Sample metal nuts with the three defect types.
Step 1 of 5 · Data curation

Load the annotated dataset

  1. Request access to ReliVision Learning Center and download the annotated dataset. It has two folders: OK (defect-free) and NOK (defective).
  2. In ReliUI, import each folder's image set with Import Data.
  3. Import each folder's annotation files with Import Annotated Dataset, choosing the LabelMe annotation format.
  4. You now have two annotated datasets in the Gallery, one per folder.
A metal nut with a bent defect annotated as a polygon.
A sample annotation of a bent defect.
Step 2 of 5 · Training

Train the defect detector

The detector finds every defect, whatever its type, and outputs a bounding box.

Prepare the training data

  1. In the NOK dataset, merge the bent, color and scratch labels into a single class called Defect (Edit ROI States).
  2. Merge the OK dataset with this single-class NOK dataset into one training dataset (Merge and download datasets).

Train the model

  1. In ReliTrainer, select Object Detection as the model type.
  2. Select the defect detector training dataset you prepared.
  3. Split the data into train and test sets, automatically or manually, to hold back some data for validation.
  4. Set the hyperparameters and start training.

Hyperparameters used in this use case

  • Epochs: 100
  • X-Y resolution: 640
  • Learning rate: 0.001
  • Momentum: 0.937 (default)
  • Weight decay: 0.0005
Training and validation loss and mAP curves for the defect detector.
Defect detector: training and validation loss and mAP curves.
Step 3 of 5 · Training

Train the defect classifier

The classifier looks at one cropped defect at a time and labels it bent, color or scratch.

Prepare the training data

  1. Extract the polygon annotations from the NOK dataset with the ReliUI data curation functions, so each defect becomes its own image.
  2. Use this dataset of extracted defects, labelled by type, to train the classifier.

Train the model

  1. In ReliTrainer, select Classification as the model type.
  2. Select the defect classifier training dataset you prepared.
  3. Split the data into train and test sets, automatically or manually, to hold back some data for validation.
  4. Set the hyperparameters and start training.

Hyperparameters used in this use case

  • Epochs: 300
  • X-Y resolution: 224 (default)
  • Learning rate: 0.0001 (default)
  • Momentum: 0.99 (default)
  • Weight decay: 0.0005 (default)
Training and validation loss and accuracy curves for the defect classifier.
Defect classifier: training and validation curves.
Step 4 of 5 · Pipeline

Build and run the pipeline

Use the pipeline editor to chain the two models. The defect detector finds each defect and outputs a bounding box; the defect classifier receives each cropped detection and decides its type: bent, color or scratch. No basic (image-processing) blocks are needed.

  1. Open the pipeline editor.
  2. Add an input data source and point it at your raw metal nut image set.
  3. Add the defect detector AI block and connect it after the input.
  4. Add the defect classifier AI block and connect it after the detector.
  5. Add an Output Imageset or End Branch block, depending on the desired output: generate an Imageset file from the executed pipeline or proceed to the audit stage.
  6. Run the pipeline with the execute button at the top.
Pipeline editor with an input source, the defect detector and the defect classifier connected in series.
Input source → defect detector → defect classifier.
Step 5 of 5 · Results

Review the results

Review the results in the ReliUI data annotation interface. The pipeline saves its outputs as a separate set of annotations for each image it runs on, so you can compare predictions against your labels image by image.

Detected scratches

Pipeline output with scratches detected and classified on a metal nut.
Sample output: scratches.

Detected bent defects

Pipeline output with bent defects detected and classified on a metal nut.
Sample output: bent defects.

Related User Guide sections

Try it yourself

Download ReliVision to run this playbook on your own metal nut images, or browse the other use cases.

Download ReliVision
← All use cases