Training sampling set acquisition method and device
By class matching and statistics on the initial sample set of object detection model training, the training sample set is obtained, which solves the problem of category imbalance in the training sample set in the existing technology and improves the model training effect.
Patent Information
- Application Number
- CN202311034224.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-16
- Publication Date
- 2025-02-21
AI Technical Summary
In the training of existing object detection models, the sampling method fails to effectively solve the problem of category imbalance in the training sample set, resulting in poor model training effect.
By obtaining the initial sample set, class matching and statistics are performed for each initial sample, the corresponding number of category elements and total number of samples are determined, thereby obtaining the training sample set and ensuring the category balance of the sample set.
It improves the accuracy and balance of the training sample set, enhances the effect of subsequent model training, and avoids the problem of large number of repeated samples in the training sample set.
Smart Images

Figure CN119493985A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of model training technology, and in particular, relates to a method and device for acquiring a training sampling set. Background Art
[0002] At present, most of the target detection model training uses grid sampling, uniform sampling, set sampling and resampling to obtain training sample sets. Grid sampling, uniform sampling, set sampling and other methods are usually sparse sampling for a single specific scene and retain point cloud features. They focus on how to better retain more effective features for a specific training sample while sparsely reducing the amount of calculation, and do not take into account the imbalance of the overall category instances in the training sample set, resulting in poor results for subsequent model training. For the resampling method, samples can be repeatedly extracted from the imbalanced training set to make the training sample set balanced, but it is a repeated extraction of the initial samples, that is, for a small number of initial sample sets, there will be a large number of repeated samples in the extracted training samples, resulting in poor results for model training. Summary of the invention
[0003] The embodiment of the present application provides a method and device for obtaining a training sampling set to improve the accuracy and balance of the training sample set, thereby improving the effect of subsequent model training.
[0004] In a first aspect, an embodiment of the present application provides a method for acquiring a training sample set, the method comprising:
[0005] Obtain an initial sample set, the initial sample set includes N initial samples, and each initial sample includes at least one object, N is a positive integer,
[0006] For each initial sample, at least one object is matched with the target objects of C categories corresponding to the target detection, and the first category corresponding to the initial sample and the number of category elements of the initial sample are determined. The number of category elements is the number of different categories in the first category. C is a positive integer.
[0007] According to the first category corresponding to each initial sample, a first total number of samples corresponding to each category in the C categories is determined from the initial sample set,
[0008] According to the number of category elements of each initial sample and the first total number of samples corresponding to each category, a training sample set is obtained from the initial sample set, and the training sample set is used to train the target detection model.
[0009] In a second aspect, an embodiment of the present application provides a training sample set acquisition device, the device comprising:
[0010] The first acquisition module is used to acquire an initial sample set, where the initial sample set includes N initial samples, and each initial sample includes at least one object, where N is a positive integer.
[0011] The first determination module is used to match at least one object with C categories of target objects corresponding to the target detection for each initial sample, determine the first category corresponding to the initial sample, and the number of category elements of the initial sample, where the number of category elements is the number of different categories in the first category, and C is a positive integer.
[0012] The second determination module is used to determine, from the initial sample set, a first total number of samples corresponding to each of the C categories according to the first category corresponding to each initial sample,
[0013] The second acquisition module is used to acquire a training sample set from the initial sample set according to the number of category elements of each initial sample and the first total number of samples corresponding to each category, and the training sample set is used to train the target detection model.
[0014] In a third aspect, an embodiment of the present application provides an electronic device, the device comprising:
[0015] A processor and a memory storing programs or instructions;
[0016] The above method is implemented when the processor executes the program or instruction.
[0017] In a fourth aspect, an embodiment of the present application provides a machine-readable storage medium, on which a program or instruction is stored, and the program or instruction implements the above method when executed by a processor.
[0018] In a fifth aspect, an embodiment of the present application provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the above method.
[0019] The training sampling set acquisition method and device of the embodiment of the present application can acquire an initial sample set, which includes N initial samples, and each initial sample includes at least one object. For each initial sample, at least one object is matched with C categories of target objects corresponding to target detection, and the first category corresponding to the initial sample and the number of category elements of the initial sample are determined. The number of category elements is the number of different categories in the first category. According to the first category corresponding to each initial sample, the first total number of samples corresponding to each category in the C categories is determined from the initial sample set. According to the number of category elements of each initial sample and the first total number of samples corresponding to each category, a training sample set is acquired from the initial sample set, and the training sample set is used to train the target detection model.
[0020] In this way, the number of category elements of each initial sample can be obtained from a massive amount of initial samples according to the type of target objects to be detected contained in each initial sample. Then, considering the total number of samples of different categories of target objects in the entire initial sample set, a certain number of initial samples can be extracted from the initial sample set to form a training sample set. This takes into account the balance of instances of each category and avoids a large number of duplicate samples in the training sample set, thereby improving the accuracy and balance of the training sample set and thus improving the effect of subsequent model training. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0022] Figure 1 It is a flowchart of a method for obtaining a training sample set provided by an embodiment of the present application;
[0023] Figure 2 It is a schematic diagram of a specific scenario embodiment of the training sample set acquisition method provided in an embodiment of the present application;
[0024] Figure 3 is a schematic diagram of another specific scenario embodiment of the training sample set acquisition method provided in an embodiment of the present application;
[0025] Figure 4 is a structural diagram of a training sample set acquisition device provided by another embodiment of the present application;
[0026] Figure 5 It is a structural schematic diagram of an electronic device provided in yet another embodiment of the present application. DETAILED DESCRIPTION
[0027] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0028] It should be noted that, in this article, 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 "include", "comprise" 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, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0029] In order to solve the problems in the prior art, the embodiment of the present application provides a method and device for acquiring a training sample set. The following first introduces the method for acquiring a training sample set provided by the embodiment of the present application.
[0030] Figure 1 FIG. 1 is a flow chart of a method for obtaining a training sample set provided by an embodiment of the present application. Figure 1 As shown, the method for obtaining a training sample set may include the following steps:
[0031] Step 101: Obtain an initial sample set, where the initial sample set includes N initial samples, and each initial sample includes at least one object, where N is a positive integer.
[0032] In step 101, the initial sample set may include multiple initial samples, and each initial sample includes at least one object. The initial sample set may be a large amount of data obtained from an open source database, or may be multiple images of different scenes collected by an image acquisition device. The specific acquisition method is not specifically limited here.
[0033] Step 102, for each initial sample, match at least one object with C categories of target objects corresponding to the target detection, determine the first category corresponding to the initial sample, and the number of category elements of the initial sample, the number of category elements is the number of different categories in the first category, and C is a positive integer.
[0034] In step 102, target detection may correspond to target objects of different categories. For example, in target detection in an intelligent driving scenario, target objects may include categories such as vehicles and pedestrians.
[0035] Each initial sample may refer to a frame of image, which may include different objects such as vehicles, pedestrians, houses, trees, etc. At least one object in each initial sample may be matched with a target object corresponding to the target detection to determine whether the initial sample includes the target object corresponding to the target detection, thereby determining the first category corresponding to the initial sample. It is understood that the first category may refer to one or more categories among the C categories.
[0036] For example, the categories of target objects that need to be detected include vehicles and pedestrians. If there are two pedestrians and one vehicle in initial sample 1, the first category corresponding to initial sample 1 is pedestrians and vehicles. If there is one pedestrian and a row of trees in initial sample 2, the first category corresponding to initial sample 2 is pedestrians.
[0037] The number of category elements of the initial sample may also be determined, where the number of category elements may be the number of different categories in the first category. The number of category elements may be calculated using the following formula:
[0038]
[0039] Among them, a i is the number of category elements of the initial sample i, n i is the number of objects included in the initial sample i, is the category of each object, C is the set of C categories. In this formula, objects of the same category are only calculated once in the same initial sample and are not calculated repeatedly.
[0040] For example, if there are two pedestrians and one vehicle in initial sample 1, the number of category elements of initial sample 1 is 2. If there is one pedestrian and a row of trees in initial sample 2, the number of category elements of initial sample 2 is 1.
[0041] Step 103 : According to the first category corresponding to each initial sample, a first total number of samples corresponding to each category in the C categories is determined from the initial sample set.
[0042] In step 103, according to the first category corresponding to each initial sample, the first total number of samples corresponding to each category in the C categories in the initial sample set can be counted. The first total number of samples corresponding to each category in the C categories can be calculated using the following formula:
[0043]
[0044] Among them, S j is the first total number of samples corresponding to category j in C categories, c i is the first category of the initial sample i, C jis category j among C categories, and N is the number of initial samples included in the initial sample set.
[0045] For example, among all the initial samples in the initial sample set, there are 100 initial samples including pedestrians and 80 initial samples including vehicles. Then, the first total number of samples corresponding to pedestrians is 100, and the first total number of samples corresponding to vehicles is 80.
[0046] Step 104 , obtaining a training sample set from the initial sample set according to the number of category elements of each initial sample and the first total number of samples corresponding to each category, and the training sample set is used to train the target detection model.
[0047] In step 104, a training sample set can be obtained from the initial sample set according to the number of category elements of each initial sample and the first total number of samples corresponding to each category. For example, the number of category elements of each initial sample can reflect the number of different categories of target objects included in the sample, and the first total number of samples corresponding to each category can reflect the distribution of each category to be detected in the entire initial sample set. With reference to these two data, the probability of each initial sample being extracted as a training sample can be analyzed, so that according to the probability of each initial sample being extracted, a certain number of initial samples can be obtained from the initial sample set as training samples to form a training sample set. The obtained training sample set can be used for subsequent training of the target detection model.
[0048] The training sampling set acquisition method of the embodiment of the present application can acquire an initial sample set, where the initial sample set includes N initial samples, and each initial sample includes at least one object. For each initial sample, at least one object is matched with C categories of target objects corresponding to target detection, and the first category corresponding to the initial sample and the number of category elements of the initial sample are determined. The number of category elements is the number of different categories in the first category. According to the first category corresponding to each initial sample, the first total number of samples corresponding to each category in the C categories is determined from the initial sample set. According to the number of category elements of each initial sample and the first total number of samples corresponding to each category, a training sample set is acquired from the initial sample set, and the training sample set is used to train the target detection model.
[0049] In this way, the number of category elements of each initial sample can be obtained from a massive amount of initial samples according to the type of target objects to be detected contained in each initial sample. Then, considering the total number of samples of different categories of target objects in the entire initial sample set, a certain number of initial samples can be extracted from the initial sample set to form a training sample set. This takes into account the balance of instances of each category and avoids a large number of duplicate samples in the training sample set, thereby improving the accuracy and balance of the training sample set and thus improving the effect of subsequent model training.
[0050] In some embodiments, the above step 104 may include the following steps:
[0051] For each initial sample, the first sampling probability of the initial sample is determined according to the number of category elements and the first total number of samples corresponding to each category.
[0052] A training sample set is obtained from the initial sample set according to the first sampling probability of each initial sample.
[0053] In this embodiment, for each initial sample, a first sampling probability of the initial sample may be determined according to the number of category elements and the first total number of samples corresponding to each category.
[0054] For example, the first sampling probability of a certain initial sample can be calculated by the number of category elements of the initial sample and the first total number of samples corresponding to each category to be detected. The first sampling probability can be a sampling probability used to reflect the balance of the instance. For example, the sum of the first total number of samples corresponding to each category to be detected can be used as the denominator, and the number of category elements of each initial sample can be used as the numerator to obtain the first sampling probability.
[0055] The training sample set can be obtained from the initial sample set according to the first sampling probability of each initial sample. For example, a certain number of initial samples can be randomly selected as training samples according to the first sampling probability of each initial sample in the initial sample set to form the training sample set.
[0056] In this way, the balance of instances in each category is taken into account, which improves the balance of the training sample set and thus improves the effect of subsequent model training.
[0057] In some embodiments, the first sampling probability is determined by the following formula:
[0058]
[0059] in, is the first sampling probability of the initial sample i, a i is the number of category elements of the initial sample i, C is the set of C categories, S j is the first total number of samples corresponding to category j in C categories.
[0060] In this embodiment, the above formula may be used to calculate the first sampling probability of each initial sample.
[0061] For example, if the number of category elements of initial sample 1 is 2, the number of category elements of initial sample 2 is 1, the first total number of samples corresponding to pedestrians is 100, and the first total number of samples corresponding to vehicles is 80. Then the first sampling probability of initial sample 1 is 2 / (100+80), that is, 1 / 90. The first sampling probability of initial sample 2 is 1 / (100+80), that is, 1 / 180.
[0062] In some embodiments, the step of obtaining a training sample set from an initial sample set according to the first sampling probability of each initial sample may include the following steps:
[0063] For each initial sample, determine a second total number of samples corresponding to each category in the first category from the first total number of samples corresponding to each category,
[0064] According to the second total number of samples corresponding to each category, the second sampling probability of the initial sample is determined,
[0065] A training sample set is obtained from the initial sample set according to the first sampling probability and the second sampling probability of each initial sample.
[0066] In this embodiment, a second sampling probability for each initial sample to reflect class balance may also be determined.
[0067] For example, for each initial sample, the second total number of samples corresponding to each category in the first category can be determined from the first total number of samples corresponding to each category. For example, if the first category corresponding to initial sample 1 is pedestrians and vehicles, then for initial sample 1, the second total number of samples corresponding to each category in the first category includes the first total number of samples corresponding to pedestrians and the first total number of samples corresponding to vehicles. If the first category corresponding to initial sample 2 is pedestrians, then for initial sample 2, the second total number of samples corresponding to each category in the first category only includes the first total number of samples corresponding to pedestrians.
[0068] The second sampling probability of the initial sample can be determined according to the second total number of samples corresponding to each category. For example, the second sampling probability of the initial sample can be calculated by the second total number of samples corresponding to each category in the first category of a certain initial sample. For example, the sum of the second total number of samples corresponding to each category in the first category can be used as the denominator. Since each initial sample contains a certain category, it can be considered that the contribution to the category is 1. Therefore, 1 can be used as the numerator, and the probability of each category can be summed up, and then the second sampling probability of the overall category average can be calculated.
[0069] A training sample set can be obtained from the initial sample set according to the first sampling probability and the second sampling probability of each initial sample. For example, the first sampling probability of instance balance and the second sampling probability of category balance can be jointly referenced to randomly select a certain number of initial samples as training samples to form a training sample set.
[0070] In this way, the instance balance and category balance are fully taken into consideration, which further improves the balance and accuracy of the acquired training sample set, thereby further improving the effect of subsequent model training.
[0071] In some embodiments, the second sampling probability is determined by the following formula:
[0072]
[0073] in, is the second sampling probability of the initial sample i, a i is the number of category elements of the initial sample i, C is the set of C categories, is the second total number of samples corresponding to category j in the first category corresponding to the initial sample i.
[0074] In this embodiment, the second sampling probability of each initial sample may be calculated using the above formula.
[0075] For example, if C categories include pedestrians and vehicles, the second total number of samples corresponding to each category in the first category corresponding to initial sample 1 includes the first total number of samples corresponding to pedestrians, 100, and the first total number of samples corresponding to vehicles, 80, and the second total number of samples corresponding to each category in the first category corresponding to initial sample 2 includes the first total number of samples corresponding to pedestrians, 100. Then the second sampling probability of initial sample 1 is (1 / 2)*(1 / 100+1 / 80), which is 9 / 800. The second sampling probability of initial sample 2 is (1 / 2)*(1 / 100), which is 1 / 200.
[0076] In some embodiments, the step of acquiring the training sample set from the initial sample set according to the first sampling probability and the second sampling probability of each initial sample may include the following steps:
[0077] For each initial sample, a third sampling probability of the initial sample is determined according to the first sampling probability, the second sampling probability, a first weight of the first sampling probability, and a second weight of the second sampling probability.
[0078] A training sample set is obtained from the initial sample set according to the third sampling probability of each initial sample.
[0079] In this embodiment, for each initial sample, the third sampling probability of the initial sample may be determined according to the first sampling probability, the second sampling probability, the first weight of the first sampling probability, and the second weight of the second sampling probability.
[0080] Among them, the first weight and the second weight can be set according to actual needs and are not specifically limited here. For the third sampling probability corresponding to each initial sample, the WeigteredRandomSampler under the implemented framework can be used to assist in dynamic implementation. Through the training rounds, the first sampling probability and the second sampling probability obtained in the previous text are weighted and summed to gradually adjust the role of the two balanced probabilities in the process of obtaining the training sample set.
[0081] For example, the third sampling probability can be determined by the following formula:
[0082]
[0083] Among them, P i is the third sampling probability of the initial sample i, is the first sampling probability of the initial sample i, is the second sampling probability of the initial sample i, λ is the first weight, and 1-λ is the second weight. It can be understood that λ can be set according to actual needs. If more emphasis is placed on instance balance, the larger the value of λ is, conversely, if more emphasis is placed on category balance, the smaller the value of λ is, λ=current_iteration / total_iteration_per_epoch, and λ∈[0,1].
[0084] The training sample set may be obtained from the initial sample set according to the third sampling probability of each initial sample. For example, a certain number of initial samples may be randomly selected as training samples according to the third sampling probability of each initial sample in the initial sample set to form the training sample set.
[0085] In some embodiments, for each initial sample, determining the third sampling probability of the initial sample according to the first sampling probability and the second sampling probability, as well as the first weight of the first sampling probability and the second weight of the second sampling probability may include the following steps:
[0086] For each initial sample, a third sampling probability of the initial sample is determined according to the first sampling probability, the second sampling probability, the first weight of the first sampling probability, the second weight of the second sampling probability, and the expected index.
[0087] In this embodiment, for each initial sample, a third sampling probability of the initial sample can be obtained according to the first sampling probability, the second sampling probability, the first weight of the first sampling probability, the second weight of the second sampling probability and the expected index.
[0088] Among them, the value range of the expected index n is [0,1], which can be set according to needs and expectations to achieve the maximum expectation. The expected index can be the expected index of the first sampling probability, the expected index of the second sampling probability, or the expected index of the first sampling probability and the second sampling probability, which is not specifically limited here. For example, the first product of the expected exponent power of the first sampling probability and the first weight can be calculated, and then the second product of the expected exponent power of the second sampling probability and the second weight can be calculated, then the third sampling probability can be equal to the sum of the first product and the second product.
[0089] In some embodiments, the third sampling probability is determined by the following formula:
[0090]
[0091] Among them, P i is the third sampling probability of the initial sample i, is the first sampling probability of the initial sample i, is the second sampling probability of the initial sample i, λ is the first weight, 1-λ is the second weight, and n is the expected index.
[0092] In this embodiment, the third sampling probability of each initial sample may be calculated using the above formula.
[0093] For example, if the expected index n is 1 and the first weight λ is 0.5, the second weight 1-λ is also 0.5. At this time, the first sampling probability of the initial sample 1 is 1 / 90, the second sampling probability of the initial sample 1 is 1 / 360, and the third sampling probability of the initial sample 1 is 1 / 2*1 / 90+1 / 2*9 / 800=1 / 180+9 / 1600. The first sampling probability of the initial sample 2 is 1 / 180, the second sampling probability of the initial sample 2 is 1 / 200, and the third sampling probability of the initial sample 2 is 1 / 2*1 / 180+1 / 2*1 / 200=1 / 360+1 / 400.
[0094] In some embodiments, the training sample set acquisition method may further include the following steps:
[0095] The target detection model is trained based on the training sample set to obtain the training results.
[0096] According to the training results, the weights and / or expected indexes are adjusted, the weights including the first weights and the second weights,
[0097] Update the third sampling probability of each initial sample according to the adjusted weight and / or expected index,
[0098] A training sample set is obtained from the initial sample set according to the updated third sampling probability of each initial sample.
[0099] In this embodiment, after obtaining the training sample set, the target detection model can also be trained based on the training sample set to obtain training results. The training results can be used as a reference to adjust the weight and / or expected index when calculating each third sampling probability when obtaining the training sample set in the next round. The weight may include a first weight and a second weight.
[0100] The third sampling probability of each initial sample can be updated according to the adjusted weight and / or expected index, and according to the updated third sampling probability of each initial sample, a certain number of initial samples are randomly selected from the initial sample set again as training samples to form a training sample set.
[0101] In other words, during each round of target detection model training, the extraction probability of the training sample set of this round can be weightedly adjusted to gradually increase or decrease according to the number of iterations. That is, the third sampling probability of each initial sample can be adjusted by adjusting the first weight, the second weight and the expected index. If it is large, it will gradually decrease, and if it is small, it will gradually increase. Then, random sampling is performed using the third sampling probability of each initial sample as a training sample set for this round for training iteration.
[0102] It is understandable that in the model training for target detection, random sampling can be performed according to the calculated third sampling probability to construct each round of training sample sets, and the proportion of each category in the overall initial sample and the contribution of each category in a single initial sample are weighed, and the third sampling probability of each initial sample is gradually adjusted with the training rounds, and then random sampling is performed according to the third sampling probability. The dynamic adjustment of the training sample set in each round improves the robustness of the trained target detection model to deal with different data, and also enhances the generalization of the target detection model to different data.
[0103] Based on the training sample set acquisition method provided in the above embodiment, the present application also provides a specific scenario embodiment of the training sample set acquisition method. Figure 2 As shown, the scenario embodiment includes the following steps:
[0104] Step 201 , counting the number of category elements of each initial sample and the total number of samples corresponding to each category.
[0105] Step 202: Calculate a first sampling probability of instance balance.
[0106] Step 203: Calculate a second class-balanced sampling probability.
[0107] Step 204, using the mechanism of weigthsampler in pytorch to fuse the two probabilities to dynamically assign sampling weights to the training samples.
[0108] Step 205: Obtain a training sample set.
[0109] For example. Figure 3 As shown, the detailed steps of the scenario embodiment can be as follows:
[0110] Step 301, count a i and S j That is, for each initial sample, at least one object is matched with the target objects of C categories corresponding to the target detection, and the first category corresponding to the initial sample and the number of category elements of different categories in the first category are determined. i , and according to the first category corresponding to each initial sample, determine the first total number S of samples corresponding to each category in the C categories from the initial sample set j .
[0111] Step 302, calculate each initial sample and That is, for each initial sample, the first sampling probability of the initial sample is determined according to the number of category elements and the first total number of samples corresponding to each category. For each initial sample, a second total number of samples corresponding to each category in the first category is determined from the first total number of samples corresponding to each category, and a second sampling probability of the initial sample is determined according to the second total number of samples corresponding to each category.
[0112] Step 303: select n in [0, 1] and use the current round to calculate the weighted P i That is, for each initial sample, according to the first sampling probability The second sampling probability The first sampling probability is determined by the first weight λ of the first sampling probability, the second weight 1-λ of the second sampling probability and the expected index n. i .
[0113] Step 304: for each initial sample, press P i Perform random sampling.
[0114] Step 305: Obtain the training sample set for this round.
[0115] Step 306: model training.
[0116] Repeat steps 303 to 306 to implement iterative training of the target detection model.
[0117] The training sample set acquisition method of this embodiment realizes dynamic adjustment and balanced sampling during the model training process, that is, compared with the existing sampling method that only sparsely extracts sample features of a single scene, it can pay more attention to solving the category imbalance of the overall data sample, and bring higher benefits overall. In addition, for the commonly used method of resampling data according to a fixed value or setting a ratio so that each category is resampled to the same number, this embodiment can dynamically adjust the sampling ratio of the data according to the specific statistical results during the model training process, and gradually balance the number of categories, that is, the form of the training set will not be fixed by sampling once, and the training sample set is sampled according to the statistical probability in each round of model training, thereby avoiding overfitting of a large number of repeated samples during each model training process, and at the same time can achieve the same or even slightly higher verification accuracy with fewer iterations.
[0118] Based on the training sample set acquisition method provided in the above embodiment, the present application also provides an embodiment of a training sample set acquisition device.
[0119] Figure 4 A schematic diagram of the structure of a training sample set acquisition device provided in another embodiment of the present application is shown. For ease of explanation, only the parts related to the embodiment of the present application are shown.
[0120] Reference Figure 4 , the training sample set acquisition device 400 includes:
[0121] The first acquisition module 401 is used to acquire an initial sample set, where the initial sample set includes N initial samples, and each initial sample includes at least one object, where N is a positive integer.
[0122] The first determination module 402 is used to match at least one object with C categories of target objects corresponding to the target detection for each initial sample, determine the first category corresponding to the initial sample, and the number of category elements of the initial sample, where the number of category elements is the number of different categories in the first category, and C is a positive integer.
[0123] The second determination module 403 is used to determine a first total number of samples corresponding to each of the C categories from the initial sample set according to the first category corresponding to each initial sample,
[0124] The second acquisition module 404 is used to acquire a training sample set from the initial sample set according to the number of category elements of each initial sample and the first total number of samples corresponding to each category, and the training sample set is used to train the target detection model.
[0125] In some embodiments, the second acquisition module 404 may also be used to:
[0126] For each initial sample, the first sampling probability of the initial sample is determined according to the number of category elements and the first total number of samples corresponding to each category.
[0127] A training sample set is obtained from the initial sample set according to the first sampling probability of each initial sample.
[0128] In some embodiments, the first sampling probability is determined by the following formula:
[0129]
[0130] in, is the first sampling probability of the initial sample i, a i is the number of category elements of the initial sample i, C is the set of C categories, S j is the first total number of samples corresponding to category j in C categories.
[0131] In some embodiments, the second acquisition module 404 may also be used to:
[0132] For each initial sample, determine a second total number of samples corresponding to each category in the first category from the first total number of samples corresponding to each category,
[0133] According to the second total number of samples corresponding to each category, the second sampling probability of the initial sample is determined,
[0134] A training sample set is obtained from the initial sample set according to the first sampling probability and the second sampling probability of each initial sample.
[0135] In some embodiments, the second sampling probability is determined by the following formula:
[0136]
[0137] in, is the second sampling probability of the initial sample i, a i is the number of category elements of the initial sample i, C is the set of C categories, is the second total number of samples corresponding to category j in the first category corresponding to the initial sample i.
[0138] In some embodiments, the second acquisition module 404 may also be used to:
[0139] For each initial sample, a third sampling probability of the initial sample is determined according to the first sampling probability, the second sampling probability, a first weight of the first sampling probability, and a second weight of the second sampling probability.
[0140] A training sample set is obtained from the initial sample set according to the third sampling probability of each initial sample.
[0141] In some embodiments, the second acquisition module 404 may also be used to:
[0142] For each initial sample, a third sampling probability of the initial sample is determined according to the first sampling probability, the second sampling probability, the first weight of the first sampling probability, the second weight of the second sampling probability, and the expected index.
[0143] In some embodiments, the third sampling probability is determined by the following formula:
[0144]
[0145] Among them, P i is the third sampling probability of the initial sample i, is the first sampling probability of the initial sample i, is the second sampling probability of the initial sample i, λ is the first weight, 1-λ is the second weight, and n is the expected index.
[0146] In some embodiments, the training sample set acquisition device 400 may further include:
[0147] The training module is used to train the target detection model based on the training sample set and obtain the training results.
[0148] An adjustment module is used to adjust the weight and / or expected index according to the training result, the weight includes a first weight and a second weight,
[0149] An updating module, for updating the third sampling probability of each initial sample according to the adjusted weight and / or expected index,
[0150] The second acquisition module may also be used to: acquire a training sample set from the initial sample set according to the updated third sampling probability of each initial sample.
[0151] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application, and are devices corresponding to the above-mentioned training sampling set acquisition method. All implementation methods in the above-mentioned method embodiment are applicable to the embodiment of the device. Its specific functions and technical effects can be found in the method embodiment part, which will not be repeated here.
[0152] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0153] Figure 5 A schematic diagram of the hardware structure of an electronic device provided in yet another embodiment of the present application is shown.
[0154] The device may include a processor 501 and a memory 502 storing programs or instructions.
[0155] When the processor 501 executes the program, the steps in any of the above method embodiments are implemented.
[0156] Exemplarily, the program may be divided into one or more modules / units, one or more modules / units are stored in the memory 502, and executed by the processor 501 to complete the present application. One or more modules / units may be a series of program instruction segments capable of completing a specific function, and the instruction segments are used to describe the execution process of the program in the device.
[0157] Specifically, the processor 501 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0158] The memory 502 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 502 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 502 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 502 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 502 is a non-volatile solid-state memory.
[0159] The memory may include read-only memory (ROM), random access memory (RAM), magnetic disk storage media devices, optical storage media devices, flash memory devices, electrical, optical or other physical / tangible memory storage devices. Thus, typically, the memory includes one or more tangible (non-transitory) machine-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to an aspect of the present disclosure.
[0160] The processor 501 implements any one of the methods in the above embodiments by reading and executing the program or instruction stored in the memory 502 .
[0161] In one example, the electronic device may further include a communication interface 503 and a bus 504. The processor 501, the memory 502, and the communication interface 503 are connected via the bus 504 and communicate with each other.
[0162] The communication interface 503 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0163] Bus 504 includes hardware, software or both, and the parts of online data flow billing equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 504 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the present application considers any suitable bus or interconnection.
[0164] In addition, in combination with the method in the above embodiment, the embodiment of the present application may provide a machine-readable storage medium for implementation. The machine-readable storage medium stores a program or instruction; when the program or instruction is executed by a processor, any one of the methods in the above embodiment is implemented. The machine-readable storage medium can be read by a machine such as a computer.
[0165] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0166] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0167] An embodiment of the present application provides a computer program product, which is stored in a machine-readable storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0168] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0169] The functional modules shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. Programs or code segments can be stored in machine-readable media, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable media" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. Code segments can be downloaded via computer grids such as the Internet, intranets, etc.
[0170] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0171] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by a computer program or instruction. These programs or instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0172] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A method for obtaining a training sample set, characterized in that: include: Obtain an initial sample set, the initial sample set includes N initial samples, and each initial sample includes at least one object, N is a positive integer, For each initial sample, the at least one object is matched with the target objects of C categories corresponding to the target detection, and the first category corresponding to the initial sample and the number of category elements of the initial sample are determined, where the number of category elements is the number of different categories in the first category, and C is a positive integer. According to the first category corresponding to each initial sample, determining a first total number of samples corresponding to each of the C categories from the initial sample set, According to the number of category elements of each initial sample and the first total number of samples corresponding to each category, a training sample set is obtained from the initial sample set, and the training sample set is used to train the target detection model.
2. The method according to claim 1, characterized in that The step of acquiring a training sample set from the initial sample set according to the number of category elements of each initial sample and the first total number of samples corresponding to each category includes: For each initial sample, determining a first sampling probability of the initial sample according to the number of category elements and a first total number of samples corresponding to each category, A training sample set is obtained from the initial sample set according to the first sampling probability of each initial sample.
3. The method according to claim 2, characterized in that The first sampling probability is determined by the following formula: in, is the first sampling probability of the initial sample i, a i is the number of category elements of the initial sample i, C is the set of C categories, S j is the first total number of samples corresponding to category j in C categories.
4. The method according to claim 2, characterized in that: The step of acquiring a training sample set from the initial sample set according to the first sampling probability of each initial sample includes: For each initial sample, determine a second total number of samples corresponding to each category in the first category from the first total number of samples corresponding to each category, Determine a second sampling probability of the initial sample according to a second total number of samples corresponding to each category, A training sample set is acquired from the initial sample set according to the first sampling probability and the second sampling probability of each initial sample.
5. The method according to claim 4, characterized in that The second sampling probability is determined by the following formula: in, is the second sampling probability of the initial sample i, a i is the number of category elements of the initial sample i, C is the set of C categories, is the second total number of samples corresponding to category j in the first category corresponding to the initial sample i.
6. The method according to claim 4, characterized in that The step of acquiring a training sample set from the initial sample set according to the first sampling probability and the second sampling probability of each initial sample includes: For each initial sample, determine a third sampling probability of the initial sample according to the first sampling probability, the second sampling probability, a first weight of the first sampling probability, and a second weight of the second sampling probability, A training sample set is obtained from the initial sample set according to the third sampling probability of each initial sample.
7. The method according to claim 6, characterized in that The determining, for each initial sample, a third sampling probability of the initial sample according to the first sampling probability and the second sampling probability, and a first weight of the first sampling probability and a second weight of the second sampling probability, comprises: For each initial sample, a third sampling probability of the initial sample is determined according to the first sampling probability, the second sampling probability, a first weight of the first sampling probability, a second weight of the second sampling probability, and an expected index.
8. The method according to claim 7, characterized in that The third sampling probability is determined by the following formula: Where P is the third sampling probability of the initial sample i, is the first sampling probability of the initial sample i, is the second sampling probability of the initial sample i, λ is the first weight, 1-λ is the second weight, and n is the expected index.
9. The method according to claim 7 or 8, characterized in that: The method further comprises: The target detection model is trained based on the training sample set to obtain a training result. According to the training result, adjusting the weight and / or the expected index, the weight including the first weight and the second weight, Update the third sampling probability of each initial sample according to the adjusted weight and / or expected index, According to the updated third sampling probability of each initial sample, a training sample set is obtained from the initial sample set.
10. A training sample set acquisition device, characterized in that: include: The first acquisition module is used to acquire an initial sample set, where the initial sample set includes N initial samples, and each initial sample includes at least one object, where N is a positive integer. A first determination module is used to match the at least one object with C categories of target objects corresponding to target detection for each initial sample, determine a first category corresponding to the initial sample, and the number of category elements of the initial sample, where the number of category elements is the number of different categories in the first category, and C is a positive integer. The second determination module is used to determine, from the initial sample set, a first total number of samples corresponding to each of the C categories according to the first category corresponding to each initial sample, The second acquisition module is used to acquire a training sample set from the initial sample set according to the number of category elements of each initial sample and the first total number of samples corresponding to each category, and the training sample set is used to train the target detection model.