Method for solving imbalance problem of target detection sample
The method addresses target detection sample imbalance by collecting diverse data, annotating accurately, preprocessing, and using weighted SMOTE to generate new samples, improving model performance and generalization for rare categories.
Patent Information
- Application Number
- CN202411210792.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2024-12-24
AI Technical Summary
Existing methods for addressing target detection sample imbalance, such as data augmentation and SMOTE, are inefficient, costly, and introduce noise or computational overhead, failing to effectively improve model performance and generalization for rare categories.
A method that includes data collection, annotation, preprocessing, and model training with weighted sample generation using the SMOTE algorithm, where samples near category boundaries receive higher weights, generating new samples to balance class distributions and enhance model accuracy and robustness.
Improves model performance and generalization by balancing class distributions, enhancing accuracy and robustness through weighted sample generation and data augmentation, particularly benefiting rare categories.
Smart Images

Figure CN119180987A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of target detection, and in particular to a method for solving the problem of target detection sample imbalance. Background Art
[0002] Unbalanced sample detection refers to the imbalance in the number of samples of each category during training. Taking deep learning-based target detection as an example, sample category imbalance is mainly reflected in two aspects: imbalance of positive and negative samples and imbalance of difficult and easy samples. There are four types of problems that may be caused by imbalanced sample detection. The first is training imbalance: In the presence of category imbalance, the model may be more likely to learn the features of common categories, while learning the features of rare categories poorly. This may lead to poor performance of the model for rare categories when predicting. The second is model bias: If the number of samples of a certain category far exceeds that of other categories, the model may be more inclined to predict that category because it encounters this category more frequently in the training set. This may lead to a decrease in the performance of the model for minority categories. The third is evaluation bias: Common evaluation indicators, such as accuracy, may not be comprehensive enough, because simply predicting all samples as common categories can also achieve high accuracy. More meaningful evaluation indicators, such as confusion matrix, precision, recall, etc., can provide a more comprehensive performance evaluation. The fourth is the problem of target scarcity: For some rare categories, it may be difficult for the model to learn effective features because they appear a limited number of times in the data set. This may lead to poor detection performance for these rare categories.
[0003] There are generally two ways to solve the problem of sample imbalance, one is from the data perspective, and the other is from the algorithm perspective. From the data perspective, for a small amount of sample data, try to expand the data set of these small samples as much as possible, or try to increase the image-specific features and generalization through data augmentation, color and contrast enhancement, scale transformation, random cropping, random jitter, etc. to enrich the diversity of data. Most existing technologies start from the data perspective, including the following methods:
[0004] 1. Increase the original data set: Data collection and data annotation are time-consuming, labor-intensive, and extremely costly. For large amounts of image and video data, it is unrealistic to rely entirely on human labor for annotation. Although automatic annotation methods can improve efficiency, they often have problems with inaccuracy and require manual correction and review, which increases annotation costs.
[0005] 2. Data augmentation. Data augmentation can solve the problem of sample imbalance to a certain extent, but different data augmentation methods also have their own advantages and disadvantages:
[0006] (1) Random cropping: Random cropping is one of the most commonly used data augmentation methods. This method generates diversified training data by randomly cropping part of the image and retaining the target object. However, random cropping may have a certain impact on the target object, especially when the size and position relationship of the target object is complex, it may be difficult to detect.
[0007] (2) Scale transformation: Scale transformation refers to changing the size of the target object in the image to simulate inputs of different resolutions, thereby enriching the dataset. This method can effectively improve the robustness and generalization ability of the model, but it may also introduce some unnecessary noise, thereby affecting the performance of the model.
[0008] (3) Color transformation: Color transformation refers to changing the color of an image to increase the diversity of data samples. This method can effectively reduce the model's sensitivity to changes in illumination and color and improve the model's generalization ability. However, color transformation may also cause some unnecessary noise to interfere with model training.
[0009] (4) Image padding: Image padding refers to adding blocks to the edge of the image to maintain the integrity of the target object. This method can avoid the target object from being cropped or truncated to a certain extent and improve the detection accuracy of the model. However, too much padding may affect the model's perception of the authenticity of the target object and reduce the performance of the model.
[0010] When solving various problems caused by sample imbalance from an algorithmic perspective, the traditional synthetic minority oversampling technique (SMOTE) is often used for model training, that is, more minority samples are generated by interpolating minority samples. The basic idea is to randomly select a sample from its K nearest neighbors (which is also one of the minority samples) for each minority sample, and then randomly select a point on the line between the two as a newly synthesized minority sample. It proposes a K-Nearest Neighbor algorithm (KNN), that is, in the feature space, if most of the K nearest (nearest in the feature space) samples near a sample belong to a certain category, then the sample also belongs to this category, and an adaptive oversampling method (Oversampling Method Based on KNN and Adaptive, KAO). First, the KNN algorithm is used to remove noise samples; second, according to the number of majority class samples in the K nearest neighbor samples of the minority class samples, the oversampling weights are adaptively assigned to the minority class samples; finally, a new sample balanced data set is generated using a new interpolation method. However, this sampling process is computationally inefficient. Usually, the distance-based neighborhood relationship Q is used to extract data distribution information, which has a high computational overhead. At the same time, the nearest neighbor algorithm Q is easily interfered by noise and may not be able to obtain accurate distribution information, resulting in unreasonable sampling strategies. Moreover, the oversampling method generates too much data, which will further increase the number of samples in the training set, increase computational overhead, and may lead to overfitting. Summary of the invention
[0011] In view of the defects in the prior art, the purpose of the present invention is to provide a method for solving the problem of sample imbalance in target detection, which comprehensively considers factors such as sample weights, boundary conditions and category weights to improve the performance and generalization ability of the model.
[0012] In order to achieve the above-mentioned object of the invention, the present invention provides the following technical solutions:
[0013] A method for solving the problem of target detection sample imbalance, the method comprising:
[0014] S1. Collect sample data: Collect sample data for target detection. The data collection methods include using cameras, sensors, and web crawlers to ensure that the collected sample data is representative and diverse so that the training model can generalize better.
[0015] S2, data annotation: mark the object location and category for each sample by drawing a bounding box in the image or video and assigning a category label;
[0016] S3. Data preprocessing: Before training the object detection model, resize the image, normalize the pixel values, crop or pad the image, or encode or convert the labels to make the data adapt to the input requirements of the model so that the model can understand and process it correctly.
[0017] S4. Data augmentation: Perform a series of transformations and amplifications on sample data to increase data diversity and improve the generalization and robustness of the model; the data augmentation methods include translation, rotation, scaling, flipping, and random cropping;
[0018] S5, model training;
[0019] S6. Model evaluation and validation: After model training is completed, use the test data set to evaluate the performance of the model. By inputting the test data into the model, observing the output of the model, and comparing it with the true label, the accuracy, recall, and precision of the model are evaluated.
[0020] Among them, as far as model training is concerned, it includes:
[0021] S51. Sample classification: Divide the minority class samples into three categories: A, B, and C. Class A samples are those in which all K nearest neighbor samples belong to the majority class, Class B samples are those in which more than half of the K nearest neighbor samples belong to the majority class, and Class C samples are those in which more than half of the K nearest neighbor samples belong to the minority class.
[0022] S52, weight allocation: assign weights to Class B samples. The closer the samples are to the boundary, the larger the weights are. Samples with large weights are used as seed samples.
[0023] S53, sample generation: starting from the seed sample, a new sample is generated by the SMOTE algorithm. When generating a new sample, if the sample at the other end of the connecting line is in the A or C sample, the random interpolation point Q should be close to the seed sample end.
[0024] According to the method for solving the problem of sample imbalance in target detection provided by the present invention, in model training, after a minority of samples are classified, weights are assigned to samples in which more than half of the K nearest neighbor samples belong to the majority class, and the samples closer to the boundary have larger weights. Samples with large weights are then used as seed samples, and new samples are generated through the SMOTE algorithm. When faced with the problem of sample imbalance, the characteristics of minority class samples can be better learned, thereby improving the accuracy, robustness and fairness of the model.
[0025] Compared with the prior art, the present invention comprehensively considers factors such as sample weights, boundary conditions and category weights, can generate new samples with diversity and useful information, and balance the number of samples of different categories in model training, thereby improving the performance and generalization ability of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0027] Figure 1 Flow chart of a method for solving the problem of sample imbalance in target detection in an embodiment;
[0028] Figure 2 A classification diagram of a method for solving the problem of sample imbalance in target detection in an embodiment. DETAILED DESCRIPTION
[0029] 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, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.
[0030] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0031] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in the subsequent figures. In addition, all directional indications in this application (such as up, down, left, right, front, back, bottom...) are only used to explain the relative position relationship, movement, etc. between the components under a certain specific posture (as shown in the figures). If the specific posture changes, the directional indication will also change accordingly. Furthermore, the descriptions involving "first", "second", etc. in the application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated.
[0032] like Figure 1 As shown, this embodiment provides a method for solving the problem of target detection sample imbalance, the method comprising:
[0033] S1. Collect sample data: Collect sample data for target detection. The data collection methods include using cameras, sensors, and web crawlers to ensure that the collected sample data is representative and diverse so that the training model can generalize better.
[0034] S2. Data annotation: Label the object location and category for each sample by drawing a bounding box in the image or video and specifying the category label. The labeled data needs to be accurate and consistent to ensure that the training model can correctly learn the characteristics and location of the target.
[0035] S3. Data preprocessing: Before training the target detection model, the data is resized, pixel values are normalized, images are cropped or padded, or labels are encoded or converted to adapt the data to the input requirements of the model so that the model can understand and process it correctly.
[0036] S4. Data augmentation: Perform a series of transformations and amplifications on sample data to increase data diversity and improve the generalization and robustness of the model. Data augmentation methods include translation, rotation, scaling, flipping, and random cropping. Data augmentation can help the model better adapt to different scenarios and changes. When the data imbalance problem is not very serious, appropriate data augmentation of data with a small number of categories will be of great help to the subsequent model training. However, when the data imbalance problem is more serious, simply using data augmentation to make up for the defects of data imbalance will bring unpredictable problems and bury hidden dangers for the final tuning of the model.
[0037] S5. Model training.
[0038] S6. Model evaluation and validation: After model training is completed, use the test data set to evaluate the performance of the model. By inputting the test data into the model, observing the output of the model, and comparing it with the true label, the accuracy, recall, precision and other indicators of the model can be evaluated. This helps to understand the performance of the model in real scenarios and make further optimization and improvement.
[0039] Among them, as far as model training is concerned, it includes:
[0040] S51. Divide the minority class samples into three categories: A, B, and C. Class A samples are those in which all K nearest neighbor samples belong to the majority class, Class B samples are those in which more than half of the K nearest neighbor samples belong to the majority class, and Class C samples are those in which more than half of the K nearest neighbor samples belong to the minority class.
[0041] S52. Assign weights to Class B samples. The closer the samples are to the boundary, the larger their weights are. Samples with large weights are used as seed samples.
[0042] S53. Taking the seed sample as the starting point, a new sample is generated by the SMOTE algorithm. When generating a new sample, if the sample at the other end of the connecting line is in the A or C class sample, the random interpolation point Q should be close to the seed sample end.
[0043] like Figure 2As shown in the figure, if the selected minority class samples are surrounded by minority class samples, the newly synthesized samples will not provide much useful information. Similarly, if the selected minority class samples are surrounded by majority class samples, such samples may be noise, and the newly synthesized samples will overlap with the majority class samples around them, making classification difficult. Therefore, class B samples are selected and weighted according to the degree of their deviation from the boundary. The more they are offset to the boundary, the greater the weight they are given. This is used as the seed as the starting point, and then the SMOTE algorithm is used to generate new samples.
[0044] At the same time, different weights are assigned to different categories in the loss function during model training. By assigning higher weights to minority categories, the model can pay more attention to categories with fewer samples. Similarly, lower weights are assigned to majority categories.
[0045] The above describes the specific embodiments of the present invention. Based on the above description, relevant personnel can make various changes and modifications without departing from the technical concept of the present invention.
Claims
1. A method for solving the problem of sample imbalance in target detection, characterized in that: The method comprises: S1. Collect sample data: Collect sample data for target detection. The data collection methods include using cameras, sensors, and web crawlers to ensure that the collected sample data is representative and diverse so that the training model can generalize better. S2, data annotation: mark the object location and category for each sample by drawing a bounding box in the image or video and assigning a category label; S3. Data preprocessing: Before training the object detection model, resize the image, normalize the pixel values, crop or pad the image, or encode or convert the labels to make the data adapt to the input requirements of the model so that the model can understand and process it correctly. S4. Data augmentation: Perform a series of transformations and amplifications on sample data to increase data diversity and improve the generalization and robustness of the model; the data augmentation methods include translation, rotation, scaling, flipping, and random cropping; S5, model training; S6. Model evaluation and validation: After model training is completed, use the test data set to evaluate the performance of the model. By inputting the test data into the model, observing the output of the model, and comparing it with the true label, the accuracy, recall, and precision of the model are evaluated. Among them, as far as model training is concerned, it includes: S51. Sample classification: Divide the minority class samples into three categories: A, B, and C. Class A samples are those in which all K nearest neighbor samples belong to the majority class, Class B samples are those in which more than half of the K nearest neighbor samples belong to the majority class, and Class C samples are those in which more than half of the K nearest neighbor samples belong to the minority class. S52, weight allocation: assign weights to Class B samples. The closer the samples are to the boundary, the larger the weights are. Samples with large weights are used as seed samples. S53, sample generation: starting from the seed sample, a new sample is generated by the SMOTE algorithm. When generating a new sample, if the sample at the other end of the connecting line is in the A or C sample, the random interpolation point Q should be close to the seed sample end.
