Severstal: Steel Defect Detection

Kireeti kunam
6 min readJul 30, 2020

Can you detect and classify defects in steel?

Predicting defects in steel using computer vision algorithms

Severstal is leading the charge in efficient steel mining and production
Severstal is leading the charge in efficient steel mining and production

Table of Contents:

  1. Business problem
  2. About data
  3. Performance metrics for the problem
  4. Pipe-line / Architecture:
  5. Binary classification model
  6. Segmentation models
  7. Inference/Final
  8. Future work
  9. GitHub,LinkedIn profile links
  10. References
  1. Business Problem :
  • Steel Defect Detection is a competition hosted on kaggle by one of the largest steel manufacture company Severstal. Here is the link for this competition. please visit kaggle site provided for more details about this competition
  • So the objective of this competition is to predict the location and type of defects found in steel manufacturing using the images provided. Severstal uses images from high frequency cameras to power a defect detection algorithm.
  • we’ll help engineers improve the algorithm by localizing and classifying surface defects on a steel sheet.

2. About data :

We have downloaded data from below Kaggle link :

  • we need to download “train_images”,”test_images” and “train.csv”.
  • Each image may have no defects, a defect of a single class, or defects of multiple classes. For each image you must segment defects of each class class_ID=[1,2,3,4]
  • we have class imbalance in our training data.
Class distribution
  • If we observe the above plot we can observe that few images have class-2 defect and class-3 defect found in most of the images.
  • We need to use the images in train_images folder for training purpose and we need to predict the defect(along with location) for the images in test_images folder.
  • In train.csv file we had information about defect images.
  • ex: Img_ID|defect_class|Encoded pixels.

Encoded pixels:

  • In order to reduce the submission file size, our metric uses run-length encoding on the pixel values. Instead of submitting an exhaustive list of indices for your segmentation, you will submit pairs of values that contain a start position and a run length. E.g. ‘1 3’ implies starting at pixel 1 and running a total of 3 pixels (1,2,3).
  • The competition format requires a space delimited list of pairs. For example, ‘1 3 10 5’ implies pixels 1,2,3,10,11,12,13,14 are to be included in the mask. The metric checks that the pairs are sorted, positive, and the decoded pixel values are not duplicated. The pixels are numbered from top to bottom, then left to right: 1 is pixel (1,1), 2 is pixel (2,1), etc.
  • So we will build two supporting functions. One for to convert run length encoding to mask and from mask to run length encoding.
  • Now we will visualize some sample Defect Images and corresponding mask.
Defect-1 Images and Corresponding masks
Defect-2 Images and Corresponding masks
Defect-3 Images and Corresponding masks
Defect-4 Images and Corresponding masks
  • Now we will see some non-defect images also.
non defect Image
non defect Image

3. Performance metrics for the problem:

  • This competition is evaluated on the mean Dice coefficient. The Dice coefficient can be used to compare the pixel-wise agreement between a predicted segmentation and its corresponding ground truth. The formula is given by:
  • Dice coefficient = 2∗|X∩Y| / (|X|+|Y|)
  • To understand more about performance metrics for segmentation problems please refer this Reference

4. Pipe-line / Architecture:

  • We can design pipe-line for this problem in so many ways. Here I am discussing the simple one or first cut approach.
pipe-line architecture
  • Here Binary model first detect whether the give image has any defect or not. If not then simply we will return empty output.
  • Suppose binary model detects that the given image has defect then that image fed to the remaining four trained segmentation models(corresponds to each defect) to predict each defect.

5. Binary classification Model:

  • Since in train data set we have both defect and non-defect images. So by using these images we will train a binary classification model to predict the defect images.
  • We are preparing data by using “tf.data.Dataset”.
  • So we are using transfer learning with Xception model and we are using it as our binary classifier.
  • More about Xception model: ref

6. Segmentation Models:

  • What is Image Segmentation?
  • Here are we are using unet++ as our segmentation model.
unet++ arhitecture
  • In our case we are using DenseNet121as our backbone network(encoder). Then we implemented skip connections from encoder to decoder.
  • So we are building four segmentation models corresponds to each defect.
  • We are preparing data by using “tf.data.Dataset”
  • Here we are reducing the training image size to save the training time. Original image size is 256*1600 , but he are we using 256*800 sized images for training.
  • Now we will see how our segmentation models are performing o n some random test images.
segmentation model results for defect-1
segmentation model results for defect-2
segmentation model results for defect-3
segmentation model results for defect-4

7. Inference/Final :

  • After the training phase of models, we will save models in our disk.
  • Now we will build final pipeline and we will load our trained models from disk to predict the defects masks for test images.
Loading trained models

8. Future work:

  • Here I just discussed about the first cut approach. We can improve the results by including more complexity in the architecture.
  • Along with binary classification model we can use multi-class classification model to predict what are all defects present in the given image.
  • While training the segmentation models include some non-defect images also to increase robustness of segmentation models.
  • Avoid the defects if the predicted defect area is less than 2% (you can set threshold).

9. Profile:

10. References:

--

--

Kireeti kunam

Machine learning enthusiast, worked at tcs for 1.5 years