Vehicle attribute recognition model training method and device, recognition method and device
Patent Information
- Application Number
- CN202010688298.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-16
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2040-07-16
AI Technical Summary
In the vehicle attribute recognition task, due to the imbalance of data set categories, using the ordinary cross entropy loss function to train the model results in low recognition accuracy, especially the low recall rate for categories with small sample numbers.
By calculating the effective sampling number of the target vehicle attributes in the training data set, adjusting the initial loss function to obtain the target loss function, and training the pre-training model based on the target loss function to obtain the target recognition model.
The recognition accuracy of the vehicle attribute recognition model is improved, the problem of unbalanced loss values of vehicle attributes in different categories is solved, and the recall rate of categories with small sample numbers is improved.
Smart Images

Figure CN114021609B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of vehicle attribute recognition, and in particular to a vehicle attribute recognition model training method and device, and a vehicle attribute recognition method and device. Background Art
[0002] In the vehicle attribute recognition task, the dataset suffers from class imbalance. Some common brands of vehicles have a large number of samples in the dataset, while some niche brands of vehicles have a very low proportion in the dataset.
[0003] Some categories have thousands of times more samples than other categories with smaller sample counts. Consequently, when using this dataset for model training, only the standard cross-entropy loss function is used for training and loss calculation. Due to the class imbalance in the dataset, when using the trained model to identify vehicle attributes, it tends to favor categories with large sample counts, penalizing categories with small sample counts, which in turn affects the recall rate of small sample counts. Using the standard cross-entropy loss function for model training results in low recognition accuracy, which in turn leads to low vehicle attribute recognition accuracy. Summary of the Invention
[0004] An embodiment of the present invention provides a vehicle attribute recognition model training method, which can improve the recognition accuracy of vehicle attributes.
[0005] In a first aspect, an embodiment of the present invention provides a method for training a vehicle attribute recognition model, the method comprising the following steps:
[0006] Obtaining a training data set, the training data set including target vehicle attributes and the number of samples corresponding to the target vehicle attributes;
[0007] Calculating the effective sampling number of the target vehicle attribute in the training data set according to the sample quantity;
[0008] Inputting the training data set into a pre-trained model for training to obtain an initial loss function corresponding to the target vehicle attribute;
[0009] Adjusting the initial loss function according to the effective sampling number to obtain a corresponding target loss function;
[0010] The pre-trained model is trained based on the target loss function to obtain a target recognition model.
[0011] Optionally, the step of calculating the effective sampling number of the target vehicle attribute in the training data set according to the sample quantity includes:
[0012] Obtaining the sample quantity, where the sample quantity includes the sampled data quantity and the new data quantity that has not been sampled;
[0013] When the sample size is arbitrarily selected as training data, obtaining a first probability that the training data falls within the sampled data size and a second probability that the training data falls within the new data size;
[0014] The effective sampling number of the target vehicle attribute in the training data set is calculated according to the sampled data amount, the first probability and the second probability.
[0015] Optionally, the step of calculating the effective sampling number of the target vehicle attribute in the training data set according to the sampled data volume, the first probability, and the second probability includes:
[0016] Obtaining a first product result of the first probability and the sampled data amount;
[0017] Calculating a second product result by adding the sampled data amount and 1 and the second probability to obtain a second product result;
[0018] The first multiplication result and the second multiplication result are accumulated to obtain the effective sampling number of the target vehicle attribute in the training data set.
[0019] Optionally, the second probability is equal to the difference between 1 and the first probability, and the first probability is equal to the ratio of the sampled data volume to the number of samples; the method further includes:
[0020] Configuring effective parameters according to the sampled data volume, the first probability, and the second probability;
[0021] The effective sampling number of the target vehicle attribute in the training data set is calculated according to the sampled data amount, the first probability, the second probability and the effective parameter.
[0022] Optionally, the effective parameter is equal to the ratio of the difference between the number of samples and 1 to the number of samples.
[0023] Optionally, the effective sampling number of the target vehicle attribute in the training data set is equal to the difference between 1 and the nth power of the effective parameter divided by the difference between 1 and the effective parameter, where n is the nth target vehicle attribute in the sample number.
[0024] Optionally, the step of inputting the training data set into a pre-trained model for training to obtain an initial loss function corresponding to the target vehicle attribute includes:
[0025] Get the number of categories of target vehicle attributes in the training dataset;
[0026] Obtaining a category label of the target vehicle attribute according to the number of categories;
[0027] Inputting the number of categories into a pre-trained model for training to obtain an output result;
[0028] An initial loss function corresponding to the target vehicle attribute is calculated based on the number of categories, category labels, and output results.
[0029] Optionally, the step of obtaining the category label of the target vehicle attribute according to the number of categories includes:
[0030] The category label of the target vehicle attribute is determined according to the number of categories and based on a preset category label strategy.
[0031] Optionally, the step of adjusting the initial loss function according to the effective sampling number to obtain a corresponding target loss function includes:
[0032] Calculating the weight of the target vehicle attribute in the training data set according to the effective sampling number;
[0033] The initial loss function is weightedly calculated according to the weight to obtain a target loss function corresponding to the target vehicle attribute.
[0034] In a second aspect, an embodiment of the present invention further provides a vehicle attribute recognition method, the vehicle attribute recognition method comprising the following steps:
[0035] Acquiring vehicle data to be identified, wherein the vehicle data to be identified includes an image of the vehicle to be identified;
[0036] Inputting the vehicle data to be identified into a pre-trained target recognition model for identification, and obtaining the vehicle attributes corresponding to the vehicle image to be identified;
[0037] The pre-trained target recognition model is obtained by training according to the vehicle attribute recognition model training method provided in the above embodiment.
[0038] In a third aspect, an embodiment of the present invention further provides a vehicle attribute recognition model training device, the vehicle attribute recognition model training device comprising:
[0039] A second acquisition module is used to acquire a training data set, wherein the training data set includes target vehicle attributes and the number of samples corresponding to the target vehicle attributes;
[0040] A calculation module is used to calculate the effective sampling number of the target vehicle attribute in the training data set based on the number of samples;
[0041] The first training module is used to input the training data set into the pre-trained model for training to obtain an initial loss function corresponding to the target vehicle attributes;
[0042] An adjustment module is used to adjust the initial loss function according to the effective sampling number to obtain the corresponding target loss function;
[0043] The second training module is used to train the pre-training model based on the target loss function to obtain a target recognition model.
[0044] In a fourth aspect, an embodiment of the present invention further provides a vehicle attribute recognition device, the vehicle attribute recognition device comprising:
[0045] A first acquisition module is used to acquire vehicle data to be identified, wherein the vehicle data to be identified includes an image of the vehicle to be identified;
[0046] An identification module is used to input the vehicle data to be identified into a pre-trained target recognition model for identification, and obtain vehicle attributes corresponding to the vehicle image to be identified;
[0047] The pre-trained target recognition model is obtained by training according to the vehicle attribute recognition model training method provided in the above embodiment.
[0048] In a fifth aspect, an embodiment of the present invention further provides an electronic device comprising: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the processor implements the steps of the vehicle attribute recognition model training method provided in the above embodiment, as well as the steps of the vehicle attribute recognition method provided in the above embodiment.
[0049] In a sixth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the vehicle attribute recognition model training method provided in the above embodiment and the steps in the vehicle attribute recognition method provided in the above embodiment are implemented.
[0050] In an embodiment of the present invention, a training data set is obtained, the training data set including target vehicle attributes and the number of samples corresponding to the target vehicle attributes; based on the number of samples, the effective sampling number of the target vehicle attributes in the training data set is calculated; the training data set is input into a pre-training model for training to obtain an initial loss function corresponding to the target vehicle attributes; the initial loss function is adjusted based on the effective sampling number to obtain a corresponding target loss function; the pre-training model is trained based on the target loss function to obtain a target recognition model. The present invention adjusts the initial loss function corresponding to the target vehicle attributes by the effective sampling number corresponding to the target vehicle attributes to obtain a target loss function, so that the loss value of each target vehicle attribute is more balanced, and the pre-training model is trained based on the target loss function to obtain a target recognition model. When the pre-trained target recognition model is used to identify the vehicle attributes of the vehicle data to be identified, the problem of uneven loss values of the vehicle attributes of each vehicle data to be identified can be solved. This improves the recognition accuracy of the target recognition model. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0052] Figure 1 This is a flow chart of a vehicle attribute recognition method provided by an embodiment of the present invention;
[0053] Figure 2 This is a flow chart of a vehicle attribute recognition model training method provided by an embodiment of the present invention;
[0054] Figure 3 yes Figure 2 A flowchart of a method provided in step 202 of the embodiment;
[0055] Figure 4 yes Figure 3 A flowchart of a method provided in step 303 of the embodiment;
[0056] Figure 5 yes Figure 2 A flowchart of a method provided in step 203 of the embodiment;
[0057] Figure 6 yes Figure 2 A flowchart of a method provided in step 204 of the embodiment;
[0058] Figure 7 This is a schematic structural diagram of a vehicle attribute recognition device provided by an embodiment of the present invention;
[0059] Figure 8 This is a schematic structural diagram of a vehicle attribute recognition model training device provided by an embodiment of the present invention;
[0060] Figure 9 yes Figure 8 A structural diagram provided by the calculation module;
[0061] Figure 10 yes Figure 9 A structural schematic diagram provided by the first computing unit;
[0062] Figure 11 yes Figure 8 A structural diagram provided by the first training module;
[0063] Figure 12 yes Figure 8 A structural diagram provided by the adjustment module;
[0064] Figure 13 It is a structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0065] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0066] See Figure 1 , Figure 1 is a flow chart of a vehicle attribute recognition method provided by an embodiment of the present invention, such as Figure 1 As shown, the vehicle attribute recognition method includes the following steps:
[0067] Step 101: Obtain vehicle data to be identified.
[0068] The vehicle data to be identified includes vehicle images to be identified. The vehicle images to be identified may be photos, pictures, videos, etc. of the vehicle to be identified, and the number of vehicle images to be identified may be one or more. The vehicle data to be identified may be vehicle images waiting to be identified in a vehicle attribute recognition task. For example, in a vehicle attribute recognition task, the vehicle data to be identified may be vehicle images waiting to be identified, and the vehicle images may be one or more. Vehicle attributes may be the brand, model, color, type, etc. of the vehicle, and the vehicle attribute data may be data corresponding to the brand, model, color, model, etc. of the vehicle. A vehicle attribute recognition task may be, for example, a vehicle brand recognition task. For example, if there are three vehicles that need to be brand recognized, the vehicle data to be identified may be data corresponding to the three vehicles, such as vehicle images corresponding to the three vehicles.
[0069] In one embodiment of the present invention, the recognition method can be switched to corresponding data based on different application scenarios. For example, in a book attribute recognition task, the vehicle attribute recognition described above can be replaced with book attribute recognition. The vehicle data to be recognized can also be replaced with a book image, which can be one or more book images, in a book attribute recognition task. Of course, the vehicle data to be recognized can also be switched to data corresponding to different application scenarios. The application scenarios of this method are not limited in this embodiment of the present invention. When this method is used for different application scenarios, it falls within the scope of protection of the present invention.
[0070] Specifically, the vehicle data to be identified can be pre-collected vehicle images awaiting identification. For example, in a vehicle data clustering task, 100 pre-collected vehicle images need to be clustered to obtain one or more vehicle image classes. In this case, the 100 vehicle images can serve as the vehicle data to be identified. Alternatively, the vehicle data to be identified can be real-time captured vehicle images to be identified. For example, in a road monitoring task, when vehicles within the monitoring range need to be identified, images of vehicles within the monitoring range are captured in real time and used as the vehicle data to be identified.
[0071] Step 102: Input the vehicle data to be identified into a pre-trained target recognition model for identification, and obtain the vehicle attributes corresponding to the vehicle image to be identified.
[0072] The pre-trained target recognition model is trained according to the vehicle attribute recognition model training method provided in the following embodiments. Specifically, the pre-trained model is trained based on a training dataset and a target loss function. The pre-trained target recognition model is the same as the target recognition model provided in the following embodiments.
[0073] The target loss function is obtained by adjusting the initial loss function corresponding to the target vehicle attribute by the effective sampling number of the target vehicle attribute in the training data set.
[0074] The training dataset is a collection of target vehicle attributes used to train the pre-trained model. When the pre-trained object recognition model is used for book attribute recognition tasks, the target vehicle attributes can be replaced with the target book attributes.
[0075] The target vehicle attributes can be determined based on the target vehicle attribute classification method. For example, when the target vehicle attributes are classified according to vehicle brand, the target vehicle attributes are vehicle brand attributes, such as vehicle brands are divided into three categories: Brand A, Brand B, and Brand C. Multiple target vehicle attributes can mean that the target vehicle attributes are divided into multiple categories. For example, if the vehicle brands are Brand A, Brand B, and Brand C, then the target vehicle attributes are three; if the vehicle brands are Brand A, Brand B, Brand C, and Brand D, then the target vehicle attributes are four. It should be noted that when the target vehicle attributes are classified according to one of the following: vehicle color, model, or vehicle type, the target vehicle attributes can correspond to vehicle color attributes, vehicle model attributes, or vehicle model attributes.
[0076] The sample size above is the total number of target vehicle attributes corresponding to each target vehicle attribute in the training dataset. For example, if there are 1000 vehicles in the training dataset, and there are 100 brand A vehicles, then the sample size for brand A is 100. If there are 200 brand B vehicles, then the sample size for brand B is 200. It should be noted that each target vehicle attribute has its own sample size. Furthermore, the training dataset consists of multiple target vehicle attributes and their corresponding sample sizes.
[0077] The training dataset can be pre-stored in a database or obtained from a target vehicle attribute platform via a training dataset link. The target vehicle attributes in the training dataset can be fixed or continuously increasing. The target vehicle attribute platform can be, for example, a vehicle production platform, a vehicle management platform, or a vehicle sales platform. When the target vehicle attributes are replaced with target book attributes, the target vehicle attribute platform can correspond to a book production company platform, a book sales platform, a library platform, or the like.
[0078] The above effective sampling number is the sum of the actual training data corresponding to the current target vehicle attributes.
[0079] The pre-trained model is used to identify or process the attributes of a target vehicle in the scenario in which it is used. It can be an untrained model or a trained model. The model can be a convolutional neural network or other neural network model.
[0080] The above-mentioned initial loss function is the loss function initially used to train the pre-trained model, and specifically can be a common cross-entropy loss function. This initial loss function can be used to train the pre-trained model, but there is a problem. When there are multiple target vehicle attributes in the training data set, and the categories of vehicle attributes are unevenly distributed, for example, when the number of samples of a certain target vehicle attribute is several thousand times the number of other samples, the trained recognition model will be biased towards the target vehicle attributes with a large sample size when calculating the loss value, which will be disadvantageous to the target vehicle attributes with a small sample size, thereby affecting the recall rate of the target vehicle attributes with a small sample size. This also shows that the recognition accuracy of the recognition model trained by the common cross-entropy loss function is low. This initial loss function can be a loss function for various vehicle attributes, and it only needs to be able to perform initial training on the pre-trained model. In the same pre-trained model, different vehicle attributes correspond to different initial loss functions.
[0081] The target loss function is the one ultimately applied to the target scenario. Training the pre-trained model with the target loss function can make the loss values of the target vehicle attributes more uniform, thereby achieving uniform accuracy across all categories.
[0082] Specifically, after obtaining the vehicle data to be identified, it can be input into a pre-trained target recognition model for identification, thereby obtaining the vehicle attributes corresponding to the vehicle image to be identified. For example, in a vehicle brand identification task, there are three vehicles that need brand attribute identification. The data of these three vehicles are sequentially input into the pre-trained target recognition model for identification. After identification, the first vehicle is identified as brand A, the second as brand B, and the third as brand C, thereby obtaining the brand categories corresponding to the three vehicles. In this way, the vehicle attributes of the vehicle data to be identified can be modeled using the pre-trained target recognition model.
[0083] In an embodiment of the present invention, vehicle data to be identified is obtained, the vehicle data to be identified includes a vehicle image to be identified; the vehicle data to be identified is input into a pre-trained target recognition model for identification, and the vehicle attributes corresponding to the vehicle image to be identified are obtained; the pre-trained target recognition model is obtained by training the pre-trained model based on a training data set and a target loss function, the training data set includes target vehicle attributes and the number of samples corresponding to the target vehicle attributes, there are multiple target vehicle attributes, and the target loss function is obtained by adjusting the initial loss function corresponding to the target vehicle attributes by the effective sampling number of the target vehicle attributes in the training data set. The present invention adjusts the initial loss function corresponding to the target vehicle attributes by the effective sampling number corresponding to the target vehicle attributes to obtain the target loss function, trains the pre-trained model based on the target loss function to obtain a pre-trained target recognition model, and uses the pre-trained target recognition model to identify the vehicle attributes of the vehicle image to be identified, so as to solve the problem of imbalance in the loss function of the vehicle attributes of each vehicle data to be identified. By improving the recognition accuracy of the pre-trained recognition model, the recognition accuracy of the vehicle attributes of the vehicle data to be identified is improved.
[0084] For details, see Figure 2 , Figure 2 This is a flow chart of a vehicle attribute recognition model training method provided by an embodiment of the present invention. Figure 2 As shown, the vehicle attribute recognition model training method includes the following steps:
[0085] Step 201: Obtain a training data set.
[0086] The training data set includes target vehicle attributes and the number of samples corresponding to the target vehicle attributes. The target vehicle attributes can be multiple.
[0087] Specifically, the training data set may be retrieved from a database, or training data may be retrieved from a target vehicle attribute platform through a training data set link as a training data set, and the target vehicle attributes of the training data set and the corresponding number of samples may be obtained.
[0088] Step 202: Calculate the effective sampling number of the target vehicle attribute in the training data set based on the sample quantity.
[0089] Specifically, when the target vehicle attributes in the training data set change, it is necessary to calculate the number of target vehicle attributes that actually participate in the training in the training data set for the current target vehicle attributes.
[0090] For details, see Figure 3 , Figure 3 yes Figure 2 In the flowchart of a method provided in the embodiment of step 202, step 202 includes the following steps:
[0091] Step 301: Obtain the sample quantity, which includes the sampled data quantity and the new data quantity that has not been sampled.
[0092] Step 302: When a sample size is arbitrarily selected as training data, a first probability of the training data falling into the sampled data size and a second probability of the training data falling into the new data size are obtained.
[0093] Step 303: Calculate the effective sampling number of the target vehicle attribute in the training data set according to the sampled data volume, the first probability, and the second probability.
[0094] The sampled data volume refers to the trained target vehicle attributes within the number of samples corresponding to a target vehicle attribute in the training dataset. The new data volume refers to the untrained target vehicle attributes within the number of samples corresponding to a target vehicle attribute in the training dataset, i.e., the newly added target vehicle attributes within the number of samples of a target vehicle attribute in the training dataset. The training data refers to the data currently required to train the pre-trained model. The first probability is the probability that the current training data is previously trained data, and the second probability is the probability that the current training data is previously untrained data. The sampled data and new data are completely disjoint. When the first probability is represented by p, the second probability is represented by 1-p. For example, the training dataset contains 10,000 training samples, of which 1,000 are trained data samples, accounting for 10% of the total training samples, and the remaining 9,000 are untrained data, accounting for 90% of the total training samples. Now randomly select a sample from these 10,000 samples as the current training data. Then the probability P of the current training data falling into 1000 is 10%, and the probability 1-P of falling into 9000 is 90%, that is, the first probability is 10% and the second probability is 90%.
[0095] Specifically, a first product result of the first probability and the amount of sampled data is obtained; the sum of the amount of sampled data and 1 is calculated with the second probability to obtain a second product result; the first product result and the second product result are accumulated to obtain the effective sampling number of the target vehicle attribute in the training data set.
[0096] For example, the number of samples of target vehicle attributes is N, and the amount of sampled data (the number of samples previously trained) is E. n-1 , when the current training data is trained, the current training data falls into E n-1The probability of the first probability p is the same as the probability of the second probability p. Because there is no intersection between the two, the second probability when the current training data falls into the new data volume that has not been sampled is equal to the difference between 1 and the first probability, and the second probability is expressed as 1-p. The nth target vehicle attribute of the sample number is represented by n, where n is less than or equal to N, and the effective sampling number is represented by E n To express, the amount of sampled data is expressed by E n-1 To express, that is, the amount of sampled data is expressed by E n-1 is the previous valid sampling range. Then the valid sampling number E n As shown in Formula 1, Formula 1 is:
[0097] E n =pE n-1 +(1-p)(E n-1 +1) (Formula 1)
[0098] From this we can see that if the current training data falls into the sampled data volume, it is equivalent to the sampled data volume E n-1 There is no increase, so the amount of sampled data E n-1 No 1 is added. If the current training data falls into the new data volume that has not been sampled, it is equivalent to the sampled data volume E n-1 New data is added on the basis of , because there is one more sample, so the amount of sampled data E n-1 Need to add 1.
[0099] From the above, we can see that the first probability is equal to the ratio of the amount of sampled data to the number of samples. The first probability p can be expressed as p=E n-1 / N, and p=E n-1 Substituting / N into Formula 1, we can get Formula 2, which is:
[0100]
[0101] More specifically, Figure 4 As shown, Figure 4 yes Figure 3 Step 303 of the embodiment provides a flowchart of a method, wherein step 303 includes the following steps:
[0102] Step 401: Configure effective parameters according to the amount of sampled data, the first probability, and the second probability.
[0103] Step 402: Calculate the effective sampling number of the target vehicle attribute in the training data set according to the sampled data volume, the first probability, the second probability, and the effective parameter.
[0104] The above-mentioned effective parameters are preset parameters, and the effective parameters are specifically set according to mathematical induction.
[0105] Specifically, after determining the effective parameter, the effective sampling number can be calculated based on the amount of sampled data, the first probability, the second probability, and the effective parameter. In Formula 2, the effective parameter is equal to the ratio of the difference between the number of samples and 1 to the number of samples. The effective parameter is represented by β, and β = (N-1) / N. It can be seen that the effective sampling number of the target vehicle attribute in the training data set is equal to the difference between 1 and the nth power of the effective parameter divided by the difference between 1 and the effective parameter, where n is the nth target vehicle attribute in the sample number. The effective sampling number of the target vehicle attribute in the training data set can also be expressed as Formula 2 can be converted to Formula 3, which is:
[0106]
[0107] Among them, j is the number of samples in the summation, that is, the jth sample in the summation.
[0108] The effective sampling number corresponding to the target vehicle attribute can be calculated from the above formula 3. Specifically, from formula 1 and the first probability P=E n-1 / N are combined to obtain Formula 2, and Formula 2 and the effective parameter β=(N-1) / N are converted into Formula 3 through mathematical induction, and the final effective sampling number is calculated.
[0109] It should be noted that, since the target vehicle attributes are multiple, the corresponding effective sampling number E can be calculated for each target vehicle attribute. n Furthermore, each target vehicle attribute can use Formula 1-Formula 3 to calculate its own effective sampling number E n .
[0110] In an embodiment of the present invention, the effective parameters are determined by the amount of sampled data, the first probability and the second probability of the target vehicle attribute, and the effective sampling number of the target vehicle attribute is calculated based on Formula 3. Then, the initial loss function can be adjusted according to the calculated effective sampling number to obtain the target loss function, so that the loss value of the target vehicle attribute is more balanced, so as to facilitate the training of the pre-training model and obtain the target recognition model, thereby improving the recognition accuracy of the recognition model to improve the recognition accuracy of the vehicle attributes of the vehicle data to be identified.
[0111] Step 203: Input the training data set into the pre-training model for training, and calculate the initial loss function corresponding to the target vehicle attributes.
[0112] Specifically, such as Figure 5 As shown, Figure 5 yes Figure 2 In the flowchart of a method provided in the embodiment of step 203, step 203 includes the following steps:
[0113] Step 501: Obtain the number of categories of target vehicle attributes in the training data set.
[0114] Step 502: Obtain the category label of the target vehicle attribute according to the number of categories.
[0115] Step 503: Input the number of categories into the pre-trained model for training to obtain output results.
[0116] Step 504: Calculate the initial loss function corresponding to the target vehicle attribute based on the number of categories, category labels, and output results.
[0117] The number of categories mentioned above refers to the total number of target vehicle attribute types in the training dataset. For example, in a vehicle attribute recognition task, the target vehicle attributes in the training dataset are classified by color, resulting in white vehicle attributes, red vehicle attributes, black vehicle attributes, blue vehicle attributes, and so on. In this case, the number of categories is four: white, red, black, and blue. This means that the number of target vehicle attribute categories in the training dataset is four.
[0118] The above-mentioned category label is a one-hot (unique hot code) category label used to represent the relationship between the target vehicle attribute and other target vehicle attributes. One-hot means that only the current target vehicle attribute is 1, and the remaining target vehicle attributes are all 0. In this embodiment, the number of one-hot states can be determined by the number of target vehicle attribute categories. When the number of categories is 6, the number of corresponding category label states is also 6, and the corresponding category labels can be represented as: 000001, 000010, 000100, 001000, 010000, 100000. When the number of categories is 16, the number of states of the corresponding category labels is also 16, and the corresponding category labels can be expressed as: 0000000000000001, 00000000000000010, 0000000000000100, 0000000000001000, 0000000000010000, 00000000000100000, ..., 10000000000000000000. Of course, the number of categories can be determined according to the number of target vehicle attributes. In this embodiment, the number of target vehicle attributes is not limited.
[0119] The above output is the result of training the pre-trained model using the initial loss function. Of course, the initial loss function of the pre-trained function can also be calculated based on this output.
[0120] Specifically, after obtaining the number of categories, category labels, and output results, the initial loss function corresponding to the target vehicle attributes can be calculated.
[0121] For example, when the number of categories is represented by C, the category label is represented by Z, and the output result is represented by P, the initial loss function in this embodiment, that is, the ordinary cross entropy loss function, can be expressed as:
[0122]
[0123] Among them, j is the number of samples in the sum, that is, the j-th sample in the sum, and Pj is the category probability of the j-th sample.
[0124] From the above, we can see that the initial loss function of the pre-training loss function is calculated according to Formula 4. It should be noted that since there are multiple target vehicle attributes, each target vehicle attribute can calculate its own initial loss function using Formula 4.
[0125] More specifically, step 502 may include determining a category label for the target vehicle attribute based on the number of categories and a preset category labeling strategy. The preset category labeling strategy (referring to a method for determining category labels) may be a one-hot strategy, where only the current target vehicle attribute is set to 1, and all other target vehicle attributes are set to 0. That is, if the current target vehicle attribute is recognized, it is marked as 1, and if the current target vehicle attribute is not recognized, it is marked as 0.
[0126] Step 204: Adjust the initial loss function according to the effective sampling number to obtain the corresponding target loss function.
[0127] Specifically, after the effective sampling number of the target vehicle attribute is calculated, the target loss function corresponding to the target vehicle attribute can be calculated based on the initial loss function corresponding to the target vehicle attribute.
[0128] like Figure 6 As shown, Figure 6 yes Figure 2 The flowchart of a method provided in the embodiment of step 204 is shown in FIG. 2 , wherein step 204 specifically includes the following steps:
[0129] Step 601: Calculate the weight of the target vehicle attribute in the training data set according to the effective sampling number.
[0130] Step 602: Perform weighted calculation on the initial loss function according to the weight to obtain a target loss function corresponding to the target vehicle attribute.
[0131] The weights are the ratio of valid samples to the number of target vehicle attribute samples in the training dataset. For example, the training dataset includes two target vehicle attribute classes: Class A has 700 samples, of which 600 are valid samples, meaning the valid number of class A samples is 600. Class B has 300 samples, of which 200 are valid samples, meaning the valid number of class B samples is 200. Therefore, the weight for class A is 6 / 10, and the weight for class B is 2 / 10.
[0132] Specifically, after the weight corresponding to the target vehicle attribute is calculated, the initial loss function is weighted according to the weight to obtain the target loss function of the target vehicle attribute. For example, according to the effective sampling number E calculated in formula 3 n , combined with the cross entropy loss function formula 4, we can get the final target loss function (formula 5), which is:
[0133]
[0134] From the above, we can see that the target loss function of the target vehicle attribute can be calculated according to Formula 5. It should be noted that since there are multiple target vehicle attributes, each target vehicle attribute can calculate its own target loss function according to Formula 5.
[0135] Step 205: Train the pre-trained model based on the target loss function to obtain a target recognition model.
[0136] The target recognition model is the recognition model actually used in the target scene.
[0137] Specifically, after calculating the target loss function corresponding to the target vehicle attribute, the target loss function is used to train the pre-trained model to obtain a target recognition model. In practical applications, this target model can be used to identify and process the target vehicle attributes in the target scene. This allows the weight of each target vehicle attribute in the loss function to be determined based on the number of valid samples corresponding to each target vehicle attribute, making the loss function of each target vehicle attribute more balanced. Consequently, the trained target model can identify and process the target vehicle attributes more evenly and accurately, thereby improving the accuracy of the target model and, therefore, the recognition precision of the target model.
[0138] In this embodiment, a training data set is obtained, the training data set includes target vehicle attributes and the number of samples corresponding to the target vehicle attributes, and there are multiple target vehicle attributes; based on the number of samples, the effective sampling number of the target vehicle attributes in the training data set is calculated; the training data set is input into a pre-training model for training to obtain an initial loss function corresponding to the target vehicle attributes; the initial loss function is adjusted according to the effective sampling number to obtain a corresponding target loss function; the pre-training model is trained based on the target loss function to obtain a target recognition model. The present invention adjusts the initial loss function of the pre-training model by the effective sampling number corresponding to the target vehicle attributes, and trains the pre-training model to obtain a target recognition model, so as to solve the problem of imbalance in the loss function of each target vehicle attribute when the recognition model is used to recognize multiple target vehicle attributes, thereby improving the recognition accuracy of the recognition model and thus improving the recognition accuracy of the vehicle attributes.
[0139] See also Figure 7 , Figure 7 FIG. 7 is a schematic diagram of the structure of a vehicle attribute recognition device provided by an embodiment of the present invention. The vehicle attribute recognition device 700 includes:
[0140] The first acquisition module 701 is used to acquire the vehicle data to be identified, and the vehicle data to be identified is the vehicle image to be identified.
[0141] The recognition module 702 is used to input the vehicle data to be recognized into a pre-trained target recognition model for recognition, and obtain the vehicle attributes corresponding to the vehicle image to be recognized.
[0142] The pre-trained target recognition model is obtained by training according to the vehicle attribute recognition model training method provided in the embodiment.
[0143] See also Figure 8 , Figure 8 FIG. 1 is a structural diagram of a vehicle attribute recognition model training device provided by an embodiment of the present invention. Figure 8 As shown, the vehicle attribute recognition model training device 800 includes:
[0144] The second acquisition module 801 is used to acquire a training data set, where the training data set includes target vehicle attributes and the number of samples corresponding to the target vehicle attributes.
[0145] The calculation module 802 is used to calculate the effective sampling number of the target vehicle attribute in the training data set according to the number of samples.
[0146] The first training module 803 is used to input the training data set into the pre-training model for training to obtain an initial loss function corresponding to the target vehicle attribute.
[0147] The adjustment module 804 is used to adjust the initial loss function according to the effective sampling number to obtain the corresponding target loss function.
[0148] The second training module 805 is used to train the pre-trained model based on the target loss function to obtain a pre-trained recognition model.
[0149] Optional, such as Figure 9 As shown, Figure 9 yes Figure 8 A schematic diagram of a structure provided by the calculation module in FIG. 802 includes:
[0150] The first acquisition unit 8021 is used to acquire the sample quantity, where the sample quantity includes the sampled data quantity and the new data quantity that has not been sampled.
[0151] The second obtaining unit 8022 is configured to obtain, when a sample size is arbitrarily selected as training data, a first probability that the training data falls within the sampled data size and a second probability that the training data falls within the new data size.
[0152] The first calculation unit 8023 is used to calculate the effective sampling number of the target vehicle attribute in the training data set according to the sampled data volume, the first probability and the second probability.
[0153] Optionally, the first calculation unit 8023 is also used to obtain a first product result of the first probability and the sampled data volume; calculate the addition result of the sampled data volume and 1 with the second probability to obtain a second product result; accumulate the first product result and the second product result to obtain the effective sampling number of the target vehicle attribute in the training data set.
[0154] Optional, such as Figure 10 As shown, Figure 10 yes Figure 9 A structural diagram provided by the first calculation unit in the embodiment, wherein the second probability is equal to the difference between 1 and the first probability, and the first probability is equal to the ratio of the amount of sampled data to the number of samples; the first calculation unit 8023 includes:
[0155] The configuration subunit 80231 is used to configure the effective parameters according to the amount of sampled data, the first probability and the second probability.
[0156] The calculation subunit 80232 is used to calculate the effective sampling number of the target vehicle attribute in the training data set according to the sampled data volume, the first probability, the second probability and the effective parameter.
[0157] Optional, the effective parameter is equal to the ratio of the difference between the sample size and 1 to the sample size.
[0158] Optionally, the number of valid samples of the target vehicle attribute in the training data set is equal to the difference between 1 and the nth power of the valid parameter divided by the difference between 1 and the valid parameter, where n is the number of samples of the nth target vehicle attribute.
[0159] Optional, such as Figure 11 As shown, Figure 11 yes Figure 8 A structural diagram of the first training module provided in FIG. 803 includes:
[0160] The third acquisition unit 8031 is used to obtain the number of categories of target vehicle attributes in the training data set.
[0161] The fourth acquiring unit 8032 is configured to acquire a category label of the target vehicle attribute according to the number of categories.
[0162] The training unit 8033 is used to input the number of categories into the pre-training model for training to obtain an output result.
[0163] The second calculation unit 8034 is used to calculate the initial loss function corresponding to the target vehicle attribute according to the number of categories, category labels and output results.
[0164] Optionally, the step of obtaining the category label of the target vehicle attribute according to the number of categories includes:
[0165] The category labels of the target vehicle attributes are determined according to the number of categories and based on a preset category labeling strategy.
[0166] Optional, such as Figure 12 As shown, Figure 12 yes Figure 8 A structural diagram provided by the adjustment module, the adjustment module 804 includes:
[0167] The third calculation unit 8041 is used to calculate the weight of the target vehicle attribute in the training data set according to the effective sampling number.
[0168] The fourth calculation unit 8042 is used to perform weighted calculation on the initial loss function according to the weight to obtain a target loss function corresponding to the target vehicle attribute.
[0169] The model training device provided in the embodiment of the present invention can implement each implementation method in the above method embodiment and the corresponding beneficial effects. To avoid repetition, they will not be described here.
[0170] See also Figure 13 , Figure 13is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. The electronic device 900 includes: a memory 902, a processor 901, and a computer program stored in the memory 902 and executable on the processor 901. When the processor 901 executes the computer program, the vehicle attribute recognition model training method provided in the above embodiment and the steps in the vehicle attribute recognition method provided in the above embodiment are implemented. The processor 901 performs the following steps:
[0171] The vehicle data to be identified is obtained, where the vehicle data to be identified includes an image of the vehicle to be identified.
[0172] Input the vehicle data to be identified into the pre-trained recognition model for identification, and obtain the vehicle attributes corresponding to the vehicle image to be identified.
[0173] The pre-trained recognition model is obtained by training the pre-trained model based on a training data set and a target loss function. The training data set includes target vehicle attributes and the number of samples corresponding to the target vehicle attributes. There are multiple target vehicle attributes. The target loss function is obtained by adjusting the initial loss function corresponding to the target vehicle attributes based on the effective sampling number of the target vehicle attributes in the training data set.
[0174] Optionally, the processor 901 executes a training method for a pre-trained recognition model including the following steps:
[0175] Get the training dataset.
[0176] Based on the number of samples, calculate the effective sampling number of the target vehicle attributes in the training data set.
[0177] The training dataset is input into the pre-trained model for training to obtain the initial loss function corresponding to the target vehicle attributes.
[0178] The initial loss function is adjusted according to the effective sampling number to obtain the corresponding target loss function.
[0179] The pre-trained model is trained based on the target loss function to obtain a pre-trained recognition model.
[0180] Optionally, the step of calculating the effective sampling number of the target vehicle attribute in the training data set according to the number of samples performed by the processor 901 includes:
[0181] Get the number of samples, which includes the amount of sampled data and the amount of new data that has not been sampled.
[0182] When the sample size is arbitrarily selected as training data, a first probability that the training data falls within the sampled data size and a second probability that the training data falls within the new data size are obtained.
[0183] The effective sampling number of the target vehicle attribute in the training data set is calculated according to the sampled data volume, the first probability and the second probability.
[0184] Optionally, the step of calculating the effective sampling number of the target vehicle attribute in the training data set according to the sampled data volume, the first probability, and the second probability performed by the processor 901 includes:
[0185] Obtaining a first product result of the first probability and the amount of sampled data;
[0186] Calculating the sum of the sampled data amount and 1 and the second probability to obtain a second product result;
[0187] The first product result and the second product result are accumulated to obtain the effective sampling number of the target vehicle attribute in the training data set.
[0188] Optionally, the second probability is equal to the difference between 1 and the first probability, and the first probability is equal to the ratio of the amount of sampled data to the number of samples; the step executed by the processor 901 of calculating the effective number of samples of the target vehicle attribute in the training data set based on the amount of sampled data, the first probability, and the second probability includes:
[0189] The effective parameters are configured according to the amount of sampled data, the first probability, and the second probability.
[0190] The effective sampling number of the target vehicle attribute in the training data set is calculated according to the sampled data volume, the first probability, the second probability and the effective parameter.
[0191] Optional, the effective parameter is equal to the ratio of the difference between the sample size and 1 to the sample size.
[0192] Optionally, the number of valid samples of the target vehicle attribute in the training data set is equal to the difference between 1 and the nth power of the valid parameter divided by the difference between 1 and the valid parameter, where n is the number of samples of the nth target vehicle attribute.
[0193] Optionally, the step of inputting the training data set into the pre-training model for training to obtain an initial loss function corresponding to the target vehicle attribute, performed by the processor 901, includes:
[0194] Get the number of categories of target vehicle attributes in the training dataset.
[0195] Get the category labels of the target vehicle attributes based on the number of categories.
[0196] Input the number of categories into the pre-trained model for training to obtain the output results.
[0197] Calculate the initial loss function corresponding to the target vehicle attributes based on the number of categories, category labels, and output results.
[0198] Optionally, the step of obtaining the category label of the target vehicle attribute according to the number of categories performed by the processor 901 includes:
[0199] The category labels of the target vehicle attributes are determined according to the number of categories and based on a preset category labeling strategy.
[0200] Optionally, the step of adjusting the initial loss function according to the valid sampling number to obtain a corresponding target loss function performed by the processor 901 includes:
[0201] Calculate the weight of the target vehicle attributes in the training dataset based on the effective sampling number.
[0202] The initial loss function is weighted according to the weight to obtain the target loss function corresponding to the target vehicle attributes.
[0203] The processor 901 further performs the following steps:
[0204] The vehicle data to be identified is acquired, where the vehicle data to be identified includes an image of the vehicle to be identified.
[0205] The vehicle data to be identified is input into a pre-trained target recognition model for identification, and the vehicle attributes corresponding to the vehicle image to be identified are obtained.
[0206] The pre-trained target recognition model is obtained by training according to the vehicle attribute recognition model training method provided in the above embodiment.
[0207] It should be noted that the electronic device 900 may be a smart terminal, a mobile phone, a tablet computer or other device.
[0208] The electronic device 900 provided in the embodiment of the present invention can implement each implementation method in the above method embodiment and the corresponding beneficial effects, which will not be described again here to avoid repetition.
[0209] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the vehicle attribute recognition model training method provided in the embodiment of the present invention and the various processes in the vehicle attribute recognition method provided in the above embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, they are not described here.
[0210] Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing the relevant hardware through a computer program. The program can be stored in a computer-readable storage medium, and when executed, the program can include the processes in the above-described method embodiments. The storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0211] The above disclosure is merely a preferred embodiment of the present invention and certainly cannot be used to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.
Claims
1. A vehicle attribute recognition model training method, characterized in that: The method comprises the following steps: Obtaining a training data set, the training data set including target vehicle attributes and the number of samples corresponding to the target vehicle attributes; Calculating the effective sampling number of the target vehicle attribute in the training data set according to the sample quantity; Inputting the training data set into a pre-trained model for training to obtain an initial loss function corresponding to the target vehicle attribute; Adjusting the initial loss function according to the effective sampling number to obtain a corresponding target loss function; Training the pre-trained model based on the target loss function to obtain a target recognition model; The step of calculating the effective sampling number of the target vehicle attribute in the training data set according to the sample quantity includes: Obtaining the sample quantity, where the sample quantity includes the sampled data quantity and the new data quantity that has not been sampled; When the sample size is arbitrarily selected as training data, obtaining a first probability that the training data falls within the sampled data size and a second probability that the training data falls within the new data size; The effective sampling number of the target vehicle attribute in the training data set is calculated according to the sampled data amount, the first probability and the second probability.
2. The vehicle attribute recognition model training method according to claim 1, characterized in that: The step of calculating the effective sampling number of the target vehicle attribute in the training data set according to the sampled data volume, the first probability and the second probability includes: Obtaining a first product result of the first probability and the sampled data amount; Calculating a second product result by adding the sampled data amount and 1 and the second probability to obtain a second product result; The first multiplication result and the second multiplication result are accumulated to obtain the effective sampling number of the target vehicle attribute in the training data set.
3. The vehicle attribute recognition model training method according to claim 2, characterized in that: The second probability is equal to the difference between 1 and the first probability, and the first probability is equal to the ratio of the amount of sampled data to the number of samples; the step of calculating the effective sampling number of the target vehicle attribute in the training data set based on the amount of sampled data, the first probability, and the second probability further includes: Configuring effective parameters according to the sampled data volume, the first probability, and the second probability; The effective sampling number of the target vehicle attribute in the training data set is calculated according to the sampled data amount, the first probability, the second probability and the effective parameter.
4. The vehicle attribute recognition model training method according to claim 3, characterized in that: The effective parameter is equal to the ratio of the difference between the number of samples and 1 to the number of samples.
5. The vehicle attribute recognition model training method according to claim 4, characterized in that: The effective sampling number of the target vehicle attribute in the training data set is equal to the difference between 1 and the nth power of the effective parameter divided by the difference between 1 and the effective parameter, where n is the number of samples of the nth target vehicle attribute.
6. The vehicle attribute recognition model training method according to claim 1, characterized in that: The step of inputting the training data set into a pre-training model for training to obtain an initial loss function corresponding to the target vehicle attribute includes: Get the number of categories of target vehicle attributes in the training dataset; Obtaining a category label of the target vehicle attribute according to the number of categories; Inputting the number of categories into a pre-trained model for training to obtain an output result; An initial loss function corresponding to the target vehicle attribute is calculated based on the number of categories, category labels, and output results.
7. The vehicle attribute recognition model training method according to claim 6, characterized in that: The step of obtaining the category label of the target vehicle attribute according to the number of categories includes: The category label of the target vehicle attribute is determined according to the number of categories and based on a preset category label strategy.
8. The vehicle attribute recognition model training method according to claim 1, characterized in that: The step of adjusting the initial loss function according to the effective sampling number to obtain a corresponding target loss function includes: Calculating the weight of the target vehicle attribute in the training data set according to the effective sampling number; The initial loss function is weightedly calculated according to the weight to obtain a target loss function corresponding to the target vehicle attribute.
9. A vehicle attribute recognition method, characterized in that: The vehicle attribute recognition method comprises the following steps: Acquiring vehicle data to be identified, wherein the vehicle data to be identified includes an image of the vehicle to be identified; Inputting the vehicle data to be identified into a pre-trained target recognition model for identification, and obtaining the vehicle attributes corresponding to the vehicle image to be identified; The pre-trained target recognition model is obtained by training according to the vehicle attribute recognition model training method according to any one of claims 1-8.
10. A vehicle attribute recognition model training device, characterized in that: The vehicle attribute recognition model training device includes: A second acquisition module is used to acquire a training data set, wherein the training data set includes target vehicle attributes and the number of samples corresponding to the target vehicle attributes; A calculation module is used to calculate the effective sampling number of the target vehicle attribute in the training data set based on the number of samples; The first training module is used to input the training data set into the pre-trained model for training to obtain an initial loss function corresponding to the target vehicle attributes; An adjustment module is used to adjust the initial loss function according to the effective sampling number to obtain the corresponding target loss function; The second training module is used to train the pre-training model based on the target loss function to obtain a target recognition model; The calculation module includes: A first acquiring unit, configured to acquire the sample quantity, where the sample quantity includes the sampled data quantity and the new data quantity that has not been sampled; a second acquiring unit, configured to acquire, when arbitrarily selecting the sample quantity as training data, a first probability that the training data falls within the sampled data quantity and a second probability that the training data falls within the new data quantity; The first calculation unit is used to calculate the effective sampling number of the target vehicle attribute in the training data set according to the sampled data volume, the first probability and the second probability.
11. A vehicle attribute recognition device, characterized in that: The vehicle attribute recognition device comprises: A first acquisition module is used to acquire vehicle data to be identified, wherein the vehicle data to be identified includes an image of the vehicle to be identified; An identification module is used to input the vehicle data to be identified into a pre-trained target recognition model for identification, and obtain vehicle attributes corresponding to the vehicle image to be identified; The pre-trained target recognition model is obtained by training according to the vehicle attribute recognition model training method according to any one of claims 1-8.
12. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the processor implements the steps of the vehicle attribute recognition model training method described in any one of claims 1 to 8, and implements the steps of the vehicle attribute recognition method described in claim 9.
13. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the vehicle attribute recognition model training method described in any one of claims 1 to 8, and implements the steps of the vehicle attribute recognition method described in claim 9.
Citation Information
Patent Citations
Classifier, neural network model training method, data processing device, and medium
CN109902722A