Abstract
The convolutional neural network (CNN) has recently achieved great breakthroughs in many computer vision tasks. However, its application in fabric texture defects classification has not been thoroughly researched. To this end, this paper carries out a research on its application based on the CNN model. Meanwhile, since the CNN cannot achieve good classification accuracy in small sample sizes, a new method combining compressive sensing and the convolutional neural network (CS-CNN) is proposed. Specifically, this paper uses the compressive sampling theorem to compress and augment the data in small sample sizes; then the CNN can be employed to classify the data features directly from compressive sampling; finally, we use the test data to verify the classification performance of the method. The explanatory experimental results demonstrate that, in comparison with the state-of-the-art methods for running time, our CS-CNN approach can effectively improve the classification accuracy in fabric defect samples, even with a small number of defect samples.
Keywords
In the textile industry, fabric defects represent an important problem in the quality control of textile manufacturing. Fabric defect detection and classification are the main methods used to ensure the quality of the fabric. Fabric defect classification is a vitally important process in the fabric quality evaluation, which can provide the defect information needed to adjust the machines and improve the processing technology. In the field of computer vision, the study of fabric defects has been a hot topic, which covers defect classification,1,2 detection 3 and recognition. 4 Conventionally, fabric defects are evaluated by visual inspections of trained workers in accordance with human-made classification standards. Fabric defect classification remains a research issue and faces some difficulties due to the following three reasons. Firstly, new classes of fabric defects may be introduced with the growing application of fabric. Secondly, the similarities among different classes of fabric defects and the intra-class diversities of fabric defects make their discriminations challenging. Finally, different fibers, patterns and organizations of fabrics also make defect classification difficult.
New methods of fabric defect classification are springing up with developments in information science and computer vision. In these approaches, techniques used to extract image features include statistical procedures and Fourier transforms, 5 the wavelet transform and dual-side co-occurrence matrix (GLCM)6,7 and the Dempster–Shafer theory. 8 Zhang et al. 9 presented a scheme combining Gabor filters and the Gaussian mixture model (GMM) for defect detection and classification. In the detection task, texture features were extracted by using Gabor filters. In the classification task, a classifier based on the GMM was trained and it assigned each defect image to known classes. The experimental results show that the proposed algorithm can reach the classification accuracy of 85% in nine different defect classes, which proves its validity in practice. Tong et al. 10 utilized composite differential evolution to optimize the parameters of Gabor filters. Xu et al. 11 presented a classification method of fabric smoothness appearance, including feature designing and wrinkle classification. Li and Cheng 12 explored an algorithm that uses combined features and modified support vector machine (SVM) classifiers to characterize and classify the fabric defects of yarn-dyed fabrics. Yildiz and Demetgul 13 used a k-nearest neighbor algorithm (KNN) for image classification. For embroidery textile defects, researchers used the back-propagation neural network (BPNN) for defect classification. 14
Researchers are paying much attention to the small sample size problem in the high-dimensional space of images. 15 The applications of small sample size classification are mainly applied to hyperspectral images16,17 and biosignals 18 at present. Shu et al. 19 utilized the extended margin Fisher criterion to feature mapping, then multiple KNN classifiers are trained for classification. For the classification of hyperspectral images in small sample sizes, Li et al. 20 applied a nonlinear joint collaborative representation model with adaptive weighted multiple feature learning to deal with the small sample size problem in hyperspectral image classification. Hamidullah et al. 21 and Aydemir and Bilgin 22 presented the kernel Fukunaga–Koontz transform (KFKT) and semi-supervised learning (SSL) techniques, respectively. One of the difficult and complex problems is the lack of labeled training sets, as the limited available training samples can lead to a deficiency in the classification and robustness ability.
The process of high-speed sampling and compression wastes a lot of time and space. Donoho 23 proposed a compressed sensing (CS) method. The CS method has been used in many areas, such as video CS coding,24,25 remote sensing, 26 compressing imaging, 27 medical imaging, 28 speech processing, 29 magnetic resonance fingerprinting 30 and ensemble learning. 31 The recovery algorithms in CS are also very important, which affect the final reconstruction accuracy.
In recent years, convolutional neural networks (CNNs) in deep learning have achieved remarkable success in computer vision applications, which have particular advantages in image classification,32–34 recognition 35 and detection.36,37 For fabric defect images, Jing et al. 38 presented a CNN based on a modified AlexNet for a yarn-dyed fabric defect classification. In Wang et al., 39 a CNN-based approach was applied to the fiber classification task. SAE40,41 is one of the popular deep architectures, which has also been applied to patterned warp-knitted fabric detection. The algorithm was tested in patterned warp-knitted fabric, which can discriminate defect images from normal ones without defects. Mei et al. 42 described an unsupervised learning-based approach to detect and localize fabric defects without any manual intervention. However, these methods do not consider the problem of fabric defect classification in small sample sizes. In addition, it is still urgent to build a deeper learning architecture and get large data for training the model so as to obtain a better detection and classification accuracy. At the same time, the high computational cost and sophisticated training algorithm should also be considered.
Considering that the CNN cannot handle the small sample sizes problem very well in classification, a new algorithm for fabric defect classification has been developed by combining compressive sensing and the CNN (CS-CNN). CS is used to compress and augment the data in small sample sizes, and then the defective fabric images are classified by using the CNN. Initially, compressive sampling was made from the fabric defect images with four different measurement matrices. Afterwards, the classification of fabric defect images is performed by employing CNN classifiers, which can extract discriminative features directly from the compressive sensing measurements. Finally, this paper validates the classification accuracy of the proposed CS-CNN by the test data in the database. This work observes the diversity of the fabric defect images, which can be increased to achieve a higher classification accuracy when only limited small samples are available. Meanwhile, the original data is reconstructed by the reconstruction algorithm. The challenge of CS reconstruction, referring to the sparse approximation problem, is to solve an underdetermined system of linear equation sparse priors. The reconstruction accuracy is largely influenced by the sampling rate and the noise of compressive observation. Our method uses a linear mapping method that avoids the design of a reconstruction algorithm.
The paper is organized as follows. In the second section, basic concepts of the CNN and CS are briefly reviewed. In the third section, the structure and steps of the CS-CNN method are presented. The fourth section describes our experiments and gives the classification results. Then several representative fabric defect classification methods are completed at different sampling rates. The fifth section gives visualizations of partial results. The sixth section draws conclusions and summarizes the whole paper.
Basic concepts of the convolutional neural network and compressive sensing
Convolutional neural networks
The basic structure of CNNs mainly includes an input layer, convolution layers, pooling layers, a fully connected layer and an output layer. The convolution operation in mathematics includes continuous and discrete convolution, which can be written as follows.
Continuous convolution operation formula
Discrete convolution operation formula
Compressive sensing
CS
23
theory mainly includes the sparse representations of the signal, the construction of the measurement matrix and the design of the reconstruction algorithm. Consider the random noiseless signal
Proposed method
In conventional methods for feature extraction, features could be extracted in the transform domains or the spatial domains, such as the Fourier transform, Gabor transform, local binary pattern (LBP) and covariance matrix. In this study, aside from those handcrafted features, CNNs can learn universal fabric defect features and categorize the features automatically. In CS theory, the most important processes are the measurements and reconstructions of signals, in which signals or images of scientific interest can be reconstructed accurately even from a far smaller number of pixels than the desired resolution of the signals or images. In addition, when different measurement matrices are used, different feature information can be obtained without losing important features. For fabric defect images classification in small sample sizes, more feature information can be achieved by using different measurement matrices of CS. Then, these features and original images are regarded as an input of the CNN. The combination of the CNN and CS can effectively solve the classification of fabric defect images in small sample sizes. The structure of the CS-CNN is shown in Figure 1.
The structure of the compressive sensing and convolutional neural network (CS-CNN). The process can be also considered as a form of data augmentation, which provides abundant transformations of the original samples by using different measurement matrices.
Data preprocessing
When a raw defect image is fed into the neural network directly, the classification performance will be significantly subject to noises and abnormal disturbances. For this reason, the original fabric defect images are preprocessed by the following two steps.
Step 1: segmentation of fabric defects. The original defect images are 1280 × 1024 pixels. It can be seen from Figure 2 that the original images contain noises, which include staining, an irregular texture and a fringe. These noises may be caused by equipment or industrial monitors. The noises can be identified and denoised by filtering, wavelet transform, and so on. In addition, an image may appear on multiple types of different fabric defects. We get the local image blocks of the original images manually that only contain one fabric defect type. The size of the local images is 227 × 227. The preprocessing results of the original images are shown in Figure 3.
The original fabric defect images. The preprocessing result of the original images.

Step 2: diversification of the images. The images are rotated and translated so that the CNNs can learn more invariant image features. The range of rotation is from 5° to 20°, while the range of translation is from 0 to 50 pixels. The results of the image rotation and translation are shown in Figure 4.
The results of the image rotation and translation.
Compressive measurements of defect images
During the data preprocessing, the original defect images are processed to form a small sample dataset. There are 50 of each class image in the small sample dataset. Then, compressive sampling theorem is used to compress and augment the data in small sample sizes. Compressive sensing is mainly used to deal with the one-dimensional vector. The two-dimensional image matrix needs to be converted into a one-dimensional vector. The following steps are carried out.
The fabric defect image The Discrete Cosine Transform (DCT) transform formula is used as follows
Based on a variety of different measurement matrices, the observation vector y is given by
To obtain the observation vector maps for the image space, the reconstruction accuracy of the construction algorithm is largely influenced by the sampling rate and the noise of compressive observation. In this work, we use a linear mapping method to avoid the design of the reconstruction algorithm
Training the CS-CNN
Algorithm 1
Training the CS-CNN model
Structure and parameters of the convolutional neural network
1: Initialize learning rate, batch size, kernel size, number of kernels, number of max iteration, dropout and so on.
2: Generate random weights with Gaussian type and biases with 0;
CS-CNN_model = InitCS-CNN_model(weights and bias matrices);
3:
Compute error according to loss function
CS-CNN_model.train(TrianingData, TraingLabels), as loss is minimalized with gradient descent;
Update weight and bias matrices;
iter ++
4: Save parameters (weight, bias) of the CS-CNN; Save graph of session
5: training CS-CNN Finished
CNN classification recognition
CNNs are special neural network models, which are inspired by the human vision system. On one hand, the connections in the neurons are sparsely connected; on the other hand, the convolution layers of CNNs have shared weights. CNNs can improve the accuracy of detection and classification by studying the spatial correlation of data and reducing the number of training parameters in the network. In this work, a new adaptive expansion is designed based on the basic CNN that is shown in Figure 1. The number and size of convolution kernels have been redesigned by considering the characteristics of fabric defect images. We add one fully connected layer based on the two fully connected layers. The nonlinear ability of the CNN can be enhanced when adding one fully connected operation. The structure of a CNN is represented in Figure 5. The output is identified as a certain type, which is the mispick in Figure 5.
The structure of a convolutional neural network (CNN). The input image uses the fabric defect “mispick” as an example.
Experimental evaluations and discussion
In order to evaluate the CS-CNN classification performance in fabric defect images, many experiments were completed to compare with KNN, multi-layer perceptron (MLP) and SVM.
The fabric defect images dataset (FDI 500)
Our experimental images are acquired using industrial monitors from a textile factory. The fabric defect dataset is built by ourselves. The original defect images are cut, rotated and translated to form a small sample dataset. Ten different fabric defect classes of the original images were selected, which included one normal fabric sample and nine different defect samples. The flaw samples are normal, mispick, broken pick, double flat, slub, felter, draw-back, sundries, broken end and oil stains, which are shown in Figure 6. There are 50 images of each class in the small sample dataset. Each measurement matrix can generate 500 images. The four measurement matrices can generate 2000 images. Namely, the dataset, which contains 2500 images through compressive sampling by different measurement matrices, is divided into train, validation and test subsets. In this work, 80% (2000) of the images are used as the training samples and 10% (250) of the images are used as the validation samples; the remaining samples (250) are used for prediction.
Normal and defect images (normal, mispick, broken pick, double flat, slub, felter, draw-back, sundries, broken end and oil stains).
Environmental configurations
The experiments were implemented on a PC with four Nvidia GeForce GTX 1080 GPUs, 128GB RAM. The operation system was on an Ubuntu 14.04 with tensorflow 0.8.0. The proposed algorithm is performed on the software of MATLAB and PYTHON. The most critical factor in fabric defect classification is the classification accuracy and speed. The average classification speed is less than 1 second on the platform, which can satisfy the general requirements of online defect classification. We evaluate the performance of the method with classification accuracy.
Feature information of defect images with different measurement matrices
A variety of different measurement matrices are tested to extract feature information, such as Gaussian measurement matrices, 44 Fourier measurement matrices, 44 Bernoulli measurement matrices, 46 random sparse measurement matrices, 47 uniform sphere measurement matrices, 23 Toeplitz measurement matrices 48 and Hadamard measurement matrices. 49 We find that some measurement matrices cannot obtain good feature information. The reasons can be summarized as follows. (1) The measurement matrices do not satisfy the form of the input data, such as Hadamard measurement matrices, where the dimension must satisfy the integral multiple of 2. The size of the input image in this work is 51,529. (2) The measurement matrices, such as Fourier measurement matrices, which require the input image to satisfy the sparsity in the Fourier domain. (3) The linear mapping by formula (11) cannot obtain better feature information to the partial measurement matrices, such as Fourier measurement matrices and Toeplitz measurement matrices. After analyzing the test result and reasons, we finally selected four measurement matrices, which are Gaussian measurement matrices, Bernoulli measurement matrices, random sparse measurement matrices and uniform sphere measurement matrices.
The four different measurement matrices are used to compressive measure x by formula (7). Figure 7 shows the partial feature information of the defect images. We have studied the correlation coefficient of the selected measurement matrices in order to illustrate the differences of the extracted feature information by different measurement matrices. The formula used is as follows
Feature information of defect images with the four measurement matrices. Correlation coefficient with different measurement matrices

Comparison of classification accuracy with different sampling rates
The classification accuracy at different measurement rates
Performance comparison of defect classification models
Classification accuracy of the convolutional neural network (CNN) and the compressive sensing and convolutional neural network (CS-CNN)
Classification accuracy of the k-nearest neighbor algorithm (KNN), convolutional neural network (CNN) and compressive sensing and convolutional neural network (CS-CNN)
Classification accuracy of the multi-layer perceptron (MLP), support vector machine (SVM), convolutional neural network (CNN) and compressive sensing and convolutional neural network (CS-CNN)
Classification accuracy of five methods
KNN: k-nearest neighbor algorithm; MLP: multi-layer perceptron; SVM: support vector machine; CNN: convolutional neural network; CS-CNN: compressive sensing and convolutional neural network.
Performance comparisons of different parameters
In the experiment, we find that some parameters can affect the performance of the proposed method, such as the learning rate, batch size, training iteration, dropout and convolution kernel. In order to explore the relationship among partial parameters and classification accuracy, in this study the influences of batch size and dropout on the results are analyzed. The number of fabric defect classes is 10. The measurement rate is fixed to 1. The number of training iterations is 500. For each of the parameters, the number of trainings is fixed to 10 times. Figures 8 and 9 show the change of the accuracy obtained by different batch sizes and dropouts. Figure 8 shows that the classification accuracy is not so good with the batch sizes of 128 and 256. The best accuracy is 97.9% with the batch size of 512. Figure 9 shows the results of the accuracy at three different dropouts. When the model is trained with different dropouts, the batch size is 512. It can be seen that the average accuracy reaches 97.9% when the dropout is 0.85. The partial curves have a slight fluctuation in Figures 8 and 9. This phenomenon may be caused by redundant information and different features in each batch of images.
The result of different batch sizes. The result of different dropout rates.

