CN115618221A - Model training method and device, storage medium and electronic equipment - Google Patents

Model training method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN115618221A
CN115618221A CN202110788040.7A CN202110788040A CN115618221A CN 115618221 A CN115618221 A CN 115618221A CN 202110788040 A CN202110788040 A CN 202110788040A CN 115618221 A CN115618221 A CN 115618221A
Authority
CN
China
Prior art keywords
sample
sample data
enhancement
target
loss value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110788040.7A
Other languages
Chinese (zh)
Inventor
齐子豪
李德财
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
TCL Technology Group Co Ltd
Original Assignee
TCL Technology Group Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by TCL Technology Group Co Ltd filed Critical TCL Technology Group Co Ltd
Priority to CN202110788040.7A priority Critical patent/CN115618221A/en
Publication of CN115618221A publication Critical patent/CN115618221A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Computational Linguistics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Evolutionary Computation (AREA)
  • Artificial Intelligence (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Image Analysis (AREA)

Abstract

The embodiment of the application provides a model training method and device, a storage medium and electronic equipment. The method comprises the steps of firstly obtaining a loss value corresponding to historical sample data; then determining the class of a target sample used for iterative training of the target model at the present time according to the loss value; further determining target sample data according to the target sample category; performing iterative training on the target model according to target sample data; and if the preset condition is met, stopping the iterative training. According to the embodiment of the application, the iterative training of the model can be performed by using the sample data of which sample type is determined according to the loss value fed back by the historical sample data, so that the sample feeding strategy of the iterative training of the model is adaptively adjusted, the problem of sample data imbalance is solved, and the accuracy of the model training is improved.

Description

Model training method and device, storage medium and electronic equipment
Technical Field
The present application relates to the field of artificial intelligence technologies, and in particular, to a model training method and apparatus, a storage medium, and an electronic device.
Background
With the rapid development of artificial intelligence technology, neural networks, such as deep neural networks, have achieved great success in processing and analyzing various media signals, such as images, videos, and voices. A neural network model with good performance generally requires a large amount of sample data to be trained to obtain a relatively ideal result.
However, sample data of each class is sometimes distributed unevenly, some sample data of the class are more, some sample data of the class are less, and unbalanced sample data affects the training effect of the model, so that the accuracy of model training is low.
Disclosure of Invention
The embodiment of the application provides a model training method and device, a storage medium and electronic equipment, which can improve the accuracy of model training.
The embodiment of the application provides a model training method, which comprises the following steps:
obtaining a loss value corresponding to historical sample data;
determining the category of the target sample according to the loss value;
determining target sample data according to the target sample category;
performing iterative training on the target model according to target sample data;
and if the preset condition is met, stopping the iterative training.
The embodiment of the present application further provides a model training device, including:
the acquisition module is used for acquiring a loss value corresponding to historical sample data;
the first determining module is used for determining the category of the target sample according to the loss value;
the second determining module is used for determining target sample data according to the target sample category;
the training module is used for carrying out iterative training on the target model according to the target sample data;
and the stopping module is used for stopping iterative training if the preset condition is met.
The embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to implement the steps in any one of the model training methods provided in the embodiment of the present application.
An embodiment of the present application further provides an electronic device, where the electronic device includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor, and the processor executes the computer program to implement the steps in any one of the model training methods provided in the embodiments of the present application.
In the embodiment of the application, firstly, a loss value corresponding to historical sample data is obtained; then determining the category of the target sample according to the loss value; further determining target sample data according to the target sample category; performing iterative training on the target model according to target sample data; and if the preset condition is met, stopping the iterative training. According to the embodiment of the application, the iterative training of the model can be determined by using the sample data of which types according to the loss value fed back by the historical sample data, so that the sample feeding strategy of the iterative training of the model is adaptively adjusted, the problem of sample data imbalance is solved, and the accuracy of the model training is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings used in the description of the embodiments will be briefly introduced below. It is obvious that the drawings in the following description are only some embodiments of the application, and that for a person skilled in the art, other drawings can be derived from them without inventive effort.
Fig. 1 is a schematic view of a first scenario provided in an embodiment of the present application.
Fig. 2 is a schematic flowchart of a first method for training a model according to an embodiment of the present disclosure.
Fig. 3 is a schematic flowchart of a second method for training a model according to an embodiment of the present disclosure.
Fig. 4 is a schematic flowchart of iterative training provided in the embodiment of the present application.
Fig. 5 is a third flowchart illustrating a model training method according to an embodiment of the present application.
Fig. 6 is a schematic diagram of a second scenario provided in the embodiment of the present application.
Fig. 7 is a schematic structural diagram of a first model training device according to an embodiment of the present application.
Fig. 8 is a schematic structural diagram of a second model training device according to an embodiment of the present application.
Fig. 9 is a schematic structural diagram of a first electronic device according to an embodiment of the present application.
Fig. 10 is a schematic structural diagram of a second electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. It is to be understood that the embodiments described are only a few embodiments of the present application and not all embodiments. All embodiments obtained by a person skilled in the art based on the embodiments in the present application without any inventive step are within the scope of the present invention.
The terms "first," "second," "third," and the like in the description and in the claims, as well as in the drawings, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the objects so described are interchangeable under appropriate circumstances. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, or apparatus, terminal, system comprising a list of steps is not necessarily limited to those steps or modules or elements expressly listed, and may include other steps or modules or elements not expressly listed, or inherent to such process, method, apparatus, terminal, or system.
Many technologies in the field of artificial intelligence relate to model training, and a good training method can remarkably improve the learning capacity of a machine, so that the machine can better learn sample data and output a learning result expected by a user. The training samples are indispensable parts in model training, and the model is generalized on the basis of the training samples by learning the training samples, so that other inputs except the training samples are successfully interpreted.
However, in practice, the distribution of training samples is not uniform. Unbalanced samples can lead to the model being over-weighted in sample classes with a higher number of samples, and "understandably" in sample classes with a lower number of samples, the generalization capability of the model can be affected, and the trained model is inaccurate. The problem of training sample maldistribution is solved in this application, can effectively improve the degree of accuracy of model training.
For example, please refer to fig. 1, wherein fig. 1 is a schematic diagram of a first scenario provided by an embodiment of the present application. The samples participating in the training model are divided into a plurality of sample categories, namely sample category 1-sample category Y, when the model is trained, sample data x taken from the sample category 1-sample category Y are input into the model for iterative training, and because the samples of the sample categories are distributed unevenly, the number of the samples in the sample categories 1-sample category Y is large, small, so that the model learns more sample categories with large sample number during training, and finally the sample categories with small sample number are difficult to accurately identify. The sample training method provided by the application determines which sample data to select for subsequent iterative training according to the loss value obtained after iterative training of the sample data y. The loss value corresponding to the sample data y already participating in the training is used as a feedback to influence the selection process of the sample data participating in the iterative training later. Therefore, the number of samples of each sample class participating in training can be balanced, the problem of unbalanced distribution of training samples is solved, and the accuracy of model training is effectively improved.
An execution subject of the model training method provided in the embodiment of the present application may be the model training apparatus provided in the embodiment of the present application, or an electronic device integrated with the model training apparatus, where the image model training apparatus may be implemented in a hardware or software manner. The electronic device may be a computer device, which may be a terminal device such as a smart phone, a tablet computer, a personal computer, or a server. The following is a detailed description of the analysis.
Referring to fig. 2, fig. 2 is a first flowchart illustrating a model training method according to an embodiment of the present disclosure. The model training method can comprise the following steps:
s101, obtaining a loss value corresponding to historical sample data.
The training process for the model may include a number of epochs (Epoch), a Epoch refers to the process in which a complete data set passes through the neural network once and back once. In training the model, the complete data set is passed multiple times through the same neural network. With the increase of the number of epochs, the weights in the neural network are continuously updated, and the fitting effect is better.
In each period of model training, a plurality of iterations (interpolation) training is performed, one iteration training being one training using a number of samples of one Batch size (Batch _ size). In one period, the batch size determines the number of iterative training sessions performed during the period.
For example, assuming that the total number of samples of the data set to be trained in a period is 1000 and the batch size is 10, the number of samples input into the neural network is 10 in each iterative training, and 100 iterations are required to train the entire data set in a period.
For another example, assuming that the total number of samples of the data set to be trained in one period is 50000, the batch size is 256, 50000/256=195, and 80 times, the number of iterations performed after training the entire data set in one period is 195+1=196 times. In the first 195 iterative trainings, the number of samples per input neural network was 256, and in the 196 th iterative training, the number of samples input to the neural network was 80.
The iteration is the action of repeated feedback, and the result obtained by each iteration is used as the initial value of the next iteration. Through continuous iterative training, the output result of the model gradually accords with the expectation.
The model training method provided by the embodiment of the application can be applied to the iterative training process of the target model. The target model is a training target of the model training method provided by the embodiment of the application. The historical sample data is sample data for which a corresponding loss value has been obtained, may be sample data that has been used in previous iterative training but has not been used in the current iterative training, and may also be sample data that has been used in the current iterative training.
In an embodiment, the historical sample data may be sample data used in a previous iteration training of the current iteration training. For example, if the ith iterative training is being performed, the historical sample data may be the sample data used in the ith-1 iterative training. Furthermore, the historical sample data may also be sample data used in earlier iterative training.
In an embodiment, if the ith iterative training is being performed, the historical sample data may also be all sample data used in the 1 st to i-1 st iterative training, and if a certain sample data is used more than once in the 1 st to i-1 st iterative training, all loss values corresponding to the historical sample data are obtained.
The embodiment of the present application does not limit this, and any sample data that has obtained a corresponding loss value may be used as the history sample data.
When each sample data is input into the model, the real value corresponding to the sample data is used as the expected result of the sample data for comparing with the predicted value output by the model. According to the difference between the real value and the predicted value, the prediction effect of the model on the sample data can be judged.
In an embodiment, after the historical sample data is input into the target model, the predicted value of the sample data can be obtained according to the target model. After the predicted value of the sample data is obtained, the predicted value can be compared with the true value, and the loss value (loss) corresponding to the sample data is obtained according to the loss function (loss function) of the target model. That is, the step of obtaining the loss value corresponding to the history sample data may include:
obtaining a predicted value obtained after historical sample data is input into a target model;
acquiring a true value of historical sample data;
and inputting the predicted value and the true value into a loss function of the target model to obtain a loss value corresponding to the historical sample data.
And S102, determining the category of the target sample according to the loss value.
The target sample class may refer to a sample class to which sample data used for iterative training of the target model currently belongs. The sample data used for training the target model belong to a plurality of sample categories, wherein the number of the sample data corresponding to some sample categories is large, and the number of the sample data corresponding to some sample categories is small, so that the number of the samples in different sample categories is unbalanced.
In the embodiment of the application, the target sample type is determined according to the loss value corresponding to the historical sample data, so that the sample data of which target sample type or target sample types are put into the target model at the time for iterative training is determined according to the loss feedback of the historical sample data. The number of target sample classes may be 1, 2, or more.
Referring to fig. 3, fig. 3 is a second flowchart illustrating a model training method according to an embodiment of the present disclosure. In an embodiment, the step of determining the target sample class according to the loss value may comprise:
and S1021, determining the sample type corresponding to the historical sample data.
Each sample data used for iterative training of the target model has a corresponding sample class. For example, when the target model is a gender prediction model, the sample category of the sample data may be male or female. From the sample classes of the historical sample data, it can be determined which sample data of the sample class or classes has been involved in the training.
When the historical sample data is used for carrying out iterative training on the target model, the label indicating the type of the historical sample data sample is carried. When the sample type of the historical sample data is determined, the sample type of the historical sample data can be directly determined according to the label of the historical sample data.
And S1022, updating the first reference loss value of the sample class according to the loss value.
In order to clarify the training condition of the sample data of each sample class, a first reference loss value is set for each sample class and is used for indicating the training condition of the sample data of the corresponding sample class. Wherein the first reference loss value of a certain sample class is determined according to the loss values of all sample data belonging to the sample class. If a sample data belonging to the sample class has not been subjected to iterative training (has no corresponding loss value), the loss value corresponding to the sample data may be replaced with a preset value, for example, may be marked as 0.
The first reference loss value may be of various forms, for example, the first reference loss value may be the cumulative sum of the loss values of all sample data belonging to the sample class, or the product of the loss values of all sample data belonging to the sample class, or the like. The calculation mode of the first reference loss value is not limited, and the overall loss condition of the corresponding sample class after being trained by the target model can be reflected.
In an embodiment, the first reference loss value of a sample class comprises a cumulative loss value of the sample class, and the cumulative loss value of each sample class is obtained by accumulating the loss values of all sample data belonging to the sample class. And after the loss value corresponding to the historical sample data is obtained, adding the loss value into the accumulated loss value of the sample class corresponding to the historical sample data to update the accumulated loss value of the corresponding sample class.
When adding the loss value to the accumulated loss value of the sample class, a weighted summation mode can be adopted. That is, the step of updating the first reference loss value of the sample class according to the loss value may include:
(1) Acquiring a first weight corresponding to the category;
(2) The product of the loss value and the first weight is added to the cumulative loss value for the sample class.
The first weights corresponding to the sample classes are preset, and when the loss values are accumulated, the loss values corresponding to the sample data of different sample classes can be multiplied by different first weights so as to reflect different values of the different sample classes. The corresponding sample class with the smaller first weight can make a larger contribution in the iterative training process. For example, assuming that the loss values of the sample data belonging to the sample class 1 and the sample data belonging to the sample class 2 are the same, the first weight corresponding to the sample class 1 is 0.1, and the first weight corresponding to the sample class 2 is 0.5, the sample class 1 needs to be 5 times that of the sample data belonging to the sample class 2 to enter the target model for iterative training, so that the cumulative loss values of the sample class 1 and the sample class 2 are the same.
When the accumulative loss value of the sample type is updated, the first weight corresponding to the sample type is obtained, the product of the loss value and the first weight is added into the accumulative loss value of the sample type to realize the weighted accumulation of the loss value, and the training condition of the sample data of the sample type participating in the iterative training is reflected according to the accumulative loss value obtained by the weighted accumulation.
In one embodiment, a first list may be created that records the loss accumulation values for each sample class. After iterative training is carried out on a target model according to historical sample data, a loss value corresponding to the historical sample data is obtained, a sample type corresponding to the historical sample data and a first weight corresponding to the sample type are obtained, the product of the loss value and the first weight is added into an accumulated loss value of the sample type corresponding to the historical sample data, and therefore the accumulated loss value of the sample type in the first list is updated, and the accumulated loss value of each sample type in the first list is guaranteed to be the latest and most accurate.
And S1023, determining a target sample class according to the first reference loss values of the plurality of sample classes.
The plurality of sample categories may be all sample categories corresponding to all sample data included in the data set, or may be partial sample categories in all sample categories. The data set is a data set used for iterative training of the target model. The target sample data may be determined by comparing the magnitude of the first reference loss value for several sample classes.
For example, when the first reference loss value is the accumulated loss value, a preset number of sample classes with the smallest accumulated loss value among the several sample classes may be determined as the target sample class in the order from the smaller accumulated loss value to the larger accumulated loss value.
In an embodiment, the step of determining the target sample class from the first reference loss values of the several sample classes may comprise:
(1) And determining candidate sample classes according to the first reference loss values of the plurality of sample classes.
(2) And determining the target sample category according to the candidate sample category.
For example, according to the sequence of the first reference loss value from small to large, N sample classes with the smallest first reference loss value are determined from a plurality of sample classes as candidate sample classes, and then N sample classes are randomly determined from the N candidate sample classes as target sample classes, wherein N and N are positive integers and N is less than or equal to N.
In this way, the present application considers the cumulative loss value of each sample class when determining the target sample class, and combines a random determination method. And determining the candidate sample categories according to the accumulated loss values of the sample categories, so that the loss values corresponding to the sample data which participates in iterative training in the selected candidate sample categories are all smaller, which indicates that the training effect of the candidate sample categories is poor and the learning needs to be continued. And the target sample class is randomly selected from the candidate sample classes, so that the model can be prevented from excessively paying attention to the candidate sample class with the smallest loss accumulated value and neglecting the candidate sample classes which are not the smallest in loss accumulated value but need to be continuously learned. According to the method and the device, the accumulative loss value of each sample class is considered, and meanwhile the generalization capability of the target model can be improved by combining a random determination mode.
S103, determining target sample data according to the target sample category.
In the case where the target sample class has been determined, the target sample data may be determined from a plurality of sample data belonging to the target sample class. The target sample data is not limited to the sample data that has not participated in the iterative training, and may also be the sample data that has participated in the iterative training.
In an embodiment, all sample data in the target sample data may be determined as the target sample data, or a part of sample data may be determined from the target sample class sample data as the target sample data. For example, using a random algorithm, part of the data is randomly determined from the target sample class sample data as the target sample data. One target sample data may be determined from each target sample category, or a plurality of target sample data may be determined from each target sample category.
In case a randomness algorithm is used, the same sample data may be selected twice. That is, the target sample data randomly determined from the sample data of the target sample category may contain the same sample data.
And S104, performing iterative training on the target model according to the target sample data.
Target sample data is selected from a target sample category, and the target sample data is used as input of current iteration training of the target model.
It should be noted that, the "current time" referred in the embodiments of the present application may be iterative training at different time points for model training. All iterative training in the model training can be regarded as 'current' iterative training. That is, the model training method provided in the embodiment of the present application is not particularly applied to a certain iterative training in the model training, but may be applied to all iterative training in the model training.
Referring to fig. 4, fig. 4 is a schematic flowchart of iterative training provided in the embodiment of the present application. The iterative training 1, the iterative training 2, the iterative training 3, and the iterative training 4 shown in the above description may be any 4 iterative training in model training, and the iterative training 1 to 4 only need to satisfy the order of the time relationship, and meanwhile, fig. 4 is only an example, and it should be understood by those skilled in the art that the distribution of the iterative training 1 to 4 is not limited to the case where the 4 iterative training shown in fig. 4 are adjacent, and may not be adjacent. For example, iterative training 2 may be iterative training separated by several iteration cycles after iterative training 1.
As shown in fig. 4, sample data 1 and sample data 2 undergo iterative training 1 to obtain a loss value 1 and a loss value 2. The sample data 1 and the sample data 2 can be used as historical sample data of the iterative training 2, the sample data 3 and the sample data 4 are determined to be used as target sample data of the iterative training 2 according to the loss value 1 corresponding to the sample data 1 and the loss value 2 corresponding to the sample data 2, and the iterative training 2 is completed according to the sample data 3 and the sample data 4.
And performing iterative training 2 on the sample data 3 and the sample data 4 to obtain a loss value 3 and a loss value 4. Sample data 1 to sample data 4 can be used as historical sample data of the iterative training 3, sample data 5 and sample data 6 are determined to be used as target sample data of the iterative training 3 according to loss values 1 to 4 corresponding to the sample data 1 to the sample data 4, and the iterative training 3 is completed according to the sample data 5 and the sample data 6.
And performing iterative training 3 on the sample data 5 and the sample data 6 to obtain a loss value 5 and a loss value 6. The sample data 1 to the sample data 6 can be used as historical sample data of the iterative training 4, the sample data 7 and the sample data 8 are determined to be used as target sample data of the iterative training 4 according to the loss values 1 to 6 corresponding to the sample data 1 to the sample data 6, and the iterative training 4 is completed according to the sample data 7 and the sample data 8.
By analogy, the sample data 1 to sample data 8 can be used as historical sample data of iterative training after the iterative training 4 to participate in determining target sample data of the iterative training. Therefore, the target sample data participating in the iterative training at the current time can be determined according to the loss value of the historical sample data in each iterative training, and the loss value obtained after the target sample data of each iterative training is iterated influences the sample data selection of the subsequent iterative training, so that the sample feeding strategy of the model iterative training can be adjusted and adjusted in a self-adaptive mode, and the problem of sample data imbalance is solved.
And S105, if the preset condition is met, stopping iterative training.
In an embodiment, according to the above S101 to S104, loop iteration is performed on the target model until a preset condition is satisfied. After a certain iterative training is finished, if a preset condition is met, stopping the iterative training to obtain a trained target model; if the preset condition is not met, repeating the steps and carrying out the next iterative training.
The preset condition is an expected target preset for the target model, and when the training result of the target model reaches the preset expected target, the target model can be regarded as the completion of the training, and the iteration can be stopped.
The preset condition may be, for example: and aiming at sample data input by certain iterative training, the average error between the predicted value and the true value output by the target model is smaller than a preset error threshold value. Then, after each iteration is finished, the predicted values and the true values of all the sample data participating in the current iteration training can be obtained, and the error of each sample data is calculated so as to obtain the average error of all the sample data participating in the current iteration training. If the average error is smaller than a preset error threshold value, stopping iterative training and outputting a trained target model; if the average error is greater than or equal to the preset error threshold, returning to S101 to perform the next iterative training, and repeating the S101-S104 until the average error is less than the preset error threshold after a certain iterative training, and stopping the iterative training.
It should be noted that, according to the actual training requirement, other preset conditions may be set by those skilled in the art. The setting mode of the preset condition is not limited, and the preset condition for stopping the iterative training is all within the protection scope of the present application.
The method according to the previous embodiment is described in further detail below by way of example.
In the present embodiment, the correction information is taken as an example of the corrected depth value. Referring to fig. 5, fig. 5 is a third flowchart illustrating a model training method according to an embodiment of the present disclosure. The model training method can comprise the following steps:
s201, obtaining a loss value corresponding to historical sample data.
The model training method provided by the embodiment of the application can be applied to the iterative training process of the target model. The target model is a training target of the model training method provided by the embodiment of the application. The historical sample data is sample data for which a corresponding loss value has been obtained, may be sample data that has been used in previous iterative training but has not been used in the current iterative training, and may also be sample data that has been used in the current iterative training.
In an embodiment, the historical sample data may be sample data used in a previous iteration training of the current iteration training. For example, if the ith iterative training is being performed, the historical sample data may be the sample data used in the ith-1 iterative training. Furthermore, the historical sample data may also be sample data used in earlier iterative training.
In an embodiment, if the ith iterative training is being performed, the historical sample data may also be all sample data used in the 1 st to i-1 st iterative training, and if a certain sample data is used more than once in the 1 st to i-1 st iterative training, all loss values corresponding to the historical sample data are obtained.
The embodiment of the present application does not limit this, and any sample data that has obtained a corresponding loss value may be used as the history sample data.
When each sample data is input into the model, the real value corresponding to the sample data is used as the expected result of the sample data for comparing with the predicted value output by the model. And according to the difference between the real value and the predicted value, the prediction effect of the model on the sample data can be judged.
In an embodiment, after the historical sample data is input into the target model, the predicted value of the sample data can be obtained according to the target model. After the predicted value of the sample data is obtained, the predicted value can be compared with the real value, and the loss value (loss) corresponding to the sample data is obtained according to the loss function (loss function) of the target model. That is, the step of obtaining the loss value corresponding to the history sample data may include:
obtaining a predicted value obtained after historical sample data is input into a target model;
acquiring a true value of historical sample data;
and inputting the predicted value and the true value into a loss function of the target model to obtain a loss value corresponding to the historical sample data.
S202, determining a sample type corresponding to the historical sample data.
Each sample data used for iterative training of the target model has a corresponding sample class. For example, when the target model is a gender prediction model, the sample category of the sample data may be male or female. From the sample classes of the historical sample data, it can be determined which sample data of the sample class or classes has been involved in the training.
When the historical sample data is used for carrying out iterative training on the target model, the label indicating the type of the historical sample data sample is carried. When the sample type of the historical sample data is determined, the sample type of the historical sample data can be directly determined according to the label of the historical sample data.
And S203, adding the loss value into the accumulated loss value of the sample class to update the accumulated loss value of the sample class.
And accumulating the accumulated loss value of each sample class according to the loss values of all sample data belonging to the sample class. And after the loss value corresponding to the historical sample data is obtained, adding the loss value into the accumulated loss value of the sample class corresponding to the historical sample data to update the accumulated loss value of the corresponding sample class.
When adding the loss value to the accumulated loss value of the sample class, a weighted summation mode can be adopted. That is, the step of updating the first reference loss value of the sample class according to the loss value may include:
(1) Acquiring a first weight corresponding to the sample type;
(2) The product of the loss value and the first weight is added to the cumulative loss value for the sample class.
The first weights corresponding to the sample types are preset, and when the loss values are accumulated, the loss values corresponding to the sample data of different sample types can be multiplied by different first weights so as to reflect different values of different sample types. The corresponding sample class with the smaller first weight can make a greater contribution in the iterative training process. For example, assuming that the loss values of the sample data belonging to the sample class 1 are the same as the loss values of the sample data belonging to the sample class 2, the first weight corresponding to the sample class 1 is 0.1, and the first weight corresponding to the sample class 2 is 0.5, the sample class 1 needs to be 5 times that of the sample data belonging to the sample class 2 to enter the target model for iterative training, so that the cumulative loss values of the sample class 1 and the sample class 2 are the same.
When the accumulated loss value of the sample type is updated, the first weight corresponding to the sample type is obtained, the product of the loss value and the first weight is added into the accumulated loss value of the sample type to realize the weighted accumulation of the loss value, and the training condition of the sample data of the sample type participating in the iterative training is reflected according to the accumulated loss value obtained by the weighted accumulation.
In one embodiment, a first list may be created that records the loss accumulation values for each sample class. After iterative training is carried out on a target model according to historical sample data, a loss value corresponding to the historical sample data is obtained, a sample type corresponding to the historical sample data and a first weight corresponding to the sample type are obtained, the product of the loss value and the first weight is added into an accumulated loss value of the sample type corresponding to the historical sample data, and therefore the accumulated loss value of the sample type in the first list is updated, and the accumulated loss value of each sample type in the first list is guaranteed to be the latest and most accurate.
And S204, determining the target sample type according to the accumulated loss values of the plurality of sample types.
In an embodiment, the step of determining the target sample class from the first reference loss values of the several sample classes may comprise:
(1) And determining candidate sample classes according to the first reference loss values of the plurality of sample classes.
(2) And determining the target sample category according to the candidate sample category.
For example, according to the sequence of the first reference loss value from small to large, N sample classes with the smallest first reference loss value are determined from a plurality of sample classes as candidate sample classes, and then N sample classes are randomly determined from the N candidate sample classes as target sample classes, wherein N and N are positive integers and N is less than or equal to N.
In this way, the application not only considers the accumulated loss value of each sample class when determining the target sample class, but also combines a random determination mode. And determining the candidate sample classes according to the accumulated loss values of the sample classes, so that the loss values corresponding to the sample data which participates in iterative training in the selected candidate sample classes are all small, which indicates that the training effect of the candidate sample classes is not good and the learning needs to be continued. And the target sample class is randomly selected from the candidate sample classes, so that the model can be prevented from excessively paying attention to the candidate sample class with the smallest loss accumulated value and neglecting the candidate sample classes which are not the smallest in loss accumulated value but need to be continuously learned. According to the method and the device, the accumulative loss value of each sample class is considered, and meanwhile the generalization capability of the target model can be improved by combining a random determination mode.
And S205, determining target sample data according to the target sample category.
In the case where the target sample class has been determined, the target sample data may be determined from a plurality of sample data belonging to the target sample class. The target sample data is not limited to the sample data that has not participated in the iterative training, and may also be the sample data that has participated in the iterative training.
In an embodiment, all sample data in the target sample data may be determined as the target sample data, or a part of sample data may be determined from the target sample type sample data as the target sample data. For example, using a random algorithm, part of the data is randomly determined from the target sample class sample data as the target sample data. One target sample data may be determined from each target sample category, or a plurality of target sample data may be determined from each target sample category.
In case a randomness algorithm is used, the same sample data may be selected twice. That is, the target sample data randomly determined from the sample data of the target sample category may contain the same sample data.
S206, determining an enhancement strategy used by historical sample data.
Wherein the historical sample data comprises historical sample data which has been subjected to data enhancement.
Data enhancement is also called data amplification, which means that under the condition of not substantially increasing data, limited data generates the value equivalent to more data, namely, the data amplification is carried out on the basis of the existing data by adopting a preset data transformation rule. The data enhancement method may include a single sample data enhancement method and a multi-sample data enhancement method, wherein the single sample data enhancement method includes performing geometric operation or color transformation on sample data, and the multi-sample data enhancement method includes generating new sample data according to a plurality of original sample data. Sample data produced by data enhancement is of lower quality than the original sample data.
If the historical sample data is the historical sample data subjected to data enhancement, it may be determined which enhancement strategy is used for the historical sample data, that is, the enhancement strategy used by the historical sample data. When the sample data subjected to historical data enhancement is input into the target model, the sample data can carry identification information corresponding to the enhancement strategy. For example, each enhancement policy may be encoded, and when a certain enhancement policy is used for a certain sample data, the encoding corresponding to the enhancement policy may be recorded. If the sample data is determined to be historical sample data in the subsequent iterative training, the enhancement strategy used by the historical sample data can be determined according to the recorded codes.
The enhancement strategy comprises 0, 1 or a plurality of data enhancement operations, wherein each data enhancement operation comprises the data enhancement operation of the type of rotation, cutting or color transformation and the like performed on sample data. When data enhancement is performed according to the enhancement policy, data enhancement operations contained in the enhancement policy are performed.
In one embodiment, not performing data enhancement is also a special enhancement strategy. When the enhancement strategy contains 0 data enhancement operation, the enhancement strategy does not perform data enhancement on the sample data, and the sample data after data enhancement according to the enhancement strategy is consistent with the sample data before data enhancement.
And S207, adding the loss value into the accumulated loss value of the enhancement strategy to update the accumulated loss value of the enhancement strategy.
In order to definitely use the training condition of the sample data of each enhancement strategy, a second reference loss value is set for each enhancement strategy and used for indicating the training condition of the sample data of the corresponding enhancement strategy. Wherein the second reference loss value of a certain enhancement strategy is determined according to the loss values of all sample data using the enhancement strategy. If a certain enhancement strategy is not used by the sample data participating in the iterative training, the second reference loss value corresponding to the enhancement strategy may be replaced by a preset value, for example, may be marked as 0.
The second reference loss value may be of various forms, for example, the second reference loss value may be the cumulative sum of all sample data using the enhancement policy, or the product of the loss values of all sample data using the enhancement policy, or the like. The calculation mode of the second reference loss value is not limited, and the whole loss condition of the sample data using the enhancement strategy after being trained by the target model can be reflected.
In an embodiment, the second reference loss value of the enhancement policy includes a cumulative loss value of the enhancement policy, and the cumulative loss value of each enhancement policy is obtained by accumulating the loss values of all sample data using the enhancement policy. And after the loss value corresponding to the historical sample data is obtained, adding the loss value into the cumulative loss value of the enhancement strategy used by the historical sample data to update the cumulative loss value of the enhancement strategy used by the historical sample data. It should be noted that more than one enhancement strategy may be used for one historical sample data.
When adding the loss value to the cumulative loss value of the enhancement policy used by the historical sample data, a weighted summation may be used. That is, the step of adding the loss value to the cumulative loss value of the enhancement policy to update the cumulative loss value of the enhancement policy may include:
(1) Acquiring a second weight corresponding to the enhancement strategy;
(2) The product of the penalty value and the second weight is added to the cumulative penalty value of the enhancement strategy.
The second weights corresponding to the enhancement strategies are preset, and when the loss values are accumulated, the loss values corresponding to different enhancement strategies can be multiplied by different second weights so as to reflect different importance degrees of different enhancement strategies. The corresponding enhancement strategy with the smaller second weight is easier to be selected as a target enhancement strategy for performing data enhancement on target sample data in subsequent iterative training. Because the quality of the generated sample data after the data enhancement processing is lower than that of the original sample data, the possibility of using the enhancement strategy of 'not performing data enhancement' can be increased by setting the second weighted value of the enhancement strategy of 'not performing data enhancement' to be larger, so that the proportion of the original sample data in the target sample data is increased.
When the accumulated loss value of the enhancement strategy used by the historical sample data is updated, the second weight corresponding to the used enhancement strategy is obtained, the product of the loss value and the second weight is added into the accumulated loss value of the enhancement strategy used by the historical sample data to realize the weighted accumulation of the loss value, and the training condition of the sample data using the enhancement strategy when the sample data participates in the iterative training is reflected according to the accumulated loss value obtained by the weighted accumulation.
If more than one enhancement policy is used for the historical sample data (for example, the enhancement policy a and the enhancement policy b are used), the product of the second weight and the loss value corresponding to the enhancement policy a is added to the cumulative loss value of the enhancement policy a to update the cumulative loss value of the enhancement policy a, and the product of the second weight and the loss value corresponding to the enhancement policy b is added to the cumulative loss value of the enhancement policy b to update the cumulative loss value of the enhancement policy a.
In one embodiment, a second list may be created, with a second sample class for recording the loss accumulation values for each enhancement strategy. After iterative training is carried out on the target model according to historical sample data, a loss value corresponding to the historical sample data is obtained, an enhancement strategy used by the historical sample data and a second weight corresponding to the enhancement strategy are obtained, and the product of the loss value and the second weight is added into an accumulated loss value of the enhancement strategy used by the historical sample data, so that the accumulated loss value of the corresponding enhancement strategy in the second list is updated, and the accumulated loss value of each enhancement strategy in the second list is guaranteed to be the latest and most accurate.
And S208, determining a target enhancement strategy according to the accumulated loss values of the plurality of enhancement strategies.
The plurality of enhancement policies may include all enhancement policies used by all sample data included in the data set, or may be some of the all enhancement policies. The data set is a data set used for iterative training of the target model. The target enhancement strategy may be determined by comparing the magnitude of the cumulative loss values of the several enhancement strategies.
For example, a preset number of enhancement strategies with the smallest accumulated loss value among the plurality of enhancement strategies may be determined as the target enhancement strategy in the order from the smaller accumulated loss value to the larger accumulated loss value.
In an embodiment, the step of determining the target enhancement strategy based on the cumulative loss values of the plurality of enhancement strategies may comprise:
(1) And determining candidate enhancement strategies according to the accumulated loss values of the plurality of enhancement strategies.
(2) And determining a target enhancement strategy according to the candidate enhancement strategies.
For example, according to the sequence of the accumulated loss values from small to large, M enhancement strategies with the minimum accumulated loss values are determined from a plurality of enhancement strategies as candidate enhancement strategies, and M sample classes are randomly determined from the M candidate enhancement strategies as current target enhancement strategies, wherein M and M are both positive integers, and M is less than or equal to M.
In this way, the application considers the accumulated loss value of each enhancement strategy when determining the target enhancement strategy, and combines the mode of random determination. And determining candidate enhancement strategies according to the accumulated loss values of the enhancement strategies, so that the loss values corresponding to the historical sample data after the selected candidate enhancement strategies are enhanced are small, and the training effect of the candidate enhancement strategies is poor and the candidate enhancement strategies need to be learned continuously. And randomly selecting the target enhancement strategy from the candidate enhancement strategies, the model can be prevented from excessively paying attention to the candidate enhancement strategy with the smallest loss accumulated value (for example, all the original sample data is used) and neglecting the candidate enhancement strategy with the smallest accumulated loss value but needing to be continuously learned. According to the method and the device, the accumulative loss value of each enhancement strategy is considered, and meanwhile the generalization capability of the target model can be improved by combining a random determination mode.
And S209, performing data enhancement on the target sample data according to the target enhancement strategy.
And S210, performing iterative training on the target model according to the target sample data after data enhancement.
And performing data enhancement on the target sample data by using a target enhancement strategy, and taking the target sample data subjected to data enhancement as the input of the current iterative training of the target model.
It should be noted that, the "current time" referred in the embodiments of the present application may be iterative training at different time points for model training. All iterative training in the model training can be regarded as 'current' iterative training. That is, the model training method provided in the embodiment of the present application is not particularly applicable to a certain iterative training in the model training, but may be applicable to all iterative training in the model training.
Referring to fig. 4, fig. 4 is a schematic flowchart of iterative training provided by an embodiment of the present application. The iterative training 1, the iterative training 2, the iterative training 3, and the iterative training 4 shown in the above description may be any 4 iterative training in model training, and the iterative training 1 to 4 only need to satisfy the order of the time relationship, and meanwhile, fig. 4 is only an example, and it should be understood by those skilled in the art that the distribution of the iterative training 1 to 4 is not limited to the case where the 4 iterative training shown in fig. 4 are adjacent, and may not be adjacent. For example, iterative training 2 may be iterative training separated by several iteration cycles after iterative training 1.
As shown in fig. 4, sample data 1 and sample data 2 undergo iterative training 1 to obtain a loss value 1 and a loss value 2. The sample data 1 and the sample data 2 can be used as historical sample data of the iterative training 2, the sample data 3 and the sample data 4 are determined to be used as target sample data of the iterative training 2 according to the loss value 1 corresponding to the sample data 1 and the loss value 2 corresponding to the sample data 2, and the iterative training 2 is completed according to the sample data 3 and the sample data 4.
And performing iterative training 2 on the sample data 3 and the sample data 4 to obtain a loss value 3 and a loss value 4. The sample data 1 to 4 can be used as historical sample data of the iterative training 3, the sample data 5 and the sample data 6 are determined to be used as target sample data of the iterative training 3 according to the loss values 1 to 4 corresponding to the sample data 1 to 4, and the iterative training 3 is completed according to the sample data 5 and the sample data 6.
And performing iterative training 3 on sample data 5 and sample data 6 to obtain a loss value 5 and a loss value 6. The sample data 1 to the sample data 6 can be used as historical sample data of the iterative training 4, the sample data 7 and the sample data 8 are determined to be used as target sample data of the iterative training 4 according to the loss value 1 to the loss value 6 corresponding to the sample data 1 to the sample data 6, and the iterative training 4 is completed according to the sample data 7 and the sample data 8.
By analogy, the sample data 1 to sample data 8 can be used as historical sample data of iterative training after the iterative training 4 and participate in determining target sample data of the iterative training after the iterative training. Therefore, the target sample data participating in the iterative training at the current time can be determined according to the loss value of the historical sample data in each iterative training, and the loss value obtained after the target sample data of each iterative training is iterated influences the sample data selection of the subsequent iterative training, so that the sample feeding strategy of the model iterative training can be adjusted and adjusted in a self-adaptive mode, and the problem of sample data imbalance is solved.
And S211, if the preset conditions are met, stopping iterative training.
In an embodiment, according to the above S201 to S210, loop iteration is performed on the target model until a preset condition is satisfied. After a certain iterative training is finished, if a preset condition is met, stopping the iterative training to obtain a trained target model; if the preset condition is not met, repeating the steps and carrying out the next iterative training.
The preset condition is an expected target preset for the target model, and when the training result of the target model reaches the preset expected target, the target model can be regarded as the completion of the training, and the iteration can be stopped.
The preset condition may be, for example: and aiming at sample data input by certain iterative training, the average error between the predicted value and the true value output by the target model is smaller than a preset error threshold value. Then, after each iteration is finished, the predicted values and the true values of all the sample data participating in the current iteration training can be obtained, and the error of each sample data is calculated so as to obtain the average error of all the sample data participating in the current iteration training. If the average error is smaller than a preset error threshold value, stopping iterative training and outputting a trained target model; if the average error is greater than or equal to the preset error threshold, returning to S201 to perform the next iterative training, and repeating the above S201-S210 until the average error is less than the preset error threshold after a certain iterative training, and stopping the iterative training.
Referring to fig. 6, fig. 6 is a schematic diagram illustrating a second scenario provided in the embodiment of the present application. The samples participating in the training model are divided into a plurality of sample categories, namely sample category 1-sample category Y, and the available enhancement strategies of the sample data are divided into a plurality of enhancement strategies, namely enhancement strategy 1-enhancement strategy F. When the model is trained, sample data Y is selected from the sample class 1 to the sample class Y, an enhancement strategy F is selected from the enhancement strategy 1 to the enhancement strategy F, data enhancement is carried out on the sample data Y by using the enhancement strategy F to obtain enhanced sample data Y, and the enhanced sample data Y is input into the model for iterative training. The sample training method provided by the application determines which type of sample data and which enhancement strategy are selected for carrying out subsequent iterative training according to the loss value obtained after iterative training of the sample data y. The loss value corresponding to the sample data y participating in the training is used as a feedback to influence the selection process of the sample data participating in the iterative training later and the selection process of the enhancement strategy for performing data enhancement processing on the sample data participating in the iterative training later. Therefore, the number of samples of each sample class participating in training can be balanced, the problem of unbalanced distribution of training samples is solved, and the accuracy of model training is effectively improved.
The model training method provided by the embodiment of the application can realize the purification of the sample data, reduce the unbalanced distribution of the sample data, improve the precision of deep learning, improve the usability of the sample data set, better exert the algorithm performance and improve the actual detection effect under the condition of keeping the complexity of the original sample data.
The target model trained by the model training method provided by the application can be applied to target detection of complex environments in multiple fields, and detection precision is improved. For example, the method can be applied to the field of video monitoring, the accuracy of intelligent video monitoring in intelligent detection of targets is improved, and the intelligent monitoring effect is improved. For example, the present invention can be applied to the field of automatic driving, and can accurately detect information on people, vehicles, signboards, and the like around a vehicle body, realize automatic driving of a vehicle, and automatically give an alarm at a dangerous time. The target model trained by the model training method provided by the application,
as can be seen from the above, the model training method provided in the embodiment of the present application first obtains the loss value corresponding to the historical sample data; then determining the category of the target sample according to the loss value; further determining target sample data according to the target sample category; and performing iterative training on the target model according to the target sample data. According to the embodiment of the application, the iterative training of the model can be performed by using the sample data of which sample type is determined according to the loss value fed back by the historical sample data, so that the sample feeding strategy of the iterative training of the model is adaptively adjusted, the problem of sample data imbalance is solved, and the accuracy of the model training is improved.
In order to better implement the model training method provided in the embodiment of the present application, the embodiment of the present application further provides a device based on the model training method. The meaning of the noun is the same as that in the model training method, and the specific implementation details can refer to the description in the method embodiment.
Referring to fig. 7, fig. 7 is a first structural diagram of a model training apparatus 300 according to an embodiment of the present disclosure. The image model training apparatus 300 includes an acquisition module 301, a first determination module 302, a second determination module 303, a training module 304, and a stop module 305:
an obtaining module 301, configured to obtain a loss value corresponding to historical sample data, where the historical sample data is sample data that has been used for iterative training of a target model;
a first determining module 302, configured to determine a target sample category according to the loss value;
a second determining module 303, configured to determine target sample data according to the target sample category;
a training module 304, configured to perform iterative training on the target model according to target sample data;
a stopping module 305, configured to stop the iterative training if a preset condition is met.
In an embodiment, when determining the target sample class according to the loss value, the first determination module 302 may be configured to:
determining a sample category corresponding to historical sample data;
updating a first reference loss value of the sample class according to the loss value;
and determining a target sample class according to the first reference loss values of the plurality of sample classes.
In an embodiment, the first reference loss value of the sample class includes a cumulative loss value of the sample class, the cumulative loss value of each sample class is obtained by accumulating loss values of all sample data belonging to the sample class, and when the first reference loss value of the sample class is updated according to the loss values, the first determining module 302 may be configured to:
the loss value is added to the cumulative loss value for the sample class to update the cumulative loss value for the sample class.
In an embodiment, different sample classes correspond to different first weights, and when adding the loss value to the cumulative loss value of the sample class, the first determining module 302 may be configured to:
acquiring a first weight corresponding to a sample category;
the product of the loss value and the first weight is added to the cumulative loss value for the sample class.
In an embodiment, when determining the target sample class according to the first reference loss value of the several sample classes, the first determination module 302 may be configured to:
determining candidate sample categories according to the first reference loss values of the plurality of sample categories;
and determining the target sample category according to the candidate sample category.
In an embodiment, when determining the candidate sample class according to the first reference loss value of several sample classes, the first determining module 302 may be configured to:
and according to the sequence of the first reference loss values from small to large, determining N sample classes with the minimum first reference loss values from the plurality of sample classes as candidate sample classes, wherein N is a positive integer.
In an embodiment, when determining the target sample class according to the candidate sample class, the first determination module 302 may be configured to:
and randomly determining N sample classes as target sample classes from the N candidate sample classes, wherein N is a positive integer and is less than or equal to N.
Referring to fig. 8, fig. 8 is a schematic diagram illustrating a second structure of the model training device according to the embodiment of the present disclosure. In an embodiment, the model training apparatus 300 may further include a third determining module 306, and the third determining module 306 may be configured to:
determining a target enhancement strategy according to the loss value;
in iteratively training the target model according to the target sample data, the training module 304 may be configured to:
performing data enhancement on target sample data according to a target enhancement strategy;
and performing iterative training on the target model according to the target sample data after data enhancement.
In an embodiment, the historical sample data includes historical sample data that has been subjected to data enhancement, and when determining the target enhancement policy according to the loss value, the third determining module 306 may be configured to:
determining an enhancement strategy for historical sample data usage;
updating a second reference loss value of the enhancement strategy used by the historical sample data according to the loss value;
and determining a target enhancement strategy according to the second reference loss value of the plurality of enhancement strategies.
In an embodiment, the second reference loss value of the enhancement policy includes an accumulated loss value of the enhancement policy, the accumulated loss value of each enhancement policy is accumulated according to loss values of all sample data using the enhancement policy, and when the second reference loss value of the enhancement policy is updated according to the loss values, the third determining module 306 may be configured to:
and adding the loss value into the accumulated loss value of the enhancement strategy to update the accumulated loss value of the enhancement strategy.
In an embodiment, the different enhancement policies correspond to different second weights, and when adding the loss value to the second reference loss value of the enhancement policy, the third determining module 306 may be configured to:
acquiring a second weight corresponding to the enhancement strategy;
the product of the penalty value and the second weight is added to the cumulative penalty value of the enhancement strategy.
In an embodiment, when determining the target enhancement policy according to a second reference loss value of the number of enhancement policies, the third determination module 306 may be configured to:
determining candidate enhancement strategies according to second reference loss values of the plurality of enhancement strategies;
determining a target enhancement strategy according to the candidate enhancement strategy; and/or the presence of a gas in the atmosphere,
when determining a candidate enhancement policy according to a second reference loss value of the plurality of enhancement policies, the third determining module 306 may be configured to:
according to the sequence of the second reference loss values from small to large, M enhancement strategies with the minimum second reference loss values are determined from the plurality of enhancement strategies to serve as candidate enhancement strategies, wherein M is a positive integer;
accordingly, in determining the target enhancement policy according to the candidate enhancement policy, the third determination module 306 may be configured to:
and randomly determining M enhancement strategies from the M candidate enhancement strategies as target enhancement strategies, wherein M is a positive integer and is less than or equal to M.
In one embodiment, the enhancement policy includes 0, 1 or more data enhancement operations, when data enhancement is performed according to the enhancement policy, the data enhancement operations included in the enhancement policy are executed, and when the enhancement policy includes 0 data enhancement operations, sample data after data enhancement is performed according to the enhancement policy is consistent with sample data before data enhancement; and/or
With continued reference to fig. 7, in an embodiment, the model training apparatus 300 may further include a fourth determining module 307, and after iteratively training the target model according to the data-enhanced target sample data, the fourth determining module 307 may be configured to:
and taking the target sample data after the data enhancement as historical sample data in the next iterative training.
In an embodiment, when determining the target sample data according to the target sample class, the second determining module 303 may be configured to:
determining partial sample data from the sample data of the target sample category as target sample data; and/or
When determining a part of sample data from the sample data of the target sample category as the target sample data, the second determining module 303 may be configured to:
and randomly determining partial sample data from the sample data of the target sample category as target sample data.
In view of the above, the embodiment of the present application provides a model training apparatus 300, wherein the obtaining module 301 first obtains a loss value corresponding to historical sample data; the first determination module 302 then determines the target sample class from the loss value; the second determining module 303 determines target sample data according to the type of the target sample; the training module 304 performs iterative training on the target model according to the target sample data; if the preset condition is met, the stopping module 305 stops the iterative training. According to the embodiment of the application, the iterative training of the model can be performed by using the sample data of which sample type is determined according to the loss value fed back by the historical sample data, so that the sample feeding strategy of the iterative training of the model is adaptively adjusted, the problem of sample data imbalance is solved, and the accuracy of the model training is improved.
The embodiment of the application also provides an electronic device 400. Referring to fig. 9, an electronic device 400 includes a processor 401 and a memory. The processor 401 is electrically connected to the memory.
The processor 401 is a control center of the electronic device 400, connects various parts of the entire electronic device using various interfaces and lines, performs various functions of the electronic device 400 by running or loading a computer program stored in the memory 402, and by data stored in the memory 402, and processes the data, thereby integrally monitoring the electronic device 400.
The memory 402 may be used to store software programs and modules, and the processor 401 executes various functional applications and data processing by operating the computer programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, a computer program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data created according to use of the electronic device, and the like. Further, the memory 402 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 access to the memory 402.
In the embodiment of the present application, the processor 401 in the electronic device 400 stores a computer program executable on the processor 401 in the memory 402, and the processor 401 executes the computer program stored in the memory 402, thereby implementing various functions as follows:
obtaining a loss value corresponding to historical sample data;
determining the category of the target sample according to the loss value;
determining target sample data according to the target sample category;
performing iterative training on the target model according to target sample data;
and if the preset condition is met, stopping the iterative training.
Referring also to fig. 10, in some embodiments, the electronic device 400 may further include: a display 403, radio frequency circuitry 404, audio circuitry 405, and a power supply 406. The display 403, the rf circuit 404, the audio circuit 405, and the power source 406 are electrically connected to the processor 401.
The display 403 may be used to display information entered by or provided to the user as well as various graphical user interfaces, which may be made up of graphics, text, icons, video, and any combination thereof. The Display 403 may include a Display panel, and in some embodiments, the Display panel may be configured in the form of a Liquid Crystal Display (LCD), an Organic Light-Emitting Diode (OLED), or the like.
The rf circuit 404 may be used for transceiving rf signals to establish wireless communication with a network device or other electronic devices through wireless communication, and for transceiving signals with the network device or other electronic devices.
The audio circuit 405 may be used to provide an audio interface between a user and an electronic device through a speaker, microphone.
The power source 406 may be used to power various components of the electronic device 400. In some embodiments, power supply 406 may be logically coupled to processor 401 via a power management system, such that functions to manage charging, discharging, and power consumption management are performed via the power management system.
Although not shown in fig. 9 and 10, the electronic device 400 may further include a camera, a bluetooth module, and the like, which are not described in detail herein.
An embodiment of the present application further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, where the computer program is executed by a processor to implement the model training method in any of the above embodiments, such as: obtaining a loss value corresponding to historical sample data; determining the category of the target sample according to the loss value; determining target sample data according to the target sample category; performing iterative training on the target model according to target sample data; and if the preset condition is met, stopping the iterative training.
In the embodiment of the present application, the computer readable storage medium may be a magnetic disk, an optical disk, a Read Only Memory (ROM), a Random Access Memory (RAM), or the like.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to the related descriptions of other embodiments.
It should be noted that, for the model training method of the embodiment of the present application, it can be understood by a person skilled in the art that all or part of the process of implementing the model training method of the embodiment of the present application may be implemented by controlling related hardware through a computer program, where the computer program may be stored in a computer readable storage medium, such as a memory of an electronic device, and executed by at least one processor in the electronic device, and during the execution process, the process of implementing the embodiment of the model training method may be included. The computer readable storage medium may be a magnetic disk, an optical disk, a read-only memory, a random access memory, etc.
For the model training device in the embodiment of the present application, each functional module may be integrated into one processing chip, or each module may exist alone physically, or two or more modules are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may also be stored in a computer readable storage medium, such as a read-only memory, a magnetic or optical disk, or the like.
The term "module" as used herein may refer to software objects that execute on the computing system. The various components, modules, engines, and services described herein may be viewed as objects implemented on the computing system. The apparatus and method described herein are preferably implemented in software, but may also be implemented in hardware, and are within the scope of the present application.
The model training method, the model training device, the storage medium, and the electronic device provided in the embodiments of the present application are described in detail above, and specific examples are applied in the present application to explain the principles and embodiments of the present application, and the description of the above embodiments is only used to help understand the method and the core ideas of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, the specific implementation manner and the application scope may be changed, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (16)

1. A method of model training, comprising:
obtaining a loss value corresponding to historical sample data;
determining a target sample category according to the loss value;
determining target sample data according to the target sample category;
performing iterative training on the target model according to the target sample data;
and if the preset condition is met, stopping the iterative training.
2. The model training method of claim 1, wherein the determining a target sample class from the loss value comprises:
determining a sample category corresponding to the historical sample data;
updating a first reference loss value of the sample class according to the loss value;
and determining a target sample class according to the first reference loss values of the plurality of sample classes.
3. The model training method according to claim 2, wherein the first reference loss value of a sample class comprises a cumulative loss value of the sample class, the cumulative loss value of each sample class is obtained by accumulating loss values of all sample data belonging to the sample class, and updating the first reference loss value of the sample class according to the loss values comprises:
adding the loss value to the cumulative loss value for the sample class to update the cumulative loss value for the sample class.
4. The model training method of claim 3, wherein different sample classes correspond to different first weights, said adding the loss value to the cumulative loss value of the sample class comprises:
acquiring a first weight corresponding to the sample category;
adding a product of the loss value and the first weight to a cumulative loss value for the sample class.
5. The model training method of claim 2, wherein the determining a target sample class from a first reference loss value of a number of sample classes comprises:
determining candidate sample categories according to the first reference loss values of the plurality of sample categories;
and determining a target sample category according to the candidate sample category.
6. The model training method of claim 5, wherein the determining a candidate sample class according to the first reference loss value of the plurality of sample classes comprises:
according to the sequence of the first reference loss values from small to large, determining N sample classes with the minimum first reference loss values from the plurality of sample classes as candidate sample classes, wherein N is a positive integer;
accordingly, the determining a target sample class from the candidate sample class comprises:
and randomly determining N classes as target sample classes from the N candidate sample classes, wherein N is a positive integer and is less than or equal to N.
7. The model training method according to any one of claims 1-6, wherein before iteratively training the target model according to the target sample data, further comprising:
determining a target enhancement strategy according to the loss value;
the iteratively training the target model according to the target sample data comprises:
performing data enhancement on the target sample data according to the target enhancement strategy;
and performing iterative training on the target model according to the target sample data after data enhancement.
8. The model training method of claim 7, wherein the historical sample data comprises historical sample data that has been data enhanced, and the determining a target enhancement policy according to the loss value comprises:
determining an enhancement strategy for the historical sample data usage;
updating a second reference loss value of the enhancement strategy according to the loss value;
and determining a target enhancement strategy according to the second reference loss value of the plurality of enhancement strategies.
9. The model training method of claim 8, wherein the second reference loss value of an enhancement strategy comprises a cumulative loss value of an enhancement strategy, the cumulative loss value of each enhancement strategy is cumulatively obtained from the loss values of all sample data using the enhancement strategy, and updating the second reference loss value of the enhancement strategy according to the loss values comprises:
adding the loss value to a cumulative loss value of the enhancement policy to update the cumulative loss value of the enhancement policy.
10. The model training method of claim 9, wherein different enhancement strategies correspond to different second weights, said adding the loss value to a second reference loss value of the enhancement strategy comprising:
acquiring a second weight corresponding to the enhancement strategy;
adding a product of the penalty value and the second weight to a cumulative penalty value for the enhancement policy.
11. The model training method of claim 8, wherein the determining a target enhancement strategy according to a second reference loss value of a plurality of enhancement strategies comprises:
determining candidate enhancement strategies according to second reference loss values of the plurality of enhancement strategies;
determining a target enhancement strategy according to the candidate enhancement strategy; and/or the presence of a gas in the atmosphere,
the determining a candidate enhancement strategy according to a second reference loss value of the plurality of enhancement strategies comprises:
according to the sequence of the second reference loss values from small to large, M enhancement strategies with the minimum second reference loss values are determined from the plurality of enhancement strategies to serve as candidate enhancement strategies, wherein M is a positive integer;
correspondingly, the determining a target enhancement strategy according to the candidate enhancement strategy comprises:
and randomly determining M enhancement strategies as target enhancement strategies from the M candidate enhancement strategies, wherein M is a positive integer and is less than or equal to M.
12. The model training method according to claim 7, wherein the enhancement strategy includes 0, 1 or more data enhancement operations, and when the enhancement strategy performs data enhancement according to the enhancement strategy, the data enhancement operations included in the enhancement strategy are executed, and when the enhancement strategy includes 0 data enhancement operations, the sample data after data enhancement according to the enhancement strategy is consistent with the sample data before data enhancement; and/or
After the iterative training of the target model according to the target sample data after data enhancement, the method further comprises:
and taking the target sample data after the data enhancement as historical sample data in the next iterative training.
13. The model training method of claim 1, wherein said determining target sample data according to the target sample class comprises:
determining partial sample data from the sample data of the target sample category as target sample data; and/or the presence of a gas in the gas,
the determining of partial sample data from the sample data of the target sample category as target sample data includes:
and randomly determining partial sample data from the sample data of the target sample type as target sample data.
14. A model training apparatus, comprising:
the acquisition module is used for acquiring a loss value corresponding to historical sample data;
the first determining module is used for determining the category of the target sample according to the loss value;
the second determining module is used for determining target sample data according to the target sample category;
the training module is used for carrying out iterative training on the target model according to the target sample data;
and the stopping module is used for stopping the iterative training if the preset condition is met.
15. A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, which computer program is executed by a processor to implement the model training method according to any one of claims 1 to 13.
16. An electronic device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, the processor executing the computer program to implement the model training method of any one of claims 1 to 13.
CN202110788040.7A 2021-07-13 2021-07-13 Model training method and device, storage medium and electronic equipment Pending CN115618221A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110788040.7A CN115618221A (en) 2021-07-13 2021-07-13 Model training method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110788040.7A CN115618221A (en) 2021-07-13 2021-07-13 Model training method and device, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN115618221A true CN115618221A (en) 2023-01-17

Family

ID=84856245

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110788040.7A Pending CN115618221A (en) 2021-07-13 2021-07-13 Model training method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN115618221A (en)

Similar Documents

Publication Publication Date Title
CN107545889B (en) Model optimization method and device suitable for pattern recognition and terminal equipment
US11681922B2 (en) Performing inference and training using sparse neural network
CN109635990B (en) Training method, prediction method, device, electronic equipment and storage medium
CN107995370A (en) Call control method, device and storage medium and mobile terminal
CN112200296A (en) Network model quantification method and device, storage medium and electronic equipment
US20220366257A1 (en) Small and Fast Video Processing Networks via Neural Architecture Search
US20240135698A1 (en) Image classification method, model training method, device, storage medium, and computer program
WO2013090853A2 (en) Method for rule-based context acquisition
CN117523218A (en) Label generation, training of image classification model and image classification method and device
CN113055984B (en) Terminal control method and device, mobile terminal and storage medium
CN112906883A (en) Hybrid precision quantization strategy determination method and system for deep neural network
CN108681480B (en) Background application program control method and device, storage medium and electronic equipment
CN115495364A (en) System fault diagnosis method, apparatus, storage medium, and program product
CN115618221A (en) Model training method and device, storage medium and electronic equipment
CN115345302A (en) Counterwork training method and device for adaptively selecting attack position, storage medium and server
CN112742026B (en) Game control method, game control device, storage medium and electronic equipment
JP2007018530A (en) Forgetting histogram calculation device, and outlier degree calculation device using same
CN111489203A (en) Financing product recommendation method and system
CN112580887A (en) Weight determination method, device and equipment for multi-target fusion evaluation and storage medium
CN113971454A (en) Deep learning model quantification method and related device
CN115952073B (en) Industrial computer performance evaluation method and device, electronic equipment and storage medium
US20220101163A1 (en) Electronic device and control method thereof
US20230342659A1 (en) Discrimination likelihood estimate for trained machine learning model
US20240062537A1 (en) Algorithm and method for dynamically varying quantization precision of deep learning network
CN116881122A (en) Test case generation method, device, equipment, storage medium and program product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination