Textile fiber classification method and device, computer equipment and storage medium
By using weighted fusion training of triple loss function and cross entropy loss function calculated by cosine similarity in textile fiber classification model, the problem of low accuracy in some scenarios is solved, and textile fiber classification is realized Improved accuracy and efficiency.
Patent Information
- Application Number
- CN202411824555.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-01-14
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing neural network-based textile fiber classification model cannot be effectively identified and classified in some scenarios, especially protein fibers such as wool and cashmere. The differences in special samples such as soil wool are large, resulting in low classification accuracy.
The textile fiber classification model is trained using the total loss function weighted fusion of triple loss function and cross entropy loss function calculated based on cosine similarity, including anchor samples and positive samples, anchor samples and negative samples, and positive samples and negative samples. Cosine similarity, optimize the model to improve classification accuracy.
The accuracy and classification efficiency of textile fiber classification have been improved, especially for fiber categories that are difficult to classify, achieving an accuracy of more than 5%, which significantly improves the accuracy of the model.
Smart Images

Figure CN119313977A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a method, device, computer equipment and storage medium for classifying textile fibers. Background Art
[0002] In the apparel industry, in order to facilitate production management and product analysis, it is necessary to scientifically identify and classify textile fiber components. With the development of deep learning technology and digital image processing technology, the application of artificial intelligence in the textile field has emerged, and many researchers have begun to study how to apply artificial intelligence technology to the fields of textile fiber detection, identification and classification.
[0003] The existing neural network-based textile fiber classification model has achieved certain success in some individual scenarios, but it is still unable to effectively identify and classify in some scenarios. For example, wool and cashmere are both protein fibers, and the surface scale layer of their fibers is composed of flaky keratin cells, which are extremely difficult to detect and identify. In addition, there are some special samples such as native wool, which may result in the difference between wool and wool being greater than the difference between wool and cashmere, and this part is also difficult to accurately identify.
[0004] Therefore, how to optimize the textile fiber classification model to improve the accuracy of textile fiber classification is a problem that needs to be solved. Summary of the invention
[0005] In view of this, the present invention provides a textile fiber classification method, apparatus, computer equipment and storage medium, which optimize the textile fiber classification model to improve the accuracy and classification efficiency of textile fiber classification.
[0006] In order to achieve the above object, the present invention adopts the following technical solutions: A first aspect of the present invention is to provide a method for classifying textile fibers, comprising: acquiring an image of textile fibers to be classified; Inputting the image of the textile fiber to be classified into a pre-trained fiber classification model for classification; The fiber classification model is obtained by training based on the total loss function of the following formula (1): ------(1); In formula (1), is the total loss function, is the triple loss function calculated based on cosine similarity, is the cross entropy loss function based on different fiber categories, is the adjustment factor of the triplet loss function, is the adjustment factor of the cross entropy loss function; The triplet loss function includes the sum of the cosine similarity between the anchor sample and the positive sample, the cosine similarity between the anchor sample and the negative sample, and the cosine similarity between the positive sample and the negative sample in the triplet sample.
[0007] In a preferred solution, the formula of the triple loss function is as follows (2): ------(2); In formula (2), is the cosine similarity between anchor sample a and positive sample p, is the cosine similarity between anchor sample a and negative sample n, is the cosine similarity between the positive sample p and the negative sample n; where any two sets of vectors and The calculation formula of cosine similarity is as follows (3): ---(3); In formula (3), the two sets of vectors and For the same type of samples, y=1, two sets of vectors and For samples of different classes, y=-1, and margin is the interval parameter; is the similarity function, and its calculation formula is as follows (4): ------(4); In formula (4), e is a hyperparameter close to 0 but not zero. In a preferred embodiment, the regulatory factor The value of is 0.7~0.8, and the adjustment factor The value is 0.9~1.1.
[0008] In a preferred solution, the formula of the cross entropy loss function is as follows (5): ------(5); In formula (5), n is the total number of textile fiber categories, is the true probability distribution of the i-th textile fiber category, is the predicted probability distribution of the i-th textile fiber category.
[0009] In a preferred solution, the cross entropy loss function is subjected to label smoothing optimization processing, and the formula of the optimized cross entropy loss function is as follows (6): ------(6); In formula (6), ,in is the Dirac function, is the uniform distribution function, e is a hyperparameter close to 0 but not zero.
[0010] In a preferred embodiment, the fiber classification model is obtained by training the total loss function based on the formula (1), comprising: Acquire a training sample, wherein the training sample includes a plurality of textile fiber categories, and each textile fiber category includes a plurality of textile fiber images; Inputting the textile fiber images into the model to be trained, and extracting feature vectors of each textile fiber image; For each textile fiber category, selecting anchor samples and positive samples in the category, selecting negative samples from other categories, and calculating a triplet loss value based on the triplet loss function; For each textile fiber category, calculating a cross entropy loss value based on the cross entropy loss function; Calculate the total loss value based on the formula (1); The total loss value is back-propagated to optimize the model parameters, and the training is iterated multiple times until the model meets the predetermined requirements to obtain the trained fiber classification model.
[0011] In a preferred embodiment, the step of inputting the textile fiber images into a model to be trained and extracting feature vectors of each textile fiber image comprises: The textile fiber images are input into the model to be trained, and multi-dimensional feature vectors of each textile fiber image are extracted; the multi-dimensional feature vectors are flattened to obtain one-dimensional feature vectors of each textile fiber image.
[0012] The second aspect of the present invention is to provide a textile fiber classification device, which includes a data receiving module and a data processing module, the data receiving module is used to obtain images of textile fibers to be classified, the data processing module is provided with a pre-trained fiber classification model, and the data processing module is used to process the images of textile fibers to be classified according to the textile fiber classification method as described above.
[0013] The third aspect of the present invention is to provide a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the textile fiber classification method as described above when executing the computer program.
[0014] A fourth aspect of the present invention is to provide a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the textile fiber classification method as described above are implemented.
[0015] A textile fiber classification method, apparatus, computer equipment and storage medium provided by an embodiment of the present invention classify textile fiber images using a pre-trained fiber classification model, wherein the model is trained by optimizing a loss function, specifically, the model is trained using a total loss function formed by weighted fusion of a triplet loss function calculated based on cosine similarity and a cross entropy loss function based on different fiber categories, and the triplet loss function includes not only the cosine similarity between an anchor sample and a positive sample and the cosine similarity between an anchor sample and a negative sample, but also the cosine similarity between a positive sample and a negative sample, which can better optimize the model and improve the accuracy of the model, thereby improving the accuracy and efficiency of textile fiber classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 is a flow chart of a method for classifying textile fibers in an embodiment of the present invention; Figure 2 It is a structural block diagram of a textile fiber classification device in an embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to make the purpose, technical scheme and advantages of the present invention clearer, the specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. Examples of these preferred embodiments are illustrated in the accompanying drawings. The embodiments of the present invention shown in the accompanying drawings and described according to the accompanying drawings are merely exemplary, and the present invention is not limited to these embodiments.
[0018] It should be noted that the same or similar numbers in the drawings of the embodiments of the present invention correspond to the same or similar parts; in the description of the present invention, it should be understood that if the terms "upper", "lower", "left", "right" and the like indicate directions or positional relationships based on the directions or positional relationships shown in the drawings, it is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction, be constructed and operated in a specific direction. Therefore, the terms describing the positional relationship in the drawings are only used for illustrative purposes and cannot be understood as limitations on this patent. For ordinary technicians in this field, the specific meanings of the above terms can be understood according to specific circumstances.
[0019] It should also be noted that, in order to avoid obscuring the present invention due to unnecessary details, only structures and / or processing steps closely related to the solutions according to the present invention are shown in the accompanying drawings, while other details that are not closely related to the present invention are omitted.
[0020] The present invention first provides a method for classifying textile fibers. Figure 1 , the classification method shown includes the following steps: S101, obtaining an image of textile fibers to be classified.
[0021] S102. Input the image of the textile fiber to be classified into a pre-trained fiber classification model for classification; wherein the fiber classification model is trained by a total loss function formed by a weighted fusion of a triplet loss function calculated based on cosine similarity and a cross entropy loss function based on different fiber categories, and the triplet loss function includes the sum of the cosine similarity between the anchor sample and the positive sample, the cosine similarity between the anchor sample and the negative sample, and the cosine similarity between the positive sample and the negative sample in the triplet sample.
[0022] Specifically, the fiber classification model is trained using the total loss function of the following formula (1): ------(1)
[0023] In formula (1), is the total loss function, is the triple loss function calculated based on cosine similarity, is the cross entropy loss function based on different fiber categories, is the adjustment factor of the triplet loss function, is the adjustment factor of the cross entropy loss function.
[0024] Among them, the triple loss function It includes the cosine similarity between the anchor sample and the positive sample, the cosine similarity between the anchor sample and the negative sample, and the sum of the cosine similarity between the positive sample and the negative sample in the triple sample.
[0025] In a specific solution, the fiber classification model is obtained by training the total loss function based on the formula (1), including the following steps: S201, obtaining training samples, wherein the training samples include multiple textile fiber categories, and each textile fiber category includes multiple textile fiber images. The textile fiber categories may include cotton fiber, hemp fiber, regenerated cellulose fiber, wool fiber, cashmere fiber, mohair fiber, etc. The fiber category may be selected according to actual needs, and the specific number of samples of each textile fiber category may be set according to actual needs. The textile fiber images may be obtained by photographing with an optical microscope.
[0026] S202, inputting the textile fiber image into the model to be trained, and extracting the feature vector of each textile fiber image, including: inputting the textile fiber image into the model to be trained, and extracting the multi-dimensional feature vector of each textile fiber image; flattening the multi-dimensional feature vector to obtain the one-dimensional feature vector of each textile fiber image.
[0027] Specifically, the image is first scaled to a uniform size while maintaining its proportion, and then scaled to a range of 0-1, so that the pixel value distributions of different images are similar, reducing the differences between different images and facilitating comparison and processing; the model then encodes the input image. During the encoding process, the model learns the texture, scales, morphology, gloss, etc. of the fibers in the input image, and converts it into a fixed-size feature map representation, such as a multi-dimensional feature map of 7*7*1024; finally, the mean of the multi-dimensional feature map is taken to convert it into a one-dimensional feature vector, such as a one-dimensional feature vector of 1*1*1024 in length.
[0028] S203. For each textile fiber category, select anchor samples and positive samples in the category, select negative samples from other textile fiber categories, and calculate the triplet loss value based on the triplet loss function.
[0029] Specifically, based on the one-dimensional feature vector obtained in step S202, the vectors are grouped according to categories, and the grouping is performed using a triplet method, that is, anchor samples and positive samples are selected from one textile fiber category, and negative samples are selected from other textile fiber categories, and then the triplet loss value is calculated based on the triplet loss function.
[0030] S204. For each textile fiber category, calculate a cross entropy loss value based on the cross entropy loss function.
[0031] Specifically, based on the one-dimensional feature vector outputted in step S202, a fully connected layer is added, the number of fully connected layers is the same as the number of textile fiber categories, and the cross entropy loss value is calculated based on the cross entropy loss function according to the output result of the fully connected layer.
[0032] S205. According to the results of step S203 and step S204, the total loss value is calculated based on the formula (1).
[0033] As in the total loss function of formula (1), the adjustment factor The value of is preferably 0.7-0.8, and the adjustment factor The value of is preferably 0.9 to 1.1. In the most preferred embodiment, The value of is 0.75. The value of is 1.
[0034] S206, back-propagating the total loss value to optimize model parameters, iterating training multiple times until the model meets predetermined requirements, and obtaining the trained fiber classification model.
[0035] Specifically, the AdamW optimizer is used for back propagation, and after multiple rounds of iterations, the model meets the predetermined requirements, thereby obtaining the trained fiber classification model.
[0036] In this embodiment, the triple loss function includes not only the cosine similarity between the anchor sample and the positive sample and the cosine similarity between the anchor sample and the negative sample, but also the cosine similarity between the positive sample and the negative sample, and its formula is as follows (2): ------(2).
[0037] In formula (2), is the cosine similarity between anchor sample a and positive sample p, is the cosine similarity between anchor sample a and negative sample n, is the cosine similarity between the positive sample p and the negative sample n.
[0038] Among them, any two sets of vectors and The calculation formula of cosine similarity is as follows (3): ---(3); In formula (3), the two sets of vectors and For the same type of samples, y=1, two sets of vectors and For samples of different classes, y=-1. For example, calculate When , the anchor sample a and the positive sample p belong to the same fiber category, then y=1; calculate and When the anchor sample a and the negative sample n as well as the positive sample p and the negative sample n are of different fiber categories, then y=-1.
[0039] Among them, margin is an interval parameter, which is a constant determined according to actual needs, for example, the value can be 0.5.
[0040] Further, is the similarity function, and its calculation formula is as follows (4): ------(4).
[0041] In formula (4), e is a hyperparameter close to 0 but not 0, For vector and The dot product of and Respectively, vector and Model. The formula of the cross entropy loss function is as follows (5): ------(5)
[0042] In formula (5), n is the total number of textile fiber categories, is the true probability distribution of the i-th textile fiber category, is the predicted probability distribution of the i-th textile fiber category.
[0043] Based on the classification method of textile fibers provided in the above embodiment, the model is trained by optimizing the loss function, specifically, the model is trained by weighted fusion of a triplet loss function calculated based on cosine similarity and a cross entropy loss function based on different fiber categories to form a total loss function, and the triplet loss function includes not only the cosine similarity between the anchor sample and the positive sample and the cosine similarity between the anchor sample and the negative sample, but also the cosine similarity between the positive sample and the negative sample, which can better optimize the model and improve the accuracy of the model, thereby improving the accuracy and classification efficiency of textile fiber classification.
[0044] The optimization of the triplet loss function is a major difference between the fiber classification model of the embodiment of the present invention and the existing fiber classification model. The triplet loss function in the embodiment of the present invention, on the one hand, uses cosine similarity instead of the traditional commonly used Euclidean distance to express similarity. On the other hand, compared with the traditional triplet loss function that only considers the cosine similarity between the anchor sample and the positive sample and the similarity between the anchor sample and the negative sample, the triplet loss function in the embodiment of the present invention also integrates the cosine similarity between the positive sample and the negative sample. In actual application, the method of the embodiment of the present invention can achieve an accuracy improvement of more than 5% for fiber categories that are easier to classify, such as cotton, linen, and regenerated cellulose fibers, and an accuracy improvement of more than 7% for fiber categories that are more difficult to classify, such as special animal hair.
[0045] In a further preferred solution, the cross entropy loss function is subjected to label smoothing optimization processing, and the formula of the optimized cross entropy loss function is as follows (6): ------(6).
[0046] In formula (6), ,in is the Dirac function, is the uniform distribution function, e is a hyperparameter close to 0 but not zero.
[0047] Among them, k is used to represent the index of the category or the label of the category. In a multi-classification problem, for example, if there are n categories, the value range of k is from 0 to n-1. 。 y is used to represent the true category label or the target category label. During the training process, y represents the correct category corresponding to each sample.
[0048] In the cross entropy loss function of the above formula (6), we introduce The role of is to ensure that the model predicts a higher probability for the correct category, thereby improving the classification performance of the model. Specifically: When k=y, , indicating that the category predicted by the model is consistent with the true label; When k≠y, , indicating that the category predicted by the model is inconsistent with the true label.
[0049] In the cross entropy loss function of the above formula (6), e is an infinitesimal quantity used to describe the uniform distribution function of minor changes.
[0050] In practical applications, classification models need to use predicted probabilities to fit true probabilities, which may cause the model to overconfidently trust the predicted categories. In order to reduce this overconfidence, Optimized to form , we get the cross entropy loss function as shown in formula (6), which reduces the confidence of the target category label y and increases the confidence of the remaining categories, thereby further optimizing the model and further improving the accuracy of the model.
[0051] Based on the textile fiber classification method provided in the above embodiment, the embodiment of the present invention further provides a textile fiber classification device, such as Figure 2 As shown, the classification device includes a data receiving module 10 and a data processing module 20. The data receiving module 10 is used to obtain an image of a textile fiber to be classified, and the data processing module 20 is provided with a pre-trained fiber classification model, and the data processing module 20 is used to process the image of the textile fiber to be classified according to the classification method of the textile fiber described in the above embodiment.
[0052] Based on the textile fiber classification method provided in the above embodiment, an embodiment of the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the textile fiber classification method described in the above embodiment when executing the computer program.
[0053] The memory is a computer-readable storage medium that can be used to store software programs, computer executable programs, and modules. The processor executes various functional applications and data processing of the device by running the software programs, instructions, and modules stored in the memory, that is, the steps of the textile fiber classification method provided in the aforementioned embodiment of the present invention.
[0054] Based on the textile fiber classification method provided in the above embodiment, the embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the textile fiber classification method described in the above embodiment are implemented. The computer storage medium can be any available medium or data storage device that can be accessed by a computer, including but not limited to magnetic memory, optical memory, and semiconductor memory.
[0055] The above is only a specific implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for classifying textile fibers, characterized in that: include: acquiring an image of textile fibers to be classified; Inputting the image of the textile fiber to be classified into a pre-trained fiber classification model for classification; The fiber classification model is obtained by training based on the total loss function of the following formula (1): ------(1); In formula (1), is the total loss function, is the triple loss function calculated based on cosine similarity, is the cross entropy loss function based on different fiber categories, is the adjustment factor of the triplet loss function, is the adjustment factor of the cross entropy loss function; The triplet loss function includes the sum of the cosine similarity between the anchor sample and the positive sample, the cosine similarity between the anchor sample and the negative sample, and the cosine similarity between the positive sample and the negative sample in the triplet sample.
2. The method for classifying textile fibers according to claim 1, characterized in that: The formula of the triplet loss function is as follows (2): ------(2); In formula (2), is the cosine similarity between anchor sample a and positive sample p, is the cosine similarity between anchor sample a and negative sample n, is the cosine similarity between the positive sample p and the negative sample n; where any two sets of vectors and The calculation formula of cosine similarity is as follows (3): ---(3); In formula (3), the two sets of vectors and For the same type of samples, y=1, two sets of vectors and For samples of different classes, y=-1, and margin is the interval parameter; is the similarity function, and its calculation formula is as follows (4): ------(4); In formula (4), ε is a hyperparameter close to 0 but not zero.
3. The method for classifying textile fibers according to claim 2, characterized in that: The regulatory factor The value of is 0.7~0.8, and the adjustment factor The value is 0.9~1.
1.
4. The method for classifying textile fibers according to claim 1, characterized in that: The formula of the cross entropy loss function is as follows (5): ------(5); In formula (5), n is the total number of textile fiber categories, is the true probability distribution of the i-th textile fiber category, is the predicted probability distribution of the i-th textile fiber category.
5. The method for classifying textile fibers according to claim 4, characterized in that: The cross entropy loss function is subjected to label smoothing optimization processing, and the formula of the optimized cross entropy loss function is as follows (6): ------(6); In formula (6), ,in is the Dirac function, is the uniform distribution function, ε is a hyperparameter close to 0 but not zero.
6. The method for classifying textile fibers according to any one of claims 1 to 5, characterized in that: The fiber classification model is obtained by training the total loss function based on the formula (1) including: Acquire a training sample, wherein the training sample includes a plurality of textile fiber categories, and each textile fiber category includes a plurality of textile fiber images; Inputting the textile fiber images into the model to be trained, and extracting feature vectors of each textile fiber image; For each textile fiber category, selecting anchor samples and positive samples in the category, selecting negative samples from other categories, and calculating a triplet loss value based on the triplet loss function; For each textile fiber category, calculating a cross entropy loss value based on the cross entropy loss function; Calculate the total loss value based on the formula (1); The total loss value is back-propagated to optimize the model parameters, and the training is iterated multiple times until the model meets the predetermined requirements to obtain the trained fiber classification model.
7. The method for classifying textile fibers according to claim 6, characterized in that: The step of inputting the textile fiber images into the model to be trained and extracting feature vectors of each textile fiber image comprises: The textile fiber images are input into the model to be trained, and multi-dimensional feature vectors of each textile fiber image are extracted; the multi-dimensional feature vectors are flattened to obtain one-dimensional feature vectors of each textile fiber image.
8. A textile fiber classification device, characterized in that: It comprises a data receiving module and a data processing module, wherein the data receiving module is used to obtain images of textile fibers to be classified, the data processing module is provided with a pre-trained fiber classification model, and the data processing module is used to process the images of the textile fibers to be classified according to the textile fiber classification method according to any one of claims 1 to 7.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method for classifying textile fibers as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for classifying textile fibers as described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Textile fiber component identification method, electronic equipment and storage medium
CN113255790A
Model training method for food image classification and image retrieval method
CN115797924A
Language recognition model training method and recognition method and system based on optimization of triple loss
CN118824234A
Cited By
Model optimization method, electronic equipment and computer readable storage medium
CN121561424A