A hybrid training method for cross-dataset object detection

The method of dynamically generating the mask matrix and F1 score to calculate the optimal threshold solves the problem of reduced model accuracy and high labeling cost when adding new category detection in target detection, and achieves efficient data set mixed training and accuracy improvement.

CN114998652BActive Publication Date: 2024-09-27WUXI YSTEN TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210576864.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-25
Publication Date
2024-09-27
Estimated Expiration
2042-05-25

AI Technical Summary

Technical Problem

In the target detection task, when existing technology is difficult to effectively add new category detection, direct mixing of data sets reduces model accuracy. Cross-labeling requires a lot of data annotation work. There are errors and missed detections in label generation that relies on model accuracy, and it is not fully considered. Potential negative samples lead to limited improvement in model accuracy.

Method used

The method of dynamically generating the mask matrix is ​​used to determine whether to perform classification loss calculation based on the sample labels on the feature map, dynamically determine which classification losses need to participate in training, and use the F1 score to calculate the optimal threshold to determine the assignment of the mask matrix, thereby determining the classification loss. Compute and train.

Benefits of technology

It is possible to directly mix multiple data sets to train the model without cross-labeling, achieving higher model accuracy and saving data labeling time and cost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114998652B
    Figure CN114998652B
Patent Text Reader

Abstract

The present invention discloses a hybrid training method for target detection cross data sets. In target detection task training, a mask matrix can be dynamically generated, an optimal threshold in the mask matrix is ​​selected by a threshold algorithm in the present invention, a value is assigned to the mask matrix based on the optimal threshold, and at the same time, it is determined which classification losses need loss calculation, and finally classification losses are calculated for these classification losses. When a model has been trained for existing data and a new category of data set training needs to be added, multiple data sets can be directly mixed without cross-labeling the mixed data sets, and higher model accuracy can be achieved, which can greatly save the time and cost of data labeling.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data set training, and in particular to a hybrid training method for target detection cross data sets. Background Art

[0002] In the target detection task, the detection model has been trained in dataset A, and new category detection needs to be added. There are generally four existing practices: 1. Directly mix datasets A and B for training, which will result in the B category in dataset A not being labeled, and the A category in dataset B not being labeled. Direct mixed training will reduce the accuracy of the model; 2. Cross-label the A and B datasets, label all the categories in dataset B for dataset A, and label all the categories in dataset B for dataset A. This method requires a lot of data labeling work; 3. Train models for data sets A and B respectively, and the trained models are denoted as MA and MB. Use the MA model to infer data set B to generate category A labels, and use the MB model to infer data set A to generate category B labels. This method relies on the accuracy of the MA and MB models. The generated labels will have a large number of incorrect labels and missed detections, and the actual application effect is not good; 4. For each sample in data set A, add a mask to shield the loss of category B when calculating the classification loss. For each sample in data set B, add a mask to shield the loss of category A when calculating the classification loss. This method shields the A and B data sets from each other when calculating the classification loss, without considering the potential negative samples of category A in the B data set and the potential negative samples of category B in the A data set, resulting in limited improvement in the accuracy of the final model. Summary of the invention

[0003] The purpose of the present invention is to provide a hybrid training method for target detection cross-datasets. In the target detection task training, a model has been trained for the existing data. When a new category of data set training needs to be added, multiple data sets can be directly mixed without cross-labeling the mixed data sets. A higher model accuracy can also be achieved, which can greatly save the time and cost of data labeling.

[0004] To solve the above technical problems, the present invention adopts the following technical solution: a hybrid training method for target detection cross data set, comprising the following steps:

[0005] Step 1: Sample label assignment: The input image is processed by conventional methods to generate a feature map. The points on the feature map are samples. After matching, the samples are assigned sample labels as positive samples or negative samples.

[0006] Step 2, dynamically generate a mask matrix: dynamically generate a mask matrix according to the feature map Featuremap, perform threshold calculations on the samples of the feature map Featuremap respectively, and determine the sample labels. Calculate the classification loss for samples labeled as positive and assign values ​​to the mask matrix; for samples labeled as negative, determine whether to perform classification loss calculations and assign values ​​to the mask matrix according to the sample threshold;

