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

Knowledge Hub

use cases
User Guide
Installation

Version 3.0.0

Quality Automation with AI and Relimetrics

Detect and Classify the Defects on Metal Nuts

The task is to detect defects on metal nuts and classify them. This is a defect detection followed by a 3-class classification task and can be realized as a pipeline.

Dataset

Raw Data Source: The MVTec Anomaly Detection Dataset*

The dataset contains 70 positive (defected) and 22 negative (normal) metal nut samples. There are 3 types of defects, all annotated in LabelMe format, as depicted below.

Data Loading & Annotation

You have 2 options:

  • 1. data annotated with LabelMe format from here. There are two folders, namely “OK” and “NOK”, in the downloaded dataset corresponding to defect free samples and defected samples. For both folders, load the imageset and the annotations that you downloaded separately, using ReliVision. To do that, import the imageset using “Import Data” and the annotation file per image folder using the “Import Annotated Dataset” (with the LabelMe annotation format option). You will have two annotated datasets, one for each folder, available in the gallery.
  • 2. Load the imageset and annotate the data yourself in any industry standard format you like using the ReliVision’s intuitive annotation functions. To do that, download the OK imageset and NOK imageset separately. Follow the ReliVision Knowledge Hub User Guide (ReliTrainer: Data) to define the target states/labels as “bent”, “color” and “scratch” and to annotate the NOK imageset using polygon annotation tool. Save them in an appropriate industry standard format (for which LabelMe is a good option). Leave the OK imageset unannotated as they do not have any defects. A sample annotation of a “bent” sample is as follows:

Building A Character Detection and Classification Pipeline:

We will be building a pipeline that is composed of a series connected defect detector and a defect classifier. The defect detector will be responsible for detecting the defects, if there are any, and outputting a bounding box. The classifier will be fed with defect detection results (the cropped images of the defects detected) and will decide on the type of the defect (bent, color, scratch).

Training a Character Detector:

1. Prepare your data for defect detector training: In order to train a defect detection model, you need to have training images in which all defects, of all types, are annotated with a common label, such as “defect”. The dataset (NOK imageset) provided has polygonal annotations with 3 labels corresponding to different defect types (bent, color, scratch). Merge your NOK labels in your NOK imageset into a single class called “Defect”. Visit ReliVision Knowledge Hub User Guide to see how to do this (Edit ROI States). Then merge the OK imageset with the single class labeled NOK imageset, that you have generated by merging the 3-class NOK labels, into a single dataset. Visit ReliVision Knowledge Hub User Guide to see how to merge two datasets (Merge & Download Datasets).

2. Follow the ReliVision Knowledge Hub User Guide (ReliTrainer: Models) to train your AI model for metal nut defect detection. The main steps, detailed in the User Guide, include

  • Model type selection: Object Detection
  • Annotated dataset selection
  • Automated or manual train/test split which essentially spares some data for training validation purposes.
  • Hyper parameter setting: We have chosen the following in this use case:
  • Epochs: 1000
  • X-Y Resolution: 448
  • Learning Rate: 0.01 (default)
  • Momentum: 0.937 (default)
  • Weight Decay: 0.005 (default)

Sample training and validation loss and mAP curves as a function of epochs are as follows:

Training a Defect Classifier:

1. Prepare your data for defect classifier training: In order to train a defect classification model, you need to have training images of individual (cropped) defects labeled with the defect type (bent, color, scratch). The dataset (NOK imageset) provided has polygonal annotations with 3 labels corresponding to different defect types. Extract the polygonal annotations (defects) using the ReliVision data curation functions. Visit ReliVision Knowledge Hub User Guide to see how to extract annotations. Use the dataset thus created with extracted defects for training your classifier.

2. Follow the ReliVision Knowledge Hub User Guide (ReliTrainer: Models) to train your AI model for whole image classification (bent, color, scratch). The main steps, detailed in the User Guide, include

  • Model type selection: Classification
  • Annotated dataset selection
  • Automated or manual train/test split which essentially spares some data for training validation purposes.
  • Hyper parameter setting: We have chosen the following in this use case:
  • Epochs: 100 (default)
  • X-Y Resolution: 224 (default)
  • Learning Rate: 0.0001 (default)
  • Momentum: 0.99 (default)
  • Weight Decay: 0.0005 (default)

Sample training and validation loss and accuracy curves as a function of epochs are as follows:

Building and Running the Pipeline:

Use the pipeline editor to build your pipeline by dragging and dropping the AI/Basic blocks. For this specific case, we do not need any Basic Block (Digital signal/image processing - DSP/DIP - functions). You will need to select an input data source (your raw image set), a detection AI Block (the defect detector you trained) and a defect classifier (the classifier you trained) connected in series as depicted below. Follow the ReliVision Knowledge Hub User Guide (ReliTrainer: Models / AI Pipeline).

You can review your results using the ReliTrainer data annotation interface. Your pipeline’s outputs will be saved as a separate set of annotations for each image it is run on.  Visit the ReliVision Knowledge Hub User Guide (ReliTrainer: Data) for more details on reviewing annotations / inference results.

Here are some output examples:

Detected Scratches

Detected bents

Try it by yourself
Download ReliVision now!

Contact Us