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.
.jpg)
Load the annotated dataset
- Request access to ReliVision Learning Center and download the annotated dataset. It has two folders: OK (defect-free) and NOK (defective).
- In ReliUI, import each folder's image set with Import Data.
- Import each folder's annotation files with Import Annotated Dataset, choosing the LabelMe annotation format.
- You now have two annotated datasets in the Gallery, one per folder.
.jpg)
Train the defect detector
The detector finds every defect, whatever its type, and outputs a bounding box.
Prepare the training data
- In the NOK dataset, merge the bent, color and scratch labels into a single class called Defect (Edit ROI States).
- Merge the OK dataset with this single-class NOK dataset into one training dataset (Merge and download datasets).
Train the model
- In ReliTrainer, select Object Detection as the model type.
- Select the defect detector training dataset you prepared.
- Split the data into train and test sets, automatically or manually, to hold back some data for validation.
- 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
.jpg)
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
- Extract the polygon annotations from the NOK dataset with the ReliUI data curation functions, so each defect becomes its own image.
- Use this dataset of extracted defects, labelled by type, to train the classifier.
Train the model
- In ReliTrainer, select Classification as the model type.
- Select the defect classifier training dataset you prepared.
- Split the data into train and test sets, automatically or manually, to hold back some data for validation.
- 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)
.jpg)
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.
- Open the pipeline editor.
- Add an input data source and point it at your raw metal nut image set.
- Add the defect detector AI block and connect it after the input.
- Add the defect classifier AI block and connect it after the detector.
- 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.
- Run the pipeline with the execute button at the top.
.jpg)
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
.jpg)
Detected bent defects
.jpg)
Related User Guide sections
- Import annotated data
- ROI annotation
- Extract ROIs
- Merge and download datasets
- Training an AI block
- Create and edit a pipeline
Try it yourself
Download ReliVision to run this playbook on your own metal nut images, or browse the other use cases.
Download ReliVision