Cloth defect detection method, system, electronic device and storage medium
Through the feature erasure and extraction network and feature classification and positioning network of the convolutional neural network, combined with multi-scale adaptive feature fusion and cosine similarity alignment, the problem of high false alarm rate, high computational cost and slow speed in cloth defect detection is solved. problem, achieving more accurate and stable detection results.
Patent Information
- Application Number
- CN202411055972.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-08-02
AI Technical Summary
Existing fabric defect detection methods have problems such as high false alarm rate, high computational cost, and slow speed.
The feature erasure and extraction network and feature classification and positioning network based on convolutional neural networks are used to extract and classify cloth defect features through multi-scale adaptive feature fusion, feature erasure and cosine similarity alignment, enhance detection performance and reduce errors. reporting rate and improve detection speed.
It achieves more accurate and stable cloth defect detection, reduces false alarm rates and computational costs, increases detection speed, and enhances the detection performance of image changes.
Smart Images

Figure CN118570209B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image recognition, and in particular, relates to a cloth defect detection method, system, electronic equipment and storage medium. Background Art
[0002] Fabric defect detection is a critical quality control point in the fabric production process. Traditional manual detection methods have low efficiency, poor robustness, and low industrialization level; while mathematical image difference detection methods also have the defects of poor robustness and high false alarm rate. At the same time, since the operation is performed on the entire image, the calculation cost is high and the speed is slow. Summary of the invention
[0003] The embodiments of the present invention provide a cloth defect detection method, system, electronic device and storage medium to at least solve the technical problems of high false alarm rate, high calculation cost and slow speed in the cloth defect detection method in the prior art.
[0004] According to a first aspect of an embodiment of the present invention, a cloth defect detection method is provided, comprising: collecting cloth defect samples detected by a fixed camera during an industrial production process, wherein each cloth defect sample consists of a defective image and a sequence of defect-free template images; defining defect types, dividing a reasonable defect category set, marking defect frame positions, and establishing a database; data preprocessing, including data cleaning, removing invalid data and low-quality data, unifying the size of the image, and synchronously scaling the defect frame position, and image normalization processing; a feature erasing and extraction network based on a convolutional neural network, which is a convolutional neural network composed of a plurality of residual block sequences, and is used to extract defect features; a feature classification and positioning network based on a convolutional neural network, which is a convolutional neural network composed of a plurality of fully connected layers, and the classification network and the positioning network have their own independent network structures, and can classify the types of defects and locate the defect frame position according to the feature vector output by the feature extraction network.
[0005] Optionally, the collecting of cloth defect samples detected by fixed cameras during industrial production includes: the cloth defects are captured by two fixed high-speed cameras, and cloth defect sample images are generated respectively. And the production sample picture without defects In the production line of cloth, high-speed cameras continuously capture cloth and generate sample sequences. ,in represents the defect map features, Represents the template image features; the sample sequence is sent to the simple image difference detection, once Then prove is a defect map, where It represents the threshold value for simple difference detection to judge whether the cloth image is abnormal. The data is sent to the database for machine annotation of defect boxes and categories, and calibration is performed. Multiple such data pairs constitute a sample data set.
[0006] Optionally, the feature erasing and extraction network based on convolutional neural network is a convolutional neural network composed of multiple residual block sequences to extract defect features, including: the feature extraction model can be defined as: ,in, and represent the defect map and template map respectively, represents the feature extraction network, It represents the extracted feature vector; based on the feature erasing network structure of the convolutional neural network, the feature erasing aligns the defect image features extracted by each convolutional layer of the convolutional neural network with the template image features, and then calculates the difference. By continuously learning the difference between the defect image and the template image, the noise is removed and the defect features are extracted. It can be represented by the following formula: ,in, represents the feature vector extracted by the network, For the layer convolutional neural network, represent the defect vector and template vector respectively, Represents a feature alignment network; in the process of extracting image features in the convolutional neural network layer, the feature vector of the template image is continuously used to erase the defect image vector in each convolutional neural network layer, and the defect features are continuously enhanced by erasing noise and flawless parts; the feature alignment method based on cosine similarity, the feature alignment method based on cosine similarity extracts the feature vectors through each layer of the convolutional neural network ,calculate Cosine similarity of , the specific characteristics can be represented by the following formula: ,in, Represents the defect map features and template map features output by each convolutional neural network feature extraction network layer, Represents a convolution operation; based on the reconstruction alignment module, the defect image is reconstructed through the template image and the template image is reconstructed through the defect image, so as to realize the alignment of the features of the template image and the defect image by the feature extraction network module.
[0007] Optionally, the feature erasing and extraction network based on the convolutional neural network is a convolutional neural network composed of multiple residual block sequences to extract defect features, including: based on multi-scale adaptive feature fusion, the feature vectors extracted by the multi-layer network layers of the convolutional neural network are fused, and the attention mechanism is adopted. The network can learn the weights of the feature vectors of different network layers and adaptively adjust the feature vector weights of the network layer output; based on the multi-scale adaptive feature fusion method, the output vectors of all network layers are fused, and through the channel attention mechanism, they are multiplied with the learned network layer weights and then fused to become the output of the feature extraction layer; specifically, it can be expressed by the following formula: , ,in represents the activation function in the neural network, is the maximum pooling, is the average pooling operation, W1, W2, f2, f1, The feature vector obtained by concatenating all feature extraction network layers by channel.
[0008] Optionally, the method of classifying the types of defects and locating the defect frame according to the feature vector output by the feature extraction network includes: the classification and positioning method of the defects is based on a feature pyramid network structure, and the network layer input is the output feature vector; based on the network model of the feature pyramid network, the local information of the image after feature extraction by the convolutional neural network is included in the feature channel, and the type and position of the defect are judged by the feature pyramid network.
[0009] According to a second aspect of an embodiment of the present invention, a cloth defect detection system is also provided, including: an acquisition module, used to acquire cloth defect samples detected by a fixed camera in an industrial production process, wherein each cloth defect sample consists of a defective picture and a sequence of defect-free template pictures; a construction module, used to define defect types, divide a reasonable defect category set, mark defect frame positions, and establish a database; a data processing module, used for data preprocessing, including data cleaning, removal of invalid data and low-quality data, unification of image size, synchronous scaling of defect frame positions, and image normalization processing; an extraction module, used for a feature erasing and extraction network based on a convolutional neural network, which is a convolutional neural network composed of a plurality of residual block sequences, and is used to extract defect features; a classification and positioning module, used for a feature classification and positioning network based on a convolutional neural network, which is a convolutional neural network composed of a plurality of fully connected layers, and the classification network and the positioning network have their own independent network structures, and can classify the types of defects and locate the defect frame positions according to the feature vectors output by the feature extraction network.
[0010] According to a third aspect of an embodiment of the present invention, there is also provided an electronic device, comprising a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the cloth defect detection method described in any embodiment of the first aspect above.
[0011] According to a fourth aspect of an embodiment of the present invention, a non-volatile storage medium is further provided, in which a computer program is stored, wherein the computer program is configured to execute the cloth defect detection method described in any embodiment of the first aspect when running on a computer or a processor.
[0012] According to a fifth aspect of the embodiments of the present invention, there is also provided a computer program product, including a computer program, which, when executed by a processor, implements the cloth defect detection method described in any embodiment of the first aspect above.
[0013] In the embodiment of the present invention, a convolutional neural network is applied to a cloth defect detection method, and adaptive weights are added to multi-scale feature fusion. A learnable convolutional neural network is used to learn the fusion weights according to the data itself, so that the detection performance is more accurate and stable. In view of the defects of the existing methods such as poor robustness, low accuracy, and serious background interference, a feature erasing method based on feature vectors is proposed, which can enhance the model's detection performance for image and image sequence changes, and the effect of image change detection is more stable and accurate. The cosine similarity metric is applied to feature alignment, and the defective part in the cloth defect image is enhanced based on cosine similarity, and the background matching the template image is weakened. In this way, the technical problems of high false alarm rate, high calculation cost, and slow speed in the cloth detection method in the prior art can be solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0015] Figure 1 is a flow chart of a cloth defect detection method according to one embodiment of the present invention;
[0016] Figure 2 The CNN network structure framework of the model proposed in the present invention;
[0017] Figure 3 The feature alignment based on cosine similarity proposed by the present invention;
[0018] Figure 4 The feature extraction module based on reconstruction proposed by the present invention;
[0019] Figure 5The feature erasing module proposed by the present invention;
[0020] Figure 6 The present invention relates to a channel attention model framework;
[0021] Figure 7 is a structural block diagram of a cloth defect detection system according to one embodiment of the present invention. DETAILED DESCRIPTION
[0022] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0023] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0024] According to an embodiment of the present invention, an embodiment of a cloth defect detection method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system containing at least one set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0025] The method embodiment can also be executed in an electronic device including a memory and a processor, a similar control device or a cloud. Taking an electronic device as an example, the electronic device may include one or more processors and a memory for storing data. Optionally, the electronic device may also include a communication device and a display device for communication functions. It can be understood by those of ordinary skill in the art that the above structural description is only illustrative and does not limit the structure of the above electronic device. For example, the electronic device may also include more or fewer components than the above structural description, or have a configuration different from the above structural description.
[0026] The processor may include one or more processing units. For example, the processor may include a central processing unit (CPU), a graphics processing unit (GPU), a digital signal processing (DSP) chip, a microcontroller unit (MCU), a field-programmable gate array (FPGA), a neural-network processing unit (NPU), a tensor processing unit (TPU), an artificial intelligence (AI) type processor, and other processing devices. Among them, different processing units may be independent components or integrated into one or more processors. In some instances, the electronic device may also include one or more processors.
[0027] The memory can be used to store computer programs, for example, to store the computer program corresponding to the cloth defect detection method in the embodiment of the present invention. The processor implements the above-mentioned cloth defect detection method by running the computer program stored in the memory. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory may further include a memory remotely arranged relative to the processor, and these remote memories can be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0028] The communication device is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the communication device includes a network adapter (network interface controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the communication device can be a radio frequency (radio frequency, RF) module, which is used to communicate with the Internet wirelessly. In some embodiments of the present solution, the communication device is used to connect to mobile devices such as mobile phones and tablets, and instructions can be sent to electronic devices through the mobile device.
[0029] The display device may be a touch screen type liquid crystal display (LCD) and a touch display (also referred to as a "touch screen" or "touch display screen"). The liquid crystal display may enable a user to interact with a user interface of the electronic device. In some embodiments, the electronic device has a graphical user interface (GUI), and a user may interact with the GUI by touching a finger release and / or gestures on a touch-sensitive surface, and executable instructions for executing the above-mentioned human-computer interaction functions are configured / stored in a computer program product or a readable storage medium executable by one or more processors.
[0030] Figure 1 is a flow chart of a cloth defect detection method according to one embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:
[0031] Step S101, collecting cloth defect samples detected by a fixed camera during an industrial production process, wherein each cloth defect sample consists of a defect image and a sequence of flawless template images.
[0032] Step S102, define the defect types, divide them into reasonable defect category sets, mark the defect frame positions, and establish a database.
[0033] Step S103, data preprocessing, including data cleaning, removing invalid data and low-quality data, unifying the image size, and synchronously scaling the defect frame position, and image normalization processing.
[0034] Step S104, a CNN-based feature erasing and extraction network is formed by a plurality of residual block sequences to extract defect features.
[0035] Step S105, the CNN-based feature classification and positioning network is a CNN network composed of multiple fully connected layers. The classification network and the positioning network have their own independent network structures. The types of defects can be classified and the position of the defect box can be located according to the feature vector output by the feature extraction network.
[0036] In the embodiment of the present invention, a convolutional neural network is applied to a cloth defect detection method, and adaptive weights are added to multi-scale feature fusion. A learnable convolutional neural network is used to learn the fusion weights according to the data itself, so that the detection performance is more accurate and stable. In view of the defects of the existing methods such as poor robustness, low accuracy, and serious background interference, a feature erasing method based on feature vectors is proposed, which can enhance the model's detection performance for image and image sequence changes, and the effect of image change detection is more stable and accurate. The cosine similarity metric is applied to feature alignment, and the defective part in the cloth defect image is enhanced based on cosine similarity, and the background matching the template image is weakened. In this way, the technical problems of high false alarm rate, high calculation cost, and slow speed in the cloth detection method in the prior art can be solved.
[0037] Optionally, the collecting of cloth defect samples detected by fixed cameras during industrial production includes: the cloth defects are captured by two fixed high-speed cameras, and cloth defect sample images are generated respectively. And the production sample picture without defects In the production line of cloth, high-speed cameras continuously capture cloth and generate sample sequences. ,in represents the defect map features, Represents the template image features; the sample sequence is sent to the simple image difference detection, once Then prove is a defect map, where It represents the threshold value for simple difference detection to judge whether the cloth image is abnormal. The data is sent to the database for machine annotation of defect boxes and categories, and calibration is performed. Multiple such data pairs constitute a sample data set.
[0038] Optionally, the CNN-based feature erasing and extraction network is a CNN network composed of multiple residual block sequences to extract defect features, including: Figure 4 , the feature extraction model can be defined as: ,in, and represent the defect map and template map respectively, represents the feature extraction network, Represents the extracted feature vector; based on the CNN feature erasing network structure, feature erasing first aligns the defect image features extracted by each CNN convolution layer with the template image features, and then calculates the difference. By continuously learning the difference between the defect image and the template image, the noise is removed and the defect features are extracted. It can be represented by the following formula: ,in, represents the feature vector extracted by the network, For the layer CNN network, represent the defect vector and template vector respectively, Represents feature alignment network; in the process of extracting image features in the CNN network layer, the feature vector of the template image is continuously used to erase the defect image vector in each CNN network layer, and the defect features are continuously enhanced by erasing the noise and flawless parts; the feature alignment method based on cosine similarity, the feature alignment method based on cosine similarity extracts the feature vectors through each layer of CNN network ,calculate Cosine similarity of , the specific characteristics can be represented by the following formula: ,in, Represents the defect map features and template map features output by each CNN feature extraction network layer, Represents a convolution operation; based on the reconstruction alignment module, the defect image is reconstructed through the template image and the template image is reconstructed through the defect image, so as to realize the alignment of the features of the template image and the defect image by the feature extraction network module.
[0039] Optionally, the CNN-based feature erasing and extraction network is a CNN network composed of multiple residual block sequences to extract defect features, including: based on multi-scale adaptive feature fusion, the feature vectors extracted by the multi-layer network layers of the CNN network are fused, and the attention mechanism is adopted, so that the network can learn the weights of the feature vectors of different network layers and adaptively adjust the feature vector weights of the network layer output; based on the multi-scale adaptive feature fusion method, the output vectors of all network layers are concatenated, and the output vectors are multiplied with the learned network layer weights through the channel attention mechanism and then fused to become the output of the feature extraction layer; it can be specifically expressed by the following formula: , ,in represents the activation function in the neural network, is the maximum pooling, is the average pooling operation, W1, W2, f2, f1, The feature vector obtained by concatenating all feature extraction network layers by channel.
[0040] Optionally, the method of classifying the type of defects and locating the position of the defect frame according to the feature vector output by the feature extraction network includes: the classification and positioning method of the defects is based on the FPN (Feature Pyramid Network) network structure, and the network layer input is the output feature vector; based on the FPN network model, the local information of the image after CNN feature extraction is included in the feature channel, and the type and position of the defect are judged through the FPN network.
[0041] Specifically, refer to Figure 2In order to solve the problems of low efficiency, high false alarm rate, poor robustness and defects of existing algorithms in cloth defect detection, the present invention proposes a cloth defect detection method based on multi-scale adaptive feature fusion. The method applies a model built based on a convolutional neural network, involving multiple fields such as target detection and change detection methods, feature alignment, feature fusion and feature enhancement, and includes multiple modules such as data acquisition, data filtering and annotation, database establishment, model learning and training, and reasoning detection. The data acquisition is to set a fixed high-speed camera on the industrial production line to take physical photos of the produced cloth at a fixed frequency, and form an image pair with a design template image that must not have defects. After a simple anomaly detection algorithm based on pixel difference statistics, a sample image of the cloth with defects is extracted and stored in a computer with its template image. The anomaly detection algorithm based on pixel difference statistics is based on the principle of setting a difference threshold. , the image is cut into 8*8 patches on average. If the pixel difference between each image patch exceeds , then mark the image as defective, otherwise it is discarded if there is no defect; the data filtering and marking module manually marks the defect category of the collected data stored in the computer, calibrates the defect position, and removes low-quality images; the database establishment is to establish the data that has been manually screened and confirmed in the form of The dataset consists of a sequence of image pairs, where For defect pictures, It is a template image; the model learning and training specifically includes data enhancement, data preprocessing, a module based on a multi-scale adaptive feature fusion method, a defect classification and defect position detection module, and the multi-scale adaptive feature fusion method specifically includes image feature extraction, a feature erasure module based on CNN, a feature alignment module, a feature fusion module, and a feature-based change extraction module; the reasoning detection module is to build the trained model on an industrial production machine, input the real-time image on the industrial assembly line into the model, predict whether there is a defect through the model, and infer the defect position. If there is a defect, a machine alarm is generated to guide the production technician to adjust and calibrate the production machine, and remove defective cloth to ensure the quality of the produced cloth.
[0042] The core of this method is a multi-scale adaptive feature fusion method, a feature erasure method based on feature vectors, and a feature alignment method based on cosine similarity. This method can train a stable model to efficiently, quickly, accurately and reliably detect defective fabrics on the fabric production line, and promptly alert technicians to guide them to make targeted adjustments to industrial production machines and screen out defective fabrics that have already been produced, greatly improving production efficiency and quality control of industrialized production, saving manpower and material resources.
[0043] The feature erasing method based on feature vector, refer to Figure 5 , further description includes: the feature erasing network is composed of multiple CNN network layers, and these CNN network layers are composed of residual network blocks; each CNN residual network layer learns image features, and the output feature vectors of these CNN network layers constitute feature sequences of multiple scales, wherein the low-level CNN network contains fine-grained information of the image, such as position, pixel, etc.; and the high-level CNN network layer can learn more semantic feature information. Therefore, based on the different information of the image contained in the above-mentioned different network layers, the present invention uses the feature vector of the template image to erase the feature vector of the defect image after extracting features in each network layer; the erasing is to use the feature vector of the template image Subtract the feature vector of the defect map , and the subtraction is to perform mathematical subtraction after feature alignment by the above feature alignment method. This method can effectively remove the image semantic features that do not contain defects in the defect map from the low-level features of CNN to the high-level features, and compared with other methods, it has a small number of parameters and a high accuracy.
[0044] The feature alignment method based on cosine similarity, refer to Figure 3 , further explained, the steps include: S1: Input is the feature vector of the defect map output by each CNN network layer and the feature vector of the template graph ; S2: Use a convolutional layer to transform the feature vector and Scaling on the channel , in the process of convolution network convolution, the local position adjustment and alignment of features can be achieved; S3: calculation and Cosine similarity of ; S4: Use cosine similarity to enhance the defect image features. The specific operation is as follows: ,here Represents matrix multiplication; S5: The output of the feature alignment module is the defect image feature vector after alignment with the template image feature. The core method of feature alignment based on cosine similarity is to calculate the defect map feature vector and template graph vector The cosine similarity between , in physical terms, in the process of convolution of the convolutional network, the feature vector and Aligned, the cosine value is calculated as and The cosine value of the aligned part is larger, and vice versa.
[0045] The multi-scale adaptive feature fusion method described above refers to Figure 6 The fusion method adopts the channel splicing method. Further explanation, the steps include: S1: The module input is the feature vector of the defect image in the above multi-layer CNN network after the feature vector of the template image is erased. , multiple CNN network layers are spliced together according to the channel to form a feature sequence ; S2: Use channel attention as sequence Adding adaptive fusion weights , module output , As the input vector for defect classification and location. The channel attention is composed of two fully connected layers, a maximum pooling layer, and an average pooling layer. The specific steps are: S21: After a maximum pooling layer and an average pooling layer, the sizes are of , take the mean ; S22: After passing through a fully connected layer, an activation layer, a fully connected layer, and a softmax activation layer, the channel weight is finally obtained. , here represents a network composed of all condensed layers; S33: adds adaptive weights to the fused multi-scale features to obtain , here is the feature vector after adaptive multi-scale fusion.
[0046] The present invention applies a convolutional neural network to a cloth defect detection method, adds adaptive weights to multi-scale feature fusion, adopts a learnable CNN network to learn the fusion weights according to the data itself, so that the detection performance is more accurate and stable; and in view of the defects of the existing method such as poor robustness, low accuracy and serious background interference, a feature erasing method based on a feature vector is proposed, which can enhance the detection performance of the model for changes in images and image sequences, and has a more stable and accurate effect on image change detection; and the cosine similarity metric is applied to feature alignment, and the defect part in the cloth defect image is enhanced based on the cosine similarity, and the background matching the template image is weakened.
[0047] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0048] In this embodiment, a cloth defect detection system is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" is a combination of software and / or hardware that can implement a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0049] Figure 7 FIG. 2 is a structural block diagram of a cloth defect detection system 200 according to one embodiment of the present invention. Figure 7 As shown, a cloth defect detection system 200 is used as an example, including: an acquisition module 201, which is used to collect cloth defect samples detected by a fixed camera in an industrial production process, wherein each cloth defect sample consists of a defective image and a sequence of defect-free template images; a construction module 202, which is used to define defect types, divide a reasonable defect category set, mark the defect frame position, and establish a database; a data processing module 203, which is used for data preprocessing, including data cleaning, removing invalid data and low-quality data, unifying the image size, and synchronously scaling the defect frame position, and image normalization processing; an extraction module 204, which is used for a CNN-based feature erasing and extraction network, which is a CNN network composed of multiple residual block sequences, and is used to extract defect features; a classification and positioning module 205, which is used for a CNN-based feature classification and positioning network, which is a CNN network composed of multiple fully connected layers, and the classification network and the positioning network have their own independent network structures, and can classify the types of defects and locate the defect frame position according to the feature vector output by the feature extraction network.
[0050] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the cloth defect detection method described in any of the above embodiments.
[0051] Optionally, in this embodiment, the processor in the above electronic device may be configured to run a computer program to perform the following steps:
[0052] Step S101, collecting cloth defect samples detected by a fixed camera during an industrial production process, wherein each cloth defect sample consists of a defect image and a sequence of flawless template images.
[0053] Step S102, define the defect types, divide them into reasonable defect category sets, mark the defect frame positions, and establish a database.
[0054] Step S103, data preprocessing, including data cleaning, removing invalid data and low-quality data, unifying the image size, and synchronously scaling the defect frame position, and image normalization processing.
[0055] Step S104, a feature erasing and extraction network based on CNN (convolutional neural network) is a CNN network composed of multiple residual block sequences, which is used to extract defect features.
[0056] Step S105, the CNN-based feature classification and positioning network is a CNN network composed of multiple fully connected layers. The classification network and the positioning network have their own independent network structures. The types of defects can be classified and the position of the defect box can be located according to the feature vector output by the feature extraction network.
[0057] Optionally, the collecting of cloth defect samples detected by fixed cameras during industrial production includes: the cloth defects are captured by two fixed high-speed cameras, and cloth defect sample images are generated respectively. And the production sample picture without defects In the production line of cloth, high-speed cameras continuously capture cloth and generate sample sequences. ,in represents the defect map features, Represents the template image features; the sample sequence is sent to the simple image difference detection, once Then prove is a defect map, where It represents the threshold value for simple difference detection to judge whether the cloth image is abnormal. The data is sent to the database for machine annotation of defect boxes and categories, and calibration is performed. Multiple such data pairs constitute a sample data set.
[0058] Optionally, the CNN-based feature erasing and extraction network is a CNN network composed of multiple residual block sequences to extract defect features, including: The feature extraction model can be defined as: ,in, and represent the defect map and template map respectively, represents the feature extraction network, Represents the extracted feature vector; based on the CNN feature erasing network structure, feature erasing first aligns the defect image features extracted by each CNN convolution layer with the template image features, and then calculates the difference. By continuously learning the difference between the defect image and the template image, the noise is removed and the defect features are extracted. It can be represented by the following formula: ,in, represents the feature vector extracted by the network, For the layer CNN network, represent the defect vector and template vector respectively, Represents feature alignment network; in the process of extracting image features in the CNN network layer, the feature vector of the template image is continuously used to erase the defect image vector in each CNN network layer, and the defect features are continuously enhanced by erasing the noise and flawless parts; the feature alignment method based on cosine similarity, the feature alignment method based on cosine similarity extracts the feature vectors through each layer of CNN network ,calculate Cosine similarity of , the specific characteristics can be represented by the following formula: ,in, Represents the defect map features and template map features output by each CNN feature extraction network layer, Represents a convolution operation; based on the reconstruction alignment module, the defect image is reconstructed through the template image and the template image is reconstructed through the defect image, so as to realize the alignment of the features of the template image and the defect image by the feature extraction network module.
[0059] Optionally, the CNN-based feature erasing and extraction network is a CNN network composed of multiple residual block sequences to extract defect features, including: based on multi-scale adaptive feature fusion, the feature vectors extracted by the multi-layer network layers of the CNN network are fused, and the attention mechanism is adopted, so that the network can learn the weights of the feature vectors of different network layers and adaptively adjust the feature vector weights of the network layer output; based on the multi-scale adaptive feature fusion method, the output vectors of all network layers are concatenated, and the output vectors are multiplied with the learned network layer weights through the channel attention mechanism and then fused to become the output of the feature extraction layer; it can be specifically expressed by the following formula: , ,in represents the activation function in the neural network, is the maximum pooling, is the average pooling operation, w, f2, f1, The feature vector obtained by concatenating all feature extraction network layers by channel.
[0060] Optionally, the method of classifying the types of defects and locating the defect frame according to the feature vector output by the feature extraction network includes: the classification and positioning method in the defect classification and positioning method is based on the FPN network structure, and the network layer input is the output feature vector; based on the FPN network model, the local information of the image after CNN feature extraction is included in the feature channel, and the type and position of the defect are judged through the FPN network.
[0061] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0062] An embodiment of the present invention further provides a non-volatile storage medium, in which a computer program is stored, wherein the computer program is configured to execute the cloth defect detection method described in any of the above embodiments when running on a computer or a processor.
[0063] Optionally, in this embodiment, the above-mentioned computer program may be configured to store a computer program for performing the following steps:
[0064] Step S101, collecting cloth defect samples detected by a fixed camera during an industrial production process, wherein each cloth defect sample consists of a defect image and a sequence of flawless template images.
[0065] Step S102, define the defect types, divide them into reasonable defect category sets, mark the defect frame positions, and establish a database.
[0066] Step S103, data preprocessing, including data cleaning, removing invalid data and low-quality data, unifying the image size, and synchronously scaling the defect frame position, and image normalization processing.
[0067] Step S104, a CNN-based feature erasing and extraction network is formed by a plurality of residual block sequences to extract defect features.
[0068] Step S105, the CNN-based feature classification and positioning network is a CNN network composed of multiple fully connected layers. The classification network and the positioning network have their own independent network structures. The types of defects can be classified and the position of the defect box can be located according to the feature vector output by the feature extraction network.
[0069] Optionally, the collecting of cloth defect samples detected by fixed cameras during industrial production includes: the cloth defects are captured by two fixed high-speed cameras, and cloth defect sample images are generated respectively. And the production sample picture without defects In the production line of cloth, high-speed cameras continuously capture cloth and generate sample sequences. ,in represents the defect map features, Represents the template image features; the sample sequence is sent to the simple image difference detection, once Then prove is a defect map, where It represents the threshold value for simple difference detection to judge whether the cloth image is abnormal. The data is sent to the database for machine annotation of defect boxes and categories, and calibration is performed. Multiple such data pairs constitute a sample data set.
[0070] Optionally, the CNN-based feature erasing and extraction network is a CNN network composed of multiple residual block sequences to extract defect features, including: The feature extraction model can be defined as: ,in, and represent the defect map and template map respectively, represents the feature extraction network, Represents the extracted feature vector; based on the CNN feature erasing network structure, feature erasing first aligns the defect image features extracted by each CNN convolution layer with the template image features, and then calculates the difference. By continuously learning the difference between the defect image and the template image, the noise is removed and the defect features are extracted. It can be represented by the following formula: ,in, represents the feature vector extracted by the network, For the layer CNN network, represent the defect vector and template vector respectively, Represents feature alignment network; in the process of extracting image features in the CNN network layer, the feature vector of the template image is continuously used to erase the defect image vector in each CNN network layer, and the defect features are continuously enhanced by erasing the noise and flawless parts; the feature alignment method based on cosine similarity, the feature alignment method based on cosine similarity extracts the feature vectors through each layer of CNN network ,calculate Cosine similarity of , the specific characteristics can be represented by the following formula: ,in, Represents the defect map features and template map features output by each CNN feature extraction network layer, Represents a convolution operation; based on the reconstruction alignment module, the defect image is reconstructed through the template image and the template image is reconstructed through the defect image, so as to realize the alignment of the features of the template image and the defect image by the feature extraction network module.
[0071] Optionally, the CNN-based feature erasing and extraction network is a CNN network composed of multiple residual block sequences to extract defect features, including: based on multi-scale adaptive feature fusion, the feature vectors extracted by the multi-layer network layers of the CNN network are fused, and the attention mechanism is adopted, so that the network can learn the weights of the feature vectors of different network layers and adaptively adjust the feature vector weights of the network layer output; based on the multi-scale adaptive feature fusion method, the output vectors of all network layers are concatenated, and the output vectors are multiplied with the learned network layer weights through the channel attention mechanism and then fused to become the output of the feature extraction layer; it can be specifically expressed by the following formula: , ,in represents the activation function in the neural network, is the maximum pooling, is the average pooling operation, w, f2, f1, The feature vector obtained by concatenating all feature extraction network layers by channel.
[0072] Optionally, the method of classifying the types of defects and locating the defect frame according to the feature vector output by the feature extraction network includes: the classification and positioning method in the defect classification and positioning method is based on the FPN network structure, and the network layer input is the output feature vector; based on the FPN network model, the local information of the image after CNN feature extraction is included in the feature channel, and the type and position of the defect are judged through the FPN network.
[0073] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0074] An embodiment of the present invention further provides a computer program product, including a computer program, which implements the cloth defect detection method described in any of the above embodiments when executed by a processor.
[0075] Optionally, in this embodiment, the above computer program implements the following steps when executed by a processor:
[0076] Step S101, collecting cloth defect samples detected by a fixed camera during an industrial production process, wherein each cloth defect sample consists of a defect image and a sequence of flawless template images.
[0077] Step S102, define the defect types, divide them into reasonable defect category sets, mark the defect frame positions, and establish a database.
[0078] Step S103, data preprocessing, including data cleaning, removing invalid data and low-quality data, unifying the image size, and synchronously scaling the defect frame position, and image normalization processing.
[0079] Step S104, a CNN-based feature erasing and extraction network is formed by a plurality of residual block sequences to extract defect features.
[0080] Step S105, the CNN-based feature classification and positioning network is a CNN network composed of multiple fully connected layers. The classification network and the positioning network have their own independent network structures. The types of defects can be classified and the position of the defect box can be located according to the feature vector output by the feature extraction network.
[0081] Optionally, the collecting of cloth defect samples detected by fixed cameras during industrial production includes: the cloth defects are captured by two fixed high-speed cameras, and cloth defect sample images are generated respectively. And the production sample picture without defects In the production line of cloth, high-speed cameras continuously capture cloth and generate sample sequences. ,in represents the defect map features, Represents the template image features; the sample sequence is sent to the simple image difference detection, once Then prove is a defect map, where It represents the threshold value for simple difference detection to judge whether the cloth image is abnormal. The data is sent to the database for machine annotation of defect boxes and categories, and calibration is performed. Multiple such data pairs constitute a sample data set.
[0082] Optionally, the CNN-based feature erasing and extraction network is a CNN network composed of multiple residual block sequences to extract defect features, including: The feature extraction model can be defined as: ,in, and represent the defect map and template map respectively, represents the feature extraction network, Represents the extracted feature vector; based on the CNN feature erasing network structure, feature erasing first aligns the defect image features extracted by each CNN convolution layer with the template image features, and then calculates the difference. By continuously learning the difference between the defect image and the template image, the noise is removed and the defect features are extracted. It can be represented by the following formula: ,in, represents the feature vector extracted by the network, For the layer CNN network, represent the defect vector and template vector respectively, Represents feature alignment network; in the process of extracting image features in the CNN network layer, the feature vector of the template image is continuously used to erase the defect image vector in each CNN network layer, and the defect features are continuously enhanced by erasing the noise and flawless parts; the feature alignment method based on cosine similarity, the feature alignment method based on cosine similarity extracts the feature vectors through each layer of CNN network ,calculate Cosine similarity of , the specific characteristics can be represented by the following formula: ,in, Represents the defect map features and template map features output by each CNN feature extraction network layer, Represents a convolution operation; based on the reconstruction alignment module, the defect image is reconstructed through the template image and the template image is reconstructed through the defect image, so as to realize the alignment of the features of the template image and the defect image by the feature extraction network module.
[0083] Optionally, the CNN-based feature erasing and extraction network is a CNN network composed of multiple residual block sequences to extract defect features, including: based on multi-scale adaptive feature fusion, the feature vectors extracted by the multi-layer network layers of the CNN network are fused, and the attention mechanism is adopted, so that the network can learn the weights of the feature vectors of different network layers and adaptively adjust the feature vector weights of the network layer output; based on the multi-scale adaptive feature fusion method, the output vectors of all network layers are concatenated, and the output vectors are multiplied with the learned network layer weights through the channel attention mechanism and then fused to become the output of the feature extraction layer; it can be specifically expressed by the following formula: , ,in represents the activation function in the neural network, is the maximum pooling, is the average pooling operation, w, f2, f1, The feature vector obtained by concatenating all feature extraction network layers by channel.
[0084] Optionally, the method of classifying the types of defects and locating the defect frame according to the feature vector output by the feature extraction network includes: the classification and positioning method in the defect classification and positioning method is based on the FPN network structure, and the network layer input is the output feature vector; based on the FPN network model, the local information of the image after CNN feature extraction is included in the feature channel, and the type and position of the defect are judged through the FPN network.
[0085] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0086] In some embodiments provided in the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the modules can be a logical function division. There may be other division methods in actual implementation. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, modules or indirect coupling or communication connection of modules, which can be electrical or other forms.
[0087] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0088] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above integrated modules may be implemented in the form of hardware or in the form of software functional modules.
[0089] If the integrated module is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk, etc., which can store program code.
[0090] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A cloth defect detection method, characterized in that: include: Collect fabric defect samples detected by fixed cameras during industrial production, where each fabric defect sample consists of a defect image and a sequence of flawless template images; Define defect types, divide them into reasonable defect category sets, mark defect box locations, and establish a database; Data preprocessing, including data cleaning, removing invalid data and low-quality data, unifying the image size, synchronously scaling the defect frame position, and image normalization; The feature erasing and extraction network based on convolutional neural network is a convolutional neural network composed of multiple residual block sequences, which is used to extract defect features, including: The feature extraction model is defined as: ,in, and represent the defect map and template map respectively, represents the feature extraction network, Indicates that the feature vector is extracted; Based on the feature erasing network structure of the convolutional neural network, feature erasing first aligns the defect image features extracted by each convolutional layer of the convolutional neural network with the template image features, and then calculates the difference. By continuously learning the difference between the defect image and the template image, the noise is removed and the defect features are extracted. It can be represented by the following formula: , in, represents the feature vector extracted by the network, For the layer convolutional neural network, represent the defect vector and template vector respectively, represents the feature alignment network; In the process of extracting image features in the convolutional neural network layer, the defect image vector is continuously erased with the feature vector of the template image in each convolutional neural network layer, and the defect features are enhanced by erasing the noise and the flawless parts; Feature alignment method based on cosine similarity. Feature alignment method based on cosine similarity. The feature vector extracted by each layer of convolutional neural network ,calculate Cosine similarity of ,The specific characteristics can be represented by the following formula: , in, Represents the defect map features and template map features output by each convolutional neural network feature extraction network layer, Represents the convolution operation; Based on the reconstruction alignment module, the defect image is reconstructed through the template image and the template image is reconstructed through the defect image, so as to realize the alignment of the features of the template image and the defect image by the feature extraction network module; The feature classification and positioning network based on convolutional neural network is a convolutional neural network composed of multiple fully connected layers. The classification network and positioning network have their own independent network structures. They can classify the types of defects and locate the position of the defect box according to the feature vector output by the feature extraction network.
2. The cloth defect detection method according to claim 1, characterized in that: The cloth defect samples detected by the fixed camera during the industrial production process include: The defects of the cloth are captured by two fixed high-speed cameras, which produce cloth defect sample images and production sample images without defects. In the cloth production line, the high-speed camera continuously captures the cloth to generate sample sequences. ,in represents the defect map features, Represents the template graph features; Feed the sample sequence into simple image difference detection, once Then prove is a defect map, where It represents the threshold value for simple difference detection to judge whether the cloth image is abnormal. The data is sent to the database for machine annotation of defect boxes and categories and calibration. Multiple such data pairs constitute a sample data set.
3. The cloth defect detection method according to claim 1, characterized in that: The feature erasing and extraction network based on convolutional neural network is a convolutional neural network composed of multiple residual block sequences to extract defect features, including: Based on multi-scale adaptive feature fusion, the feature vectors extracted by the multi-layer network layers of the convolutional neural network are fused, and the attention mechanism is adopted. The network can learn the weights of the feature vectors of different network layers and adaptively adjust the weights of the feature vectors output by the network layer; Based on the multi-scale adaptive feature fusion method, the output vectors of all network layers are fused, and through the channel attention mechanism, they are multiplied with the learned network layer weights and fused to become the output of the feature extraction layer; It can be expressed by the following formula: , , in represents the activation function in the neural network, is the maximum pooling, is the average pooling operation, W1, W2, f2, f1, The feature vector obtained by concatenating all feature extraction network layers by channel.
4. The cloth defect detection method according to claim 3, characterized in that: The method of classifying the types of defects and locating the defect frame positions according to the feature vector output by the feature extraction network includes: The classification and positioning method of defects is based on a convolutional neural network structure, and the input of the network layer is a feature vector of the output; based on the network model of the convolutional neural network, the local information of the image after the convolutional neural network feature extraction is included in the feature channel, and the convolutional neural network is used to judge the type and location of the defect.
5. A cloth defect detection system, characterized in that: include: The acquisition module is used to collect cloth defect samples detected by a fixed camera during the industrial production process, where each cloth defect sample consists of a defect image and a sequence of flawless template images; The construction module is used to define the types of defects, divide them into reasonable defect category sets, mark the defect box positions, and establish a database; Data processing module, used for data preprocessing, including data cleaning, removing invalid data and low-quality data, unifying the image size, synchronously scaling the defect frame position, and image normalization; The extraction module is used for feature erasure and extraction based on convolutional neural network. The convolutional neural network is composed of multiple residual block sequences and is used to extract defect features, including: The feature extraction model is defined as: ,in, and represent the defect map and template map respectively, represents the feature extraction network, Indicates that the feature vector is extracted; Based on the feature erasing network structure of the convolutional neural network, feature erasing first aligns the defect image features extracted by each convolutional layer of the convolutional neural network with the template image features, and then calculates the difference. By continuously learning the difference between the defect image and the template image, the noise is removed and the defect features are extracted. It can be represented by the following formula: , in, represents the feature vector extracted by the network, For the layer convolutional neural network, represent the defect vector and template vector respectively, represents the feature alignment network; In the process of extracting image features in the convolutional neural network layer, the defect image vector is continuously erased with the feature vector of the template image in each convolutional neural network layer, and the defect features are enhanced by erasing the noise and the flawless parts; Feature alignment method based on cosine similarity. Feature alignment method based on cosine similarity. The feature vector extracted by each layer of convolutional neural network ,calculate Cosine similarity of ,The specific characteristics can be represented by the following formula: , in, Represents the defect map features and template map features output by each convolutional neural network feature extraction network layer, Represents the convolution operation; Based on the reconstruction alignment module, the defect image is reconstructed through the template image and the template image is reconstructed through the defect image, so as to realize the alignment of the features of the template image and the defect image by the feature extraction network module; The classification and positioning module is used for feature classification and positioning network based on convolutional neural network. It is a convolutional neural network composed of multiple fully connected layers. The classification network and positioning network have their own independent network structures. They can classify the types of defects and locate the position of the defect box according to the feature vector output by the feature extraction network.
6. An electronic device comprising a memory and a processor, characterized in that: The memory stores a computer program, and the processor is configured to run the computer program to execute the cloth defect detection method described in any one of claims 1 to 4 above.
7. A non-volatile storage medium, characterized in that: The non-volatile storage medium stores a computer program, wherein the computer program is configured to execute the cloth defect detection method described in any one of claims 1 to 4 when running on a computer or a processor.
8. A computer program product, characterized in that It comprises a computer program, which implements the cloth defect detection method according to any one of claims 1 to 4 when executed by a processor.
Citation Information
Patent Citations
Printing defect detection method and system based on deep learning
CN111784644A
