Automatic Colorfastness Rating Method and System for Textiles Based on CNN-Transformer Fusion Model
Through the CNN-Transformer fusion model, combined with local and global feature extraction, the accuracy and consistency of textile color fastness ratings are solved, and the automated five-level nine-level ratings are realized, which improves the accuracy and stability of ratings.
Patent Information
- Application Number
- CN202510323086.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-19
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2045-03-19
AI Technical Summary
The existing textile color fastness rating methods are affected by human factors and instrument calibration accuracy, making it difficult to accurately capture local details and global structural characteristics, and it is difficult to adapt to the five-level nine-level fine rating standards, resulting in insufficient rating accuracy and consistency.
The CNN-Transformer fusion model is adopted to collect images through a high-resolution RGB color camera, combined with grayscale and spectral data preprocessing, and the local features are extracted by the CNN module and the Transformer module are extracted. After the fusion, the model is weighted through the attention mechanism and rated by the Softmax function, and the model is optimized by combining cross entropy loss and label smoothing technology.
It realizes automated and high-precision textile color fastness rating, solves the accuracy and consistency of existing methods, adapts to the five-level nine-level rating rating standards, and improves the accuracy and stability of ratings.
Smart Images

Figure CN119850607B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of digital detection of textiles, and specifically relates to an automatic grading method and system for textile color fastness based on a CNN-Transformer fusion model. Background Art
[0002] In the textile quality inspection system, color fastness, as a key quality indicator, reflects the stability of textile colors under the action of various external factors such as light, washing, and friction. The currently widely used five-level and nine-grade grading system for color fastness divides color fastness into 5 levels and 9 grades from excellent to poor to accurately measure the color retention ability of textiles.
[0003] Traditional means for grading textile color fastness mainly include visual grading and instrumental grading. Visual grading relies on manual observation and comparison, which is greatly affected by subjective factors of grading personnel (such as visual differences and experience levels) and environmental factors (such as lighting conditions), resulting in poor accuracy and consistency of grading results. The grading of the same piece of textile by different grading personnel may even differ by 1-2 grades. Although instrumental grading can reduce human interference to a certain extent, due to the limitations of instrument calibration accuracy, measurement principles, and errors in the operation process, there are deviations between its measurement results and actual color fastness, and the comparability of measurement results between different instruments is poor. Existing methods have many deficiencies in dealing with textile color fastness grading. On the one hand, in the feature extraction process, it is difficult to effectively capture both local detail features and global structural features of textiles at the same time. Local detail features are crucial for accurately identifying subtle color changes, while global structural features help to grasp the overall color distribution and the impact of patterns on color fastness. On the other hand, existing deep learning models lack targeted optimization for the fine grading standard of five levels and nine grades, and it is difficult to accurately distinguish adjacent levels, making the accuracy of grading results to be improved. Summary of the Invention
[0004] Aiming at the deficiencies of the existing technology, the purpose of the present invention is to provide an automatic grading method and system for textile color fastness based on a CNN-Transformer fusion model.
[0005] To achieve the above purpose, the present invention provides the following technical solutions:
[0006] An automatic grading method for textile color fastness based on a CNN-Transformer fusion model, which includes the following steps:
[0007] S1 Use a high-resolution RGB color industrial camera to collect image data of textiles in a standard D65 light source environment , where represents the coordinates of image pixels, Represents the color value of a pixel point, recorded in the RGB color space, and , , are the red, green, and blue channel values of the pixel point in the RGB image, and preprocess the grayscale data and spectral data of the image;
[0008] S2 Construct a CNN module, and output local features containing the local texture and color changes of the textile image through the alternating stacking of multiple convolutional layers, pooling layers, and activation functions ;
[0009] S3 Reshape the feature map output by the CNN module to meet the input requirements of the Transformer, then input it into the Transformer module. After being processed by the Transformer module and introducing positional encoding, obtain global features containing the global color distribution and pattern structure features ;
[0010] S4 Fuse the local features extracted by the CNN module and the global features extracted by the Transformer module , and input the fused features into the fully connected layer after being weighted by the attention mechanism, calculate the colorfastness level probability through the Softmax function, and output the colorfastness level corresponding to the maximum probability;
[0011] S5 Use the cross-entropy loss function combined with label smoothing technology to train the model, use the Adam optimizer and learning rate decay strategy to optimize the model parameters, and improve the generalization ability through data augmentation and model integration; evaluate the confidence of the rating result, and trigger the correction mechanism if the confidence is lower than the threshold.
[0012] In S1, perform grayscale conversion, denoising, and contrast enhancement on the image data , and convert it to the CIE XYZ color space to derive spectral reflectance data, and perform normalization, dimensionality reduction, and standardization processing on the spectral reflectance data.
[0013] In S1, perform grayscale conversion on the image data , including the following steps:
[0014] I. Convert the image data through to a grayscale image ;
[0015] II. Obtain the denoised image through Gaussian filtering;
[0016] III. Apply histogram equalization technology to enhance the image contrast and make the gray distribution of the image more uniform.
[0017] In S1, preprocess the spectral data of the image, including the following steps:
[0018] I. Based on the acquired image data, adopt Convert the image data from the RGB color space to the CIE XYZ color space, where , , are the CIE XYZ color space values after conversion;
[0019] II. According to , calculate the spectral reflectance data within a specific wavelength range based on the CIE XYZ values , where in the formula, , , are the CIE XYZ values at different wavelengths ; , , are the CIE standard observer spectral tristimulus values; is the spectral power distribution of the illumination source;
[0020] III. Normalize the obtained spectral reflectance data according to for the spectral reflectance data , map its value range to the interval, where and are the minimum and maximum values of the spectral reflectance data respectively;
[0021] IV. Use the principal component analysis method to reduce the dimension of the spectral data, extract the main components , calculate the covariance matrix of the spectral data, perform eigenvalue decomposition on to obtain the eigenvalues and eigenvectors , select the first eigenvectors according to the eigenvalue contribution rate, so that , is the original number of features, thus obtaining the spectral data after dimension reduction;
[0022] V. Standardize the spectral data after dimension reduction to make it have zero mean and unit variance.
[0023] The CNN module consists of multiple convolutional layers, pooling layers, and activation functions. At the same time, dilated convolution technology is introduced in the convolutional layer to expand the receptive field of the convolutional kernel to capture more extensive local color change information, and the dilation rate is set to 2.
[0024] The Transformer module includes a multi-head attention mechanism and positional encoding, and encodes the feature positions through sine and cosine functions.
[0025] In S4, the local features extracted by the CNN module and the global features extracted by the Transformer module are fused, and the fused features are obtained by concatenation , and the fused features are weighted using the attention mechanism, and the weights of the attention mechanism are dynamically adjusted by learnable parameters.
[0026] In S5, the model ensemble adopts the voting method. Multiple CNN-Transformer fusion models with different initializations are trained, the prediction results of each model are statistically analyzed, and the grade with the most votes is selected as the final rating result.
[0027] A system for implementing the above-mentioned automatic textile colorfastness rating method based on the CNN-Transformer fusion model, which includes:
[0028] An image acquisition module for acquiring image data of textiles in a standard D65 light source environment;
[0029] A preprocessing module for performing grayscale conversion, denoising, spectral data conversion, and normalization processing on the image;
[0030] A fusion model module, which includes a CNN module and a Transformer module, for feature extraction and fusion;
[0031] A classification module for outputting the probability of colorfastness grade and the final rating result;
[0032] A post-processing module for confidence evaluation and result correction.
[0033] A computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the above-mentioned automatic textile colorfastness rating method based on the CNN-Transformer fusion model.
[0034] Advantages of the present invention: By combining the powerful local feature extraction ability of CNN with the excellent global information capture ability of Transformer, features related to the color fastness of textiles are accurately extracted, and the rating process is optimized for the five-level nine-grade rating system, realizing automatic and high-precision rating of textile color fastness, effectively solving the problems of poor accuracy, low consistency and difficulty in adapting to fine rating standards existing in the existing rating methods. Brief Description of the Drawings
[0035] Figure 1 is a flow schematic diagram of the present invention.
[0036] Figure 2 is a schematic diagram of the CNN model adopted by the present invention.
[0037] Figure 3 is a schematic diagram of the Transformer model adopted by the present invention.
[0038] Figure 4 is a corresponding relationship table between the color change fastness and the color change grey scale of the present invention.
[0039] Figure 5 is a corresponding relationship table between the staining fastness and the staining grey scale of the present invention. Detailed Embodiments
[0040] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without making creative efforts shall fall within the protection scope of the present invention.
[0041] It should be noted that all directional indications (such as up, down, left, right, front, back...) in the embodiments of the present invention are only used to explain the relative position relationship and movement conditions between components in a specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indications will also change accordingly.
[0042] As Figure 1 shown, the present invention provides an automatic rating method for textile color fastness based on a CNN-Transformer fusion model, which includes the following steps:
[0043] S1 Use a high-resolution RGB color industrial camera to collect image data of textiles in a standard D65 light source environment , where represents the coordinates of the image pixels, represents the pixel point The color values are recorded in the RGB color space, , , are the red, green, and blue channel values of the pixel point in the RGB image, and preprocess the grayscale data and spectral data of the image;
[0044] S2 Construct a CNN module, and through the alternating stacking of multiple convolutional layers, pooling layers, and activation functions, output local features including the local texture and color changes of the textile image ;
[0045] S3 Reshape the feature map output by the CNN module to meet the input requirements of the Transformer, and then input it into the Transformer module. After being processed by the Transformer module and introducing positional encoding, obtain global features including the global color distribution and pattern structure features ;
[0046] S4 Fuse the local features extracted by the CNN module and the global features extracted by the Transformer module , and weight the fused features through the attention mechanism and input them into the fully connected layer. Calculate the colorfastness level probability through the Softmax function, and output the colorfastness level corresponding to the maximum probability;
[0047] S5 Use the cross-entropy loss function combined with label smoothing technology to train the model, use the Adam optimizer and learning rate decay strategy to optimize the model parameters, and improve the generalization ability through data augmentation and model integration; evaluate the confidence of the rating result, and trigger the correction mechanism if the confidence is lower than the threshold.
[0048] 1. Data acquisition and preprocessing
[0049] Use a high-resolution RGB color industrial camera to collect image data of textiles in a standard D65 light source environment , where represents the coordinates of the image pixel, represents the pixel point 's color value, recorded in the RGB color space, , , are the red, green, and blue channel values of the pixel point in the RGB image. The standard D65 light source simulates average daylight. Collecting images under this light source can ensure that the obtained color information has good generality and reference value.
[0050] (1) Preprocessing of image grayscale data
[0051] To facilitate subsequent focus on the extraction of texture and structural features of the image and simplify the image information, the color image is converted into a grayscale image with only luminance information to remove the interference of color. The collected RGB image is grayscale processed and converted into a grayscale image using Equation (1): , and the denoised image is obtained through Gaussian filtering (Equation 2):
[0052] (1)
[0053] (2)
[0054] Here, 0.299, 0.587, and 0.114 are the weight coefficients determined according to the sensitivity of the human eye to different colors of light. is the Gaussian kernel function. is the radius of the filtering window. is the standard deviation of the Gaussian distribution.
[0055] The value of can be determined by calculating the noise power spectral density of the image: that is, performing a Fourier transform on the image to obtain the spectrum , calculating the power spectral density , and statistically calculating the mean value of the power spectral density , according to the empirical formula ( is a constant, determined to be 10 through experiments).
[0056] After that, the histogram equalization technique is used to enhance the image contrast, make the grayscale distribution of the image more uniform, improve the clarity, and facilitate subsequent feature extraction. Histogram equalization redistributes the grayscale values of the image, making the pixels originally concentrated in certain grayscale intervals more evenly distributed. This can highlight the differences in color and texture details in the image and is crucial for the extraction of features related to color fastness.
[0057] (2) Spectral data preprocessing
[0058] Based on the collected image data, the image data is converted from the RGB color space to the CIE XYZ color space using Equation (3):
[0059] (3)
[0060] where , , are the converted CIE XYZ color space values (the CIE XYZ color space is a device-independent color space that can more accurately describe the characteristics of colors).
[0061] Spectral reflectance It reflects the reflection ability of textiles to light of different wavelengths. Different curve shapes and values represent the differences in textile colors at the spectral level and are closely related to the color fastness rating. Assume that within a specific wavelength range (e.g., 380nm - 780nm), through a pre-established relationship model between spectral reflectance and CIE XYZ values, combined with the XYZ values of each pixel point in the image, the corresponding spectral reflectance data is derived . Calculate the spectral reflectance data according to the CIE XYZ values by Equation (4) :
[0062] (4)
[0063] In the formula, , , are the CIE XYZ values at different wavelengths ; , , are the spectral tristimulus values of the CIE standard observer; is the spectral power distribution of the illumination source, measured by a dedicated device.
[0064] Normalization can eliminate the differences in the dimensions and numerical ranges of the spectral reflectance data of different samples, making the data comparable and facilitating the learning and processing of subsequent models. Therefore, the obtained spectral reflectance data is normalized according to Equation (5) to map its value range to the interval:
[0065] (5)
[0066] where and are the minimum and maximum values of the spectral reflectance data respectively.
[0067] Spectral data usually has a high dimension and contains a large amount of redundant information. PCA dimensionality reduction can reduce the data dimension while retaining the main information, improve the calculation efficiency, and also help to remove noise and irrelevant information, highlighting the spectral features related to color. Use the principal component analysis (PCA) method to reduce the dimension of the spectral data and extract the main components . Calculate the covariance matrix of the spectral data , perform eigenvalue decomposition on to obtain the eigenvalues and eigenvectors , select the first eigenvectors according to the eigenvalue contribution rate, so that ( (where is the number of original features), thus obtaining the spectral data after dimensionality reduction.
[0068] The normalization process further optimizes the data distribution, making it easier for the model to learn the patterns in the data and improving the performance and stability of the model. Finally, the dimensionality-reduced spectral data is normalized to have zero mean and unit variance, as shown in Equation (6):
[0069] (6)
[0070] where is the mean of the dimensionality-reduced spectral data, is the standard deviation.
[0071] 2. Feature Extraction and Rating Based on the CNN-Transformer Fusion Model
[0072] (1) Local Feature Extraction of the CNN Module
[0073] Construct a CNN module, as Figure 2 shown, which consists of multiple convolutional layers, pooling layers, and activation functions. The convolutional layer performs convolution operations by sliding the convolutional kernel over the image to extract local features. The convolution operation formula is shown in Equation (7):
[0074] (7)
[0075] where is the pixel value of the image after convolution, is the weight of the convolutional kernel with size , is the pixel value of the image before convolution, is the bias term. During the sliding process of the convolutional kernel, it performs weighted summation on the pixel values at different positions of the image. Since the color information of the image is contained in the pixel values (manifested as , , values in an RGB image), the convolutional kernel can not only capture the spatial position information of the image but also fuse the physical quantities related to color information, extracting local features containing color changes and texture details (for example, for areas with obvious color changes in a textile image, the convolutional kernel can capture the changing trend of RGB values and then extract local features related to color, such as the change of color boundaries and the non-uniformity of local colors). These local features are crucial for judging the color measurement performance of textiles in local areas. The pooling layer is used to reduce the data dimension and retain the main features, and max pooling is adopted, as shown in Equation (8):
[0076] (8)
[0077] where , is a function to find the maximum value, where is the pooling window size. Through selecting the maximum value within the pooling window, the pooling operation can highlight the regions with more significant color and texture changes in the image, further simplify the data, reduce the computational amount, and meanwhile retain the key features.
[0078] The ReLU function can introduce non - linear factors, enabling the neural network to learn more complex feature relationships, which is very important for extracting non - linear changes in color and texture features. In this invention, the activation function adopts the classic ReLU function.
[0079] Through the alternating stacking of multiple convolutional layers, pooling layers, and activation functions, the CNN module can effectively extract detailed features such as local texture and color changes in textile images. .
[0080] To further enhance the feature extraction ability, the dilated convolution technology shown in Equation (9) is introduced into the convolutional layer:
[0081] (9)
[0082] where is the dilation rate, which is set to 2 according to experiments. It can expand the receptive field of the convolutional kernel without increasing the number of parameters, capture richer local details, including color change information in a wider area. Dilated convolution can perceive color and texture changes in a larger range and has a significant effect on capturing some subtle but color - related local features.
[0083] (2) Global feature extraction of the Transformer module
[0084] Reshape the feature map output by the CNN module to meet the input requirements of the Transformer, and then input it into the Transformer module, as Figure 3 shown. The multi - head attention mechanism in the Transformer module can simultaneously focus on different parts of the input features to capture global information. The multi - head attention mechanism can capture the influence of color distribution and pattern structure on color fastness from a global perspective by calculating the correlation between features at different positions. The multi - head attention formula is:
[0085] (10)
[0086] where , , here, , , are the query, key, and value matrices respectively, , , , is the weight matrix, is the dimension of the key vector, is the number of heads.
[0087] After being processed by the Transformer module, the global features are obtained . In the Transformer module, the input feature map contains the color and texture information that has been preliminarily processed by the CNN. For example, in the case of a textile with complex patterns, the Transformer module can analyze the color relationships between different pattern areas and the uniformity of the overall color distribution, so as to obtain the global features related to color fastness.
[0088] To better utilize the ability of the Transformer module to capture global information, positional encoding is added, and the positional encoding formula is:
[0089] (11)
[0090] (12)
[0091] where, and are the sine and cosine functions respectively, is the position index, is the dimension index, is the hidden layer dimension of the Transformer model. Through positional encoding, the Transformer module can perceive the position information of the features and capture the global structural features more accurately, including the distribution features of color on the entire textile sample to be measured. Positional encoding helps the Transformer module consider the spatial position relationship of color and texture features when processing features, which is crucial for accurately grasping the overall color characteristics of the textile and color fastness evaluation.
[0092] (2) Fusion Feature Generation and Rating
[0093] The local features extracted by the CNN module and the global features extracted by the Transformer module are fused, and the fused feature is obtained by concatenation. The fused feature is input into the fully connected layer for classification. Considering the five-level and nine-grade rating system for staining color fastness and color change color fastness (refer to Figure 4 , Figure 5 ), different grades are represented by the number , and the number of output nodes of the fully connected layer is set to 9. The output of the fully connected layer represents the probability that the model believes the sample belongs to the Color fastness grades Value Correspondence The prediction scores of , which are not yet directly reflected as probabilities.
[0094] With the help of Softmax function, Converted into probability values belonging to each color fastness grade ,Right now
[0095] (13)
[0096] In the formula, The score is converted by exponential operation Mapped to the positive range, the denominator The index scores of all grades are summed up and normalized so that the sum of all probability values is 1, which conforms to the characteristics of probability distribution. The model finally takes the category with the largest probability value as the predicted color fastness grade to determine the color fastness rating of the textile.
[0097] The attention mechanism can automatically learn the importance weight of each feature element, strengthen the color and texture features that have an important impact on the color fastness rating, and improve the accuracy of the rating. Before the fusion features are input into the fully connected layer, in order to achieve feature enhancement, the attention mechanism is used to weight them, as shown in formula (14):
[0098] (14)
[0099] in, It is the first fusion feature elements, is the length of the fused feature, , and are learnable weights and biases to highlight the features that are more critical to color fastness rating. These features contain color information and its change characteristics from local to global.
[0100] (4) Model training optimization
[0101] Design an optimization objective based on the cross entropy loss function and combine it with label smoothing technology to prevent model overfitting. Represents different levels, and the loss function is:
[0102] (15)
[0103] In the formula, is the sample size, is the label smoothing parameter, is the indicator function (when is 1 when it is, otherwise 0), is the model prediction sample belongs to the level probability.
[0104] The model is trained using the Adam optimizer, and the optimizer updates the parameters according to Equation (16):
[0105] (16)
[0106] where is the first moment estimate of the gradient, is the exponential decay rate of the first moment estimate, usually set to 0.9, is the gradient of the loss function at the current parameter The second moment estimate of the gradient is obtained from Equation (17)
[0107] (17)
[0108] Here is the exponential decay rate of the second moment estimate, usually set to 0.999;
[0109] Then, the first moment estimate and the second moment estimate are corrected. The corrected first moment estimate is , and the corrected second moment estimate is ; , is the model parameter at the current moment, is the learning rate, is a small constant to prevent the denominator from being zero.
[0110] During the training process, a learning rate decay strategy is adopted. After every certain number (such as 10 rounds) of training epochs, the learning rate is multiplied by a decay factor (such as 0.9). The formula is , where is the updated learning rate, is the learning rate before update, is the decay factor. As the training progresses, gradually reducing the learning rate can make the model converge more stably in the later stage of training and avoid missing the optimal solution due to too large a learning rate.
[0111] 3. Model performance improvement strategy
[0112] To increase the diversity of the training data and improve the generalization ability of the model, various enhancement processes are implemented on the training data. Geometric transformations such as rotation, translation, scaling, and flipping, as well as color transformations such as brightness adjustment, contrast adjustment, and color jitter are adopted. The rotation operation is
[0113] (18)
[0114] in is the original pixel coordinate, is the pixel coordinate after rotation, is the rotation center coordinate, is the rotation angle, and the range of random radians during training is .
[0115] The brightness is adjusted according to formula (19):
[0116] (19)
[0117] in is the brightness adjustment factor, Random value in the range.
[0118] In addition, Cutout data enhancement technology is used to randomly block some areas on the image to enhance the model's robustness to local feature loss. These enhancement operations not only act on the spatial structure of the image, but also diversify the color information, so that the model can learn the characteristics of different color changes and improve the recognition ability of various color fastness conditions. For example, through brightness adjustment and color jitter, the color changes of textiles under different lighting conditions can be simulated, allowing the model to better adapt to the complex environment in practical applications.
[0119] Train multiple CNN-Transformer fusion models with different initialization parameters and use voting method for model integration. Assume that The trained CNN-Transformer fusion models are denoted as For a test sample $X$, each model predicts it, and the prediction result is the color fastness grade.
[0120] In the five-level nine-grade rating system, the numbers To indicate different levels. Each model For samples The predicted color fastness grade is recorded as , .
[0121] Let the voting count array be , initially , . The prediction results of each model are statistically analyzed. The predicted color fastness grade is ,but ,Right now: Finally, the grade with the most votes is the final predicted color fastness grade of the test sample. It can be expressed as: , where represents the finally predicted colorfastness grade.
[0122] By integrating models through this voting method, the prediction results of multiple models can be comprehensively considered. Since different models are trained from different initial states and there are differences in the learned features and decision boundaries, the variance of the model can be effectively reduced, the stability and accuracy of the model can be improved, the error of a single model can be reduced, and the overall prediction performance can be enhanced.
[0123] 4. Post-processing of Rating Results
[0124] (1) Confidence Evaluation: For the colorfastness grade predicted by the model, calculate its confidence through the probability value output by the Softmax function. Select the grade with the largest prediction probability as the prediction result, and this maximum probability value is the confidence.
[0125] When the confidence is lower than the set threshold (such as 0.7), it can be considered that the reliability of the model's rating result for this sample is relatively low, and further manual verification or other auxiliary means need to be used for confirmation.
[0126] For example, the image of this sample can be recollected at different angles or under different light sources and analyzed again; or combined with the data of other detection devices to comprehensively judge the colorfastness grade to ensure the accuracy of the rating result.
[0127] (2) Result Correction: Establish a rating result correction mechanism, collect a large amount of actual rating data, and analyze the deviation law between the model's prediction result and the actual rating.
[0128] The correction mechanism includes:
[0129] When the confidence is lower than the threshold, recollect the sample image or comprehensively judge by combining the data of other detection devices; establish a rule correction system according to the historical deviation law to dynamically adjust the rating results for specific colors or patterns.
[0130] For example, if it is found that the model has systematic deviations in the rating of textiles with certain specific colors (such as dark-colored textiles) or patterns (such as complex patterns), the parameters of the model can be adjusted accordingly or the corresponding training data can be increased. A rule-based correction system can also be constructed, and a series of correction rules can be formulated according to the difference between the model's prediction result and the actual rating.
[0131] For example, when the model's prediction result is higher or lower than the actual rating by a certain degree, adjust the prediction result according to the rules to improve the accuracy of the rating. The feedback mechanism can also be used to re-enter the corrected result into the model for training, so that the model can learn this correction information, further optimize the model performance, and reduce the deviation of future predictions.
[0132] The present invention also provides a system for implementing the above-mentioned automatic grading method of textile color fastness based on the CNN-Transformer fusion model, which includes:
[0133] An image acquisition module, which is used to acquire image data of textiles in a standard D65 light source environment. Using a high-resolution RGB color industrial camera, it acquires image data of textiles in a standard D65 light source environment , ensuring the accuracy and universality of color information;
[0134] A preprocessing module, which is used to perform grayscale conversion, denoising, spectral data conversion and normalization processing on the image, that is, perform grayscale conversion, denoising, contrast enhancement and spectral data conversion on the acquired image data to generate standardized input data. Among them, the grayscale conversion adopts a weighted formula
[0135] , and obtains the denoised image through Gaussian filtering. The spectral data conversion is based on the CIE XYZ color space. Through a pre-established relationship model between spectral reflectance and CIEXYZ values, combined with the XYZ values of each pixel point in the image, the corresponding spectral reflectance data is deduced , uses the principal component analysis (PCA) method to reduce the dimension of the spectral data, and inputs it into the model after normalization;
[0136] A fusion model module, which includes a CNN module and a Transformer module, and is used for feature extraction and fusion. Among them, the CNN module includes 4 convolutional layers (including dilated convolution), a max-pooling layer and a ReLU activation function, which are used to extract local texture and color change features. The Transformer module includes a multi-head attention mechanism and sine-cosine position encoding, which are used to capture global color distribution and pattern structure features. Then, the local features output by the CNN are concatenated with the global features output by the Transformer, and weighted by the attention mechanism;
[0137] A classification module, which classifies the fused features and outputs a five-level and nine-grade color fastness rating result. The Softmax function calculates the probabilities of each level, and selects the level corresponding to the maximum probability value as the final result;
[0138] A post-processing module, which is used for confidence evaluation and result correction.
[0139] The present invention also provides a computer-readable storage medium, such as a solid-state drive, an optical disc, a cloud server storage unit, etc., on which a computer program is stored. When the computer program is executed by a processor, it implements the above-mentioned automatic grading method of textile color fastness based on the CNN-Transformer fusion model.
[0140] When executed by a processor, the following operations are implemented:
[0141] Control the image acquisition device to obtain textile images under a D65 light source;
[0142] Call the preprocessing algorithm to grayscale, denoise, convert spectral data, and standardize the images;
[0143] Load the pre-trained CNN-Transformer fusion model to extract and fuse local and global features;
[0144] Output the colorfastness grade probability through a fully connected layer and a Softmax function;
[0145] Perform data augmentation and model integration (voting method);
[0146] Evaluate the confidence level and trigger the correction logic (such as rule base matching or feedback training).
[0147] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory. When the processor executes the program, the above-mentioned automatic textile colorfastness rating method based on the CNN-Transformer fusion model is implemented.
[0148] Memory: Includes non-volatile storage units (such as SSDs) and volatile storage units (such as RAMs) for storing programs and temporary data;
[0149] Processor: A multi-core CPU or GPU (such as the NVIDIA Tesla series), supporting parallel computing, for efficiently performing CNN-Transformer model inference;
[0150] Image acquisition interface: Supports connecting an industrial camera to transmit RAW or JPEG format image data;
[0151] Communication module: Supports Wi-Fi / 5G for receiving external instructions or uploading rating results to a cloud database.
[0152] Device working process:
[0153] 1. The processor loads program instructions from the memory;
[0154] 2. Obtain textile images through the image acquisition interface;
[0155] 3. Call the preprocessing module to generate standardized inputs;
[0156] 4. Run the fusion model for feature extraction and classification;
[0157] 5. Output the rating result to a display screen or an external system, and at the same time execute the post-processing logic.
[0158] The embodiments should not be regarded as limitations on the present invention, but any improvements made based on the spirit of the present invention should fall within the protection scope of the present invention.
Claims
1. An automatic grading method for textile color fastness based on a CNN-Transformer fusion model, characterized in that: It includes the following steps: S1 uses a high-resolution RGB color industrial camera to collect image data of textiles in a standard D65 light source environment , where represents the coordinates of the image pixels, represents the pixel point 's color value, recorded in the RGB color space, , , are the red, green, and blue channel values of the pixel point in the RGB image, and preprocess the grayscale data and spectral data of the image; S2 constructs a CNN module, and through the alternating stacking of multiple convolutional layers, pooling layers, and activation functions, outputs local features containing the local texture and color changes of the textile image ; The S3 reshapes the feature map output by the CNN module to meet the input requirements of the Transformer, and then inputs it into the Transformer module. After being processed by the Transformer module and introducing positional encoding, global features containing global color distribution and pattern structure features are obtained. ; S4 fuses the local features extracted by the CNN module and the global features extracted by the Transformer module and inputs the fused features weighted by the attention mechanism into the fully connected layer, calculates the color fastness grade probability through the Softmax function, and outputs the color fastness grade corresponding to the maximum probability; In S5, the model is trained using the cross-entropy loss function combined with label smoothing technology, the model parameters are optimized using the Adam optimizer and the learning rate decay strategy, and the generalization ability is improved through data augmentation and model integration; the confidence of the rating result is evaluated, and if the confidence is lower than the threshold, the correction mechanism is triggered. In S4, the local features extracted by the CNN module and the global features extracted by the Transformer module are fused, and the fused features are obtained by concatenation , and the fused features are weighted using the attention mechanism , and the weights of the attention mechanism are dynamically adjusted by learnable parameters In S5, the voting method is adopted for model integration. Multiple CNN-Transformer fusion models with different initializations are trained, the prediction results of each model are statistically analyzed, and the grade with the most votes is selected as the final rating result.
2. The automatic grading method for textile color fastness based on the CNN-Transformer fusion model according to claim 1, characterized in that: In S1, for the image data perform grayscale conversion, denoising, and contrast enhancement processing, and convert it to the CIE XYZ color space to derive spectral reflectance data, and perform normalization, dimensionality reduction, and standardization processing on the spectral reflectance data.
3. The automatic color fastness rating method for textiles based on the CNN-Transformer fusion model according to claim 2, characterized in that: In S1, for the image data perform grayscale processing, including the following steps: I. Convert the image data through to a grayscale image ; II. The denoised image is obtained through Gaussian filtering; III. The histogram equalization technology is used to enhance the image contrast and make the gray distribution of the image more uniform.
4. The automatic grading method for textile color fastness based on the CNN-Transformer fusion model according to claim 2, characterized in that: In S1, the spectral data preprocessing of the image data includes the following steps: I. Based on the acquired image data, use to convert the image data from the RGB color space to the CIE XYZ color space, where , , are the converted CIE XYZ color space values; II. According to , calculate the spectral reflectance data within a specific wavelength range based on the CIE XYZ values , where , , are the CIE XYZ values at different wavelengths ; , , are the spectral tristimulus values of the CIE standard observer; is the spectral power distribution of the illumination light source; III. For the obtained spectral reflectance data, according to For the spectral reflectance data perform normalization processing to map its value range to interval, where and are the minimum and maximum values of the spectral reflectance data respectively; IV. Use the principal component analysis method to reduce the dimensionality of spectral data and extract the main components , calculate the covariance matrix of the spectral data , for perform eigenvalue decomposition to obtain eigenvalues and eigenvectors , select the first eigenvectors according to the eigenvalue contribution rate, such that , is the original number of features, thus obtaining the spectral data after dimensionality reduction; V. The dimensionality-reduced spectral data is normalized to have zero mean and unit variance.
5. The automatic color fastness rating method for textiles based on the CNN-Transformer fusion model according to claim 1, characterized in that: The CNN module consists of multiple convolutional layers, pooling layers and activation functions. At the same time, the dilated convolution technology is introduced in the convolutional layer to expand the receptive field of the convolutional kernel to capture more extensive local color change information, and the dilation rate is set to 2.
6. The automatic grading method for textile color fastness based on the CNN-Transformer fusion model according to claim 1, characterized in that: The Transformer module contains the multi-head attention mechanism and position encoding, and the feature positions are encoded through sine and cosine functions.
7. A system for implementing the automatic grading method of textile color fastness based on the CNN-Transformer fusion model according to any one of claims 1-6, characterized in that: It includes: An image acquisition module for acquiring the image data of textiles in the standard D65 light source environment; A preprocessing module for grayscaling, denoising, spectral data conversion and normalization of the image; A fusion model module containing a CNN module and a Transformer module for feature extraction and fusion; A classification module for outputting the color fastness grade probability and the final rating result; A post-processing module for confidence evaluation and result correction.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the automatic rating method for textile color fastness based on the CNN-Transformer fusion model according to any one of claims 1 to 6.
Citation Information
Patent Citations
Automatic color fastness grading method and device for textiles
CN110644216A
Textile color fastness detection method and system based on machine vision
CN118794895A