Severstal Steel Defect Detection
TABLE OF CONTENT:
- Business Problem
- Understanding the Data
- Exploratory Data Analysis
- Modeling
- Results
- My Complete Solution
- Future Work
- Profile
- References
1. Business Problem:
Introduction :
Steel is one of the most important building materials of modern times. Steel buildings are resistant to natural and man-made wear which has made the material ubiquitous around the world. To help make the production of steel more efficient, we identify the defects present in steel sheets.
Severstal is leading the charge in efficient steel mining and production. They believe the future of metallurgy requires development across the economic, ecological, and social aspects of the industry. Severstal is now looking to machine learning to improve automation, increase efficiency, and maintain high quality in their production.
Objective:
Severstal uses images from high-frequency cameras to power a defect detection algorithm. From that data, we predict the locations of the defect site and type of the defects present in them. This results in efficient production and maintaining manufacturing standards high.
2. Understanding The Data:
Source of Data:
Data is available in a Kaggle competition posted by Severstal.
Data Overview:
There are 12,568 train images and 5506 test images. Some of them are shown below.
The defects present in the images are given in Run-Length-Encoded(RLE) pixel values in the CSV file provided. Run-length Encoding gives the location of the defect present in the image.
Unique images in the above DataFrame ie. (Number of images with at least one defect) = 6666. So the number of images without Defects = 12568-6666= 5902.
3. Exploratory Data Analysis :
3.1 All the train and test images have the same size (1600,256).
3.2 Number of images for each defect class:
3.3 Number of Images with No_defect/single_defect/multiple_defects:
Observation:
- There is a clear imbalance in the data.
- Class3 and Class2 are majority and minority classes respectively.
- The number of images with no defects are pretty high (5902).
- Most of the images have a single defect, the number of images with two defects are less than 500, and the number of images with 3 defects =2 which is very low.
3.4 Visualization using Masked images formed with Run-Length-Encoding Values:
Observations From EDA:
- Class 4 and class 3 defects look worst among all the defects.
- All the train and test images have the same size, resizing images is not required.
- The data is highly imbalanced. class2 images are very less. Performing Data Augmentation might be helpful.
- 5902 images have no defect ie. almost half of the images.
- Number of Images with Class3 > Class1 > Class4 > Class2.
- Images with multiple defects are less. (images with 2 defects are < 300, images with 3 defects = 2).
4. Model:
- Binary Classification Model:
The number of images with no defect are very high, so we start by building a binary classification model to identify the presence of a defect in the image. My best model architecture for this task is shown Below
Xception_model = Xception(weights='imagenet', include_top=False,input_shape=(299,299, 3))
x = Xception_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(2048, activation='relu')(x)
x = BatchNormalization()(x)
x = Dropout(0.5)(x)
x = Dense(1024, activation='relu')(x)
x = BatchNormalization()(x)
x = Dropout(0.3)(x)
x = Dense(512, activation='relu')(x)
x = BatchNormalization()(x)
x = Dropout(0.3)(x)
x = Dense(256, activation='relu')(x)
x = BatchNormalization()(x)
x = Dropout(0.3)(x)
x = Dense(64, activation='relu')(x)
outputlayer = Dense(1, activation='sigmoid')(x)binary_model_Xception = Model(inputs = Xception_model.input, outputs = outputlayer)
The images having Defect are sent to Multi-Label Classification Model.
2. Multi-Label Classification Model:
An image can have more than one defect here, This Model predicts the defects present in the image. The images from this model are sent to the segmentation model.
InceptionResNetV2_model = InceptionResNetV2(weights='imagenet', input_shape=(299,299,3), include_top=False)
x = InceptionResNetV2_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(2048, activation='relu')(x)
x = BatchNormalization()(x)
x = Dropout(0.5)(x)
x = Dense(1024, activation='relu')(x)
x = BatchNormalization()(x)
x = Dropout(0.3)(x)
x = Dense(512, activation='relu')(x)
x = BatchNormalization()(x)
x = Dropout(0.3)(x)
x = Dense(256, activation='relu')(x)
x = BatchNormalization()(x)
x = Dropout(0.3)(x)
x = Dense(64, activation='relu')(x)
outputlayer = Dense(4, activation='sigmoid')(x)
Multi_model_InceptionResNetV2 = Model(inputs = InceptionResNetV2_model.input, outputs = outputlayer)
3. Segmentation Model:
Segmentation_model = Unet('inceptionresnetv2', encoder_weights='imagenet', classes=1, activation='sigmoid')
Metrics:(Precision, Recall, F1-Score, and Dice Coefficient)
def recall(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recalldef precision(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precisiondef f1_score(y_true, y_pred):
precision_1 = precision(y_true, y_pred)
recall_1 = recall(y_true, y_pred)
x = 2*((precision_1*recall_1)/(precision_1+recall_1+K.epsilon()))
return x
def dice_coef(y_true, y_pred):
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = K.sum(y_true_f * y_pred_f)
return (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
5. Results
I have Trained the model for 50 Epochs, Train and validation loss is shown below:
Some of the predicted test images are shown below:
6. My Complete Solution:
7. Future Work:
While using the u-net segmentation model, we can explore using various backbones can be explored for better results. And complex architectures like unet++ should be used.
8. Profile:
Github:
Linkedin: