Hole in the Wall — computer vision-based method for defect detection

Foreword

Leveraging AI to improve work efficiency becomes one of manufacturing 4.0’s deliverables as we start to explore more ways to advance automation, control manufacturing processes remotely and enable a remote workforce. In the last several years, visual inspection technologies have been helping manufacturers to ease the operation pressures. computer vision is being used in quality inspection for electronics part, retail goods and even food products.

Project Objectives

After completing NYP specialist diploma in business analytics and big data, I developed strong interest in deep learning. Recently I have taken my first step in Computer Vision using one of most popular deep learning frameworks PyTorch. In this personal project, I would like to demo the potential applications of computer vision by developing a ANN (artificial neural network) model to detect the potential concrete cracks which play a major role in the building inspection to determine the building health.

Work Accomplished

Data Preparation

I will be using a dataset that contains images of various concrete surfaces with and without crack from www.kaggle.com. The image data are organized by folders with one folder for each class — into Negative (without crack) and Positive (with crack) for image classification. Later, the dataset will be train-test 80/20 split using the SubsetRandomSampler into a training and testing set before training ML model. The code also converts the image into Pytorch Tensor. A tensor is a container which can house data in N dimensions.

Modelling

I am going to use a machine learning method called Transfer Learning where a model developed for a task is reused as the starting point for a model on a second task. I load a pretrained model ResNet 50. ResNet-50 is a convolutional neural network that is 50 layers deep. The network trained on more than a million images from the ImageNet database. I will change the final output layer of ResNet50 Model, including defining activation functions, loss function and optimizer. My output final layers will train with concrete surface images for my own image classification modelling problem.

When train the model, the batches of images are fed as input to the network by calling the model( ) function, then, compute the loss function, and use the optimizer to apply gradient descent in back-propagation to finally get the minimum loss or error. Within the same piece of code below, while training is running, the ML model is tested every 10 batches.

The code also calculates the losses and accuracy as well. The model has achieved the low losses and good accuracy.

Once training is done and the model named “cracksmodel.pth” is saved for later predictions.

Evaluation

Now I am going to introduce a new set of images which are unseen by the trained ML model (‘cracksmodel.pth’). The user defined function “get_random_images” will picks 10 random images from data/eval folder, then “predict_image” transforms each image and use the trained model to makes a prediction.

The results are looking good. Here’s one example of such predictions on 10 concrete surface images.

Conclusion

Computer vision can inspect, analyze thousands of products and identify subtle defects in minutes. It can quickly surpass human capabilities. However, It is not an easy task to implement the computer vision technology. Setting up and deploying AI for inspection not only needs a reliable IT infra, but there is usually a limited amount of sample data to make training models, for example, I have used 2000 images to train a model for a concrete crack detection problem. In addition, training ML models can be challenging and require a specialized skill set.

IT Solution (ERP MFG & MES) Architect exploring the potential of Machine Learning to improve manufacturing processes. linkedin.com/in/ganlida