Checking the quality of manufactured goods — on cAInvas

Use deep learning to identify the defective goods in the manufacturing line.

Photo by Yulia Yu on Dribbble

Production of goods is a highly automated process. The goods produced in bulk are not immune to defects and identifying defective products is a crucial part of the manufacturing process to maintain the reputation of the product in the market as well as for safety concerns in some cases.

How does deep learning help?

Manual filtering is time consuming, tedious, and inefficient. It is a waste of labor hours and energy.

Deep learning models can be trained to pick out defective products with high efficiency and in almost no time. The output of the model can be used to trigger a movement to separate them from the production belt.

This article differentiates between defective and non-defective casting products.

Casting defects

A casting defect is an undesired irregularity in a metal casting process.

There are many types of defects in casting like blow holes, pinholes, burr, shrinkage defects, mold material defects, pouring metal defects, metallurgical defects, etc.

Link to the cAInvas notebook implementation of the concept — here


The dataset

The dataset zip file given in the notebook has two folders — train and test, each with subfolders — def_front (defective) and ok_front (non-defective).

The train and test datasets are created using the image_data_from_directory function of the Keras preprocessing library. Each subfolder is taken as a separate class.

https://gist.github.com/Gunjan933/ed2d953a4d467209fb09f578cb67c922

The train folder had 6377 images in total and the test folder has 715.

The images are of size 256×256. Here are a few samples-

Some of the defects are evident to us from the images.

Input to the model

The image data is normalized for faster convergence of the model using the rescaling function of the Keras library.

https://gist.github.com/Gunjan933/facf25316b63f422d0b5c3c4ea465f33

The model

We use a sequential model with CNN layers followed by Dense layers.

https://gist.github.com/Gunjan933/5662dadbb278d7a1c5ea97c8aa8db8b0

The model uses Adam optimizer with a learning rate of 0.01.

The sparse categorical cross-entropy loss is used as the class labels are given as integers.

The model’s accuracy is tracked to evaluate its performance.

Training and prediction

The model achieves 99.6% accuracy on the test set after training for 8 epochs.

Model evaluation

The metrics

Training accuracy plot
Training loss plot

Let’s visualize the test image while seeing the model’s prediction —

https://gist.github.com/Gunjan933/1bdbe63d44f70db2df7820e755dbabeb

Example prediction

deepC

deepC library, compiler, and inference framework are designed to enable and perform deep learning neural networks by focussing on features of small form-factor devices like micro-controllers, eFPGAs, CPUs, and other embedded devices like raspberry-pi, odroid, Arduino, SparkFun Edge, RISC-V, mobile phones, x86 and arm laptops among others.

deepC compilation

Head over to the cAInvas platform and check out the predictions by the generated .exe file.

Credit: Ayisha D