Image label classification network training method, image label classification method and device
By adjusting the weight of the loss value, the problem of low classification accuracy caused by missing labels in the multi-label classification network is solved, and the accuracy of the image label classification network is improved.
Patent Information
- Application Number
- CN202210266515.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-17
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2042-03-17
AI Technical Summary
In multi-label classification networks, the phenomenon of missing labels leads to low classification accuracy of image label classification networks, and it is difficult for existing technologies to effectively solve this problem.
By inputting the sample image into the initial image label classification network, the loss value of the first sample label and the second sample label is determined, and the loss value weight is adjusted according to the classification result of the first sample label to reduce the loss value of negative samples with missing labels. contribution to train the initial image label classification network.
It effectively reduces the sensitivity of the image label classification network to the phenomenon of missing labels and improves the label classification accuracy of the image label classification network.
Smart Images

Figure CN114723987B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information technology, and more specifically, to a training method for an image label classification network, an image label classification method, a device, an electronic device, and a readable storage medium. Background Art
[0002] Multi-Label Classification is a technology that identifies multiple objects in an image and sets corresponding labels. As a basic technology in the field of computer vision in artificial intelligence, it is widely used in scenarios such as target detection and semantic segmentation.
[0003] Missing label refers to the phenomenon that when a sample image includes an object corresponding to a sample label, the annotator forgets to use the sample label to mark the sample image, causing the sample image to become a negative sample of the sample label.
[0004] In the training process of the image label classification network corresponding to multiple labels, label missing phenomenon is inevitable, resulting in low classification accuracy of the trained image label classification network. Summary of the invention
[0005] In view of this, embodiments of the present application provide a training method for an image label classification network, an image label classification method, a device, an electronic device, and a readable storage medium.
[0006] In a first aspect, an embodiment of the present application provides a training method for an image label classification network, the method comprising: inputting a sample image into an initial image label classification network, obtaining sample label classification results corresponding to multiple sample labels output by the initial image label classification network, the multiple sample labels being divided into a first sample label that takes the sample image as a negative sample and a second sample label that takes the sample image as a positive sample; determining a loss value of the label classification result of the first sample label as a first loss value, and determining a loss value of the label classification result of the second sample label as a second loss value; adjusting the first loss value according to a weight corresponding to the first loss value to obtain a third loss value, the weight being determined according to the sample label classification result corresponding to the first sample label, and the weight being used to reduce the contribution of negative samples with missing labels to the loss value; training the initial image label classification network according to the second loss value and the third loss value to obtain an image label classification network.
[0007] In a second aspect, an embodiment of the present application provides an image label classification method, the method comprising: obtaining an image to be classified; inputting the image to be classified into a trained image label classification network obtained using the method of the first aspect above, to obtain a label classification result of the image to be classified.
[0008] In a third aspect, an embodiment of the present application provides a training device for an image label classification network, the device comprising: a sample image label classification module, used to input a sample image into an initial image label classification network, and obtain sample label classification results corresponding to multiple sample labels output by the initial image label classification network, wherein the multiple sample labels are divided into a first sample label that takes the sample image as a negative sample and a second sample label that takes the sample image as a positive sample; a loss value determination module, used to determine the loss value of the label classification result of the first sample label as the first loss value, and determine the loss value of the label classification result of the second sample label as the second loss value; a loss value adjustment module, used to adjust the first loss value according to a weight corresponding to the first loss value to obtain a third loss value, wherein the weight is determined according to the sample label classification result corresponding to the first sample label, and the weight is used to reduce the contribution of negative samples with missing labels to the loss value; a network training module, used to train the initial image label classification network according to the second loss value and the third loss value to obtain an image label classification network.
[0009] In a fourth aspect, an embodiment of the present application provides an image label classification device, the device comprising: an image acquisition module, used to acquire an image to be classified; an image label classification module, used to input the image to be classified into a trained image label classification network obtained using the method of the first aspect above, to obtain a label classification result of the image to be classified.
[0010] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory; one or more programs are stored in the memory and configured to be executed by the processor to implement the above method.
[0011] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a program code is stored, wherein the above method is executed when the program code is executed by a processor.
[0012] In a seventh aspect, an embodiment of the present application provides a computer program product or a computer program, the computer program product or the computer program including computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the above method.
[0013] The technical solution provided in the embodiments of the present application can bring the following beneficial effects:
[0014] The first loss value is adjusted according to the weight corresponding to the first loss value to obtain a third loss value, wherein the weight is determined according to the sample label classification result corresponding to the first sample label, and the weight is used to reduce the contribution of negative samples with missing labels to the loss value, and the first loss value is the loss value of the label classification result of the first sample label, and the first sample label is a sample label that uses the sample image as a negative sample among multiple sample labels. In the present application, the initial image label classification network is trained by the adjusted third loss value corresponding to the first loss value, which effectively reduces the sensitivity of the initial image label classification network to the label missing phenomenon during the training process, thereby improving the label classification accuracy of the image label classification network obtained by training. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0016] Figure 1 A flowchart of a training method for an image label classification network provided in an embodiment of the present application is shown;
[0017] Figure 2 A flow chart of a method for obtaining the third loss value in an embodiment of the present application is shown;
[0018] Figure 3 A curve diagram showing the relationship between the predicted probability and the gradient of a sample image in an embodiment of the present application is shown;
[0019] Figure 4 A flow chart of a method for obtaining the second loss value in an embodiment of the present application is shown;
[0020] Figure 5 A curve diagram showing the relationship between the predicted probability and the gradient of another sample image in an embodiment of the present application is shown;
[0021] Figure 6 A flowchart of another method for training an image label classification network provided in an embodiment of the present application is shown;
[0022] Figure 7 A flowchart of an image label classification method provided by an embodiment of the present application is shown;
[0023] Figure 8 A schematic diagram of a training device for an image label classification network provided in an embodiment of the present application is shown;
[0024] Fig. 9A schematic diagram of an image label classification device provided in an embodiment of the present application is shown;
[0025] Fig.10 A schematic diagram of an electronic device provided in an embodiment of the present application is shown;
[0026] Fig.11 A schematic diagram of a computer-readable storage medium provided by an embodiment of the present application is shown. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0028] Multi-label classification is a technology that identifies multiple objects in an image and sets corresponding labels. As a basic technology in the field of computer vision in artificial intelligence, it is widely used in scenarios such as target detection and semantic segmentation. A label can refer to a certain category of things, for example, a person can be counted as a label, a cat can be counted as a label, and a dog can also be counted as a label.
[0029] Missing labels refers to the phenomenon that when labeling a sample image, the sample image includes an object corresponding to a certain label, but the object is omitted when the labeler labels the sample image. For each image, ideally, the labeler should make an independent judgment on whether the object corresponding to each label exists in the image. When the number of labels reaches hundreds or thousands, this is almost impossible, so there will definitely be varying degrees of missing labels in the sample images.
[0030] When a label does not exist in a sample image, the sample image is a negative sample image of the label. However, in fact, the sample image may include two situations: the object corresponding to the label does not exist in the image, and the object corresponding to the label exists in the image but is missed.
[0031] Therefore, in the training process of the image label classification network corresponding to multiple labels, the phenomenon of missing labels is inevitable. The sample images corresponding to missing labels are actually positive sample images, but they will be trained as negative sample images by the image label classification network, which leads to a low classification accuracy of the image label classification network obtained through training.
[0032] In view of this, the embodiment of the present application provides a training method for an image label classification network, an image label classification method, a device, an electronic device and a readable storage medium. Specifically, a sample image is input into an initial image label classification network to obtain sample label classification results corresponding to multiple sample labels output by the initial image label classification network, wherein the multiple sample labels are divided into a first sample label that takes the sample image as a negative sample and a second sample label that takes the sample image as a positive sample; the loss value of the label classification result of the first sample label is determined as the first loss value, and the loss value of the label classification result of the second sample label is determined as the second loss value; the first loss value is adjusted according to the weight corresponding to the first loss value to obtain a third loss value, wherein the weight is determined according to the sample label classification result corresponding to the first sample label, and the weight is used to reduce the contribution of negative samples with missing labels to the loss value; the initial image label classification network is trained according to the second loss value and the third loss value to obtain an image label classification network. In the present application, the initial image label classification network is trained by the adjusted third loss value corresponding to the first loss value, which effectively reduces the sensitivity of the initial image label classification network to the label missing phenomenon during the training process, thereby improving the label classification accuracy of the image label classification network obtained by training.
[0033] See also Figure 1 , Figure 1 A flowchart of a training method for an image label classification network provided in an embodiment of the present application is shown, which is used in an electronic device, and the method includes:
[0034] S110, inputting the sample image into the initial image label classification network, and obtaining sample label classification results corresponding to multiple sample labels output by the initial image label classification network, wherein the multiple sample labels are divided into a first sample label that takes the sample image as a negative sample and a second sample label that takes the sample image as a positive sample.
[0035] The sample image may include multiple objects, and the objects may be any objects, such as people, dogs, cats, and cars. The sample labels may indicate the categories of the objects included in the sample image. For example, the objects included in the sample image may be Chinese, black dogs, cats, and cars, and the corresponding sample labels may be people, dogs, cats, and cars.
[0036] In a possible implementation, the electronic device obtains sample images from a sample image set, wherein the number of sample labels corresponding to different sample images may be the same or different. In an illustrative example, the electronic device uses the public PASCAL VOC2007 dataset and the MSCOCO dataset as the sample image set.
[0037] The multiple sample labels may be all sample labels used for classification by the initial image label classification network, and the sample image may include objects corresponding to some of the multiple sample labels. When the sample image includes an object corresponding to a sample label, the sample image is a positive sample of the sample label, and when the sample image does not include an object corresponding to a sample label, the sample image is a negative sample of the sample label.
[0038] In the present application, the initial image label classification network can be an untrained network constructed based on a convolutional neural network. The user can set multiple sample labels that need to be classified based on needs, and then construct an initial image label classification network to classify multiple sample labels. After the electronic device inputs the sample image into the constructed initial image label classification network, the initial image label classification network outputs the sample label classification results of each of the multiple sample labels. The sample label classification result of a sample label can be the predicted probability of the object corresponding to the sample label in the sample image (the predicted probability is the probability that has not been normalized).
[0039] The sample image can be used as a positive sample of a part of the sample label (the second sample label): the sample image includes the object corresponding to the sample label, and the sample image can also be used as a negative sample of a part of the sample label (the first sample label): the sample image includes the object corresponding to the sample label.
[0040] For example, the sample image includes a person and a dog, and the sample labels include person, dog, and car. Then, person and dog are the second sample labels, and the sample image is a positive sample of person and dog; car is the first sample label, and the sample image is a negative sample of car. The sample image is input into the initial image label classification network to obtain the predicted probability of person, dog, and car in the sample image (this probability is the probability without normalization).
[0041] S120. Determine a loss value of a label classification result of the first sample label as a first loss value, and determine a loss value of a label classification result of the second sample label as a second loss value.
[0042] After obtaining the label classification result of the first sample label and the label classification result of the second sample label, the loss value of the label classification result of the first sample label can be determined as the first loss value according to the loss function, and the loss value of the label classification result of the second sample label can be determined as the second loss value.
[0043] In the present application, the loss function may be a BCE loss function (Binary Cross Entropy), a Focal loss function or an ASL loss function.
[0044] Among them, the BCE loss function is expressed as follows:
[0045]
[0046] in, is the loss value of the positive sample, is the loss value of the negative sample, and p is the predicted probability of the normalized label classification result corresponding to the sample image.
[0047]
[0048] The Focal loss function is an improvement on BCE. It is used to solve the problem of imbalance between positive and negative samples and adds a difficult sample mining mechanism:
[0049]
[0050] When the parameter γ>0, the weight of difficult samples (samples with a prediction probability lower than 0.2 are called difficult samples, and samples with a prediction probability between 0.3 and 0.5 are called semi-difficult samples) is larger, which plays a role in mining difficult samples. The parameter α + and α - The numerical relationship used to balance the two parts of loss.
[0051] The ASL loss function is an improvement on Focal in recent years. It can reduce the impact of the imbalance of positive and negative samples and is defined as:
[0052]
[0053] Among them, γ + <γ - are the parameters of positive and negative samples respectively. Let m be a probability threshold, p m Expressed as max(pm,0).γ + <γ - The weight of simple negative samples is reduced. In addition, through the setting of m, the loss caused by negative samples with very low prediction probability is discarded.
[0054] S130. Adjust the first loss value according to the weight corresponding to the first loss value to obtain a third loss value, where the weight is determined according to the sample label classification result corresponding to the first sample label, and the weight is used to reduce the contribution of negative samples with missing labels to the loss value.
[0055] Since the sample image may have missing labels, and at the same time, when the traditional loss function is used as the loss function of the initial image label classification network, the initial image label classification network is relatively sensitive to the missing labels, resulting in poor classification accuracy of the image label classification network obtained after directly using the first loss value corresponding to the sample image to train the initial image label classification network. In this embodiment, the weight is determined according to the sample label classification result corresponding to the first sample label, and then the first loss value is adjusted according to the weight, so that when the initial image label classification network is trained according to the third loss value obtained after the adjustment, the image label classification network obtained is insensitive to missing labels, thereby improving the classification accuracy of the image label classification network obtained by training.
[0056] In the present application, the weight of the sample label classification result corresponding to the first sample label can be determined according to the sample label classification result corresponding to the first sample label, and then the first loss value is adjusted according to the weight to obtain the adjusted first loss value as the third loss value.
[0057] Optionally, a method for obtaining the weight of a sample label classification result corresponding to a first sample label includes: normalizing the label classification result corresponding to the first sample label through a normalization function to obtain a label classification probability of the label classification result corresponding to the first sample label; and using the difference between a preset value and the label classification probability as a weight.
[0058] In the present application, the normalization function may be a Sigmoid function, and the label classification result of the first sample label is normalized by the Sigmoid function to obtain a label classification probability in the interval (0,1) (the label classification probability of the first sample label also refers to the predicted probability corresponding to the first sample label), and then the difference between the label classification probability and the preset value is used as the weight. In the present application, the preset value may be 1.5.
[0059] In the early stage of the training process of the initial image label classification network, the initial image label classification network can distinguish which samples are missing labels with a higher accuracy and a lower recall rate. That is to say, if a preset value is defined, then when the predicted probability corresponding to the sample label classification result corresponding to the first sample label output by the initial image label classification network is greater than the preset value, the sample image may not be a negative sample of the first sample label, but a positive sample of the missing label corresponding to the first sample label. This is because, in multi-label learning, negative samples are far more than positive samples, and the positive and negative samples are seriously unbalanced, and the label missing problem will further aggravate this imbalance. In this case, if the initial image label classification network can still give a relatively high prediction probability, the credibility of this prediction probability should be relatively high. Through the method of the present application, according to the sample label classification result corresponding to the first sample label, the weight corresponding to the sample label classification result corresponding to the first sample label is determined, and the loss value of the sample label classification result corresponding to the first sample label is adjusted by the weight, thereby reducing the sensitivity of the adjusted loss value to the missing label.
[0060] S140. Train the initial image label classification network according to the second loss value and the third loss value to obtain an image label classification network.
[0061] In the present application, each sample label corresponds to a loss value, multiple first sample labels correspond to multiple third loss values one by one, and multiple second sample labels correspond to multiple second loss values one by one. After obtaining the loss values corresponding to each of the multiple sample labels, the loss values of each of the multiple sample labels are weighted and summed as the final loss value of the sample image, and the initial image label classification network is trained according to the final loss value to obtain the image label classification network.
[0062] In some embodiments, the sample images include a large number of sample images, and each sample image trains the initial image label classification network according to the methods S110-S140 of the present application. When the initial image label classification network converges during training, an image label classification network is obtained.
[0063] It can be understood that in this embodiment, when the sample image is a negative sample, the loss value of the corresponding label classification result can be adjusted by the method of the present application to obtain the corresponding adjusted loss value. When the sample image is a positive sample, the loss value of the corresponding label classification result can be solved by the traditional loss function.
[0064] For example, for a sample image A1, when it is a negative sample of a sample label A2, A1 is input into the initial image label classification network to obtain the sample label classification result A3 of the sample label A2 output by the initial image label classification network, and then the corresponding first loss value A4 and weight A5 are determined according to A3, and then A4 is adjusted by weight A5 to obtain the corresponding third loss value A6. When the sample image A1 is a negative sample of a sample label B1, A1 is input into the initial image label classification network to obtain the sample label classification result B2 of the sample label B1 output by the initial image label classification network, and then the corresponding second loss value B3 is determined according to B2. Finally, the initial image label classification network is trained according to the second loss value B3 and the third loss value A6.
[0065] In this embodiment, a sample image is input into an initial image label classification network to obtain sample label classification results corresponding to a plurality of sample labels output by the initial image label classification network, wherein the plurality of sample labels are divided into a first sample label that takes the sample image as a negative sample and a second sample label that takes the sample image as a positive sample; a loss value of the label classification result of the first sample label is determined as a first loss value, and a loss value of the label classification result of the second sample label is determined as a second loss value; the first loss value is adjusted according to a weight corresponding to the first loss value to obtain a third loss value, wherein the weight is determined according to the sample label classification result corresponding to the first sample label; the initial image label classification network is trained according to the second loss value and the third loss value to obtain an image label classification network. The initial image label classification network is trained by the adjusted third loss value corresponding to the first loss value, which effectively reduces the sensitivity of the initial image label classification network to the label missing phenomenon during the training process, thereby improving the label classification accuracy of the image label classification network obtained by training.
[0066] See also Figure 2 , Figure 2 A flow chart of a method for obtaining the third loss value in an embodiment of the present application is shown, which is used in an electronic device, and the method includes:
[0067] S210, determining the scalar product of the first loss value and the weight.
[0068] S220: Taking the inverse of the dot product as the third loss value.
[0069] In the present application, the method for determining the third loss value may refer to Formula 1, which is as follows:
[0070]
[0071] in, is the first loss value, ω(p1) is the weight, is the third loss value. Wherein, ω(p1)=λ-p1, p1 is the label classification probability of the label classification result of the first sample label, and λ is a preset value.
[0072] In the present application, the method for determining the first loss value includes: normalizing the label classification result corresponding to the first sample label through a normalization function to obtain the label classification probability of the label classification result corresponding to the first sample label; determining the mean square error of the label classification probability, and using the mean square error as the first loss value.
[0073] Therefore, in this application, is the mean square error of the label classification probability. Substitute the mean square error of the label classification probability into formula 1 to obtain formula 2, which is as follows:
[0074]
[0075] Among them, MSE is the mean square error of label classification probability.
[0076] See also Figure 3 , Figure 3 A curve diagram showing the relationship between the predicted probability and the gradient of a sample image in an embodiment of the present application is shown.
[0077] exist Figure 3 In , the horizontal axis represents the predicted probability of the sample image output by the initial image label classification network during the training process (the value obtained after normalizing the sample label classification result corresponding to the sample image output by the initial image label classification network), and the vertical axis is the gradient. Different line types represent the curves of the image label classification network corresponding to different loss functions. Among them, Figure 2 The loss functions involved include the traditional BCE loss function, Focal loss function, ASL loss function, MSE loss function (mean square error loss function) and Hill loss function, wherein the Hill loss function refers to a loss function that obtains a corresponding third loss value based on the label classification result of the first sample label through the method of the present application (the calculation process of the Hill loss function includes the process of obtaining a first loss value according to the label classification result of the first sample label, and the process of adjusting the first loss value according to the weight).
[0078] exist Figure 2 In , the higher the gradient of a certain prediction probability, the higher the importance the initial image label classification network attaches to the prediction probability. Figure 2 It can be seen that compared with the image label classification networks corresponding to various traditional loss functions, the image label classification network obtained according to the Hill loss function of the present application pays more attention to sample images with prediction probabilities in the range of 0.3-0.8. In other words, the image label classification network is less sensitive to missing labels.
[0079] See also Figure 4 , Figure 4 A flow chart of a method for obtaining a second loss value in an embodiment of the present application is shown. The method is used in an electronic device and includes:
[0080] S310 , preprocessing the label classification result corresponding to the second sample label according to a preset threshold to obtain a preprocessed label classification result.
[0081] The label classification result corresponding to the second sample label is similar in form to the label classification result corresponding to the first sample label. The label classification result corresponding to the second sample label may refer to the predicted probability that an object corresponding to the second sample label exists in the sample image, and the predicted probability is also an unnormalized value.
[0082] The preset threshold can be set by the user based on the needs, for example, the preset threshold is 0.5, 1 or 2. In the specific implementation of this application, the difference between the label classification result corresponding to the second sample label and the preset threshold can be used as the preprocessing label classification result. For example, the label classification result corresponding to the second sample label is C1, the preset threshold is C2, and the obtained preprocessing label classification result is C3 = C1-C2.
[0083] When the traditional loss function mines positive samples, a large number of semi-difficult positive samples with predicted probabilities between 0.3 and 0.5 corresponding to the sample label classification results are ignored. Therefore, in the present application, the label classification results corresponding to the second sample label are preprocessed by a preset threshold, and then the loss value of the preprocessed label classification results is determined, and the loss value of the preprocessed label classification results is used as the loss value of the label classification results corresponding to the second sample label, thereby achieving the purpose of efficiently mining semi-difficult positive samples with predicted probabilities between 0.3 and 0.5.
[0084] S320, determining a loss value corresponding to a preprocessing label classification result, and using the loss value of the preprocessing label classification result as a second loss value.
[0085] The electronic device determines a loss value of a preprocessing label classification result, and determines the loss value as a loss value of a sample label classification result corresponding to the second sample label.
[0086] Specifically, determining the loss value corresponding to the preprocessing label classification result includes: normalizing the preprocessing label classification result through a normalization function to obtain the preprocessing label classification probability corresponding to the preprocessing label classification result; and obtaining the loss value of the preprocessing label classification result based on the preprocessing label classification probability.
[0087] The normalization function of this embodiment may also be a Sigmoid function. The label classification result corresponding to the second sample label has not been normalized, and the label classification result corresponding to the second sample label is preprocessed according to a preset threshold, and the obtained preprocessed label classification result is also not normalized. The preprocessed label classification result may be normalized by a Sigmoid function to obtain a preprocessed label classification probability in the interval (0,1).
[0088] The loss value of the preprocessing label classification result can be obtained according to the preprocessing label classification probability through the traditional value loss solution method (such as any one of the BCE loss function, Focal loss function and ASL loss function).
[0089] The process of solving the second loss value in this embodiment can refer to Formula 3, which is as follows:
[0090]
[0091] Among them, p n =σ(xn), n is the preset threshold, is the second loss value, γ has the same meaning as γ of the Focal loss function, x is the sample label classification result corresponding to the second sample label, σ is the normalization function Sigmoid function, where the preprocessed sample label classification result z = xn.
[0092] See also Figure 5 , Figure 5 A curve diagram showing the relationship between prediction probability and gradient of another sample image in an embodiment of the present application is shown.
[0093] exist Figure 5 In , the horizontal axis represents the predicted probability corresponding to the sample image output by the initial image label classification network during the training process (the value obtained after normalizing the sample label classification result corresponding to the sample image output by the initial image label classification network), and the vertical axis is the gradient. Different line types represent the image label classification network curves corresponding to different loss functions. Among them, Figure 5 The loss functions involved include the traditional BCE loss function and the Focal margin loss function in this application.
[0094] Among them, the Focal margin loss function refers to a loss function that obtains the corresponding second loss value based on the label classification result of the second sample label through the method of the present application (the calculation process of the Focal margin loss function includes the process of obtaining the preprocessing label classification result according to the label classification result of the first sample label, and the process of solving the second loss value according to the preprocessing label classification result), n refers to the preset threshold value, when n=0, the Focal margin loss function becomes the traditional Focal loss function, Figure 5 Includes curves corresponding to the Focal margin loss function for four different n values.
[0095] exist Figure 5 In , the higher the gradient of a certain prediction probability, the higher the importance the initial image label classification network attaches to the prediction probability. Figure 5 It can be seen that compared with the image label classification networks corresponding to various traditional loss functions, the image label classification network obtained according to the focal margin loss function of the present application pays more attention to sample images with output probabilities in the range of 0.3-0.5; compared with n with a smaller value, the image label classification network corresponding to n with a larger value pays more attention to sample images with output probabilities in the range of 0.3-0.5, and the image label classification network also pays more attention to semi-difficult samples.
[0096] See also Figure 6 , Figure 6 A flowchart of another method for training an image label classification network provided in an embodiment of the present application is shown. The method can be used in an electronic device, and the method includes:
[0097] S410, inputting the sample image into the initial image label classification network, obtaining sample label classification results corresponding to multiple sample labels output by the initial image label classification network, wherein the multiple sample labels are divided into a first sample label that takes the sample image as a negative sample and a second sample label that takes the sample image as a positive sample;
[0098] S420, determining a loss value of a label classification result of the first sample label as a first loss value, and determining a loss value of a label classification result of the second sample label as a second loss value;
[0099] S430. Adjust the first loss value according to a weight corresponding to the first loss value to obtain a third loss value, where the weight is determined according to a classification result of a sample label corresponding to the first sample label.
[0100] Among them, the description of S410-S430 refers to the description of S110-S130 above, and will not be repeated here.
[0101] S440. Obtain a final loss value of the sample image according to the second loss value, the third loss value, and a weight coefficient corresponding to the second loss value, wherein the weight coefficient is determined based on the order of magnitude of the first dot product and the order of magnitude of the second dot product.
[0102] In this application, the final loss value of the sample image is determined based on the loss value corresponding to each sample label. Specifically, the calculation formula of the final loss value refers to Formula 4, which is as follows:
[0103]
[0104] Among them, α is the weight coefficient, is the final loss, K is the total number of sample labels, y i is the supervision of sample label i. When there is an object corresponding to sample label i in the sample image, and when the sample image is a positive sample of sample label i, is the loss value of sample label i - the second loss value. When the sample image is a negative sample of sample label i, is the loss value of sample label i - the third loss value. When there is an object corresponding to sample label i in the sample image, y i = 1, when there is no object corresponding to sample label i in the sample image, y i =0.
[0105] Based on Formula 4, we can know that when the sample image is a positive sample, y i =1, the loss value for sample label i is The second loss value; when the sample image is a negative sample, y i = 0, the loss value for sample label i is The third loss value.
[0106] In the specific implementation of the present application, the loss value of the first sample label (the sample label of the sample image as a negative sample) can be obtained according to the Hill loss function of the present application, and the loss value of the second sample label (the sample label of the sample image as a positive sample) can be obtained according to the traditional method (for example, through any one of the BCE loss function, Focal loss function and ASL loss function, the loss value of the second sample label is obtained based on the label classification result corresponding to the second sample label), and then the final loss value is obtained based on the loss value of the first sample label and the loss value of the second sample label.
[0107] In some embodiments, the loss value of the first sample label can also be obtained according to traditional methods (for example, through any one of the BCE loss function, the Focal loss function, and the ASL loss function, the loss value of the first sample label is obtained based on the label classification result corresponding to the first sample label), and the loss value of the second sample label is obtained according to the Focal margin loss function of the present application, and then the final loss value is obtained based on the loss value of the first sample label and the loss value of the second sample label.
[0108] After obtaining the final loss value of the sample image, the parameters of the initial image label classification network are adjusted according to the final loss value to obtain the trained image label classification network.
[0109] Referring to Table 1, Table 1 is a comparison table of the classification effects of the image label classification network obtained according to the method of the present application and the image label classification network obtained according to the traditional method. Table 1 is as follows:
[0110] Table 1
[0111]
[0112] Among them, BCE means that the BCE loss function is used to solve the loss value for both positive and negative samples; Focal+ means that the BCE loss function is used to solve the loss value for negative samples, and the Focal loss function is used to solve the loss value for positive samples; Focalmargin+ means that the BCE loss function is used to solve the loss value for negative samples, and the Focalmargin loss function of this application is used to solve the loss value for positive samples; Focal- means that the BCE loss function is used to solve the loss value for positive samples, and the Focal loss function is used to solve the loss value for negative samples; ALS- means that the BCE loss function is used to solve the loss value for positive samples, and the ALS loss function is used to solve the loss value for negative samples; Hill- means that the BCE loss function is used to solve the loss value for positive samples, and the Hill loss function of this application is used to solve the loss value for negative samples; Hill+Focalmargin means that the Hill loss function of this application is used to solve the loss value for positive samples, and the Focalmargin loss function is used to solve the loss value for negative samples.
[0113] Based on Table 1, it can be seen that by solving the corresponding loss values through the Hill loss function and / or Focalmargin loss function of the present application, the mAP score, OF1 score and CF1 score of the image label classification network obtained are all high. In other words, by solving the corresponding loss values through the Hill loss function and / or Focalmargin loss function of the present application, the label classification effect of the image label classification network obtained is better.
[0114] See also Figure 7, Figure 7 A flowchart of an image label classification method provided by an embodiment of the present application is shown. The method is used in an electronic device and includes:
[0115] S510, obtaining an image to be classified;
[0116] S520: Input the image to be classified into the trained image label classification network to obtain a label classification result of the image to be classified.
[0117] In the present application, the trained image label classification network may refer to the image label classification network obtained by training according to the above method of the present application.
[0118] The label classification result of the image to be classified may refer to the probability of each sample label included in the image to be classified. Schematically, the label classification result is: person (0.95), dog (0.90), cat (0.15), ..., lawn (0.01), car (0.001).
[0119] Similar to the training process of the image label classification network, the electronic device inputs the acquired target image into the image label classification network to obtain an output image label classification result.
[0120] In some embodiments, the electronic device inputs the acquired target image into the image label classification network to obtain an output image label classification result, and then normalizes the image label classification result to obtain a normalized image label classification result. The normalized image label classification result can be the label classification result output by S520.
[0121] See also Figure 8 , Figure 8 A schematic diagram of a training device for an image label classification network provided in an embodiment of the present application is shown, which is used in an electronic device. The device 800 includes:
[0122] A sample image label classification module 810 is used to input the sample image into the initial image label classification network to obtain sample label classification results corresponding to multiple sample labels output by the initial image label classification network, where the multiple sample labels are divided into a first sample label that takes the sample image as a negative sample and a second sample label that takes the sample image as a positive sample;
[0123] A loss value determination module 820 is used to determine a loss value of a label classification result of a first sample label as a first loss value, and to determine a loss value of a label classification result of a second sample label as a second loss value;
[0124] A loss value adjustment module 830 is used to adjust the first loss value according to a weight corresponding to the first loss value to obtain a third loss value, wherein the weight is determined according to the sample label classification result corresponding to the first sample label, and the weight is used to reduce the contribution of negative samples with missing labels to the loss value;
[0125] The network training module 840 is used to train the initial image label classification network according to the second loss value and the third loss value to obtain the image label classification network.
[0126] Optionally, the apparatus 800 further includes:
[0127] The weight acquisition module is used to normalize the label classification result corresponding to the first sample label through a normalization function to obtain the label classification probability of the label classification result corresponding to the first sample label; and use the difference between the preset value and the label classification probability as the weight.
[0128] Optionally, the loss value adjustment module 830 is further used to determine the scalar product of the first loss value and the weight; and take the inverse of the scalar product as the third loss value.
[0129] Optionally, the loss value determination module 820 is also used to normalize the label classification result corresponding to the first sample label through a normalization function to obtain the label classification probability of the label classification result corresponding to the first sample label; determine the mean square error of the label classification probability, and use the mean square error as the first loss value.
[0130] Optionally, the loss value determination module 820 is also used to preprocess the label classification result corresponding to the second sample label according to a preset threshold to obtain a preprocessed label classification result; determine the loss value corresponding to the preprocessed label classification result, and use the loss value of the preprocessed label classification result as the second loss value.
[0131] Optionally, the loss value determination module 820 is also used to normalize the preprocessed label classification result through a normalization function to obtain the preprocessed label classification probability corresponding to the preprocessed label classification result; based on the preprocessed label classification probability, obtain the loss value of the preprocessed label classification result.
[0132] Optionally, the network training module 840 is also used to obtain a final loss value of the sample image based on the second loss value, the third loss value and a weight coefficient corresponding to the second loss value, wherein the weight coefficient is determined based on the order of magnitude of the first scalar product and the order of magnitude of the second scalar product; and train the initial image label classification network according to the final loss value to obtain an image label classification network.
[0133] See also Fig. 9 , Fig. 9A schematic diagram of an image label classification device provided in an embodiment of the present application is shown, which is used in an electronic device. The device 900 includes:
[0134] An image acquisition module 910 is used to acquire an image to be classified;
[0135] The image label classification module 920 is used to input the image to be classified into the trained image label classification network to obtain the label classification result of the image to be classified.
[0136] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0137] In several embodiments provided in the present application, the coupling or direct coupling or communication connection between the modules shown or discussed may be an indirect coupling or communication connection through some interfaces, devices or modules, which may be electrical, mechanical or other forms.
[0138] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.
[0139] The following will be combined Fig.10 An electronic device provided by the present application is described.
[0140] See also Fig.10 , Fig.10 A schematic diagram of an electronic device provided in an embodiment of the present application is shown, based on the above-mentioned data display method.
[0141] The electronic device 1000 further includes a memory 1004 . The memory 1004 stores a program that can execute the contents of the aforementioned embodiments, and the processor 1002 can execute the program stored in the memory 1004 .
[0142] Among them, the processor 1002 may include one or more cores for processing data and a message matrix unit. The processor 1002 uses various interfaces and lines to connect the various parts of the entire electronic device 1000, and executes various functions and processes data of the electronic device 1000 by running or executing instructions, programs, code sets or instruction sets stored in the memory 1004, and calling data stored in the memory 1004. Optionally, the processor 1002 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 1002 can integrate one or more combinations of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 1002, but may be implemented separately through a communication chip.
[0143] The memory 1004 may include a random access memory (RAM) or a read-only memory (ROM). The memory 1004 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 1004 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function, instructions for implementing the following various method embodiments, etc. The data storage area may also store data (such as data to be recommended and operation methods) obtained by the electronic device 1000 during use.
[0144] The electronic device 1000 may also include a network module and a screen. The network module is used to receive and send electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, and thus communicate with a communication network or other devices, such as communicating with an audio playback device. The network module may include various conventional circuit components for performing these functions, such as antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, user identity modules (SIM) cards, memories, etc. The network module may communicate with various networks such as the Internet, corporate intranets, wireless networks, or communicate with other devices via wireless networks. The above-mentioned wireless networks may include cellular telephone networks, wireless local area networks, or metropolitan area networks. The screen may display interface content and perform data interaction.
[0145] In some embodiments, the electronic device 1000 may also include: a peripheral interface and at least one peripheral device. The processor 1002, the memory 1004 and the peripheral interface 1006 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral interface via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency component 1008, a positioning component 1012, a camera 1014, an audio component 1016, a display screen 1018 and a power supply 1022.
[0146] The peripheral interface 1006 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 1002 and the memory 1004. In some embodiments, the processor 1002, the memory 1004, and the peripheral interface 1006 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1002, the memory 1004, and the peripheral interface 1006 may be implemented on a separate chip or circuit board, which is not limited in the embodiments of the present application.
[0147] The radio frequency component 1008 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency component 1008 communicates with the communication network and other communication devices through electromagnetic signals. The radio frequency component 1008 converts the electrical signal into an electromagnetic signal for transmission, or converts the received electromagnetic signal into an electrical signal. Optionally, the radio frequency component 1008 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The radio frequency component 1008 can communicate with other terminals through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: the World Wide Web, a metropolitan area network, an intranet, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency component 1008 may also include circuits related to NFC (Near Field Communication), which is not limited in this application.
[0148] The positioning component 1012 is used to locate the current geographic location of the electronic device to implement navigation or LBS (Location Based Service). The positioning component 1012 can be a positioning component based on the US GPS (Global Positioning System), China's Beidou system or Russia's Galileo system.
[0149] Camera 1014 is used to capture images or videos. Optionally, camera 1014 includes a front camera and a rear camera. Usually, the front camera is arranged on the front panel of the electronic device 1000, and the rear camera is arranged on the back of the electronic device 1000. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize the panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, camera 1014 may also include a flash. The flash can be a monochrome temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.
[0150] The audio component 1016 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 1002 for processing, or input them into the RF component 1008 to achieve voice communication. For the purpose of stereo acquisition or noise reduction, there can be multiple microphones, which are respectively arranged at different parts of the electronic device 1000. The microphone can also be an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signal from the processor 1002 or the RF component 1008 into sound waves. The speaker can be a traditional film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio component 1014 may also include a headphone jack.
[0151] The display screen 1018 is used to display the UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 1018 is a touch display screen, the display screen 1018 also has the ability to collect touch signals on the surface or above the surface of the display screen 1018. The touch signal can be input to the processor 1002 as a control signal for processing. At this time, the display screen 1018 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 1018 can be one, and the front panel of the electronic device 1000 is set; in other embodiments, the display screen 1018 can be at least two, which are respectively set on different surfaces of the electronic device 1000 or are folded; in some other embodiments, the display screen 1018 can be a flexible display screen, which is set on the curved surface or folded surface of the electronic device 1000. Even, the display screen 1018 can also be set to a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 1018 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0152] The power supply 1022 is used to power various components in the electronic device 1000. The power supply 1022 can be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 1022 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery that is charged through a wired line, and a wireless rechargeable battery is a battery that is charged through a wireless coil. The rechargeable battery can also be used to support fast charging technology.
[0153] See also Fig.11 , Fig.11A schematic diagram of a computer-readable storage medium provided by an embodiment of the present application is shown. The computer-readable storage medium 1100 stores program code, which can be called by a processor to execute the method described in the above method embodiment.
[0154] The computer readable storage medium 1100 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer readable storage medium 1100 includes a non-transitory computer-readable storage medium. The computer readable storage medium 1100 has storage space for program code 1110 that executes any method step of the above method. These program codes can be read from or written to one or more computer program products. The program code 1110 can be compressed, for example, in an appropriate form.
[0155] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device performs the method described in the above various optional implementations.
[0156] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A training method for an image label classification network, It is characterized in that The method comprises: Inputting the sample image into an initial image label classification network, obtaining sample label classification results corresponding to a plurality of sample labels output by the initial image label classification network, wherein the plurality of sample labels are divided into a first sample label taking the sample image as a negative sample and a second sample label taking the sample image as a positive sample; Determine a loss value of a label classification result of the first sample label as a first loss value, and determine a loss value of a label classification result of the second sample label as a second loss value; Normalizing the label classification result corresponding to the first sample label by a normalization function to obtain the label classification probability of the label classification result corresponding to the first sample label; The difference between the preset value and the label classification probability is used as a weight, and the weight is used to reduce the contribution of negative samples with missing labels to the loss value; Determining a scalar product of the first loss value and the weight; Using the inverse of the dot product as a third loss value; The initial image label classification network is trained according to the second loss value and the third loss value to obtain an image label classification network.
2. The method according to claim 1, It is characterized in that The determining, as a first loss value, a loss value of a label classification result of the first sample label includes: Normalizing the label classification result corresponding to the first sample label by a normalization function to obtain a label classification probability of the label classification result corresponding to the first sample label; Determine a mean square error of the label classification probability, and use the mean square error as the first loss value.
3. The method according to claim 1, It is characterized in that The determining the loss value of the label classification result of the second sample label as the second loss value includes: Preprocessing the label classification result corresponding to the second sample label according to a preset threshold to obtain a preprocessed label classification result; Determine a loss value corresponding to the preprocessing label classification result, and use the loss value of the preprocessing label classification result as the second loss value.
4. The method according to claim 3, It is characterized in that The determining of the loss value corresponding to the preprocessing label classification result includes: Normalizing the preprocessing label classification result by a normalization function to obtain a preprocessing label classification probability corresponding to the preprocessing label classification result; Based on the preprocessing label classification probability, a loss value of the preprocessing label classification result is obtained.
5. The method according to claim 1, It is characterized in that The step of training the initial image label classification network according to the second loss value and the third loss value to obtain the image label classification network comprises: Obtaining a final loss value of the sample image according to the second loss value, the third loss value, and a weight coefficient corresponding to the second loss value, wherein the weight coefficient is determined based on the order of magnitude of the first dot product and the order of magnitude of the second dot product; The initial image label classification network is trained according to the final loss value to obtain an image label classification network.
6. A method for classifying image labels, It is characterized in that The method comprises: Get the image to be classified; The image to be classified is input into the trained image label classification network obtained by using any one of claims 1 to 5 to obtain a label classification result of the image to be classified.
7. A training device for an image label classification network, It is characterized in that The device comprises: A sample image label classification module, used to input a sample image into an initial image label classification network, and obtain a sample label classification result corresponding to a plurality of sample labels output by the initial image label classification network, wherein the plurality of sample labels are divided into a first sample label that takes the sample image as a negative sample and a second sample label that takes the sample image as a positive sample; A loss value determination module, used to determine the loss value of the label classification result of the first sample label as the first loss value, and determine the loss value of the label classification result of the second sample label as the second loss value; A loss value adjustment module, configured to normalize the label classification result corresponding to the first sample label through a normalization function to obtain a label classification probability of the label classification result corresponding to the first sample label; use the difference between the preset value and the label classification probability as a weight, wherein the weight is used to reduce the contribution of negative samples with missing labels to the loss value; determine the scalar product of the first loss value and the weight; and use the inverse of the scalar product as a third loss value; A network training module is used to train the initial image label classification network according to the second loss value and the third loss value to obtain an image label classification network.
8. An image label classification device, It is characterized in that The device comprises: An image acquisition module, used to acquire images to be classified; An image label classification module is used to input the image to be classified into a trained image label classification network obtained by using any one of claims 1-5 to obtain a label classification result of the image to be classified.
9. An electronic device, It is characterized in that The method comprises a processor and a memory; one or more programs are stored in the memory and configured to be executed by the processor to implement the method according to any one of claims 1 to 6.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores program codes, wherein when the program codes are executed by a processor, the method according to any one of claims 1 to 6 is executed.
Citation Information
Patent Citations
Method and device for training a multi-label classification model
CN109840531A
Model training method and device and storage medium
CN110163234A
Supervised learning method and device, label prediction method and device, electronic equipment and storage medium
CN110781934A
