Training method and device for clothing classification model, clothing classification method and device
By combining the MASK mechanism and the attention mechanism, the problems of difficult training and low accuracy of clothing classification models in the existing technology are solved, and more efficient clothing feature learning and classification accuracy are achieved.
Patent Information
- Application Number
- CN202111550868.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-12-17
AI Technical Summary
Existing clothing classification models are difficult to train and have low classification accuracy. In particular, the attention module cannot effectively focus on clothing attribute features, resulting in poor classification performance.
The MASK mechanism is used for semantic segmentation to assist the model in learning to distinguish portrait areas and backgrounds. It combines the attention mechanism and the residual attention mechanism to jointly optimize the model through multiple loss functions to improve the convergence stability and classification accuracy of the model.
It effectively reduces the difficulty of training the clothing model, enables the model attention mechanism to better learn human body clothing characteristics, filters background interference, and significantly improves the accuracy of multi-label classification tasks.
Smart Images

Figure CN114241202B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a training method and device for a clothing classification model, and a clothing classification method and device. Background Art
[0002] There are currently two main classification methods for clothing classification: the first is to manually annotate the landmarks (key feature points) of the portrait clothing before model training. When learning clothing features, it is necessary to train a landmark network to obtain the location and visibility information of the clothing feature points in the image, encode the local features near the feature points, and then fuse the local features as the final clothing features for representation. There may be dozens or even hundreds of landmarks in the entire image. Therefore, the manual annotation cost of this method is quite high, the training is difficult, and the local area features extracted based on the landmarks do not pay attention to the global information; the second method adds a class-specific residual attention module to the model, and by making full use of the separate attention modules of each category, combined with class-independent global features to improve the expression ability of various attribute features and improve the performance of multi-label classification tasks. However, in the clothing classification task, it is difficult for the attention module of this method to effectively pay attention to the characteristics of various clothing attributes themselves, which greatly reduces the accuracy of clothing classification. Summary of the invention
[0003] The technical problem to be solved by the present invention is to overcome the defects of the difficulty in training a clothing classification model and the low classification accuracy in the prior art, and to provide a clothing classification model training method and device, and a clothing classification method and device.
[0004] The present invention solves the above technical problems through the following technical solutions:
[0005] According to a first aspect of the present invention, a method for training a clothing classification model is provided, comprising the following steps:
[0006] Acquire a training sample, wherein the training sample includes a sample image and a corresponding clothing classification label;
[0007] Inputting the sample image into a clothing classification model, the clothing classification model is used to extract a first feature of the sample image, and process the first feature based on an attention mechanism to obtain a second feature, and process the second feature based on a residual attention mechanism to obtain a clothing classification result;
[0008] Performing semantic segmentation on the portrait area in the sample image based on a MASK mechanism to obtain a target image;
[0009] A target loss is calculated based on the second feature, the target feature, the clothing classification result and the corresponding clothing classification label, and the parameters of the clothing classification model are adjusted according to the target loss until a convergence condition is met; wherein the target feature is obtained based on the target image and the first feature.
[0010] Preferably, the step of calculating the target loss based on the second feature, the target feature, the clothing classification result and the corresponding clothing classification label specifically includes:
[0011] Calculate a first loss based on the second feature and the target feature;
[0012] Calculating a second loss based on the clothing classification result and the corresponding clothing classification label;
[0013] A target loss is determined according to the first loss and the second loss.
[0014] Preferably, the step of calculating the first loss based on the second feature and the target feature specifically includes:
[0015] Substituting the second feature and the target feature into the first loss function to obtain a first loss;
[0016] The first loss function is used to force the second feature to continuously approach the target feature.
[0017] Preferably, the step of calculating the target loss based on the second feature, the target feature, the clothing classification result and the corresponding clothing classification label specifically includes:
[0018] Calculate a first loss based on the second feature and the target feature;
[0019] Substituting the clothing classification result and the corresponding clothing classification label into a second loss function to calculate a second loss;
[0020] Substituting the clothing classification result and the corresponding clothing classification label into a third loss function to calculate a third loss; the third loss function is a regularization term of the second loss function;
[0021] A target loss is determined according to the first loss, the second loss, and the third loss.
[0022] Preferably, the step of performing semantic segmentation on the portrait area in the sample image based on the MASK mechanism to obtain the target image comprises:
[0023] Performing semantic segmentation on the portrait region in the sample image based on the MASK mechanism to obtain an intermediate image;
[0024] Perform semantic segmentation on the non-face area in the intermediate image to obtain a target image.
[0025] According to a second aspect of the present invention, there is provided a training device for a clothing classification model, comprising:
[0026] An acquisition module, used to acquire training samples, wherein the training samples include sample images and corresponding clothing classification labels;
[0027] a classification module, configured to input the sample image into a clothing classification model, wherein the clothing classification model is configured to extract a first feature of the sample image, process the first feature based on an attention mechanism to obtain a second feature, and process the second feature based on a residual attention mechanism to obtain a clothing classification result;
[0028] A segmentation module, used for performing semantic segmentation on the portrait area in the sample image based on a MASK mechanism to obtain a target image;
[0029] A training module is used to calculate a target loss based on the second feature, a target feature, the clothing classification result and a corresponding clothing classification label, and adjust the parameters of the clothing classification model according to the target loss until a convergence condition is met; wherein the target feature is obtained based on the target image and the first feature.
[0030] According to a third aspect of the present invention, there is provided a method for classifying clothing, comprising the following steps:
[0031] Acquire an image to be classified, wherein the image to be classified includes clothing information;
[0032] The image to be classified is subjected to clothing classification processing by means of a clothing classification model to obtain a clothing classification result of the image to be classified. The clothing classification model is obtained by means of the training method of the clothing classification model of the present invention.
[0033] According to a fourth aspect of the present invention, there is provided a clothing classification device, comprising:
[0034] An image acquisition module to be classified is used to acquire an image to be classified, wherein the image to be classified contains clothing information;
[0035] The classification processing module is used to perform clothing classification processing on the image to be classified through a clothing classification model to obtain a clothing classification result of the image to be classified. The clothing classification model is obtained through the training method of the clothing classification model of the present invention.
[0036] According to a fifth aspect of the present invention, there is provided an electronic device, comprising a memory and a processor connected to the memory, wherein the processor implements the training method of the clothing classification model of the present invention or the clothing classification method of the present invention when executing a computer program stored on the memory.
[0037] According to a sixth aspect of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the training method of the clothing classification model of the present invention or the clothing classification method of the present invention is implemented.
[0038] The positive and progressive effects of the present invention are:
[0039] Through the MASK mechanism for semantic segmentation, the clothing classification model is assisted to learn to distinguish the foreground, i.e. the portrait area, from the background, which reduces the difficulty of clothing model training and allows the attention mechanism of the clothing classification model to effectively learn the foreground area of human clothing and filter out background interference, thereby better characterizing the characteristics of various clothing attributes themselves, thereby accurately and efficiently realizing the multi-label classification task of human clothing. In addition, by designing a variety of loss functions to jointly optimize the model, it is ensured that the clothing classification model can converge to the optimal solution more stably, greatly improving the accuracy of clothing classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 Schematic diagram of the flow of the training method of the clothing classification model of Example 1 of the present invention.
[0041] Figure 2 Schematic diagram of the framework of the training method of the clothing classification model of Example 1 of the present invention.
[0042] Figure 3 Schematic diagram of the structure of the training device of the clothing classification model of embodiment 3 of the present invention.
[0043] Figure 4 Schematic diagram of the flow of the clothing classification method according to Embodiment 5 of the present invention.
[0044] Figure 5 Schematic diagram of the structure of the clothing classification device according to embodiment 6 of the present invention.
[0045] Figure 6 This is a schematic diagram of the structure of an electronic device according to Embodiment 7 of the present invention. DETAILED DESCRIPTION
[0046] The present invention is further described below by way of examples, but the present invention is not limited to the scope of the examples.
[0047] Example 1
[0048] This embodiment provides a method for training a clothing classification model. Figure 1 As shown, the training method of the clothing classification model includes the following steps:
[0049] S11. Obtain training samples, wherein the training samples include sample images and corresponding clothing classification labels.
[0050] In this embodiment, the training samples are specifically human clothing images taken by the device or crawled from the network (i.e., sample images), and different clothing categories in the human clothing images are labeled (i.e., clothing classification labels). In order to better extract the features of the sample images, the sample images are preprocessed. As an optional implementation, all sample images are scaled to the same size on the short side, such as 224×224, and then the pixels of the sample images are normalized, that is, the pixels are mapped to between 0 and 1, thereby eliminating the influence of unit and scale differences in image features, and some color jittering operations are performed to enhance the color of the image by adjusting the brightness, saturation and contrast of the image to eliminate the differences in the image in different backgrounds, etc. Of course, this embodiment is not limited to the above data preprocessing operations.
[0051] S12. Input the sample image into a clothing classification model, where the clothing classification model is used to extract a first feature of the sample image, and process the first feature based on an attention mechanism to obtain a second feature, and process the second feature based on a residual attention mechanism to obtain a clothing classification result.
[0052] The sample image after the above preprocessing is input into the clothing classification model to obtain the clothing classification result. Specifically, the features of the sample image are extracted through the feature extraction network of the clothing classification model, such as ResNet50 (deep residual network). Of course, this embodiment is not limited to the above feature extraction network. Figure 2 As shown in the figure, the size of the sample image is 224×224, and the feature extraction network consists of a 7-layer deep self-attention transformation network, and finally a feature map (i.e., the first feature) with a dimension of 2048×7×7 is obtained.
[0053] Introduce the attention mechanism into the clothing classification model, and process the first feature based on the attention mechanism to obtain the second feature, such as CBAM (Convolutional Block Attention Module), see Figure 2, an attention mechanism is added after the convolution layer of the feature extraction network. The attention mechanism includes a channel attention module and a spatial attention module. The first feature is input to the channel attention module, and then global maximum pooling and global average pooling are performed respectively to obtain two 2048×1×1 feature maps. The two 2048×1×1 feature maps are respectively sent to the shared multi-layer perceptron neural network, and the addition operation and activation operation are performed respectively to obtain the output vector of the channel attention module. Then the output vector of the channel attention module is multiplied by the input 2048×7×7 dimension feature map to obtain a 2048×7×7 dimension feature map again. The feature map output by the channel attention module is used as the input feature map of the spatial attention module, and is divided into two feature maps of size 7×7×1 through maximum pooling and average pooling. The two are stacked together through concatenation operation and the channel is changed to 1 through convolution operation. Then the output vector of the spatial attention module is obtained through activation operation, and then the output vector of the spatial attention module is multiplied by the feature map output by the channel attention module to obtain the final generated feature map (i.e., the second feature). Of course, this embodiment is not limited to the above-mentioned attention mechanism.
[0054] Then, Residual Attention is introduced into the clothing classification model, and the second feature is processed based on the residual attention mechanism to obtain the clothing classification result. Figure 2 , a residual attention mechanism is added after the attention mechanism, such as CSRA (class-specific residual attention module), the features of the clothing classification label are learned through CSRA, the second feature is input to CSRA, global average pooling and global maximum pooling are performed respectively, the features obtained by the two different pooling methods are fused, and then the predicted probability of each clothing classification label (i.e., clothing classification result) is obtained through activation operation. Of course, this embodiment is not limited to the above-mentioned residual attention mechanism.
[0055] S13. Perform semantic segmentation on the portrait area in the sample image based on the MASK mechanism to obtain a target image.
[0056] As an optional implementation, the MASK mechanism is a model pre-trained by human parsing (human body parsing data set). The sample image is input into the pre-trained model to extract the semantic mask information of each body part of the human body, thereby obtaining an image of the portrait area. In order to avoid the interference of the face on the clothing classification, the semantic mask information of the face area is deducted, and finally the semantic mask information of the human clothing area is obtained (i.e., the target image), and then the target image is uniformly scaled to a size of 7×7. It should be noted that in this embodiment, the MASK mechanism is only used as a priori means and does not require learning parameters. Therefore, in the training stage of the clothing classification model, there is no need to extract the semantic mask information of the human clothing area through the MASK mechanism.
[0057] S14. Calculate the target loss based on the second feature, the target feature, the clothing classification result and the corresponding clothing classification label, and adjust the parameters of the clothing classification model according to the target loss until the convergence condition is met; wherein the target feature is obtained based on the target image and the first feature.
[0058] like Figure 2 As shown, the semantic mask information of the human clothing area (i.e., the target image) is multiplied element by element with the feature extracted by the feature extraction network (i.e., the first feature) by broadcasting, and the face area of the background area and the foreground area is filtered out to obtain the feature of only the human clothing area (i.e., the target feature). In this embodiment, the first feature is obtained by the attention mechanism to obtain the second feature, and the loss (i.e., the first loss) is calculated based on the second feature and the target feature. Specifically, the second feature and the target feature are substituted into the first loss function to calculate the first loss. The calculation formula of the first loss function is as follows:
[0059] L s =SmoothL1Loss(f a ,f m )
[0060] Among them, L s represents the first loss, f a represents the second feature obtained through the attention mechanism, f m Represents the target feature obtained with the help of the MASK mechanism. The first loss function is used to force the second feature obtained by the attention mechanism to continuously approach the target feature obtained with the help of the MASK mechanism, and finally the attention mechanism has the ability to actively focus on the human clothing area, so that the second feature can more effectively represent the characteristics of the human clothing area.
[0061] When training the clothing classification model, the cross entropy loss function is used to train the model, and the corresponding clothing classification result is obtained by learning the second feature through the residual attention mechanism. Then, the cross entropy loss (i.e., the second loss) is calculated based on the clothing classification result and the clothing classification label corresponding to the sample image. Since there is an imbalance problem of difficult and easy samples during the model training process, as an optional implementation method, a greater weight is given to difficult samples during the model training process, so that it focuses on learning and optimizing difficult samples. Specifically, the clothing classification result and the corresponding clothing classification label are substituted into the second loss function to calculate the second loss. The calculation formula of the second loss function is as follows:
[0062] L c =-(1-p i ) γ y i log(p i )-p iγ (1-y i )log(1-p i )
[0063] Among them, L c represents the second loss, γ is the difficult and easy sample weight parameter, and p i is the clothing classification result of the i-th clothing category predicted by the model, y i is the clothing classification label of the i-th clothing category. Specifically, p i is the predicted probability value from 0 to 1, y i The label value is "0" or "1".
[0064] The second loss function is the dominant function for training the clothing classification model. In the early stage of training, it is only necessary to back-propagate the second loss and adjust the parameters of the clothing classification model until the second loss converges. As an optional implementation, the back-propagation of the second loss adopts a momentum-based stochastic gradient descent method to accelerate convergence.
[0065] As the number of iterations of the dress classification model training increases, the second loss gradually converges, and the first loss is introduced to further adjust the parameters of the dress classification model. The first loss enhances the features that are more useful for the dress classification task and suppresses the features that are useless for the dress classification task. The first loss and the second loss are combined to obtain the total loss (i.e., the target loss) of the dress classification model. By back-propagating the target loss, the parameters of the dress classification model are adjusted until the dress classification model meets the convergence condition. As an optional implementation, the convergence condition may be that the target loss is less than a preset threshold, and a relatively small loss threshold is pre-set. When the target loss is less than the set loss threshold, the dress classification model is determined to converge; as another optional implementation, the convergence condition may also be that the number of iterations of the dress classification model training is greater than a preset number of iterations. By pre-setting a relatively large number of iterations, when the number of iterations of the dress classification model training is greater than the set maximum number of iterations, the dress classification model is determined to converge.
[0066] As an optional implementation, when the first loss and the second loss are combined to calculate the target loss, a weight parameter α is set to coordinate the weights of the first loss function and the second loss function in the clothing classification model training. L represents the target loss, and its calculation formula is as follows:
[0067] L=L c +αL s
[0068] In the early stage of clothing classification model training, the value of α is set to 0. As the number of iterations of clothing classification model training increases, the value of α is gradually increased, and iterative training is continued, wherein the value of α is not greater than 1. Until the value of the target loss L is minimized, it is determined that the clothing classification model converges.
[0069] This embodiment performs semantic segmentation through the MASK mechanism to assist the clothing classification model in learning to distinguish the foreground, i.e., the portrait area, from the background, thereby reducing the difficulty of clothing model training and allowing the attention mechanism of the clothing classification model to effectively learn the foreground area of human clothing, filter out background interference, and thus better characterize the characteristics of various clothing attributes themselves, thereby accurately and efficiently achieving the multi-label classification task of human clothing. In addition, by designing the first loss function and the second loss function to jointly optimize the model, it is ensured that the clothing classification model can converge to the optimal solution more stably, thereby greatly improving the accuracy of clothing classification.
[0070] Example 2
[0071] This embodiment provides another method for training a clothing classification model, which is a further improvement of Embodiment 1.
[0072] See also Figure 1In step 14, in addition to calculating the first loss based on the second feature and the target feature and calculating the second loss based on the clothing classification result and the clothing classification label corresponding to the sample image, the third loss is also calculated based on the clothing classification result and the clothing classification label corresponding to the sample image. Specifically, the clothing classification result and the corresponding clothing classification label are substituted into the third loss function to calculate the third loss. The third loss function is an auxiliary function of the second loss function (i.e., a regularization term). The calculation formula of the third loss function is as follows:
[0073]
[0074] Among them, L o represents the third loss, p i is the clothing classification result of the i-th clothing category predicted by the model, y i is the clothing classification label of the i-th clothing category. Specifically, p i is the predicted probability value from 0 to 1, y i The third loss function is used to strengthen the clothing classification model's attention to the clothing classification label of 1, ensuring that the clothing classification model is i The predicted probability of the clothing classification label of 1 is greater than 0.5.
[0075] The first loss, the second loss and the third loss are combined to obtain the total loss (i.e., the target loss) of the clothing classification model. By back-propagating the target loss, the parameters of the clothing classification model are adjusted until the clothing classification model meets the convergence conditions.
[0076] As an optional implementation, when the first loss, the second loss and the third loss are combined to calculate the target loss, their weights in the clothing classification model training need to be coordinated. The second loss function plays a dominant role in the clothing classification model training, while the first loss function and the third loss function are only used to fine-tune the model parameters, so the weights of the first loss function and the third loss function are relatively small; as the number of iterations of the clothing classification model training increases, the second loss gradually converges, and at this time the weights of the first loss function and the third loss function can be gradually increased, and the weight parameter α is set as the weight of the first loss function and the third loss function. The relationship between the number of iterations t of the clothing classification model training and the weight parameter α is as follows:
[0077]
[0078] Among them, T1 and T2 are the starting and stopping points of the linear change in the number of iterations of clothing classification model training, α f is the weight value of the clothing classification model after stabilization. As an optional implementation, α f The default value of is 1. During the training of the clothing classification model, α gradually increases with the increase of the number of iterations t.
[0079] As an optional implementation, the optimization goal of the clothing classification model is to minimize the target loss, and L is used to represent the target loss, and its calculation formula is as follows:
[0080] L=L c +α(L s +L o )
[0081] The target threshold of the target loss L is set, and iterative training is performed until the value of the target loss L is lower than the target threshold and the model parameters change very little, and it is determined that the clothing classification model converges.
[0082] This embodiment performs semantic segmentation through the MASK mechanism to assist the clothing classification model in learning to distinguish the foreground, i.e., the portrait area, from the background, thereby reducing the difficulty of training the clothing model and allowing the attention mechanism of the clothing classification model to effectively learn the foreground area of human clothing, filter out background interference, and thus better characterize the characteristics of various clothing attributes themselves, thereby accurately and efficiently achieving the multi-label classification task of human clothing. In addition, by designing the first loss function, the second loss function, and the third loss function to jointly optimize the model, it is ensured that the clothing classification model can converge to the optimal solution more stably, thereby greatly improving the accuracy of clothing classification.
[0083] Example 3
[0084] This embodiment provides a training device for a clothing classification model. Figure 3 As shown, the training device of the clothing classification model includes an acquisition module 21, a classification module 22, a segmentation module 23 and a training module 24.
[0085] The acquisition module 21 is used to acquire training samples, wherein the training samples include sample images and corresponding clothing classification labels.
[0086] In this embodiment, the training samples are specifically human clothing images (i.e., sample images) captured by the device or crawled from the network, and different clothing categories in the human clothing images are labeled (i.e., clothing classification labels). In order to better extract the features of the sample images, the acquisition module 21 preprocesses the sample images. As an optional implementation, the acquisition module 21 scales all sample images to the same short side size, such as 224×224, and then normalizes the pixels of the sample images, that is, the pixels are mapped to between 0 and 1, thereby eliminating the influence of unit and scale differences in image features, and performs some color jitter operations, by adjusting the brightness, saturation and contrast of the image to enhance the color of the image to eliminate the differences in the image in different backgrounds, etc. Of course, this embodiment is not limited to the above data preprocessing operations.
[0087] The classification module 22 is used to input the sample image into the clothing classification model. The clothing classification model is used to extract the first feature of the sample image, process the first feature based on the attention mechanism to obtain the second feature, and process the second feature based on the residual attention mechanism to obtain the clothing classification result.
[0088] The classification module 22 inputs the preprocessed sample image into the clothing classification model to obtain the clothing classification result. Specifically, the classification module 22 extracts the features of the sample image through the feature extraction network of the clothing classification model, such as ResNet50 (deep residual network). Of course, this embodiment is not limited to the above feature extraction network. Figure 2 As shown in the figure, the size of the sample image is 224×224, and the feature extraction network consists of a 7-layer deep self-attention transformation network, and finally a feature map (i.e., the first feature) with a dimension of 2048×7×7 is obtained.
[0089] The attention mechanism is introduced into the clothing classification model. The classification module 22 is used to process the first feature based on the attention mechanism to obtain the second feature, such as CBAM (convolutional block attention module), see Figure 2 , an attention mechanism is added after the convolution layer of the feature extraction network. The attention mechanism includes a channel attention module and a spatial attention module. The classification module 22 inputs the first feature to the channel attention module, and then undergoes global maximum pooling and global average pooling respectively to obtain two 2048×1×1 feature maps. The two 2048×1×1 feature maps are then sent to the shared multi-layer perceptron neural network, and the addition operation and activation operation are performed respectively to obtain the output vector of the channel attention module. The output vector of the channel attention module is then multiplied by the input 2048×7×7 dimension feature map to obtain a 2048×7×7 dimension feature map again. The feature map output by the channel attention module is used as the input feature map of the spatial attention module, and is divided into two feature maps of size 7×7×1 by maximum pooling and average pooling. The two are stacked together by concatenation operation and the channel is changed to 1 by convolution operation, and then the output vector of the spatial attention module is obtained by activation operation. The output vector of the spatial attention module is then multiplied by the feature map output by the channel attention module to obtain the final generated feature map (i.e., the second feature). Of course, this embodiment is not limited to the above-mentioned attention mechanism.
[0090] Then, Residual Attention is introduced into the clothing classification model. The classification module 22 is used to process the second feature based on the residual attention mechanism to obtain the clothing classification result. Figure 2, a residual attention mechanism is added after the attention mechanism, such as CSRA (class-specific residual attention module), and the features of the clothing classification label are learned through CSRA. The classification module 22 inputs the second feature to CSRA, performs global average pooling and global maximum pooling respectively, and fuses the features obtained by the two different pooling methods. Then, the predicted probability of each clothing classification label (i.e., the clothing classification result) is obtained through an activation operation. Of course, this embodiment is not limited to the above-mentioned residual attention mechanism.
[0091] The segmentation module 23 is used to perform semantic segmentation on the portrait area in the sample image based on the MASK mechanism to obtain a target image.
[0092] As an optional implementation, the MASK mechanism is a model pre-trained by human parsing (human body parsing data set). The segmentation module 23 inputs the sample image into the pre-trained model to extract the semantic mask information of each body part of the human body, thereby obtaining an image of the portrait area. In order to avoid the interference of the face on the clothing classification, the segmentation module 23 deducts the semantic mask information of the face area, and finally obtains the semantic mask information of the human clothing area (i.e., the target image), and then uniformly scales the target image to a size of 7×7. It should be noted that in this embodiment, the MASK mechanism is only used as a priori means and does not require learning parameters. Therefore, in the training stage of the clothing classification model, there is no need to extract the semantic mask information of the human clothing area through the MASK mechanism.
[0093] The training module 24 is used to calculate the target loss based on the second feature, the target feature, the clothing classification result and the corresponding clothing classification label, and adjust the parameters of the clothing classification model according to the target loss until the convergence condition is met; wherein the target feature is obtained based on the target image and the first feature.
[0094] like Figure 2 As shown, the training module 24 multiplies the semantic mask information of the human clothing area (i.e., the target image) by the feature extracted by the feature extraction network (i.e., the first feature) element by element through broadcasting, filters out the face area of the background area and the foreground area, and obtains the feature of only the human clothing area (i.e., the target feature). In this embodiment, the classification module 22 obtains the second feature from the first feature through the attention mechanism, and the training module 24 calculates the loss (i.e., the first loss) based on the second feature and the target feature. Specifically, the second feature and the target feature are substituted into the first loss function to calculate the first loss. The calculation formula of the first loss function is as follows:
[0095] L s =SmoothL1Loss(f a ,f m )
[0096] Among them, L s represents the first loss, f a represents the second feature obtained through the attention mechanism, f m The training module 24 uses the first loss function to force the second feature obtained by the attention mechanism to continuously approach the target feature obtained by the MASK mechanism, and finally enables the attention mechanism to actively focus on the human clothing area, so that the second feature can more effectively represent the characteristics of the human clothing area.
[0097] When training the clothing classification model, the training module 24 uses the cross entropy loss function to train the model, and the classification module 22 learns the second feature through the residual attention mechanism to obtain the corresponding clothing classification result. Then the training module 24 calculates the cross entropy loss (i.e., the second loss) based on the clothing classification result and the clothing classification label corresponding to the sample image. Due to the imbalance problem of difficult and easy samples in the model training process, as an optional implementation method, a greater weight is given to difficult samples during the model training process, so that it focuses on learning and optimizing difficult samples. Specifically, the clothing classification result and the corresponding clothing classification label are substituted into the second loss function to calculate the second loss. The calculation formula of the second loss function is as follows:
[0098] L c =-(1-p i ) γ y i log(p i )-p iγ (1-y i )log(1-p i )
[0099] Among them, L c represents the second loss, γ is the difficult and easy sample weight parameter, and p i is the clothing classification result of the i-th clothing category predicted by the model, y i is the clothing classification label of the i-th clothing category. Specifically, p i is the predicted probability value from 0 to 1, y i The label value is "0" or "1".
[0100] The second loss function is the dominant function for training the clothing classification model. In the initial stage of training, the training module 24 only needs to back-propagate the second loss and adjust the parameters of the clothing classification model until the second loss converges. As an optional implementation, the back-propagation of the second loss adopts a momentum-based stochastic gradient descent method to accelerate convergence.
[0101] As the number of iterations of the dress classification model training increases, the second loss gradually converges, and the training module 24 introduces the first loss to further adjust the parameters of the dress classification model. The first loss enhances the features that are more useful for the dress classification task and suppresses the features that are useless for the dress classification task. The first loss and the second loss are combined to obtain the total loss (i.e., the target loss) of the dress classification model. The training module 24 adjusts the parameters of the dress classification model by back-propagating the target loss until the dress classification model meets the convergence condition. As an optional embodiment, the convergence condition may be that the target loss is less than a preset threshold value, and a relatively small loss threshold value is pre-set. When the target loss is less than the set loss threshold value, the dress classification model is determined to converge; as another optional embodiment, the convergence condition may also be that the number of iterations of the dress classification model training is greater than a preset number of iterations. By pre-setting a relatively large number of iterations, when the number of iterations of the dress classification model training is greater than the set maximum number of iterations, the dress classification model is determined to converge.
[0102] As an optional implementation, when the training module 24 calculates the target loss by combining the first loss and the second loss, it sets the weight parameter α to coordinate the weights of the first loss function and the second loss function in the clothing classification model training, and L represents the target loss, and its calculation formula is as follows:
[0103] L=L c +αL s
[0104] In the early stage of clothing classification model training, the value of α is set to 0. As the number of iterations of clothing classification model training increases, the value of α is gradually increased, and iterative training is continued, wherein the value of α is not greater than 1. Until the value of the target loss L is minimized, it is determined that the clothing classification model converges.
[0105] Example 4
[0106] This embodiment provides another training device for a clothing classification model, which is a further improvement of Embodiment 3.
[0107] In addition to calculating the first loss based on the second feature and the target feature and calculating the second loss based on the clothing classification result and the clothing classification label corresponding to the sample image, the training module 24 is also used to calculate the third loss based on the clothing classification result and the clothing classification label corresponding to the sample image. Specifically, the training module 24 substitutes the clothing classification result and the corresponding clothing classification label into the third loss function to calculate the third loss. The third loss function is an auxiliary function (i.e., a regularization term) of the second loss function. The calculation formula of the third loss function is as follows:
[0108]
[0109] Among them, L o represents the third loss, p i is the clothing classification result of the i-th clothing category predicted by the model, y i is the clothing classification label of the i-th clothing category. Specifically, p i is the predicted probability value from 0 to 1, y i The third loss function is used to strengthen the clothing classification model's attention to the clothing classification label of 1, ensuring that the clothing classification model is i The predicted probability of the clothing classification label of 1 is greater than 0.5.
[0110] The training module 24 combines the first loss, the second loss and the third loss to obtain the total loss (ie, the target loss) of the clothing classification model, and adjusts the parameters of the clothing classification model by back-propagating the target loss until the clothing classification model meets the convergence conditions.
[0111] As an optional implementation, when the training module 24 calculates the target loss by combining the first loss, the second loss and the third loss, it is necessary to coordinate their weights in the clothing classification model training. The second loss function plays a dominant role in the clothing classification model training, while the first loss function and the third loss function are only used to fine-tune the model parameters, so the weights of the first loss function and the third loss function are relatively small; as the number of iterations of the clothing classification model training increases, the second loss gradually converges, and at this time the weights of the first loss function and the third loss function can be gradually increased, and the weight parameter α is set as the weight of the first loss function and the third loss function. The relationship between the number of iterations t of the clothing classification model training and the weight parameter α is as follows:
[0112]
[0113] Among them, T1 and T2 are the starting and stopping points of the linear change in the number of iterations of clothing classification model training, α f is the weight value of the clothing classification model after stabilization. As an optional implementation, α f The default value of is 1. During the training of the clothing classification model, α gradually increases with the increase of the number of iterations t.
[0114] As an optional implementation, the optimization goal of the clothing classification model is to minimize the target loss, and L is used to represent the target loss, and its calculation formula is as follows:
[0115] L=L c +αL s +βL o
[0116] The target threshold of the target loss L is set, and iterative training is performed until the value of the target loss L is lower than the target threshold and the model parameters change very little, and it is determined that the clothing classification model converges.
[0117] Example 5
[0118] This embodiment provides a clothing classification method, such as Figure 4 As shown, the clothing classification method comprises the following steps:
[0119] S31. Obtain an image to be classified, where the image to be classified contains clothing information.
[0120] Among them, the clothing information includes the portrait and the clothes worn by the portrait, including but not limited to hats, tops, pants, shoes, scarves, skirts, etc. In actual applications, clothing labels are further divided according to attributes such as type, material, color, etc., such as a red shirt, black high heels or a white skirt, etc. Of course, this embodiment is not limited to the above-mentioned clothing labels.
[0121] S32, performing clothing classification processing on the image to be classified by using the clothing classification model to obtain a clothing classification result of the image to be classified.
[0122] The clothing classification model is obtained by the training method of the clothing classification model of Example 1 or Example 2, and the clothing classification processing includes but is not limited to scenes involving classification such as clothing detection, clothing recognition or clothing data tracking. Assuming that the clothing information in an image to be classified includes a red shirt, black high heels or a white skirt, the image is input into the clothing classification model, and the clothing classification result of the image can be obtained, that is, the hat is not, the top is a red shirt, the pants are not, the shoes are black high heels, the scarf is not, and the skirt is a white skirt.
[0123] In this embodiment, since the clothing classification model used for clothing classification processing is obtained through the training method of the clothing classification model of Example 1 or Example 2, when the clothing classification model is applied to a specific clothing classification task, the clothing classification result outputted by the clothing classification model will also be more accurate.
[0124] Example 6
[0125] This embodiment provides a clothing classification device, such as Figure 5 As shown, the clothing classification device includes a to-be-classified image acquisition module 41 and a classification processing module 42.
[0126] The image acquisition module 41 is used to acquire the image to be classified, and the image to be classified includes clothing information. The clothing information includes the portrait and the clothing worn by the portrait, including but not limited to hats, tops, pants, shoes, scarves, skirts, etc. In actual applications, the image acquisition module 41 further divides clothing labels according to attributes such as type, material, color, etc., such as red shirts, black high heels or white skirts, etc. Of course, this embodiment is not limited to the above clothing labels.
[0127] The classification processing module 42 is used to perform clothing classification processing on the image to be classified through the clothing classification model to obtain the clothing classification result of the image to be classified. Among them, the clothing classification model is obtained by the training method of the clothing classification model of Example 1 or Example 2, and the clothing classification processing includes but is not limited to clothing detection, clothing recognition or clothing data tracking and other scenes involving classification. Assuming that the clothing information in an image to be classified includes a red shirt, black high heels or a white skirt, the image is input into the clothing classification model, and the clothing classification result of the image can be obtained that the hat is not, the top is a red shirt, the pants are not, the shoes are black high heels, the scarf is not, and the skirt is a white skirt.
[0128] Example 7
[0129] This embodiment provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the training method of the clothing classification model of Embodiment 1 or Embodiment 2 and the clothing classification method of Embodiment 5 are implemented.
[0130] like Figure 6 The electronic device 50 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0131] The electronic device 50 may be in the form of a general-purpose computing device, for example, it may be a server device. The components of the electronic device 50 may include, but are not limited to: at least one processor 51, at least one memory 52, and a bus 53 connecting different system components (including the memory 52 and the processor 51).
[0132] The bus 53 includes a data bus, an address bus, and a control bus.
[0133] The memory 52 may include a volatile memory, such as a random access memory (RAM) 521 and a cache memory 522 , and may further include a read only memory (ROM) 523 .
[0134] The memory 52 may also include a program tool 525 having a set (at least one) of program modules 524, such program modules 524 including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include the implementation of a network environment.
[0135] The processor 51 executes various functional applications and data processing by running the computer program stored in the memory 52, such as the training method of the clothing classification model of Example 1 or Example 2 and the clothing classification method of Example 5.
[0136] The electronic device 50 may also communicate with one or more external devices 54. Such communication may be performed via an input / output (I / O) interface 55. Furthermore, the model generating device 50 may also communicate with one or more networks via a network adapter 56. Figure 6 As shown, the network adapter 56 communicates with other modules of the model generation device 50 via the bus 53. It should be understood that although Figure 6 Not shown, other hardware and / or software modules may be used in conjunction with the model generated device 50, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems.
[0137] It should be noted that although several units / modules or sub-units / modules of the electronic device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be embodied.
[0138] Example 8
[0139] This embodiment provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the training method of the clothing classification model of Embodiment 1 or Embodiment 2 and the clothing classification method of Embodiment 5 are implemented.
[0140] The readable storage medium may include but is not limited to: a portable disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical storage device, a magnetic storage device or any suitable combination of the above.
[0141] In an optional embodiment, the present invention can also be implemented in the form of a program product, which includes a program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the training method of the clothing classification model of Example 1 or Example 2 and the clothing classification method of Example 5.
[0142] The program code for executing the present invention may be written in any combination of one or more programming languages, and may be executed entirely on a user device, partially on a user device, as an independent software package, partially on a user device and partially on a remote device, or entirely on a remote device.
[0143] Although the specific embodiments of the present invention are described above, it should be understood by those skilled in the art that this is only for illustration and the protection scope of the present invention is defined by the appended claims. Those skilled in the art may make various changes or modifications to these embodiments without departing from the principles and essence of the present invention, but these changes and modifications all fall within the protection scope of the present invention.
Claims
1. A method for training a clothing classification model, characterized in that: The following steps are involved: Acquire a training sample, wherein the training sample includes a sample image and a corresponding clothing classification label; Inputting the sample image into a clothing classification model, the clothing classification model is used to extract a first feature of the sample image, and process the first feature based on an attention mechanism to obtain a second feature, and process the second feature based on a residual attention mechanism to obtain a clothing classification result; Performing semantic segmentation on the portrait area in the sample image based on the MASK mechanism to obtain a target image; Calculating a target loss based on the second feature, the target feature, the clothing classification result and the corresponding clothing classification label, and adjusting the parameters of the clothing classification model according to the target loss until a convergence condition is met; wherein the target feature is obtained based on the target image and the first feature; The step of calculating the target loss based on the second feature, the target feature, the clothing classification result and the corresponding clothing classification label specifically includes: Calculate a first loss based on the second feature and the target feature; Calculating a second loss based on the clothing classification result and the corresponding clothing classification label; determining the target loss according to the first loss and the second loss; The step of obtaining the target feature based on the target image and the first feature comprises: The target image is multiplied element by element by the first feature in a broadcasting manner, and the face areas in the background area and the foreground area are filtered to obtain the target feature.
2. The training method of the clothing classification model according to claim 1, characterized in that: The step of calculating the first loss based on the second feature and the target feature specifically includes: Substituting the second feature and the target feature into the first loss function to obtain a first loss; The first loss function is used to force the second feature to continuously approach the target feature.
3. The training method of the clothing classification model according to claim 1, characterized in that: The step of calculating the target loss based on the second feature, the target feature, the clothing classification result and the corresponding clothing classification label specifically includes: Calculate a first loss based on the second feature and the target feature; Substituting the clothing classification result and the corresponding clothing classification label into a second loss function to calculate a second loss; Substituting the clothing classification result and the corresponding clothing classification label into a third loss function to calculate a third loss; the third loss function is a regularization term of the second loss function; A target loss is determined according to the first loss, the second loss, and the third loss.
4. The method for training a clothing classification model according to claim 1, characterized in that: The step of performing semantic segmentation on the portrait area in the sample image based on the MASK mechanism to obtain the target image comprises: Performing semantic segmentation on the portrait region in the sample image based on the MASK mechanism to obtain an intermediate image; Perform semantic segmentation on the non-face area in the intermediate image to obtain a target image.
5. A training device for a clothing classification model, characterized in that: include: An acquisition module, used to acquire training samples, wherein the training samples include sample images and corresponding clothing classification labels; a classification module, configured to input the sample image into a clothing classification model, wherein the clothing classification model is configured to extract a first feature of the sample image, process the first feature based on an attention mechanism to obtain a second feature, and process the second feature based on a residual attention mechanism to obtain a clothing classification result; A segmentation module, used for performing semantic segmentation on the portrait area in the sample image based on a MASK mechanism to obtain a target image; a training module, configured to calculate a target loss based on the second feature, the target feature, the clothing classification result and the corresponding clothing classification label, and adjust the parameters of the clothing classification model according to the target loss until a convergence condition is met; wherein the target feature is obtained based on the target image and the first feature; The training module is also used to multiply the target image by the first feature element by element in a broadcasting manner, filter the face area in the background area and the foreground area, and obtain the target feature; The training module is also used to calculate a first loss based on the second feature and the target feature, calculate a second loss based on the clothing classification result and the corresponding clothing classification label, and determine the target loss based on the first loss and the second loss.
6. A clothing classification method, characterized in that: The following steps are involved: Acquire an image to be classified, wherein the image to be classified includes clothing information; The image to be classified is subjected to clothing classification processing by means of a clothing classification model to obtain a clothing classification result of the image to be classified, wherein the clothing classification model is obtained by means of a training method for a clothing classification model as described in any one of claims 1 to 4.
7. A clothing classification device, characterized in that: include: An image acquisition module to be classified is used to acquire an image to be classified, wherein the image to be classified contains clothing information; A classification processing module is used to perform clothing classification processing on the image to be classified through a clothing classification model to obtain a clothing classification result of the image to be classified, wherein the clothing classification model is obtained by the training method of the clothing classification model as described in any one of claims 1 to 4.
8. An electronic device, characterized in that: It comprises a memory and a processor connected to the memory, and when the processor executes a computer program stored in the memory, it implements the training method of the clothing classification model described in any one of claims 1 to 4 or the clothing classification method described in claim 6.
9. 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 training method of the clothing classification model described in any one of claims 1 to 4 or the clothing classification method described in claim 6.