Visualizing partial results
In this research, the CNN model is a complex black-box model, in order to further understand the learning process of the model more intuitively. Meanwhile, we attempt to explain how the network learns the feature and weights when the data is input to the CNN model and some visualization results are given.
Visualization of the convolution layer
Figures 10 and 11 show the feature map visualization of the convolution layer. It can be seen from the feature map that the first convolution layer can learn some low-level features, such as color, edge and size. The second convolution layer can learn the more discriminative and distinguishing features, such as fabric defect and texture.
The feature map of convolution layer 1. Each block is a convolution kernel, while the size of each block is 11 × 11. There are 32 different convolution kernels in convolution layer 1. The feature map of convolution layer 2. Each block is a convolution kernel, while the size of each block is 5 × 5. There are 64 different convolution kernels in convolution layer 2.

Feature visualizations with different parameters
This work visualizes the results of several layers of the trained model with different parameters to analyze the relationships between the accuracy of classification and the process of training the model.
Figures 12 and 13 show the results of convolution layers and pooling layers for which the batch sizes are 64 and 512, respectively. Figure 12 shows that the proposed CS-CNN does not learn the necessary feature information with the batch size of 64. Namely, the important feature information is not clearly expressed in the model, such as the broken pick, draw-back, oil stains and broken end. The CS-CNN cannot achieve a high accuracy of classification with a batch size of 64.
Visualizations with the batch size of 64. Visualizations with the batch size of 512.

