Automated Fabric Defect Detection and Classification: A Deep Learning Approach

A computer-based intelligent visual inspection system plays a major role in evaluating the quality of textile fabrics and its demand is continuously increasing in the textile industry, especially when the quality of textile is to be considered. In this paper, we propose an AI-based automated fabric defect detection algorithm which utilizes pre-trained deep neural network models for classifying possible fabric defects. The fabric images are enhanced by pre-processing at various levels using conventional image processing techniques and they are used to train the networks. The Deep Convolutional Neural Network (DCNN) and a pre-trained network, AlexNet, are used to train and classify various fabric defects. With the exiting textile dataset, a maximum classification accuracy of 92.60% is achieved in the conducted simulations. With this accuracy, the detection and classification system based on this classifier model can aid the human to find faults in the fabric manufacturing unit.


INTRODUCTION
In the textile industry, fabrics are prone to various defects and deformities which have an obstructive effect on the quality of the product. The defects are caused by the misuse of the materials and carelessness while manufacturing. It is challenging to inspect the real fabric defects manually, due to the huge number and various categories of defects which are characterized by uncertainty. A low percentage of the defects are being detected by a manual inspection due to human fatigue, which decreases the efficiency, whereas in a real-time automatic system defect detection could be more efficient.
The textile industry, like any other industry, is concerned with quality. As we all know, industries generally aim to manufacture the highest standard of goods in the stipulated time. Fabric faults makeup approximately 85% of the defects in the textile industry and perhaps the manufacturers obtain only SANDHYA NC et al. Automated Fabric Defect Detection and Classification ... TLR 4 2021 315-335. www.tlr-journal.com 316 45% to 65% of their profits from reselling or from off-quality goods [1]. Statistics (as of January 2020) published by NITI Aayog revealed that India is the second-largest manufacturer of textiles and clothing and the second-largest exporter of textiles and apparel [2]. The major concerns are the contamination and the poor quality of the fibre. India uses old technology even though it has the largest installed production bases. Certainly, by adopting state-of-the-art technologies related to the textile industry, competitive manufacturing can be done.
Currently, fabric defects are being detected manually by trained inspectors, which has its own share of issues. Firstly, inspectors who have been deployed must be skilled and experienced. Also, staring at the fabric for prolonged periods of time strains one's eyes, which in turn takes a toll on the accuracy with which faults can be identified. Hence, in order to detect, identify and prevent these defects from reoccurring there is a growing demand for an automated fabric fault detection system in the industry.
Common fabric defects include holes, scratches, stretching, loose yarn, dirty spots, cracked points, misprints, colour bleeding etc. [3]. Apparently, using computer vision (CV) to address this problem is a good solution and we employ an artificial intelligence (AI) -based model to classify possible defects such as colour, cut, holes, metal contamination and thread. A machine learning/deep learning model is trained with a dataset consisting of at least 500,000 images.
Section 1 introduces the current scenario, section 2 highlights the application of AI in the textile industry and section 3 reviews broadly the works related to textile defect detection and classification.
Section 4 discusses the dataset and the methodology is discussed in section 5. Various image preprocessing techniques used in this experiment are discussed in section 6, while the network architecture for training and classification is discussed in section 7. The experimental results and its evaluation is discussed in section 8 and section 9 provides the concluding remarks with the outlook for extension of this work.

AI IN TEXTILE
In the textile industry, AI is revolutionizing the total production process and it is the need of the hour since there is an inflated demand for quality textiles. In the past decade there has been a significant leap in the number of industries using AI because both production costs and the number of faults are kept low without compromising speed and accuracy. Fabric defects deteriorate the value of textile products. The final product with a single minuscule defect can be easily rejected. Neural network (NN) with deep learning plays a vital role in inspecting and identifying defects at a much faster rate and with better accuracy. This new era of textile industry leveraged with AI brings cutting-edge revolution and has a great future a head.

RELATED WORKS
A variety of works has been carried out in detecting fabric defects since the 1980s. Several approaches used to classify fabric defects generally fall into one of the following categories i.e., spectral, structural, model-based, statistical, learning, hybrid or comparative studies [4]. The following sections, 3.1 to 3.3, present a brief overview of these commonly used approaches.

Spectral-based approaches
The spectral-based approaches exploit the fact that faultless fabrics exhibit periodic property and the occurrence of faults leads to aperiodicity. Upon translating the images into frequencies, faults become clearly visible as high frequency components. Chi-Ho Chan and G. K. H. Pang proposed the central spatial frequency spectrum-based approach that relies on the Fourier analysis to understand the fabric structure by mapping the image space and frequency space representations [5]. A fast Fourier transform was used to find the faults in the fabric images consisting of double yarn, missing yarn and web. A. Bodnarova et al. treated fabric defect detection like a semi-supervised segmentation problem and the Gabor filter was applied twice: for obtaining the feature matrix for the first time and for smoothening the images [6]. The optimal Gabor filter is obtained by tuning the fisher function and the results were said to have low false alarm rates. Le Tong et al. proposed a novel algorithm for Gabor filter optimization using composite differential evolution (CoDE) together with fusion and threshold processes [7]. In the optimization phase, decision vectors are encoded, followed by population initialization and finally the mutation and crossover processes. In spite of having the advantage of being less sensitive to noise, the spectral-based approaches are outdated owing to the lack of prominence in the results obtained

Deep learning-based approaches
With the emergence of AI, the application of machine learning and deep learning-based approaches for anomaly detection has been increasing drastically and fabric defect detection is no exception. Jun-Feng Jing et al. presented the DCNN model which has initially been trained by using the MNIST dataset and applied transfer learning by using LeNet-5, AlexNet and VGG16 models [8]. The model was trained by using local patches of the images and whole images were used in the testing phase. The trained model is said to have been evaluated using two public datasets: TILDA and Guangdong Esquel Textiles histogram equalization. The inception VI model was then incorporated to detect defects locally and the LeNet5 model was used to recognize the feature map and thus predict the defect.

Zhoufeng Liu et al. optimized deep neural networks and used the Xiamen Face++ Company dataset
consisting of 8000 fabric images for training the VGG16 model [10]. In order to reduce the memory consumption and the number of parameters involved, an additional layer, called deconvolutional network layer, was introduced. This layer served the purpose of projecting the feature activation back to the input pixel space, so that the input pattern that caused a specific activation in the feature maps can be identified.

Hybrid approaches
Guangzhong Cao et al. focused on detecting large and complex surface defects [11]. Here, the texture of the material under study, in test and reference product images, is divided into background and special pattern areas. Defect in the background is detected by using threshold segmentation, whereas the defects in the special pattern area are detected by applying image registration and image differentiation techniques. Yundong Li and Cheng Zhang used a hybrid approach for detecting defects in warp-knitted fabrics that had two phases, involving image enhancement and image segmentation [12]. The former was carried out using Gabor filters with the aim of making the defects clearly visible, whereas the latter was implemented using an adaptive pulse coded neural network (PCNN). The results from these two stages underwent morphology filtering before yielding the final output.
Hermanus Vermaak et al. proposed a hybrid method for fabric defect detection using dual-tree complex wavelet transform (DTCWT) [13]. The DTCWT was applied for wavelet decomposition of the fabric images and computing features like mean energy, mean magnitude and variance of magnitudes of the wavelet coefficients. The features obtained for defective and non-defective in the train set from the previous steps went through an Euclidean Distance Classifier, which compares the test and train sets to predict whether the given sample is defective or not.

DATASET
The machine learning model presented in this paper has been trained with a dataset taken from the public dataset -MVTec Anomaly Detection [14]. Our dataset consists of a whopping 540,000 images having five defect classes i.e., colour, cut, hole, metal contamination, thread and the non-defective class (here, good) and is divided into test and train sets having 180,000 and 360,000 images respectively. Figure 1 illustrates the sample image patches used in the training set that has 72,000 images and is equally divided into 6 classes, with each class having 12,000 images.

METHODOLOGY
The collected fabric dataset is initially checked for any corrupted pixels and it is further pre-processed [15,16]. Figure 3 shows the block diagram of the proposed fabric defect detection system. The preprocessing techniques, like image scaling, pixel normalization and dimension reduction, are used for the training dataset. Feature extraction by the CNN model aids in characterizing and analysing the defective and non-defective texture of the fabric images. Datasets consisting of defective and nondefective fabric images are used to train the system for defect detection and classification. If the fabric image is clean, it is classified as good else it is defective. The defective images are further classified into colour, cut, hole, thread and metal contamination. Thus, image processing algorithms in DNN are used and the defects in fabrics are detected and classified.

IMAGE PRE-PROCESSING TECHNIQUES
Image pre-processing involves operation and manipulation of images at the lowest level of abstraction for all the input images in order to improve the effectiveness of image processing algorithms and the image quality. It reduces unwanted distortions and enhances some other image features for further processing so that the ML model can benefit from this improved data. In this method, the grayscale image is normalized to have a stable learning process and to reduce the number of training epochs.
Once the image pre-processing is done, it moves to the next stage (feature extraction).
The commonly used steps include: I. Resizing the image II. Denoising III. Segmentation

IV. Morphing
The following sub-sections elaborate on the pre-processing and data augmentation techniques that were carried out on our fabric dataset.

Image scaling
The raw image (of size 1024x1024) was resized to 32x32 by retaining the features necessary for testing and training, in order to eliminate the unnecessary details in the image.
Mathematically the algorithm for image scaling is interpreted as follows [17]: Let w h be the image size, t be the threshold and the ratio be r  w / h . If t  max w, h no operation needs to be performed. Now, let w  h ; if we want to find a linear mapping f :0, w 0,t then from the first condition = 0 and from the second a  t w .
The new width is wt ' since we have to preserve the ratio:

Image Normalization
Image normalization makes sure that all the pixels are uniformly distributed. We implemented this with the help of the transform, which is a part of the pandas library with the parameters (mean and standard deviation) being 0.5. The normalized images are made to undergo pixel transformations in accordance with the formula whose simplified form is as follows: Let the pixels from the image be { } and the data matrix be = [ 0 , 1 , 2, . . . ] . The normalized image data ′ is computed as [18]: where is the mean value of { } and is the standard deviation of { } of the entire dataset.

Dimension Reduction
Dimension reduction technique reduces the number of channels used, in order to avoid complexity be seen quoted frequently [19][20][21]. Figure 4 depicts a set of sample images from each class after the pre-processing.

Good Cut Colour
Hole Metal contamination Thread x 2  cos  *x 1  x 0  sin   * y 1  y 0  x 0 (4) Yet another simple mathematical representation for rotation can be in the form of the following matrix [23]: where q is the angle of rotation.

Flipping
Flipping refers to mirroring any given image either parallel or perpendicular to the plane being

Blurring
Blurring is an augmentation technique wherein the quality of the image is deteriorated deliberately, to ensure that it is better equipped for dealing with real-time scenarios. Relating to the context of our project, it is very likely that a camera might capture a hazy sample image of fabric in an industrial setup, given large rolls of fabrics would be moving in a conveyor.
Here, Gaussian blur is used to blur the image, which inherently replaces a pixel by a weighted average of the connected pixels. It is given by [24];  where σ is the standard deviation and (x, y) are the coordinates of the pixels in the Gaussian Blur Kernel.

Noise Addition
In this augmentation technique, random noise is added to the images in the dataset so that each image is different. This would mimic a real-time situation wherein sometimes the sample image captured might be corrupted by noise [25]. To the images in our dataset, Gaussian noise has been injected while augmenting. Figure 5 depicts the sample images using the mentioned augmentation techniques from the "Hole" class.

Image Enhancement
Histogram equalization is generally employed for adjusting image intensities and hence reinforcing contrast [26]. Its primary goal is to make sure that the intensity is uniformly distributed on the histogram thus improving the visibility of the image. The conventional equalization described in is used here to ensure all the pixels are defined [27]. Figure 6 represents the histogram of the various classes before and after equalization.

AlexNet
AlexNet is a pre-trained network that has the ability to classify images into 1000 object categories. The network was initially introduced by A. Krizhevsky [28]. Figure 7 shows the architecture of AlexNet which consists of eight layers. In the eight layers of Alexnet, the initial five layers are convolutional and the pending 3 are fully connected layers. There are 4096 neurons in each of the fully connected layers.
The various convolutional filters (kernels) extract interesting features in a fabric image. Each single convolutional layer has several filters of the same size. After the five convolutional layers, the output of the remaining overlapping max-pooling layers is fed into two fully connected layers. The down sampling of the height and width of the tensors are performed by the max-pooling layers.

Optimization Algorithm
The foremost goal of incessant training in a NN is to reduce the error and increase the accuracy, for which adjusting the weights in each consecutive iteration is indispensable. In order to ensure that the learning rate is perfect, optimizers are used. estimation (Adam) algorithm, which is often used interchangeably with the vanilla stochastic gradient descent (SGD) algorithm.
Adam optimizer inherits the AdaGrad and RMSProp algorithms and merges its best properties. Adam stores an exponentially decaying average of past squared gradients and past gradients vt and mt, respectively, given by [29]: where β1 , β2 are the decay rates and gt is the current gradient.

Performance Evaluation
AlexNet provides better performance than the other networks with an accuracy of 92.60%. The test accuracy of various architectures is given in Table 1.

Error Matrix
The confusion matrix shown in Table 2 summarizes the number of correct and incorrect predictions obtained after training with AlexNet architecture.
Among the various commonly used evaluation metrics, the sensitivity, specificity, positive predictive value (PPV), negative predictive value (NPV) and their denotations are discussed in the succeeding section [32]. Depending on the actual class and the class predicted while testing the model, the prediction is classified into one of the following [33]: The proposed model turned out to obtain 95% (approx.) specificity, sensitivity, NPV and PPV.

Testing and Cross-Validation
An image of a colour defect is given as a sample for testing the network and the network was able to classify it accurately as shown in Figure 10. efficiency of the fabric in quality and cost. This will not only enable accurate and rapid defect identification but also help differentiate minute differences between the defect classes. Particularly, it aids the industry in functioning without manual inspectors, which plays a crucial role concerning efficiency and net profit, especially in times like the current pandemic where remote operation is the new normal.
Future scope of this work includes: • Incorporating many more defect classes and making it more suitable for real-time scenarios.
• Integrating possible hardware components, preferably those often used in textile inspection sites.

Author Contribution
Conceptualization

Conflicts of Interest
The authors declare no conflict of interest.