A method for identifying textile defect types
By combining convolutional neural network and spatial attention mechanism, the problem of low recognition rate of subtle defects in textile defect recognition is solved, and more efficient feature extraction and recognition is achieved, which significantly improves the recognition rate and automation level.
Patent Information
- Application Number
- CN202411975471.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2044-12-31
AI Technical Summary
The prior art has low recognition rate of subtle defects in textile defect recognition, poor processing efficiency, and lacks comprehensive feature extraction, so it is impossible to effectively deal with high complexity and diversified defect types.
The combination of convolutional neural network (CNN) and spatial attention mechanism is used to generate feature extraction vectors through feature maps output by multiple convolutional layers, and feature expression is enhanced by fusion feature vectors. The spatial attention mechanism is used to weight the feature map, generate the weighted feature map, and build a segmentation model for identification of defect areas and feature extraction.
It significantly improves the ability to identify subtle defects, improves the recognition rate, reduces the dependence on manual feature design and extraction, improves the automation level of the detection process, and speeds up the processing speed, meeting the needs of real-time detection.
Smart Images

Figure CN119399187B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of textile defect recognition, and in particular to a method for identifying textile defect types. Background Art
[0002] When defects appear on the surface of textiles, it will affect the appearance of subsequent fabrics and even cause quality problems. Defect detection and identification of defect types are key links in the production of textile industry. In the textile industry, there are more than 50 types of textile defects, including stains, damage, drawing, etc. With the advancement of image recognition technology, the way of identifying defects in textiles has gradually changed from traditional manual recognition to identification through machine vision. In the process of using machine vision to identify textiles, it is generally necessary to first obtain images of the surface of the textiles through cameras and other shooting devices, and then filter, segment, extract features and other operations on the images, and perform image recognition processing based on the extracted features to determine whether the textiles have defects.
[0003] In the prior art 1, a textile defect type identification method with publication number CN117893467A uses mean square error to compare the preprocessed image with the pre-stored textile defect image. The mean square error is a commonly used loss function that calculates the average of the squared difference between the predicted value and the true value. Although it is effective in capturing overall deviations, it is not sensitive enough to subtle defects. For example, in the presence of subtle defects (such as slight color changes or uneven fabric texture), the mean square error cannot fully reflect these small deviations, resulting in a low recognition rate;
[0004] In the prior art 2, a textile defect recognition method and system with publication number CN115937186A relies on a set of intersection pixel points to determine the defect area. This method calculates the intersection by comparing the defect area in the segmented image with the normal area in the standard image. However, this method performs poorly when dealing with edges or subtle defects because the intersection calculation ignores the detailed information in the case of blurred or irregular edges.
[0005] However, there are still the following shortcomings. From the above statements, it can be seen that the existing technologies 1 and 2 have problems such as low recognition rate of subtle defects, poor processing efficiency and lack of comprehensive feature extraction. The defect recognition technology based on image processing often relies on simple feature comparison and cannot effectively deal with highly complex and diverse defect types, especially when there are minor defects such as color changes and uneven textures, the recognition accuracy is significantly reduced.
[0006] The above information disclosed in this Background section is only for enhancement of understanding of the background of the present disclosure and therefore it may contain information that does not constitute the prior art that is already known to one of ordinary skill in the art. Summary of the invention
[0007] The object of the present invention is to provide a method for identifying textile defect types to solve the problems raised in the above background technology.
[0008] To achieve the above object, the present invention provides the following technical solutions:
[0009] A method for identifying textile defect types, the specific steps comprising:
[0010] S1. Collect original images of multiple textile samples, including defect-free textile samples and defective textile samples with known defect types, and annotate the original images in the data set, where the annotation content includes image ID, defect location, defect size, defect shape, and segmentation mask image, where the segmentation mask image includes defect area and normal area;
[0011] S2. Adjust the original image to a recognition image of 224x224 pixels, build a convolutional neural network model, input the recognition image into the convolutional neural network model, output feature maps of different convolutional layers, and assign feature layer weights to the feature maps output by each convolutional layer, respectively generate feature extraction vectors using the feature maps output by different convolutional layers, use multiple feature extraction vectors to obtain a convolutional layer feature set, combine the feature extraction vectors and feature layer weights of different convolutional layers to obtain a fused feature vector, and convert the fused feature vector into a fused feature map through deconvolution;
[0012] S3. Take the fused feature map extracted by the convolutional neural network as input, perform pooling on the fused feature map to generate two feature vectors, concatenate the two feature vectors to generate a single-channel spatial attention map, perform data processing on the spatial attention map and the attention adjustment coefficient to generate an adjusted feature map, multiply the adjusted feature map with the input fused feature map point by point to generate a spatially weighted feature map, and multiply the channel attention weight with each channel of the spatially weighted feature map point by point to obtain a weighted feature map;
[0013] S4. construct a segmentation model, use the weighted feature map as the input of the segmentation model, use the labeled segmentation mask image as the output to train the segmentation model, so as to obtain a trained segmentation model, wherein the mask output by the segmentation model identifies the category of each pixel in the image, and the categories include normal areas and defective areas;
[0014] S5. Obtain a weighted feature map of the textile to be tested, and input it into the segmented image after training to identify and mark the defect area of the image to be tested, and calculate the area, roundness and aspect ratio of the defect area;
[0015] S6. Calculate the first comprehensive scoring coefficient, the second comprehensive scoring coefficient and the third comprehensive scoring coefficient respectively using the area, roundness and aspect ratio of the defective area, and identify the defect type of the textile to be tested based on the area, roundness, aspect ratio and the three comprehensive scoring coefficients of the defective area.
[0016] Furthermore, a data set containing various defect types and normal samples is collected, and the original images in the data set are annotated. The specific process is as follows:
[0017] Collect image samples of various defect types and normal samples to determine the total number of samples , where the number of defect samples is , the normal sample size is , ;
[0018] The following information is annotated for each original image:
[0019] Image ID, defect location , defect size , defect shape , segmentation mask ;in, and Indicates the coordinates of the upper left corner of the defect area, and Indicates the coordinates of the lower right corner of the defect area, , is the width of the defect, is the height of the defect, , , segmentation mask image Use binary image to represent the defect area Marked as 255, background area Marked as 0;
[0020] For each original image , generate the segmentation mask for each pixel:
[0021]
[0022] in, The coordinates in the original image are The pixel segmentation mask of is the coordinate position of the pixel in the original image, x is the horizontal coordinate of the pixel in the original image, and y is the vertical coordinate of the pixel in the original image;
[0023] Original image , segmentation mask image Both images, is the height of the image, indicating the number of pixels in the vertical direction. Is the width of the image, which indicates the number of pixels in the horizontal direction.
[0024] Furthermore, the specific process of step S2 is as follows:
[0025] Convolutional neural network consists of multiple convolutional layers, activation layers, and pooling layers for feature extraction. Assume that the constructed CNN model contains The convolution layer performs convolution operation on the input image and extracts features based on the convolution kernel. The input of the convolutional layer is , then Feature map of the convolutional layer output It is expressed as:
[0026]
[0027] in, represents the convolution operation, For the The output of the convolutional layer is the The output of the convolutional layer, For the The weight matrix of the convolutional layer, For the The bias term of the convolutional layer, is the index of the convolutional layer, The value range is , is the total number of convolutional layers, For the activation function, select the ReLU function as the activation function;
[0028] For each convolutional layer output feature map , generate feature extraction vectors through global average pooling or global maximum pooling method , based on the following formula:
[0029]
[0030] in, For the feature map The corresponding feature extraction vector is obtained by The convolutional layer output of layer Perform the pooling operation to obtain For pooling operation;
[0031] Combining multiple feature extraction vectors To form a convolutional layer feature set :
[0032]
[0033] in, Contains from the 1st to the Feature extraction vector of convolutional layer;
[0034] The feature extraction vectors of different convolutional layers and the feature layer weights are fused to obtain the fused feature vector , using weighted average for fusion:
[0035]
[0036] in, For the The feature layer weights associated with the feature extraction vector of the convolutional layer;
[0037] Finally, the fused feature vector is converted into a fused feature map through a deconvolution operation. :
[0038]
[0039] in, is the deconvolution operation.
[0040] Furthermore, the specific process of step S3 is as follows:
[0041] Input fusion feature map is a high-dimensional feature map, and the dimension of the fused feature map is ,in, is the number of channels, and They are the height and width of the fused feature map respectively;
[0042] Pooling is performed on the fused feature map, and global average pooling and global maximum pooling are used to generate the global average feature vector and the global maximum feature vector respectively;
[0043] These two feature vectors are concatenated to generate a single-channel spatial attention map in the following form:
[0044]
[0045]
[0046] in, is the concatenated feature vector, is the spatial attention map, is the Sigmoid function, which normalizes the output to between 0 and 1. is the convolution kernel, is the bias term, is the global average eigenvector, is the global maximum eigenvector;
[0047] Process the spatial attention map to generate the adjusted feature map , based on the following formula:
[0048] ,
[0049] in, represents point-wise multiplication;
[0050] Multiply the adjusted feature map with the input fusion feature map point by point to generate a spatially weighted feature map , based on the following formula:
[0051] ,
[0052] Channel attention weight Generated by SE module:
[0053] ,
[0054] in, is the fully connected layer, is the weight of the fully connected layer;
[0055] The channel attention weight is multiplied point by point with each channel of the spatially weighted feature map to obtain the weighted feature map, based on the following formula:
[0056] ,
[0057] in, is the weighted feature map.
[0058] Furthermore, the mask image is subjected to connected component analysis to identify and mark the defective area. For the screened defective area, relevant features are extracted to obtain a feature set including the screened defective area. The specific process is as follows:
[0059] Starting from the current pixel of the mask image, recursively visit all adjacent foreground pixels and mark them as visited. Each time a new pixel is visited, the position of the pixel is recorded until no new adjacent foreground pixels are accessible. Each time a connected region is found, all pixels in the region are marked with a unique identifier to distinguish different defect regions.
[0060] For each connected defect region, the following features are extracted:
[0061] Area, roundness, aspect ratio, for the screened defect area, obtain the feature set in the following form:
[0062]
[0063]
[0064] in, For the The feature set of the defect area, is the feature set of the defect area, For the The area of the defect region, For the The roundness of the defect area, For the The aspect ratio of the defect area.
[0065] Furthermore, the first comprehensive scoring coefficient is constructed using the area, roundness, and aspect ratio of the defective region, and the textile defect type is identified according to the characteristic value of the defective region and the first comprehensive scoring coefficient. The specific process is as follows:
[0066] The first comprehensive scoring coefficient is constructed by using area, roundness, and aspect ratio to identify whether the textile is a stain. The polynomial function form is as follows:
[0067]
[0068] in, is the first comprehensive scoring coefficient, , , are area, circularity, and aspect ratio, , , are the weight coefficients of area, roundness, and aspect ratio during stain detection, , ;
[0069] When the first comprehensive rating coefficient The value is greater than the coefficient threshold and the area When it is smaller than the area threshold, the textile is a stain;
[0070] When the first comprehensive rating coefficient Less than or equal to coefficient threshold, area When it is greater than or equal to the area threshold, the textile is not a stain;
[0071] The first comprehensive rating coefficient The threshold is 0.5 and the area The threshold value is 0.4.
[0072] Furthermore, the area, roundness and aspect ratio of the defective area are used to construct a second comprehensive scoring coefficient for identifying whether the textile is damaged. The polynomial function form is as follows:
[0073]
[0074] in, is the second comprehensive scoring coefficient, , , are the weight coefficients of area, roundness, and aspect ratio during damage detection, , ;
[0075] When the second comprehensive rating coefficient The value is greater than the coefficient threshold and the area If the area is larger than the threshold, the textile is damaged;
[0076] When the second comprehensive rating coefficient Less than or equal to coefficient threshold, area When the area is less than or equal to the area threshold, the textile is not damaged; the threshold of the second comprehensive scoring coefficient is 0.5.
[0077] Furthermore, the area, roundness, and aspect ratio of the defective area are used to construct a third comprehensive scoring coefficient for identifying whether the textile is wiredrawing. The polynomial function form is as follows:
[0078]
[0079] in, is the third comprehensive scoring coefficient, , , They are the weight coefficients of area, roundness and aspect ratio during wire drawing detection. , ;
[0080] When the third comprehensive rating coefficient The value is greater than the threshold and the aspect ratio When it is greater than the threshold, the textile is brushed;
[0081] When the third comprehensive rating coefficient Less than or equal to threshold, aspect ratio When it is less than or equal to the threshold, the textile is not brushed;
[0082] The third comprehensive rating coefficient The coefficient threshold is 0.7, the aspect ratio The threshold value is 0.25.
[0083] Compared with the prior art, the present invention has the following beneficial effects:
[0084] The present invention can effectively enhance the recognition ability of subtle defects by combining convolutional neural network with spatial attention mechanism, and can capture more subtle deviations, thereby significantly improving the recognition rate;
[0085] Automatic feature extraction through convolutional neural networks reduces the reliance on manual feature design and extraction, and improves the automation level of the detection process. In addition, the use of fusion feature vectors and the introduction of spatial attention enable the model to effectively screen out the features most relevant to defect identification, thereby speeding up the processing speed and meeting the needs of real-time detection.
[0086] The feature extraction vector is generated by the feature graphs output by multiple convolutional layers, and the feature expression is enhanced by fusing the feature vectors. This not only captures local features, but also comprehensively considers information at different levels to provide a more comprehensive feature set, thereby enhancing the recognition ability of complex and diverse defect types. This improvement makes the inspection system more adaptable when facing various types of defects.
[0087] By constructing a segmentation model and connected component analysis, the defect area can be accurately identified and marked, and relevant features can be extracted, especially the calculation of features such as the defect area, roundness, and aspect ratio, making the classification and evaluation of defects more scientific and accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0088] Figure 1 It is a schematic diagram of the overall method flow of the present invention. DETAILED DESCRIPTION
[0089] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with specific embodiments.
[0090] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the present invention should be understood by people with ordinary skills in the field to which the present invention belongs. The words "first", "second" and similar words used in the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0091] Embodiment 1:
[0092] See also Figure 1 , the present invention provides a technical solution:
[0093] A method for identifying textile defect types, the specific steps comprising:
[0094] S1. Collect original images of multiple textile samples, including defect-free textile samples and defective textile samples with known defect types, and annotate the original images in the data set, where the annotation content includes image ID, defect location, defect size, defect shape, and segmentation mask image, where the segmentation mask image includes defect area and normal area;
[0095] S2. Adjust the original image to a recognition image of 224x224 pixels, build a convolutional neural network model, input the recognition image into the convolutional neural network model, output feature maps of different convolutional layers, and assign feature layer weights to the feature maps output by each convolutional layer, respectively generate feature extraction vectors using the feature maps output by different convolutional layers, use multiple feature extraction vectors to obtain a convolutional layer feature set, combine the feature extraction vectors and feature layer weights of different convolutional layers to obtain a fused feature vector, and convert the fused feature vector into a fused feature map through deconvolution;
[0096] S3. Take the fused feature map extracted by the convolutional neural network as input, perform pooling on the fused feature map to generate two feature vectors, concatenate the two feature vectors to generate a single-channel spatial attention map, perform data processing on the spatial attention map and the attention adjustment coefficient to generate an adjusted feature map, multiply the adjusted feature map with the input fused feature map point by point to generate a spatially weighted feature map, and multiply the channel attention weight with each channel of the spatially weighted feature map point by point to obtain a weighted feature map;
[0097] S4. construct a segmentation model, use the weighted feature map as an input of the segmentation model, and use the labeled segmentation mask image as an output to train the segmentation model to obtain a trained segmentation model;
[0098] S5. Obtain a weighted feature map of the textile to be tested, and input it into the segmented image after training to identify and mark the defect area of the image to be tested, and calculate the area, roundness and aspect ratio of the defect area;
[0099] S6. Calculate the first comprehensive scoring coefficient, the second comprehensive scoring coefficient and the third comprehensive scoring coefficient respectively using the area, roundness and aspect ratio of the defective area, and identify the defect type of the textile to be tested based on the area, roundness, aspect ratio and the three comprehensive scoring coefficients of the defective area.
[0100] On the basis of the above embodiment, a data set containing multiple defect types and normal samples is collected, and the original images in the data set are annotated. The specific process is as follows:
[0101] Collect image samples of various defect types and normal samples to determine the total number of samples , where the number of defect samples is , the normal sample size is , ;
[0102] The following information is annotated for each original image:
[0103] Image ID, defect location , defect size , defect shape , segmentation mask ;in and Indicates the coordinates of the upper left corner of the defect area, and Indicates the coordinates of the lower right corner of the defect area, , is the width of the defect, is the height of the defect, , , segmentation mask image Represented by a binary image, (foreground) defect area Marked as 255, background area Marked as 0,
[0104] For each original image , generate a segmentation mask for each pixel :
[0105]
[0106] in, The coordinates in the original image are The pixel segmentation mask of is the coordinate position of the pixel in the original image, x is the horizontal coordinate of the pixel in the original image, and y is the vertical coordinate of the pixel in the original image;
[0107] Original image , segmentation mask image Both images, is the height of the image, indicating the number of pixels in the vertical direction. Is the width of the image, which indicates the number of pixels in the horizontal direction.
[0108] Based on the above embodiment, the specific process of step S2 is as follows:
[0109] Convolutional neural network consists of multiple convolutional layers, activation layers, and pooling layers for feature extraction. Assume that the constructed CNN model contains The convolution layer performs convolution operation on the input image and extracts features based on the convolution kernel. The input of the convolutional layer is , then Feature map of the convolutional layer output It can be expressed as:
[0110]
[0111] in, represents the convolution operation, For the The input of the convolutional layer is The output of the convolutional layer, For the The weight matrix of the convolutional layer, For the The bias term of the convolutional layer, is the index of the convolutional layer, The value range is , is the total number of convolutional layers, For the activation function, select the ReLU function as the activation function;
[0112] For each convolutional layer output feature map , generate feature extraction vectors through global average pooling or global maximum pooling method , based on the following formula:
[0113]
[0114] in, For the feature map The corresponding feature extraction vector is obtained by The convolutional layer output of layer Perform the pooling operation to obtain For the pooling operation,
[0115] Combining multiple feature extraction vectors To form a convolutional layer feature set :
[0116]
[0117] in, Contains from the 1st to the Feature extraction vector of convolutional layer;
[0118] The feature extraction vectors of different convolutional layers and the feature layer weights are fused to obtain the fused feature vector , using weighted average for fusion:
[0119]
[0120]
[0121] in, For the The feature layer weights associated with the feature extraction vector of the convolutional layer;
[0122] Usually, the convolutional layers close to the input layer extract more basic features (such as edges, corners, etc.), while the convolutional layers close to the output layer extract more abstract features (such as shapes, objects). The weights can be set according to the contribution of the layer to the final task in the model.
[0123] Assuming there are three convolutional layers, the weights can be set separately:
[0124] (The first layer of features is relatively basic);
[0125] (The second layer features are more complex);
[0126] (The third layer features are more abstract and have a greater impact on the task); finally, the fused feature vector is converted into a fused feature map through a deconvolution operation :
[0127]
[0128] in, is the deconvolution operation.
[0129] Based on the above embodiment, the specific process of step S3 is as follows:
[0130] Input fusion feature map It is a high-dimensional feature map. Assume that the dimension of the fused feature map is ,in, is the number of channels, and They are the height and width of the fused feature map respectively;
[0131] Pooling is performed on the fused feature map, and global average pooling and global maximum pooling are used to generate the global average feature vector and the global maximum feature vector respectively;
[0132] These two feature vectors are concatenated to generate a single-channel spatial attention map in the following form:
[0133]
[0134]
[0135] in, is the new feature vector, is the spatial attention map, is the activation function (using the Sigmoid function), normalizing the output to between 0 and 1. is the convolution kernel, is the bias term, is the global average eigenvector, is the global maximum eigenvector;
[0136] Process the spatial attention map to generate the adjusted feature map , based on the following formula:
[0137]
[0138] in, represents point-wise multiplication;
[0139] Multiply the adjusted feature map with the input fusion feature map point by point to generate a spatially weighted feature map , based on the following formula:
[0140] ;
[0141] Channel attention weight Generated by SE module:
[0142]
[0143] in, is the fully connected layer, is the weight of the fully connected layer;
[0144] The channel attention weight is multiplied point by point with each channel of the spatially weighted feature map to obtain the weighted feature map, based on the following formula:
[0145]
[0146] in, is the weighted feature map.
[0147] Based on the above embodiment, U-Net is selected as the segmentation model, which includes an encoder, a bottleneck layer and a decoder structure.
[0148] The encoder (downsampling part) consists of multiple convolutional layers and pooling layers to extract features and gradually reduce the spatial dimensions of the feature map. Each convolutional block usually includes two convolutional layers (activation functions such as ReLU) followed by a maximum pooling layer;
[0149] The bottleneck layer is the part that connects the encoder and decoder to further extract features;
[0150] The decoder (upsampling part) gradually restores the spatial dimensions of the feature map through deconvolution (transposed convolution) layers. Each decoding block usually includes an upsampling layer followed by two convolution layers.
[0151] Segmentation model training: The weighted feature map is used as input, and the category of each pixel in the corresponding original image is used as the output label for training. The mean square error is used as the loss function. When the mean square error is When is within the range, the training of the segmentation model is completed.
[0152] On the basis of the above embodiment, the mask image is subjected to connected component analysis to identify and mark the defective area, and for the screened defective area, relevant features are extracted to obtain a feature set including the screened defective area. The specific process is as follows:
[0153] Starting from the current pixel of the mask image, recursively visit all adjacent foreground pixels and mark them as visited. Each time a new pixel is visited, the position of the pixel is recorded until no new adjacent foreground pixels are accessible. Each time a connected region is found, all pixels in the region are marked with a unique identifier to distinguish different defect regions.
[0154] For each connected defect region, the following features are extracted:
[0155] Area, roundness, aspect ratio, for the screened defect area, obtain the feature set in the following form:
[0156]
[0157]
[0158] in, For the The feature set of the defect area, is the feature set of the defect area, For the The area of the defect region, For the The roundness of the defect area, For the The aspect ratio of the defect area.
[0159] Area is the number of foreground pixels in the area; roundness can be calculated by area and perimeter. A roundness value close to 1 indicates that the shape is close to a circle, and a smaller value indicates more irregularity. The perimeter refers to the number of pixels surrounding the boundary of the defect area, which is usually obtained using an edge detection algorithm or by directly calculating the boundary pixels. The aspect ratio is the ratio of the width to the height of the defect area bounding box.
[0160] The calculation of area, circularity and aspect ratio is prior art and will not be described in detail here.
[0161] On the basis of the above embodiment, the area, roundness and aspect ratio of the defect area are used to construct the first comprehensive scoring coefficient, the second comprehensive scoring coefficient and the third comprehensive scoring coefficient respectively, and the textile defect type is identified according to the characteristic value of the defect area and the multiple comprehensive scoring coefficients. The specific process is as follows:
[0162] Types of textile defects include stains, tears, and stringing;
[0163] Since the area, roundness and aspect ratio of the defective area can be used separately to identify and judge the defects of textiles, in order to make the evaluation more accurate and comprehensive, they are combined into a polynomial function with multiple feature parameters. It is only necessary to set the corresponding weight coefficient. In the process of evaluating textile defects, when the defect is a stain, the area, roundness and aspect ratio contribute differently to the score, which leads to different weights of each feature in the score. It is necessary to adjust the weights of area, roundness and aspect ratio. Therefore, through this feature function, we can clearly see the contribution of each feature to the comprehensive score. This function form is convenient for analyzing the performance of defective areas and identifying which features have the greatest impact on the score.
[0164] Stains usually appear as obvious visible areas on textiles. The larger the size, the more significant the impact of the stain on the overall appearance. Larger stains are easier to identify, so their area It is very important to judge the impact of the stain. It can be used as an important basis for judging whether a stain exists. Usually, the area of the stain It will only be considered a defect when it is greater than a certain threshold. By setting a higher weight, we can ensure that the influence of the area is highlighted in the score.
[0165] The shape of the stain is often related to its nature, roundness Can help determine the type of stain, for example, the roundness of the stain Higher usually means it is more regular in shape, which can be associated with certain types of stains, such as oil stains or water droplets.
[0166] Aspect Ratio and similarity The importance of aspect ratio is relatively low. While it can provide some shape information, its impact is relatively limited compared to key features of stains such as area and circularity.
[0167] In summary, in order to highlight the area and roundness importance, and to simplify the model, the area and roundness The weights are set equal, and the area The weight is greater than the aspect ratio The weight of , .
[0168] The first comprehensive scoring coefficient is constructed using area, roundness and aspect ratio to identify whether the textile is a stain. The polynomial function form is as follows:
[0169]
[0170] in, is the first comprehensive scoring coefficient, , , are area, circularity, and aspect ratio, , , They are the weight coefficients of area, roundness, and aspect ratio during stain detection.
[0171] Stains have the following characteristics:
[0172] Area: Small;
[0173] Roundness: When it is close to 1, it means the shape is close to a circle;
[0174] Aspect ratio: A ratio close to 1 indicates a shape close to a circle;
[0175] When the first comprehensive rating coefficient The value is greater than the coefficient threshold and the area When it is smaller than the area threshold, the textile is a stain;
[0176] When the first comprehensive rating coefficient Less than or equal to coefficient threshold, area When the area is greater than or equal to the area threshold, the textile is not a stain.
[0177] The threshold of the first comprehensive scoring coefficient is 0.5, and the area The threshold value is 0.4.
[0178] Similarly, a second comprehensive scoring coefficient is constructed using the function of the first comprehensive scoring coefficient to determine whether the defect is damage. The collected feature parameters include area, roundness, and aspect ratio. The collected feature parameters are different from those when the defect is a stain, and the contribution of area, roundness, and aspect ratio to the score is also different from that when the defect is a stain, which results in different weights of each feature in the score.
[0179] When identifying whether a textile is damaged, the area It is a direct indicator of the scale of damage. Large-area damage usually indicates a more serious defect that affects the function and appearance of the product. Therefore, in the comprehensive score, the weight of area should be higher to reflect its direct impact on the damage judgment.
[0180] Roundness It is an important feature to measure the regularity of the damage shape. The damage usually presents an irregular shape, and its roundness value is often low. It is valuable in assessing the shape of the damage, but in many cases its impact is less than the area. So obvious.
[0181] Aspect Ratio Evaluate the shape characteristics of the damaged area, aspect ratio Although the shape characteristics of the damage can be revealed, in actual operation, the aspect ratio The change will not be like the area and roundness That obviously affects the severity of the damage. Therefore, the aspect ratio The weight is lower than the area and roundness The weight of .
[0182] In summary, the area The weight is greater than the roundness Weight, roundness The weight is greater than the aspect ratio The weight of , .
[0183] The second comprehensive scoring coefficient is now constructed using area, roundness and aspect ratio to identify whether the textile is damaged. The polynomial function form is as follows:
[0184]
[0185] in, is the second comprehensive scoring coefficient, , , They are the weight coefficients of area, roundness and aspect ratio during damage detection.
[0186] The damage has the following characteristics:
[0187] Area: Larger, higher than the area of the stain;
[0188] Roundness: The damaged shape is irregular and the roundness is low (less than 0.5);
[0189] Aspect ratio: The damage is long and narrow, and the aspect ratio is greater than 1;
[0190] When the second comprehensive rating coefficient The value is greater than the coefficient threshold and the area If the area is larger than the threshold, the textile is damaged;
[0191] When the second comprehensive rating coefficient Less than or equal to coefficient threshold, area When the area is less than or equal to the area threshold, the textile is not damaged.
[0192] The threshold of the second comprehensive scoring coefficient is 0.5.
[0193] Similarly, the third comprehensive scoring coefficient is constructed using the function of the defect type being stain, which is used to determine whether the defect is wiredrawing. However, when the defect is wiredrawing, the contribution of area, roundness and aspect ratio to the score is different, which leads to different weights of each feature in the score. The weights of area, roundness and aspect ratio need to be adjusted.
[0194] Among the characteristics of wire drawing, the aspect ratio before standardization is usually greater than 2, or even higher, which means that the shape of the wire drawing is very slender and the aspect ratio is The change of can effectively reflect the characteristics and severity of wire drawing, so the aspect ratio is given Higher weight.
[0195] Despite the area It is also important in describing the characteristics of wire drawing, but the area of wire drawing Usually small and ductile. Therefore, in the overall score, the area The change is not as good as the aspect ratio That significantly affects the properties and functions of the wire drawing, but it still has a certain evaluation value.
[0196] Roundness of wire drawing Low, usually reflects its irregularity, because the roundness Not as influential as aspect ratio in identifying wire drawing defects and area Therefore, it is given less weight in the scoring.
[0197] In summary, in order to highlight the aspect ratio and area The importance of aspect ratio is also to simplify the model. The weight is set to be larger than the area The weight, area The weight is greater than the roundness The weight of , .
[0198] The third comprehensive scoring coefficient is constructed by using area, roundness and aspect ratio to identify whether the textile is brushed. The polynomial function form is as follows:
[0199]
[0200] in, is the third comprehensive scoring coefficient, , , They are the weight coefficients of area, roundness and aspect ratio during wire drawing detection.
[0201] Wire drawing has the following characteristics:
[0202] Area: Small area;
[0203] Roundness: The roundness is low;
[0204] Aspect ratio: The aspect ratio is greater than 2;
[0205] When the third comprehensive rating coefficient The value is greater than the coefficient threshold and the aspect ratio When it is greater than the threshold, the textile is brushed;
[0206] When the third comprehensive rating coefficient Less than or equal to coefficient threshold, aspect ratio When it is less than or equal to the threshold, the textile is not brushed.
[0207] The third comprehensive rating coefficient The threshold is 0.7, the aspect ratio The threshold is 0.25.
[0208] In order to increase the recognition accuracy of textile defect types, a data set including standardized area, roundness, and aspect ratio was constructed. The entire data set was divided into a training set and a validation set. 80% of the data was used for training and 20% of the data was used for validation. The standardized area, roundness, and aspect ratio were used as input, and the corresponding first, second, and third comprehensive scoring coefficients were used as output labels to train the defect recognition model. The back propagation algorithm was used to train the first comprehensive scoring coefficient corresponding to the defect recognition model. , , , the second comprehensive scoring coefficient corresponds to , and , the third comprehensive scoring coefficient corresponds to , , Optimize and use the mean square error as the loss function. When the mean square error is When the defect recognition model is within the range, the training of the defect recognition model is completed. Once the training is completed, the obtained weight coefficient can be used to predict the new first comprehensive scoring coefficient, the second comprehensive scoring coefficient, and the third comprehensive scoring coefficient.
[0209] The above formulas are all dimensionless and numerical calculations. The formula is a formula for the most recent real situation obtained by collecting a large amount of data and performing software simulation. The preset parameters in the formula are set by technicians in this field according to actual conditions.
[0210] The above embodiments may be implemented in whole or in part by software, hardware, firmware or any other combination thereof. When implemented using software, the above embodiments may be implemented in whole or in part in the form of a computer program product. Those skilled in the art may appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein may be implemented by computer software, electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed by hardware or software depends on the specific application and design constraints of the technical solution.
[0211] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, and may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0212] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. A method for identifying textile defect types, characterized in that: The specific steps include: S1. Collect original images of multiple textile samples, including defect-free textile samples and defective textile samples with known defect types, and annotate the original images in the dataset. The annotation content includes image ID, defect location, defect size, defect shape, and segmentation mask image. The segmentation mask image includes defect area and normal area: S2. Adjust the original image to a recognition image of 224x224 pixels, build a convolutional neural network model, input the recognition image into the convolutional neural network model, output feature maps of different convolutional layers, and assign feature layer weights to the feature maps output by each convolutional layer, respectively generate feature extraction vectors using the feature maps output by different convolutional layers, use multiple feature extraction vectors to obtain a convolutional layer feature set, combine the feature extraction vectors and feature layer weights of different convolutional layers to obtain a fused feature vector, and convert the fused feature vector into a fused feature map through deconvolution; S3. Take the fused feature map extracted by the convolutional neural network as input, perform pooling on the fused feature map to generate two feature vectors, concatenate the two feature vectors to generate a single-channel spatial attention map, perform data processing on the spatial attention map and the attention adjustment coefficient to generate an adjusted feature map, multiply the adjusted feature map with the input fused feature map point by point to generate a spatially weighted feature map, and multiply the channel attention weight with each channel of the spatially weighted feature map point by point to obtain a weighted feature map; S4. construct a segmentation model, use the weighted feature map as an input of the segmentation model, and use the labeled segmentation mask image as an output to train the segmentation model to obtain a trained segmentation model; S5. Obtain a weighted feature map of the textile to be tested, and input it into the segmented image after training to identify and mark the defect area of the image to be tested, and calculate the area, roundness and aspect ratio of the defect area; S6. Calculate the first comprehensive scoring coefficient, the second comprehensive scoring coefficient and the third comprehensive scoring coefficient respectively by using the area, roundness and aspect ratio of the defective area, and identify the defect type of the textile to be detected according to the area, roundness, aspect ratio and the three comprehensive scoring coefficients of the defective area; Collect a data set containing various defect types and normal samples, and annotate the original images in the data set. The specific process is as follows: Collect image samples and normal samples of various defect types and determine the total number of samples N, where the number of defect samples is N. d , the normal sample size is N n , N=N d +N n ; The following information is annotated for each original image: Image ID, defect position P(x min ,y min , x max ,y max ), defect size S, defect shape Z, segmentation mask M; where x min and min Indicates the coordinates of the upper left corner of the defect area, x max and max Indicates the coordinates of the lower right corner of the defect area, S = (w, h), w is the width of the defect, h is the height of the defect, w = x max -x min , h=y max -y min , the segmentation mask image M is represented by a binary image, the defect area D is marked as 255, and the background area B is marked as 0; For each original image I, generate a segmentation mask for each pixel: Wherein, M(x, y) is the segmentation mask of the pixel with coordinates (x, y) in the original image, (x, y) is the coordinate position of the pixel in the original image, x is the horizontal coordinate of the pixel in the original image, and y is the vertical coordinate of the pixel in the original image; The original image I and the segmentation mask image M are both H×W images, where H is the height of the image, indicating the number of pixels in the vertical direction, and W is the width of the image, indicating the number of pixels in the horizontal direction. The specific process of step S2 is as follows: Convolutional neural network consists of multiple convolutional layers, activation layers, and pooling layers for feature extraction. Assume that the constructed CNN model contains L convolutional layers, performs convolution operation on the input image, extracts features based on the convolution kernel, and sets the input of the lth convolutional layer to X (l) , then the feature map Y output by the l-th convolutional layer (l) It is expressed as: Y (l) =f(X (l) *K (l) +b (l) ) Among them, * represents the convolution operation, X (l) is the input of the lth convolutional layer, that is, the output of the l-1th convolutional layer, K (l) is the weight matrix of the lth convolutional layer, b (l) is the bias term of the lth convolutional layer, l is the index of the convolutional layer, the value range of l is [1, L], L is the total number of convolutional layers, f(·) is the activation function, and the ReLU function is selected as the activation function; For each convolutional layer output feature map Y (l) , generate feature extraction vector V through global average pooling or global maximum pooling method (l) , based on the following formula: V (l) =Pooling(Y (l) ) Among them, V (l) is the feature map Y (l) The corresponding feature extraction vector is outputted by the convolutional layer of the lth layer Y (l) The pooling operation is performed, and Pooling is a pooling operation; Combine multiple feature extraction vectors V (1) , V (2) , …, V (L) To form the convolutional layer feature set V multi : V multi ={V (1) ,V (2) ,…,V (L) } Among them, V multi Contains the feature extraction vectors from the 1st to the Lth convolutional layers; The feature extraction vectors of different convolutional layers and the feature layer weights are fused to obtain the fused feature vector V fused , using weighted average for fusion: Among them, W (l) is the feature layer weight associated with the feature extraction vector of the lth convolutional layer; Finally, the fused feature vector is converted into a fused feature map Y through a deconvolution operation. fused : Y fused =G(V fused ) Among them, G is the deconvolution operation; The specific process of step S3 is as follows: Input fusion feature map Y fused It is a high-dimensional feature map, and the dimension of the fused feature map is C×H RH ×W RH , where C is the number of channels, H RH and W RH They are the height and width of the fused feature map respectively; Pooling is performed on the fused feature map, and global average pooling and global maximum pooling are used to generate the global average feature vector and the global maximum feature vector respectively; The two feature vectors are concatenated to generate a single-channel spatial attention map in the following form: V con =[V avg ;V max ] A spa =σ(W s ·V con +b s ) Among them, V con is the concatenated feature vector, A spa is the spatial attention map, σ is the Sigmoid function, which normalizes the output to between 0 and 1, and W s is the convolution kernel, b s is the bias term, V avg is the global average eigenvector, V max is the global maximum eigenvector; the spatial attention map is processed to generate the adjusted feature map Y adj , based on the following formula: AND adj =A spa ⊙And fused Among them, ⊙ represents point-by-point multiplication; Multiply the adjusted feature map with the input fusion feature map point by point to generate the spatially weighted feature map Y wei , based on the following formula: AND wei =And adj ⊙And fused Channel attention weight A cha Generated by SE module: A cha =σ[g(W c ·Y wei )] Among them, g is the fully connected layer, W c is the weight of the fully connected layer; The channel attention weight is multiplied point by point with each channel of the spatially weighted feature map to obtain the weighted feature map, according to the following formula: AND fin =A cha ⊙And wei Among them, Y fin is the weighted feature map; Connected component analysis is performed on the mask image to identify and mark the defective area. For the screened defective area, relevant features are extracted to obtain a feature set containing the screened defective area. The specific process is as follows: Starting from the current pixel of the mask image, recursively visit all adjacent foreground pixels and mark them as visited. Each time a new pixel is visited, the position of the pixel is recorded until no new adjacent foreground pixels are accessible. Each time a connected region is found, all pixels in the region are marked with a unique identifier to distinguish different defect regions. For each connected defect region, the following features are extracted: Area, roundness, aspect ratio, for the screened defect area, obtain the feature set in the following form: F δ ={T δ ,Q δ ,R δ } F={F1,F2,…,F δ ,…,F m } Among them, F δ is the feature set of the δth defect area, F is the feature set of the defect area, T δ is the area of the δth defect region, Q δ is the roundness of the δth defect area, R δ is the aspect ratio of the δth defect area; The first comprehensive scoring coefficient is constructed by using the area, roundness and aspect ratio of the defective area. The textile defect type is identified according to the characteristic value of the defective area and the first comprehensive scoring coefficient. The specific process is as follows: The first comprehensive scoring coefficient is constructed by using area, roundness, and aspect ratio to identify whether the textile is a stain. The polynomial function form is as follows: ZX1=μ1T'+μ2Q'+μ3R' Among them, ZX1 is the first comprehensive scoring coefficient, T', Q', R' are area, roundness, and aspect ratio respectively, μ1, μ2, and μ3 are weight coefficients of area, roundness, and aspect ratio during stain detection respectively, 1>μ1=μ2>μ3>0μ1+μ2+μ3=1; When the value of the first comprehensive scoring coefficient ZX1 is greater than the coefficient threshold and the area T' is less than the area threshold, the textile is a stain; When the first comprehensive scoring coefficient ZX1 is less than or equal to the coefficient threshold and the area T' is greater than or equal to the area threshold, the textile is not a stain; The threshold value of the first comprehensive score coefficient ZX1 is 0.5, and the threshold value of the area T' is 0.
4.
2. The method for identifying textile defect types according to claim 1, characterized in that: The second comprehensive scoring coefficient is constructed by using the area, roundness and aspect ratio of the defective area to identify whether the textile is damaged. The polynomial function form is as follows: Among them, ZX2 is the second comprehensive scoring coefficient, are the weight coefficients of area, roundness and aspect ratio in damage detection, When the value of the second comprehensive scoring coefficient ZX2 is greater than the coefficient threshold and the area T' is greater than the area threshold, the textile is damaged; When the second comprehensive scoring coefficient ZX2 is less than or equal to the coefficient threshold and T' is less than or equal to the area threshold, the textile is not damaged; the threshold of the second comprehensive scoring coefficient is 0.
5.
3. The method for identifying textile defect types according to claim 2, characterized in that: The third comprehensive scoring coefficient is constructed by using the area, roundness, and aspect ratio of the defect area to identify whether the textile is wiredrawing. The polynomial function form is as follows: ZX3=θ1T'+θ2(1-Q')+θ3R' Among them, ZX3 is the third comprehensive scoring coefficient, θ1, θ2, and θ3 are the weight coefficients of area, roundness, and aspect ratio during wire drawing detection, 1>θ3>θ1>θ2>0, θ3+θ1+θ2=1; When the value of the third comprehensive scoring coefficient ZX3 is greater than the threshold and the aspect ratio R' is greater than its threshold, the textile is drawn; When the third comprehensive scoring coefficient ZX3 is less than or equal to the threshold value and the aspect ratio R' is less than or equal to its threshold value, the textile is not drawn; The coefficient threshold of the third comprehensive scoring coefficient ZX3 is 0.7, and the threshold of the aspect ratio R' is 0.25.
Citation Information
Patent Citations
Textile defect identification method and system
CN115937186A
Textile defect type identification method
CN117893467A