In Figure 13, the important feature information of the defects can be learned obviously with the batch size of 512. With the learned important information, the dependence of the model on the classifier will be reduced and the classification performance of the model can also be improved. Figures 14 and 15 show the results of convolution layers and pooling layers for which the dropouts are 0.1 and 0.85, respectively. In Figure 14, the proposed CS-CNN loses the ability to learn the important feature information of images with the dropout of 0.1. With the extraction of better feature information, the model has a better accuracy of classification with the dropout of 0.85. It can also be observed from Figures 13 and 15 that not all of the feature information can be extracted well, even if the model has a better accuracy of classification, such as images of broken ends.
Results with a dropout of 0.1. Results with a dropout of 0.85.

Tracking of weights of the fully connected layer
In the training process, the stability of the weights is also an important basis for considering whether the model can converge to the stable state. In this work, we track the changes of weights in the third fully connected layer. It can be seen from Table 1 that there are 2592 connection weights in the third fully connected layer. The initial weights are randomly generated, so it is not necessary to track all connection weights. We select five weights randomly and track the changes when the model is in the training phase. Figure 16 shows the changing trend when the batch size is 512 and the dropout is 0.85. With the training process of the model, it can be seen that the selected weights tend to be stable finally. It can be concluded that the model can converge to the stable state with stable weights.
The tracking results of weights.
Conclusions and future work
In this research, a novel method CS-CNN is proposed to solve the problem of fabric defect classification in small sample sizes, which is based on CS and CNNs. Different types of feature information are extracted by CS. Utilizing this feature information and the original images, the newly designed CS-CNN model is used to classify the defect images. The experimental results show the effectiveness of the proposed method in comparison with the usual classification techniques, where we observe that even at low measurements rates, excellent classification recognition accuracy can be obtained. Meanwhile, this study visualizes medium results of the proposed CS-CNN that help one to better understand and explain the effects of the model. Further investigation is required to research the unique particularity of the fabric defect images and optimize the architecture in terms of a low measurement rate to maximize the classification performance.
Footnotes
Declaration of conflicting interests
The authors declared no potential conflicts of interest with respect to the research, authorship and/or publication of this article.
Funding
The authors disclosed receipt of the following financial support for the research, authorship, and/or publication of this article: This work was supported in part by the International Collaborative Project of the Shanghai Committee of Science and Technology (Grant No. 16510711100), the Fundamental Research Funds for the Central Universities (Grant No. 2232017D-08, 2232017D-13), the National Natural Science Foundation of China (Grant Nos. 61503075, 61603090), the Shanghai Sailing Program (Grant No. 17YF1426100) and the Program for Changjiang Scholars from the Ministry of Education (2015-2019).
