Target detection method, device, electronic device and storage medium
By setting the loss weight according to the sample gradient information in the object detection model and correcting the loss function, the impact of long-tail distribution on the model is solved, and the detection accuracy is improved, especially the detection effect of tail categories is improved.
Patent Information
- Application Number
- CN202111666389.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2024-12-20
- Estimated Expiration
- 2041-12-30
AI Technical Summary
The deep learning object detection model is easily affected by the long-tail distribution during multi-category detection, resulting in a decrease in the detection ability of tail category. The head category suppresses the learning effect of tail category and reduces the detection accuracy.
By entering the current batch of samples into the object detection model to obtain the feature map, determine the sample gradient information of each category, and set the loss weight based on the gradient information, correct the loss function to adjust the model parameters, and use the modified model to perform object detection operations to avoid long The effect of tail distribution on the model.
It effectively improves the accuracy of the target detection model, especially the detection effect of the tail category, significantly improves the training effect of the small sample category, and does not affect the detection performance of the head category.
Smart Images

Figure CN114330573B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a target detection method, device, electronic device and storage medium. Background Art
[0002] In deep learning-based target detection algorithms, the problem of long-tail distribution is often encountered. When detecting multiple categories, the head materials are dozens or even hundreds of times more than the tail materials due to the different difficulty levels of obtaining materials for each category. During model training, the category with more materials will significantly suppress the learning effect of the category with less materials, resulting in a significant decrease in the tail detection capability.
[0003] Therefore, how to avoid the influence of long-tail distribution on the target detection model and improve the accuracy of target detection is a technical problem that technical personnel in this field currently need to solve. Summary of the invention
[0004] The purpose of this application is to provide a target detection method, device, electronic device and storage medium, which can avoid the influence of long-tail distribution on the target detection model and improve the accuracy of target detection.
[0005] In order to solve the above technical problems, the present application provides a target detection method, which includes:
[0006] Inputting the current batch of samples into the target detection model to obtain a feature map; wherein the current batch of samples includes training samples of multiple categories;
[0007] Determine sample gradient information of each category according to the feature map, and set the loss weight of each category according to the sample gradient information;
[0008] Correcting the loss function of the target detection model according to the loss weight, and adjusting the parameters of the target detection model using the corrected loss function to obtain a trained target detection model;
[0009] The trained target detection model is used to perform target detection operations on unknown information.
[0010] Optionally, determining sample gradient information of each category according to the feature map includes:
[0011] Determine the positive sample gradient generated by the prediction point corresponding to the positive sample of each category according to the feature map;
[0012] Determine the negative sample gradient generated by the prediction point corresponding to the negative sample of each category according to the feature map;
[0013] The sample gradient information includes the positive sample gradient and the negative sample gradient.
[0014] Optionally, setting the loss weight of each category according to the sample gradient information includes:
[0015] The prediction point in the feature graph where the positive sample gradient is greater than the gradient threshold is set as the first prediction point to be optimized;
[0016] Setting the prediction point in the feature map where the negative sample gradient is greater than the gradient threshold as the second prediction point to be optimized;
[0017] Select a target category, and calculate a first ratio and a second ratio of the target category; wherein the first ratio is the ratio of the number of first prediction points to be optimized of the target category to the number of prediction points corresponding to the target category; the second category is the ratio of the number of second prediction points to be optimized of the target category to the target number, and the target number is the difference between the number of prediction points corresponding to all the current batch samples and the number of prediction points corresponding to the target category;
[0018] Determine whether the first ratio and the second ratio of all categories are obtained;
[0019] If so, the category weight of each category is calculated according to the first ratio and the second ratio of all categories, and the category weight is calculated by the category balancing algorithm to obtain the loss weight of each category;
[0020] If not, the step of selecting the target category is entered.
[0021] Optionally, the category weight of each category is calculated according to the first ratio and the second ratio of all categories, including:
[0022] Setting the ratio of the maximum value of the first proportions to the first proportion of each category as the first category weight of the corresponding category;
[0023] A ratio of a maximum value among the second proportions to the second proportion of each category is set as a second category weight of the corresponding category.
[0024] Optionally, calculating the category weights by a category balancing algorithm to obtain the loss weight of each category includes:
[0025] Calculating the first category weight by a category balancing algorithm to obtain a first calculation result, and multiplying the first calculation result by the total number of samples of the corresponding category to obtain a positive sample loss weight of each category;
[0026] The second category weight is calculated using a category balancing algorithm to obtain a second calculation result, and the second calculation result is multiplied by the total number of samples of the corresponding category to obtain the negative sample loss weight of each category.
[0027] Optionally, the loss function of the target detection model is modified according to the loss weight, including:
[0028] Obtain the loss function loss of the target detection model;
[0029] Modify the loss function loss using the positive sample loss weight Q(pos) and the negative sample loss weight Q(neg);
[0030] Among them, the loss function before correction is loss = -(y i log(σ(x))+(1-y i )log(1-(σ(x))), the corrected loss function is loss=-(Q(pos)y i log(σ(x))+Q(neg)(1-y i )log(1-(σ(x))),y i is the label of whether the sample belongs to class i, and σ(x) is the predicted score of the class.
[0031] Optionally, after adjusting the parameters of the target detection model using the modified loss function, the method further includes:
[0032] Determine whether the target detection model has been iterated;
[0033] If not, a training sample is selected from the training set as a new current batch of samples, and the step of inputting the current batch of samples into the target detection model to obtain a feature map is entered.
[0034] The present application also provides a target detection device, which includes:
[0035] A sample input module, used to input the current batch of samples into the target detection model to obtain a feature map; wherein the current batch of samples includes training samples of multiple categories;
[0036] A weight setting module, used to determine sample gradient information of each category according to the feature map, and set the loss weight of each category according to the sample gradient information;
[0037] A loss function adjustment module, used to correct the loss function of the target detection model according to the loss weight, and use the corrected loss function to adjust the parameters of the target detection model to obtain a trained target detection model;
[0038] The target detection module is used to perform target detection operations on unknown information using the trained target detection model.
[0039] The present application also provides a storage medium on which a computer program is stored, and when the computer program is executed, the steps of the target detection method described above are implemented.
[0040] The present application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the target detection method when calling the computer program in the memory.
[0041] The present application provides a target detection method, comprising: inputting a current batch of samples into a target detection model to obtain a feature map; wherein the current batch of samples includes training samples of multiple categories; determining sample gradient information of each category according to the feature map, and setting a loss weight of each category according to the sample gradient information; correcting the loss function of the target detection model according to the loss weight, and adjusting parameters of the target detection model using the corrected loss function to obtain a trained target detection model; and using the trained target detection model to perform target detection operations on unknown information.
[0042] The present application inputs the current batch of samples into the target detection model to obtain a feature map, and determines the sample gradient information of each category based on the feature map. The sample gradient information can reflect the training effect of the target detection model after this iteration, and then the loss weight of each category can be set based on the sample gradient information. The present application uses the loss weight to adjust the parameters of the loss function, and trains the target detection model using the loss function after adjusting the parameters. The present application can adjust the loss function based on the training effect of the current batch of samples on the target detection model, and can avoid the influence of the long-tail distribution on the target detection model, thereby improving the target detection accuracy. The present application also provides a target detection device, a storage medium, and an electronic device, which have the above-mentioned beneficial effects, which will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 A flow chart of a target detection method provided in an embodiment of the present application;
[0045] Figure 2 A schematic diagram of the structure of a target detection device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are 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.
[0047] See below Figure 1 , Figure 1 A flowchart of a target detection method provided in an embodiment of the present application.
[0048] Specific steps may include:
[0049] S101: Input the current batch of samples into the target detection model to obtain a feature map;
[0050] Before this step, there may be an operation of constructing a training set, and the training set may include samples of multiple categories, such as pedestrian images, car images, motorcycle images, etc. In this embodiment, the original target detection model may be iteratively trained, and each iteration reads part of the samples from the training set for training. The samples read are the current batch samples in this embodiment, and the current batch samples include training samples of multiple categories. The target detection model may be a target detection model based on a deep learning algorithm. When the current batch samples are input into the target detection model, the target detection model may output a corresponding feature map.
[0051] S102: determining sample gradient information of each category according to the feature map, and setting a loss weight of each category according to the sample gradient information;
[0052] Among them, the feature map may include multiple prediction points, and the sample gradient information of each category includes positive sample gradients and negative sample gradients. For all classifiers of the target detection model, if the category of a sample is equal to the predicted category of a classifier, then the sample is a positive sample for the classifier, and the sample is a negative sample for all other classifiers. The positive sample gradient is the gradient of the positive sample to the classifier output x, and the negative sample gradient is the gradient of the negative sample to the classifier output x. Specifically, this embodiment can determine the positive sample gradient generated by the corresponding prediction point of the positive sample of each category based on the feature map, and can also determine the negative sample gradient generated by the corresponding prediction point of the negative sample of each category based on the feature map.
[0053] The sample gradient information can represent the training effect of the target detection model. Taking the Yolo series algorithm as an example, the specific derivation process of the above conclusion is as follows:
[0054] When Yolo series algorithms (such as Yolov5) are trained, the classification loss is calculated using Binary Cross Entropy. When the number of samples of different types in the training set is unbalanced, the classifier of the sample category with a smaller proportion is always trained with negative samples, which causes the imbalance of single-category samples, resulting in the inability of the classifier to effectively predict positive samples, so that the detection effect of the tail is significantly worse than that of the head.
[0055] In yolov5, the classification training branch Loss is defined as follows:
[0056] loss(cls)=-(y i log(σ(x))+(1-y i )log(1-σ(x)));
[0057] Among them, x is the output of the neural network; σ(x) is the Sigmoid function, that is, the prediction score of the category, the value range of σ(x) is [-1, 1], and the σ(x) formula is defined as:
[0058]
[0059] Network optimization is related to gradient and learning rate, so the gradient of classification loss to network prediction score is calculated to obtain the following formula:
[0060] σ′(x)=σ(x)(1-σ(x));
[0061]
[0062]
[0063] In the above formula, y i Is the label of whether the sample belongs to category i. is the gradient generated by the positive sample, that is, the positive sample gradient; The gradient generated by negative samples is called negative sample gradient. Analyzing the above formula, we can get the following conclusions: for positive samples, if the prediction confidence is lower, it means that the model's prediction effect on positive samples is worse, and the generated gradient is larger; for negative samples, if the prediction confidence is higher, it means that the model's prediction effect on negative samples is worse, and the generated gradient is larger.
[0064] Based on the sample gradient information, the prediction effect of the target detection model on each type of sample can be determined according to the sample gradient information. The present application can set the loss weight of each category according to the prediction effect, thereby avoiding the long-tail distribution problem.
[0065] S103: modifying the loss function of the target detection model according to the loss weight, and adjusting the parameters of the target detection model using the modified loss function, so as to obtain a trained target detection model;
[0066] Among them, before this step, there may be an operation of obtaining the loss function of the target detection model, and the loss function of the target detection model can be corrected according to the loss weight, and the parameters of the target detection model can be adjusted using the corrected loss function to obtain the trained target detection model. After this step, it can also be determined whether the target detection model has been iterated; if it has been iterated, the step S104 can be entered; if it has not been iterated, a training sample is selected from the training set as a new current batch sample, and the step of inputting the current batch sample into the target detection model to obtain a feature map is entered, so as to perform the relevant operations of S101 to S103 again.
[0067] S104: Utilize the trained target detection model to perform target detection operations on unknown information.
[0068] Before this step, a target detection task may be received, corresponding position information may be determined according to the target detection task, and then the trained target detection model may be used to perform target detection operations on unknown information.
[0069] This embodiment inputs the current batch of samples into the target detection model to obtain a feature map, and determines the sample gradient information of each category based on the feature map. The sample gradient information can reflect the training effect of the target detection model after this iteration, and then the loss weight of each category can be set based on the sample gradient information. This embodiment uses the loss weight to adjust the parameters of the loss function, and uses the loss function after adjusting the parameters to train the target detection model. This embodiment can adjust the loss function based on the training effect of the current batch of samples on the target detection model, and can avoid the influence of the long-tail distribution on the target detection model, thereby improving the accuracy of target detection.
[0070] As for Figure 1 For further description of the corresponding embodiment, the present embodiment sets the loss weight of each category in the following manner:
[0071] Step 1: setting the prediction point in the feature map where the positive sample gradient is greater than the gradient threshold as the first prediction point to be optimized;
[0072] Step 2: setting the prediction point in the feature map where the negative sample gradient is greater than the gradient threshold as the second prediction point to be optimized;
[0073] Step 3: Select a target category, and calculate a first ratio and a second ratio of the target category; wherein the first ratio is the ratio of the number of first prediction points to be optimized of the target category to the number of prediction points corresponding to the target category; the second category is the ratio of the number of second prediction points to be optimized of the target category to the target number, and the target number is the difference between the number of prediction points corresponding to all the current batch samples and the number of prediction points corresponding to the target category;
[0074] Step 4: Determine whether the first ratio and the second ratio of all categories are obtained; if so, proceed to step 5; if not, proceed to step 3;
[0075] Step 5: Calculate the category weight of each category according to the first ratio and the second ratio of all categories, and calculate the category weight through a category balancing algorithm (such as softmax) to obtain the loss weight of each category.
[0076] Specifically, during training, the prediction effect of each category in the current batch of samples can be pre-calculated. For example, the gradient threshold α can be set to 0.1. For a positive sample, if the positive gradient generated by the prediction point The prediction point is judged as the first prediction point to be optimized BPP (bad pos prediction); for negative samples, if the negative gradient generated by the prediction point Then the prediction point is judged as the second prediction point to be optimized BNP (bad neg prediction). By performing the above calculations on the positive samples and negative samples of each category, the number of the first prediction points to be optimized BPP of each category can be obtained. The number of prediction points of c-class samples N c The first ratio Rate c (BPP), and the number of the second prediction point to be optimized BNP The second ratio Rate of the total number of prediction points N corresponding to each category c (BNP).
[0077]
[0078]
[0079] As a feasible implementation method, the category weight of each category can be calculated in the following way: the maximum value max(Rate) in the first ratio is c (BPP)) and the ratio of the first ratio of each category is set as the first category weight of the corresponding category; the maximum value max(Rate c The ratio of (BNP)) to the second ratio of each category is set as the second category weight of the corresponding category.
[0080] Specifically, the proportion of poor prediction effects of each category can be linked together, and the weight of the category with the worst prediction effect is set to 1. The better the prediction effect, the higher the weight of the first category Rate′ c (BPP), the second category weight Rate′ c The larger the (BNP) value, the formula is as follows:
[0081]
[0082]
[0083] Based on the first category weight and the second category weight, the loss weight can be calculated in the following way: the first category weight is calculated by a category balancing algorithm to obtain a first calculation result, and the first calculation result is multiplied by the total number of samples of the corresponding category to obtain the positive sample loss weight Q(pos) of each category; the second category weight is calculated by a category balancing algorithm to obtain a second calculation result, and the second calculation result is multiplied by the total number of samples of the corresponding category to obtain the negative sample loss weight Q(neg) of each category.
[0084] Through the above method, the weight of each category is corrected by the category balancing algorithm, Rate′ c (BPP) and Rate′ c The ratio range of the classes with large differences in (BNP) is greatly reduced. Therefore, the class with poor network prediction effect is: Rate′ c (BPP) and Rate′ c The larger of the (BNP) will be assigned a larger weight. This embodiment uses a class balancing algorithm to correct the weight and multiply it by the total number of samples N in each class. c , ensuring that the overall Loss remains consistent with that before weighting, so there is no need to configure additional hyperparameters. The formula is as follows:
[0085] Q(pos)=softmax(Rate′ c (BPP))*N c ;
[0086] Q(neg)=softmax(Rate′ c (BNP))*N c ;
[0087] Under the training of the current batch of samples, the prediction effect of each category has been pre-calculated, and the weight of the loss of each category has been corrected accordingly. Through the filtering of the α threshold, the guided network will no longer pay attention to the samples with good training effect, which are usually the head samples, and can reduce the inhibitory effect of the head data on the tail data. This embodiment can show the softmax weight redistribution scheme based on gradient guidance in the following way:
[0088] Obtain the loss function loss of the target detection model;
[0089] Modify the loss function loss using the positive sample loss weight Q(pos) and the negative sample loss weight Q(neg);
[0090] Among them, the loss function before correction is loss(cls)=-(y i log(σ(x))+(1-y i )log(1-σ(x))), the corrected loss function is loss′(cls)=-(Q(pos)y i log(σ(x))+Q(neg)(1-y i )log(1-σ(x))),y i is the label of whether the sample belongs to class i, and σ(x) is the predicted score of the class.
[0091] The conventional solutions to the long-tail distribution problem in the related art are Re-sampling and Re-weighting, but Re-sampling usually requires detailed statistics and division of different data sets, and Re-weighting is sensitive to hyperparameter settings. This embodiment proposes a simple and universal method Grad-Guided-Softmax to suppress long-tail distribution. This method does not depend on the data set or the number of categories to be detected, and is an end-to-end training method. This embodiment is based on the yolov5 target detection algorithm, Grad-Guided-Softmax, which can significantly improve the detection effect of the tail category without affecting the detection effect of the head category. In actual applications, a 5-category detection model was trained, namely person, bike, trike, car, and face. Among them, the trike tricycle category has a small number of samples, and the car with the largest sample size is 40 times that of the trike. When trained using yolov5 alone, the trike category index is 49.1%. After using the Grad-Guided-Softmax method, the trike category index is increased to 51.6%, and the other four categories of indicators are basically the same.
[0092] In this embodiment, the prediction effect of each category is evaluated based on the gradient generated by each category during each batch training, and the loss weights of each category are dynamically reallocated based on softmax, which significantly improves the training effect of small samples. This embodiment has strong universality after testing and is an end-to-end training method without the need to configure hyperparameters.
[0093] See also Figure 2 , Figure 2 A schematic diagram of the structure of a target detection device provided in an embodiment of the present application, the device may include:
[0094] The sample input module 201 is used to input the current batch of samples into the target detection model to obtain a feature map; wherein the current batch of samples includes training samples of multiple categories;
[0095] A weight setting module 202, used to determine sample gradient information of each category according to the feature map, and set the loss weight of each category according to the sample gradient information;
[0096] A loss function adjustment module 203, used to modify the loss function of the target detection model according to the loss weight, and use the modified loss function to adjust the parameters of the target detection model to obtain a trained target detection model;
[0097] The target detection module 204 is used to perform target detection operations on unknown information using the trained target detection model.
[0098] This embodiment inputs the current batch of samples into the target detection model to obtain a feature map, and determines the sample gradient information of each category based on the feature map. The sample gradient information can reflect the training effect of the target detection model after this iteration, and then the loss weight of each category can be set based on the sample gradient information. This embodiment uses the loss weight to adjust the parameters of the loss function, and uses the loss function after adjusting the parameters to train the target detection model. This embodiment can adjust the loss function based on the training effect of the current batch of samples on the target detection model, and can avoid the influence of the long-tail distribution on the target detection model, thereby improving the accuracy of target detection.
[0099] Furthermore, the weight setting module 202 includes:
[0100] A gradient calculation unit is used to determine the positive sample gradient generated by the prediction point corresponding to the positive sample of each category according to the feature map; and is also used to determine the negative sample gradient generated by the prediction point corresponding to the negative sample of each category according to the feature map; wherein the sample gradient information includes the positive sample gradient and the negative sample gradient.
[0101] Furthermore, the weight setting module 202 includes:
[0102] A weight calculation unit is used to set the prediction point in the feature map where the positive sample gradient is greater than the gradient threshold as the first prediction point to be optimized; and is also used to set the prediction point in the feature map where the negative sample gradient is greater than the gradient threshold as the second prediction point to be optimized; and is also used to select a target category and calculate a first ratio and a second ratio of the target category; wherein the first ratio is the ratio of the number of first prediction points to be optimized of the target category to the number of prediction points corresponding to the target category; the second category is the ratio of the number of second prediction points to be optimized of the target category to the target number, and the target number is the difference between the number of prediction points corresponding to all the current batch samples and the number of prediction points corresponding to the target category; and is also used to determine whether the first ratio and the second ratio of all categories are obtained; if so, the category weight of each category is calculated according to the first ratio and the second ratio of all categories, and the category weight is calculated through a category balancing algorithm to obtain the loss weight of each category; if not, the step of selecting the target category is entered.
[0103] Furthermore, the process of the weight calculation unit calculating the category weight of each category based on the first ratios and the second ratios of all categories includes: setting the ratio of the maximum value in the first ratios to the first ratio of each category as the first category weight of the corresponding category; setting the ratio of the maximum value in the second ratios to the second ratio of each category as the second category weight of the corresponding category.
[0104] Furthermore, the process in which the weight calculation unit calculates the category weights through a category balancing algorithm to obtain the loss weights of each category includes: calculating the first category weights through a category balancing algorithm to obtain a first calculation result, multiplying the first calculation result by the total number of samples of the corresponding category to obtain the positive sample loss weight of each category; calculating the second category weights through a category balancing algorithm to obtain a second calculation result, multiplying the second calculation result by the total number of samples of the corresponding category to obtain the negative sample loss weight of each category.
[0105] Furthermore, the loss function adjustment module 203 is used to obtain the loss function loss of the target detection model; and is also used to modify the loss function loss using the positive sample loss weight Q(pos) and the negative sample loss weight Q(neg); wherein the loss function before modification is loss=-(y i log(σ(x))+(1-y i )log(1-(σ(x))), the corrected loss function is loss=-(Q(pos)y i log(σ(x))+Q(neg)(1-y i )log(1-(σ(x))),y iis the label of whether the sample belongs to class i, and σ(x) is the predicted score of the class.
[0106] Furthermore, it also includes:
[0107] The iterative control module is used to determine whether the target detection model has been iterated after adjusting the parameters of the target detection model using the modified loss function; if not, select training samples from the training set as new current batch samples, and enter the step of inputting the current batch samples into the target detection model to obtain a feature map.
[0108] Since the embodiments of the apparatus part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the apparatus part, which will not be repeated here.
[0109] The present application also provides a storage medium on which a computer program is stored, and when the computer program is executed, the steps provided in the above embodiment can be implemented. The storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0110] The present application also provides an electronic device, which may include a memory and a processor, wherein a computer program is stored in the memory, and when the processor calls the computer program in the memory, the steps provided in the above embodiment may be implemented. Of course, the electronic device may also include various network interfaces, power supplies and other components.
[0111] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same and similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of this application.
[0112] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises", "comprising" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
Claims
1. A target detection method, characterized in that: include: Input the current batch of samples into the target detection model to obtain a feature map; wherein the current batch of samples includes training samples of multiple categories; the current batch of samples are images; Determine sample gradient information of each category according to the feature map, and set the loss weight of each category according to the sample gradient information; wherein the sample gradient information is used to represent the training effect of the target detection model; Correcting the loss function of the target detection model according to the loss weight, and adjusting the parameters of the target detection model using the corrected loss function to obtain a trained target detection model; Using the trained target detection model to perform target detection operations on unknown information; Wherein, determining the sample gradient information of each category according to the feature map includes: Determine the positive sample gradient generated by the prediction point corresponding to the positive sample of each category according to the feature map; Determine the negative sample gradient generated by the prediction point corresponding to the negative sample of each category according to the feature map; Wherein, the sample gradient information includes the positive sample gradient and the negative sample gradient; The loss weight of each category is set according to the sample gradient information, including: The prediction point in the feature graph where the positive sample gradient is greater than the gradient threshold is set as the first prediction point to be optimized; Setting the prediction point in the feature map where the negative sample gradient is greater than the gradient threshold as the second prediction point to be optimized; Select a target category, and calculate a first ratio and a second ratio of the target category; wherein the first ratio is the ratio of the number of first prediction points to be optimized of the target category to the number of prediction points corresponding to the target category; the second ratio is the ratio of the number of second prediction points to be optimized of the target category to the target number, and the target number is the difference between the number of prediction points corresponding to all the current batch samples and the number of prediction points corresponding to the target category; Determine whether the first ratio and the second ratio of all categories are obtained; If so, the category weight of each category is calculated according to the first ratio and the second ratio of all categories, and the category weight is calculated by the category balancing algorithm to obtain the loss weight of each category; If not, the step of selecting the target category is entered.
2. The target detection method according to claim 1, characterized in that: The calculating the category weight of each category according to the first ratio and the second ratio of all categories includes: Setting the ratio of the maximum value of the first proportions to the first proportion of each category as the first category weight of the corresponding category; A ratio of a maximum value among the second proportions to the second proportion of each category is set as a second category weight of the corresponding category.
3. The target detection method according to claim 2, characterized in that: The step of calculating the category weights by a category balancing algorithm to obtain the loss weight of each category includes: Calculating the first category weight using the category balancing algorithm to obtain a first calculation result, and multiplying the first calculation result by the total number of samples of the corresponding category to obtain a positive sample loss weight of each category; The second category weight is calculated by the category balancing algorithm to obtain a second calculation result, and the second calculation result is multiplied by the total number of samples of the corresponding category to obtain the negative sample loss weight of each category.
4. The target detection method according to claim 3, characterized in that: The loss function of the target detection model is modified according to the loss weight, including: Obtain the loss function loss of the target detection model; Modify the loss function loss using the positive sample loss weight Q(pos) and the negative sample loss weight Q(neg); Among them, the loss function before correction is loss=-(y i log(σ(x))+(1-y i )log(1-(σ(x))), the corrected loss function is loss=-(Q(pos)y i log(σ(x))+Q(neg)(1-y i )log(1-(σ(x))),y i is the label of whether the sample belongs to class i, and σ(x) is the predicted score of the class.
5. The target detection method according to any one of claims 1 to 4, characterized in that: After adjusting the parameters of the target detection model using the modified loss function, the method further includes: Determine whether the target detection model has been iterated; If not, a training sample is selected from the training set as a new current batch of samples, and the step of inputting the current batch of samples into the target detection model to obtain a feature map is entered.
6. A target detection device, characterized in that: include: A sample input module, used to input the current batch of samples into the target detection model to obtain a feature map; wherein the current batch of samples includes training samples of multiple categories; the current batch of samples are images; A weight setting module, used to determine the sample gradient information of each category according to the feature map, and set the loss weight of each category according to the sample gradient information; wherein the sample gradient information is used to represent the training effect of the target detection model; A loss function adjustment module, used to correct the loss function of the target detection model according to the loss weight, and use the corrected loss function to adjust the parameters of the target detection model to obtain a trained target detection model; A target detection module, used to perform target detection operations on unknown information using the trained target detection model; Wherein, the weight setting module includes: A gradient calculation unit, used to determine the positive sample gradient generated by the prediction point corresponding to the positive sample of each category according to the feature map; and also used to determine the negative sample gradient generated by the prediction point corresponding to the negative sample of each category according to the feature map; wherein the sample gradient information includes the positive sample gradient and the negative sample gradient; A weight calculation unit is used to set the prediction point in the feature map where the positive sample gradient is greater than the gradient threshold as the first prediction point to be optimized; and is also used to set the prediction point in the feature map where the negative sample gradient is greater than the gradient threshold as the second prediction point to be optimized; and is also used to select a target category and calculate a first ratio and a second ratio of the target category; wherein the first ratio is the ratio of the number of first prediction points to be optimized of the target category to the number of prediction points corresponding to the target category; the second ratio is the ratio of the number of second prediction points to be optimized of the target category to the target number, and the target number is the difference between the number of prediction points corresponding to all the current batch samples and the number of prediction points corresponding to the target category; and is also used to determine whether the first ratio and the second ratio of all categories are obtained; if so, the category weight of each category is calculated according to the first ratio and the second ratio of all categories, and the category weight is calculated through a category balancing algorithm to obtain the loss weight of each category; if not, the step of selecting the target category is entered.
7. An electronic device, characterized in that: The method comprises a memory and a processor, wherein a computer program is stored in the memory, and when the processor calls the computer program in the memory, the steps of the target detection method according to any one of claims 1 to 5 are implemented.
8. A storage medium, characterized in that: The storage medium stores computer executable instructions, and when the computer executable instructions are loaded and executed by the processor, the steps of the target detection method according to any one of claims 1 to 5 are implemented.