[0007] Step 3: Calculate classification loss: Use conventional methods to calculate classification loss and decide whether the classification loss should continue to participate in training.

[0008] The image input in the above step 1 is passed through the backbone network and the feature pyramid network to generate a feature map Featuremap. Each point of the feature map Featuremap corresponds to a sample of a predefined size. A sample corresponds to a rectangular area on the input image. The activation value of each sample on the feature map Featuremap represents the probability that the sample belongs to the corresponding category. After the samples are matched, positive samples and negative samples are obtained. The matching process of the samples is as follows: each sample is matched with the real GT through the maximum IoU or the distance from the nearest center point. After the sample successfully matches the GT, it is assigned to the category label corresponding to the GT. The successfully matched sample is called a positive sample, and the sample that does not match any GT is called a negative sample.

[0009] The above-mentioned sample category labels can be specifically as follows: suppose the number of categories contained in data set A is C1, and the category labels are {1, ..., C1}, the number of categories contained in data set B is C2, and the category labels are {C1+1, ..., C1+C2}, the negative sample label of data set A is C1+C2+1, and the negative sample label of data set B is C1+C2+2.

[0010] In the above step 2, according to the sample labels generated by the feature map Featuremap, a mask matrix is ​​dynamically generated: suppose the number of samples generated by the feature map Featuremap of an image is N, and the total number of categories of the A and B data sets is C1+C2, then the feature map Featuremap contains C1+C2 channels, each channel represents the probability of the corresponding category existing at that position, and all activation values ​​are output as N*(C1+C2). At the same time, a mask matrix of N*(C1+C2) is dynamically generated, and the samples and the mask matrix correspond one to one. The values ​​in the mask matrix that meet the conditions are set to 1, and those that do not meet the conditions are set to 0. The mask is multiplied by the final classification loss to dynamically decide whether to ignore the loss of a certain category of a certain sample.

[0011] The judgment process of setting 1 or 0 in the above mask matrix is ​​as follows: for each sample of the feature map Featuremap, determine whether it is a positive sample. If it is a positive sample, set the corresponding i-th row in the mask to 1. For i∈[0,N), mask[i,:]=1. If it is not a positive sample, determine whether the sample label is C1+C2+1 or C1+C2+2. If the sample label is C1+C2+1, then loop to determine whether the activation value of the sample is greater than the optimal threshold T of each category in the B data set. If it is greater than the optimal threshold T, set the category mask position corresponding to the sample to 0. For sample number i and category ci, then mask[ i, ci] = 0, if it is not greater than the optimal threshold T, the category mask position corresponding to the sample is set to 1, for sample number i and category ci, then mask[i, ci] = 1; if the sample label is C1+C2+2, then the activation value of the sample is determined cyclically whether it is greater than the optimal threshold T of each category in the A data set. If it is greater than the optimal threshold T, the category mask position corresponding to the sample is set to 0, for sample number i and category ci, then mask[i, ci] = 0, if it is not greater than the optimal threshold T, the category mask position corresponding to the sample is set to 1, for sample number i and category ci, then mask[i, ci] = 1.

[0012] The selection process of the above-mentioned optimal threshold T: In one implementation, the threshold interval can be evenly divided into K intervals from 0-1, and the parameter K=100 is set, then each interval is divided into {0.01, 0.02, ....., 0.99, 1}, and the positive and negative samples are counted separately, denoted as P_bin and N_bin, and the dimensions of P_bin and N_bin are (C1+C2)*100. Each category separately counts the total number of activation values ​​falling in the bin interval. For the sample activation value of the positive sample, the count of P_bin of the corresponding category is increased by one, the category of the sample is i, and the activation value is j, then P_bin[i, j]+=1, for the sample activation value of the negative sample, the count of N_bin of the corresponding category is increased by one, the category of the sample is i, and the activation value is j, then N_bin[i, j]+=1. After one round of training, we can count the positive and negative samples of all categories in the training set in 100 different bins, calculate the F1 score for the positive and negative sample count bins, and take the bin value with the highest F1 score as the threshold T for generating the dynamic mask.

[0013] The calculation formula (1) of the F1 score is:

[0014]

[0015] The calculation formula (2) for precision in the calculation formula (1) is:

[0016] The calculation formula (3) for recall in the calculation formula (1) is:

[0017] In calculation formula (2) and calculation formula (3), TP means that the prediction is a positive sample and the label is also a positive sample, FP means that the prediction is a positive sample and the label is a negative sample, and FN means that the prediction is a negative sample and the label is a positive sample. For P_bin and N_bin obtained by statistics in an epoch, then for the i-th bin of category ci, its TP is FP is FN Substituting TP, FP, and FN into formulas (1), (2), and (3) we can obtain the F1 score of each category in each bin. For each category, the bin value corresponding to the maximum F1 score is taken as the mask threshold of the category, denoted as the optimal threshold T, with a dimension of (C1+C2).

[0018] The classification loss calculation process in the above step 3: The classification loss of target detection can be calculated using cross entropy or Focalloss. Simply multiply the mask matrix and the classification loss to determine whether the classification loss should continue to participate in training.

[0019] For cross entropy or Focalloss loss, the loss of all samples can be expressed as the following expression (4):

[0020] L = {l 1 ,l 2 ,...,l n} T

[0021] The dimension of L in expression (4) is N*(C1+C2), where N is the total number of samples and the loss of each sample is l n :

[0022] Cross Entropy n The calculation formula (5) is as follows:

[0023] l n =-y n log(x n )-(1-y n )log(1-x n )

[0024] Focalloss n The calculation formula (6) is as follows:

[0025] l n = -α(1-x n ) β y n log(x n)-(1-α)(x n ) β (1-y n )log(1-x n )

[0026] In the calculation formula (5) and the calculation formula (6), y n is the label of each sample, the dimension is (C1+C2),x n is the activation value of each sample, with a dimension of (C1+C2); α and β in formula (6) are hyperparameters, which are generally set to 0.25 and 2;

[0027] The modified L_mask for cross entropy or Focalloss is as follows (7):

[0028] L_mask=L*mask={l 1 ,l 2 ,...,l n} T *mask.

[0029] Compared with the prior art, the superiority of the present invention lies in that, during the target detection task training, a mask matrix can be dynamically generated, the optimal threshold in the mask matrix is ​​selected by the algorithm of the present invention, and the mask matrix is ​​assigned a value based on the optimal threshold. At the same time, it can be determined which classification losses need loss calculation, and finally these classification losses are classified and calculated, and it is determined whether training needs to be continued; thus, multiple data sets can be directly mixed without cross-labeling the mixed data sets, and higher model accuracy can be achieved, which can greatly save the time and cost of data labeling. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 It is the overall flow chart of the present invention.

[0031] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments. DETAILED DESCRIPTION

[0032] Embodiment 1 of the present invention: A hybrid training method for target detection cross-datasets comprises the following steps:

[0033] Step 1: Sample label assignment: The input image is processed by conventional methods to generate a feature map. The points on the feature map are samples. After matching, the samples are assigned sample labels as positive samples or negative samples.

[0034] Step 2, dynamically generate a mask matrix: dynamically generate a mask matrix according to the feature map Featuremap, perform threshold calculations on the samples of the feature map Featuremap respectively, and determine the sample labels. Calculate the classification loss for samples labeled as positive and assign values ​​to the mask matrix; for samples labeled as negative, determine whether to perform classification loss calculations and assign values ​​to the mask matrix according to the sample threshold;

[0035] Step 3: Calculate classification loss: Use conventional methods to calculate classification loss and decide whether the classification loss should continue to participate in training.

[0036] Embodiment 2 of the present invention: A hybrid training method for target detection cross-datasets, comprising the following steps:

[0037] Step 1, sample label assignment: The input image is passed through the backbone network and feature pyramid network to generate a feature map Featuremap. Each point of the feature map Featuremap corresponds to a sample of a predefined size. A sample corresponds to a rectangular area on the input image. The activation value of each sample on the feature map Featuremap represents the probability that the sample belongs to the corresponding category. After the samples are matched, positive samples and negative samples are obtained. The sample matching process is as follows: each sample is matched with the real GT through the maximum IoU or the distance of the nearest center point. After the sample successfully matches the GT, it is assigned to the category label corresponding to the GT. The successfully matched sample is called a positive sample, and the sample that does not match any GT is called a negative sample.

[0038] The sample category labels can be specifically: suppose the number of categories contained in the A data set is C1, the category labels are {1, ..., C1}, the number of categories contained in the B data set is C2, the category labels are {C1+1, ..., C1+C2}, the negative sample label of the data set A is C1+C2+1, and the negative sample label of the data set B is C1+C2+2;

[0039] Step 2, dynamically generate a mask matrix: dynamically generate a mask matrix according to the feature map Featuremap, perform threshold calculations on the samples of the feature map Featuremap respectively, and determine the sample labels. Calculate the classification loss for samples labeled as positive and assign values ​​to the mask matrix; for samples labeled as negative, determine whether to perform classification loss calculations and assign values ​​to the mask matrix according to the sample threshold;

[0040] Step 3: Calculate classification loss: Use conventional methods to calculate classification loss and decide whether the classification loss should continue to participate in training.

[0041] Embodiment 3 of the present invention: A hybrid training method for target detection cross-datasets, comprising the following steps:

[0042] Step 1, sample label assignment: The input image is passed through the backbone network and feature pyramid network to generate a feature map Featuremap. Each point of the feature map Featuremap corresponds to a sample of a predefined size. A sample corresponds to a rectangular area on the input image. The activation value of each sample on the feature map Featuremap represents the probability that the sample belongs to the corresponding category. After the samples are matched, positive samples and negative samples are obtained. The sample matching process is as follows: each sample is matched with the real GT through the maximum IoU or the distance of the nearest center point. After the sample successfully matches the GT, it is assigned to the category label corresponding to the GT. The successfully matched sample is called a positive sample, and the sample that does not match any GT is called a negative sample.

[0043] The sample category labels can be specifically: suppose the number of categories contained in the A data set is C1, the category labels are {1, ..., C1}, the number of categories contained in the B data set is C2, the category labels are {C1+1, ..., C1+C2}, the negative sample label of the data set A is C1+C2+1, and the negative sample label of the data set B is C1+C2+2;

[0044] Step 2, dynamically generate a mask matrix: According to the sample labels generated by the feature map Featuremap, dynamically generate a mask matrix: suppose the number of samples generated by the feature map Featuremap of an image is N, and the total number of categories of the A and B data sets is C1+C2, then the feature map Featuremap contains C1+C2 channels, each channel represents the probability of the corresponding category at that position, and all activation values ​​are output as N*(C1+C2). At the same time, a mask matrix of N*(C1+C2) is dynamically generated, and the samples and the mask matrix correspond one to one. The mask matrix is ​​set to 1 if the conditions are met, and set to 0 if the conditions are not met. The mask is multiplied by the final classification loss to dynamically decide whether to ignore the loss of a certain category of a certain sample;

[0045] The judgment process of setting 1 or 0 in the mask matrix is ​​as follows: for each sample of the feature map Featuremap, determine whether it is a positive sample. If it is a positive sample, set the corresponding i-th row in the mask to 1. For i∈[0,N), mask[i,:]=1. If it is not a positive sample, determine whether the sample label is C1+C2+1 or C1+C2+2. If the sample label is C1+C2+1, then loop to determine whether the activation value of the sample is greater than the optimal threshold T of each category in the B data set. If it is greater than the optimal threshold T, set the category mask position corresponding to the sample to 0. For sample number i and category ci, then mask[i , ci]=0, if it is not greater than the optimal threshold T, the category mask position corresponding to the sample is set to 1, for sample number i, category ci, then mask[i, ci]=1; if the sample label is C1+C2+2, then the activation value of the sample is determined cyclically whether it is greater than the optimal threshold T of each category in the A data set. If it is greater than the optimal threshold T, the category mask position corresponding to the sample is set to 0, for sample number i, category ci, then mask[i, ci]=0, if it is not greater than the optimal threshold T, the category mask position corresponding to the sample is set to 1, for sample number i, category ci, then mask[i, ci]=1;

[0046] The process of selecting the optimal threshold T: In one implementation, the threshold interval can be evenly divided into K intervals from 0-1, and the parameter K=100 is set. Then each interval is divided into {0.01, 0.02, ..., 0.99, 1}, and the positive and negative samples are counted separately, denoted as P_bin and N_bin. The dimensions of P_bin and N_bin are (C1+C2)*100. Each category is counted separately for the total number of activation values ​​falling in the bin interval. For the sample activation value of the positive sample, the calculation of P_bin of the corresponding category is The number is increased by one, the category of the sample is i, and the activation value is j, then P_bin[i, j]+=1, for the sample activation value of the negative sample, the count of N_bin of the corresponding category is increased by one, the category of the sample is i, and the activation value is j, then N_bin[i, j]+=1; after one round of training iterations, the counts of positive and negative samples of all categories in the training set in 100 different bins can be statistically obtained, and the F1 score of the count bins of positive and negative samples is calculated, and the bin value with the highest F1 score is taken as the threshold T for generating the dynamic mask;

[0047] The calculation formula (1) of the F1 score is:

[0048]

[0049] The calculation formula (2) for precision in the calculation formula (1) is:

[0050] The calculation formula (3) for recall in the calculation formula (1) is:

[0051] In calculation formula (2) and calculation formula (3), TP means that the prediction is a positive sample and the label is also a positive sample, FP means that the prediction is a positive sample and the label is a negative sample, and FN means that the prediction is a negative sample and the label is a positive sample. For P_bin and N_bin obtained by statistics in an epoch, then for the i-th bin of category ci, its TP is FP is FN Substituting TP, FP, and FN into formulas (1), (2), and (3) can obtain the F1 score of each category in each bin. For each category, the bin value corresponding to the maximum F1 score is taken as the mask threshold of the category, denoted as the optimal threshold T, with a dimension of (C1+C2);

[0052] Step 3: Calculate classification loss: Use conventional methods to calculate classification loss and decide whether the classification loss should continue to participate in training.

[0053] Embodiment 4 of the present invention: A hybrid training method for target detection cross-datasets, comprising the following steps:

[0054] Step 1, sample label assignment: The input image is passed through the backbone network and feature pyramid network to generate a feature map Featuremap. Each point of the feature map Featuremap corresponds to a sample of a predefined size. A sample corresponds to a rectangular area on the input image. The activation value of each sample on the feature map Featuremap represents the probability that the sample belongs to the corresponding category. After the samples are matched, positive samples and negative samples are obtained. The sample matching process is as follows: each sample is matched with the real GT through the maximum IoU or the distance of the nearest center point. After the sample successfully matches the GT, it is assigned to the category label corresponding to the GT. The successfully matched sample is called a positive sample, and the sample that does not match any GT is called a negative sample.

[0055] The sample category labels can be specifically: suppose the number of categories contained in the A data set is C1, the category labels are {1, ..., C1}, the number of categories contained in the B data set is C2, the category labels are {C1+1, ..., C1+C2}, the negative sample label of the data set A is C1+C2+1, and the negative sample label of the data set B is C1+C2+2;

[0056] Step 2, dynamically generate a mask matrix: According to the sample labels generated by the feature map Featuremap, dynamically generate a mask matrix: suppose the number of samples generated by the feature map Featuremap of an image is N, and the total number of categories of the A and B data sets is C1+C2, then the feature map Featuremap contains C1+C2 channels, each channel represents the probability of the corresponding category at that position, and all activation values ​​are output as N*(C1+C2). At the same time, a mask matrix of N*(C1+C2) is dynamically generated, and the samples and the mask matrix correspond one to one. The mask matrix is ​​set to 1 if the conditions are met, and set to 0 if the conditions are not met. The mask is multiplied by the final classification loss to dynamically decide whether to ignore the loss of a certain category of a certain sample;

[0057] The judgment process of setting 1 or 0 in the mask matrix is ​​as follows: for each sample of the feature map Featuremap, determine whether it is a positive sample. If it is a positive sample, set the corresponding i-th row in the mask to 1. For i∈[0,N), mask[i,:]=1. If it is not a positive sample, determine whether the sample label is C1+C2+1 or C1+C2+2. If the sample label is C1+C2+1, then loop to determine whether the activation value of the sample is greater than the optimal threshold T of each category in the B data set. If it is greater than the optimal threshold T, set the category mask position corresponding to the sample to 0. For sample number i and category ci, then mask[i , ci]=0, if it is not greater than the optimal threshold T, the category mask position corresponding to the sample is set to 1, for sample number i, category ci, then mask[i, ci]=1; if the sample label is C1+C2+2, then the activation value of the sample is determined cyclically whether it is greater than the optimal threshold T of each category in the A data set. If it is greater than the optimal threshold T, the category mask position corresponding to the sample is set to 0, for sample number i, category ci, then mask[i, ci]=0, if it is not greater than the optimal threshold T, the category mask position corresponding to the sample is set to 1, for sample number i, category ci, then mask[i, ci]=1;

[0058] The process of selecting the optimal threshold T: In one implementation, the threshold interval can be evenly divided into K intervals from 0-1, and the parameter K=100 is set. Then each interval is divided into {0.01, 0.02, ..., 0.99, 1}, and the positive and negative samples are counted separately, denoted as P_bin and N_bin. The dimensions of P_bin and N_bin are (C1+C2)*100. Each category is counted separately for the total number of activation values ​​falling in the bin interval. For the sample activation value of the positive sample, the calculation of P_bin of the corresponding category is The number is increased by one, the category of the sample is i, and the activation value is j, then P_bin[i, j]+=1, for the sample activation value of the negative sample, the count of N_bin of the corresponding category is increased by one, the category of the sample is i, and the activation value is j, then N_bin[i, j]+=1; after one round of training iterations, the counts of positive and negative samples of all categories in the training set in 100 different bins can be statistically obtained, and the F1 score of the count bins of positive and negative samples is calculated, and the bin value with the highest F1 score is taken as the threshold T for generating the dynamic mask;

[0059] The calculation formula (1) of the F1 score is:

[0060]

[0061] The calculation formula (2) for precision in the calculation formula (1) is:

[0062] The calculation formula (3) for recall in the calculation formula (1) is:

[0063] In calculation formula (2) and calculation formula (3), TP means that the prediction is a positive sample and the label is also a positive sample, FP means that the prediction is a positive sample and the label is a negative sample, and FN means that the prediction is a negative sample and the label is a positive sample. For P_bin and N_bin obtained by statistics in an epoch, then for the i-th bin of category ci, its TP is FP is FN Substituting TP, FP, and FN into formulas (1), (2), and (3) can obtain the F1 score of each category in each bin. For each category, the bin value corresponding to the maximum F1 score is taken as the mask threshold of the category, denoted as the optimal threshold T, with a dimension of (C1+C2);

[0064] Step 3: Calculate classification loss: The classification loss of target detection can be calculated using cross entropy or Focalloss. Simply multiply the mask matrix and the classification loss to determine whether the classification loss should continue to participate in training.

[0065] For cross entropy or Focalloss loss, the loss of all samples can be expressed as the following expression (4):

[0066] L = {l 1 ,l 2 ,...,l n} T

[0067] The dimension of L in expression (4) is N*(C1+C2), where N is the total number of samples and the loss of each sample is l n :

[0068] Cross Entropy n The calculation formula (5) is as follows:

[0069] l n =-y n log(x n )-(1-y n )log(1-x n )

[0070] Focalloss n The calculation formula (6) is as follows:

[0071] l n = -α(1-x n ) β y n log(x n )-(1-α)(x n ) β (1-y n )log(1-x n )

[0072] In the calculation formula (5) and the calculation formula (6), y n is the label of each sample, the dimension is (C1+C2),x n is the activation value of each sample, with a dimension of (C1+C2); α and β in formula (6) are hyperparameters, which are generally set to 0.25 and 2;

[0073] The modified L_mask for cross entropy or Focalloss is as follows (7):

[0074] L_mask=L*mask={l 1 ,l 2 ,...,l n} T *mask.

[0075] The working principle of an embodiment of the present invention is as follows: an input image is passed through a backbone network and a feature pyramid network to generate a feature map Featuremap, each point of the feature map Featuremap corresponds to a sample of a predefined size, and a sample corresponds to a rectangular area on the input image. Each sample is matched with the real GT through the maximum IoU or the distance of the nearest center point. After the sample successfully matches the GT, it is assigned to the category label corresponding to the GT. The successfully matched sample is called a positive sample, and the sample that does not match any GT is called a negative sample; at the same time, a mask matrix is ​​dynamically generated to determine whether each sample of the feature map Featuremap is a positive sample. If it is a positive sample, the corresponding point in the mask matrix is ​​set to 1. If it is not a positive sample, it is determined The label of the sample is C1+C2+1 or C1+C2+2. If the sample label is C1+C2+1, then the activation value of the sample is judged cyclically whether it is greater than the optimal threshold T of each category in the B data set. If it is greater than the optimal threshold T, the point of the mask matrix corresponding to the sample is set to 0. If it is not greater than the optimal threshold T, the point of the mask matrix corresponding to the sample is set to 1. If the sample label is C1+C2+2, then the activation value of the sample is judged cyclically whether it is greater than the optimal threshold T of each category in the A data set. If it is greater than the optimal threshold T, the point of the mask matrix corresponding to the sample is set to 0. If it is not greater than the optimal threshold T, the point of the mask matrix corresponding to the sample is set to 1. Finally, the classification loss is calculated using cross entropy or Focalloss, and the mask matrix is ​​multiplied by the classification loss to determine whether the classification loss continues to participate in training.

Claims

1. A hybrid training method for target detection cross-datasets, characterized in that: The following steps are involved: Step 1: Sample label assignment: The input image is processed by conventional methods to generate a feature map. The points on the feature map are samples. After matching, the samples are assigned sample labels as positive samples or negative samples. Step 2, dynamically generate a mask matrix: dynamically generate a mask matrix according to the feature map Featuremap, calculate the threshold for the samples of the feature map Featuremap respectively, assign values ​​to the mask matrix, and determine the sample labels. Calculate the classification loss for samples labeled as positive and assign values ​​to the mask matrix; for samples labeled as negative, determine whether to calculate the classification loss and assign values ​​to the mask matrix according to the sample threshold; dynamically generate a mask matrix according to the sample labels generated by the feature map Featuremap: suppose the number of samples generated by the feature map Featuremap of an image is N, and the total number of categories of the A and B data sets is C1+C2, then the feature map Featuremap contains C1+C2 channels, each channel represents the probability of the corresponding category at the position, and all activation values ​​are output as N*(C1+C2). At the same time, dynamically generate a mask matrix of N*(C1+C2), with one-to-one correspondence between samples and mask matrices. Set 1 if the conditions are met in the mask matrix, and set 0 if the conditions are not met. Multiply the mask to the final classification loss to dynamically decide whether to ignore the loss of a certain category of a certain sample; Step 3: Calculate classification loss: Use conventional methods to calculate classification loss and decide whether the classification loss should continue to participate in training.

2. The hybrid training method for target detection cross-dataset according to claim 1, characterized in that: The image input in step 1 is passed through the backbone network and feature pyramid network to generate a feature map Featuremap. Each point of the feature map Featuremap corresponds to a sample of a predefined size. A sample corresponds to a rectangular area on the input image. The activation value of each sample on the feature map Featuremap represents the probability that the sample belongs to the corresponding category. After the samples are matched, positive samples and negative samples are obtained. The sample matching process is as follows: each sample is matched with the real GT through the maximum IoU or the distance from the nearest center point. After the sample successfully matches the GT, it is assigned to the category label corresponding to the GT. The successfully matched sample is called a positive sample, and the sample that does not match any GT is called a negative sample.

3. The hybrid training method for target detection cross-dataset according to claim 2, characterized in that: The sample category labels can be specifically as follows: suppose the number of categories contained in data set A is C1, and the category labels are {1, ..., C1}, the number of categories contained in data set B is C2, and the category labels are {C1+1, ..., C1+C2}, the negative sample label of data set A is C1+C2+1, and the negative sample label of data set B is C1+C2+2.

4. A hybrid training method for target detection cross-datasets according to claim 1 or 3, characterized in that: The judgment process of setting 1 or 0 in the mask matrix is ​​as follows: for each sample of the feature map Featuremap, determine whether it is a positive sample. If it is a positive sample, set the corresponding i-th row in the mask to 1. For i∈[0,N), mask[i,:]=1. If it is not a positive sample, determine whether the sample label is C1+C2+1 or C1+C2+2. If the sample label is C1+C2+1, then loop to determine whether the activation value of the sample is greater than the optimal threshold T of each category in the B data set. If it is greater than the optimal threshold T, set the category mask position corresponding to the sample to 0. For sample number i and category ci, then mask[i , ci]=0, if it is not greater than the optimal threshold T, the category mask position corresponding to the sample is set to 1, for sample number i and category ci, then mask[i, ci]=1; if the sample label is C1+C2+2, then it is cyclically determined whether the activation value of the sample is greater than the optimal threshold T of each category in the A data set. If it is greater than the optimal threshold T, the category mask position corresponding to the sample is set to 0, for sample number i and category ci, then mask[i, ci]=0, if it is not greater than the optimal threshold T, the category mask position corresponding to the sample is set to 1, for sample number i and category ci, then mask[i, ci]=1.

5. A hybrid training method for target detection cross-datasets according to claim 4, characterized in that: The process of selecting the optimal threshold T: In one implementation, the threshold interval can be evenly divided into K intervals from 0-1, and the parameter K=100 is set. Then each interval is divided into {0.01, 0.02, ..., 0.99, 1}, and the positive and negative samples are counted separately, denoted as P_bin and N_bin. The dimensions of P_bin and N_bin are (C1+C2)*100. Each category is counted separately for the total number of activation values ​​falling in the bin interval. For the sample activation value of the positive sample, the calculation of P_bin of the corresponding category is The number is increased by one, the category of the sample is i, and the activation value is j, then P_bin[i, j]+=1, for the sample activation value of the negative sample, the count of N_bin of the corresponding category is increased by one, the category of the sample is i, and the activation value is j, then N_bin[i, j]+=1; after one round of training iterations, the counts of positive and negative samples of all categories in the training set in 100 different bins can be statistically obtained, and the F1 score of the count bins of positive and negative samples is calculated, and the bin value with the highest F1 score is taken as the threshold T for generating the dynamic mask; The calculation formula (1) of the F1 score is: The calculation formula (2) for precision in the calculation formula (1) is: The calculation formula (3) for recall in the calculation formula (1) is: In calculation formula (2) and calculation formula (3), TP means that the prediction is a positive sample and the label is also a positive sample, FP means that the prediction is a positive sample and the label is a negative sample, and FN means that the prediction is a negative sample and the label is a positive sample. For P_bin and N_bin obtained by statistics in an epoch, then for the i-th bin of category ci, its TP is FP is FN Substituting TP, FP, and FN into formulas (1), (2), and (3) we can obtain the F1 score of each category in each bin. For each category, the bin value corresponding to the maximum F1 score is taken as the mask threshold of the category, denoted as the optimal threshold T, with a dimension of (C1+C2).

6. A hybrid training method for target detection cross-datasets according to claim 1, characterized in that: Step 3 Classification loss calculation process: The classification loss of target detection can be calculated using cross entropy or Focalloss. Simply multiply the mask matrix and the classification loss to determine whether the classification loss should continue to participate in training. For cross entropy or Focalloss loss, the loss of all samples can be expressed as the following expression (4): L={l1,l2,...,l n} T The dimension of L in expression (4) is N*(C1+C2), where N is the total number of samples and the loss of each sample is l n : Cross Entropy n The calculation formula (5) is as follows: l n =-y n log(x n )-(1-y n )log(1-x n ) Focalloss n The calculation formula (6) is as follows: L n =-α(1-x n ) β y n log(x n )-(1-α)(x n ) β (1-y n )log(1-x n ) In the calculation formula (5) and the calculation formula (6), y n is the label of each sample, the dimension is (C1+C2),x n is the activation value of each sample, with a dimension of (C1+C2); α and β in formula (6) are hyperparameters, which are generally set to 0.25 and 2; The modified L_mask for cross entropy or Focalloss is as follows (7): <h2 style=";text-align:left;direction:ltr">L_mask = L*mask = {l1,l2,...,l<h2 style=";text-align:left;direction:ltr"> n <h2 style=";text-align:left;direction:ltr">}<h2 style=";text-align:left;direction:ltr"> T <h2 style=";text-align:left;direction:ltr"> *mask。