WO2019127924A1 - Sample weight allocation method, model training method, electronic device, and storage medium - Google Patents

Sample weight allocation method, model training method, electronic device, and storage medium Download PDF

Info

Publication number
WO2019127924A1
WO2019127924A1 PCT/CN2018/079371 CN2018079371W WO2019127924A1 WO 2019127924 A1 WO2019127924 A1 WO 2019127924A1 CN 2018079371 W CN2018079371 W CN 2018079371W WO 2019127924 A1 WO2019127924 A1 WO 2019127924A1
Authority
WO
WIPO (PCT)
Prior art keywords
distance
sample
sample set
training
distribution
Prior art date
Application number
PCT/CN2018/079371
Other languages
French (fr)
Chinese (zh)
Inventor
严蕤
牟永强
Original Assignee
深圳云天励飞技术有限公司
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 深圳云天励飞技术有限公司 filed Critical 深圳云天励飞技术有限公司
Publication of WO2019127924A1 publication Critical patent/WO2019127924A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/21Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
    • G06F18/214Generating training patterns; Bootstrap methods, e.g. bagging or boosting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/24Classification techniques

Definitions

  • the present invention relates to the field of artificial intelligence, and in particular, to a sample weight distribution method, a model training method, an electronic device, and a storage medium.
  • loss functions are classified into two categories in the training of models (such as feature extraction models, face feature expression models, etc.).
  • the first category is classification-based metrics. Since the features are not directly measured, the performance is limited. The other is an end-to-end approach to feature metrics directly. Such methods are better able to converge because they need to select a suitable sample network.
  • the existing methods mainly obtain samples with appropriate difficulty levels by the following two methods: First, after the model is trained to a certain stage, according to the characteristic expression of the model, selecting some samples with moderate difficulty, such a method is troublesome to operate, and With the training of the model, the difficulty level of the selected samples changes, and the original offline selected samples are not representative and cannot fully express the characteristics of the subsequently added samples. Second, in the process of model training, select the moderately difficult samples according to the model of each training. Although the training samples selected by this method are representative, they can effectively improve the expression ability of the model, but the required computing resources are Large, difficult to achieve in actual model training.
  • a sample weight distribution method comprising:
  • Obtaining a training sample comprising a positive sample set and a negative sample set, the positive sample set comprising a positive sample pair and the negative sample set comprising a negative sample pair;
  • the distance distribution of the positive sample set indicating a relationship between a frequency of occurrence of a positive sample pair and a distance
  • the distance distribution of the negative sample set indicating a relationship between a frequency of occurrence of a negative sample pair and a distance
  • determining the weight distribution of the training sample based on the distance distribution of the positive sample set and the distance distribution of the negative sample set includes:
  • the weight of each sample pair in the second sample set is reduced.
  • the weight distribution of the training samples is a normal distribution, and when the maximum distance of the positive sample pairs in the positive sample set is less than or equal to the minimum distance of the negative sample pairs in the negative sample set,
  • the method further includes:
  • the mean of the maximum distance and the minimum distance is determined as the mean of the weight distribution of the training samples.
  • the weight distribution of the training samples is a normal distribution, and the training is determined when the maximum distance of the positive sample pairs in the positive sample set is greater than the minimum distance of the negative sample pairs in the negative sample set.
  • the method further includes:
  • the distance corresponding to the absolute value of the difference between the frequency at which the positive sample pair appears and the frequency at which the negative sample pair appears is taken as the mean of the weight distribution of the training sample.
  • the method when determining the mean value of the weight distribution of the training samples, the method further includes:
  • the weight distribution of the training samples is a normal distribution, and when determining the weight distribution of the training samples, the method further includes:
  • the standard deviation of the weight distribution of the training samples in each training process is updated according to the standard deviation of the distance between the positive sample pairs in the positive sample set.
  • a model training method comprising:
  • Model parameters are trained based on the training samples using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training samples, and the weight distribution of the training samples utilizes samples as described in any embodiment
  • the weight distribution method is obtained.
  • the method further includes:
  • the loss function is used to increase the contribution rate of the sample with the wrong classification to the target loss.
  • An electronic device comprising: a memory and a processor, the memory for storing at least one instruction, the processor for executing the at least one instruction to implement as described in any embodiment A sample weight assignment method, and/or a model training method as described in any embodiment.
  • a computer readable storage medium storing at least one instruction, the at least one instruction being executed by a processor to implement a sample weight assignment method as described in any embodiment, and/or any implementation The model training method described in the example.
  • the present invention provides a sample weight allocation method, the method comprising: acquiring a training sample, the training sample comprising a positive sample set and a negative sample set; and calculating each positive sample in the positive sample set a distance of the pair, and a distance of each negative sample pair in the negative sample set; determining a distance distribution of the positive sample set according to a distance of each positive sample pair in the positive sample set; a distance of the negative sample pair, determining a distance distribution of the negative sample set; determining a weight distribution of the training sample based on the distance distribution of the positive sample set and the distance distribution of the negative sample set.
  • the invention also provides a model training method, an electronic device and a storage medium. The invention can increase the weight of the sample pairs with the wrong classification. In the model training process, the contribution of the sample with the wrong classification to the target loss is increased, so that the model parameters can be better corrected and the expression ability of the model parameters can be improved.
  • FIG. 1 is a flow chart of a preferred embodiment of a sample weighting method of the present invention.
  • FIG. 2 is a schematic diagram of a distance distribution and a weight distribution of a sample in an example of the present invention.
  • Figure 3 is another schematic illustration of the distance distribution of a sample in an example of the present invention.
  • FIG. 4 is a flow chart of a preferred embodiment of the model training method of the present invention.
  • Figure 5 is a functional block diagram of a preferred embodiment of the sample weight distribution device of the present invention.
  • Figure 6 is a functional block diagram of a preferred embodiment of the model training device of the present invention.
  • Figure 7 is a block diagram showing a preferred embodiment of an electronic device in at least one example of the present invention.
  • FIG. 1 it is a flow chart of a preferred embodiment of the sample weight distribution method of the present invention.
  • the order of the steps in the flow chart can be changed according to different requirements, and some steps can be omitted.
  • the electronic device acquires a training sample, where the training sample includes a positive sample set and a negative sample set, the positive sample set includes a positive sample pair and the negative sample set includes a negative sample pair.
  • the electronic device configures a training sample set.
  • a part of the samples are first taken out from the configured training sample set for training, and the part of the samples is used as the training sample.
  • the training samples correspond to samples in each mini-batch.
  • the positive sample set comprises one or more positive sample pairs, wherein one of the positive sample pairs represents a sample pair belonging to a same category.
  • the negative sample set includes one or more negative sample pairs.
  • a positive sample pair includes a sample pair of a face, such as a positive sample pair. Two pictures of a human face.
  • the electronic device calculates a distance of each positive sample pair in the positive sample set and a distance of each negative sample pair in the negative sample set.
  • the electronic device calculates the Euclidean distance for each positive sample pair, using the Euclidean distance for each positive sample pair as the distance for each positive sample pair.
  • the electronic device calculates an Euclidean distance for each negative sample pair, and uses the Euclidean distance of each negative sample pair as the distance of each of the negative sample pairs.
  • the expression of the distance of each positive sample pair and the distance of each negative sample pair is not limited to the Euclidean distance, and may be other distance forms, and the present invention does not impose any limitation.
  • the electronic device determines a distance distribution of the positive sample set according to a distance of each positive sample pair in the positive sample set, where the distance distribution of the positive sample set represents a relationship between a positive sample pair appearance frequency and a distance.
  • the distance distribution of the positive sample set comprises a plurality of distance points, each distance point corresponding to a positive sample pair appearance frequency.
  • the positive sample set has 100 positive sample pairs, at a distance of 0.2, corresponding to 30 positive sample pairs.
  • the electronic device determines a distance distribution of the negative sample set according to a distance of each negative sample pair in the negative sample set, and the distance distribution of the negative sample set represents a relationship between a negative sample pair appearance frequency and a distance.
  • the distance distribution of the negative sample set comprises a plurality of distance points, each distance point corresponding to a negative sample pair appearance frequency.
  • the negative sample set has 100 negative sample pairs, at a distance of 0.5, corresponding to 20 negative sample pairs.
  • the electronic device determines a weight distribution of the training sample based on a distance distribution of the positive sample set and a distance distribution of the negative sample set.
  • the present invention when there is no overlapping portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, it indicates that there is no sample pair of the classification error in the positive sample set and the negative sample set.
  • the distance distribution of the positive sample set overlaps with the distance distribution of the negative sample set, it indicates that there is a sample pair of the classification error in the positive sample set and the negative sample set.
  • a sample pair corresponding to the distance of the intersection of the positive sample set and the distance overlap of the distance distribution of the negative sample set represents a sample pair that is misclassified. Therefore, in the subsequent training process, it is necessary to increase the weight of the sample pair of the classification error, so that the contribution rate of the sample of the classification error to the modified model parameter and the contribution rate of the expression ability of the model can be increased.
  • FIG. 2 a schematic diagram of a distance distribution of a positive sample set and a distance distribution of the negative sample set, wherein the distance of each positive sample pair in the positive sample set is represented by a Euclidean distance, the negative The distance of each negative sample pair in the sample set is represented by the Euclidean distance. Of course, it can also be represented by other distances. This example cannot be used as a limitation on the distance calculation method.
  • the sample pairs corresponding to the distance between the distance A and the distance B are all sample pairs that are misclassified. If the total number of positive sample pairs is 1000, the total number of negative sample pairs is 2000, the positive sample pair corresponding to A is 0.02, and the positive sample corresponding to point A is 20, distance A.
  • the corresponding negative sample pair has a frequency of 0.15, and the negative sample pair corresponding to point A has 300. If the distance of a target sample pair is equal to the distance A, the target sample pair may belong to a positive sample pair or a negative sample pair, and thus the target sample pair may be classified incorrectly.
  • the determining, according to the distance distribution of the positive sample set and the distance distribution of the negative sample set, determining a weight distribution of the training sample includes:
  • the loss function and the training are performed in the subsequent model training process by increasing the weight of the misclassified sample pair in the weight distribution of the training sample, and/or reducing the weight of the correctly classified sample.
  • the weight distribution of the sample is associated, and the loss function is established based on the weight distribution of the training sample, which can increase the contribution of the sample with the wrong classification to the network loss, thereby better correcting the model parameters and improving the expression of the model parameters. ability.
  • the weight distribution of the training samples is a normal distribution.
  • the parameter of the normal distribution is configured to achieve a weighting of a pair of samples that increase the classification error, and/or to reduce the weight of the sample that is correctly classified.
  • the normal distribution represents the relationship between the distance of the pair of samples and the weight.
  • the parameters of the normal distribution include, but are not limited to, mean, standard deviation.
  • the method further includes: maximizing the maximum The mean of the distance from the minimum distance is determined as the mean of the weight distribution of the training samples.
  • the maximum distance of the positive sample pair in the positive sample set is smaller than the minimum distance of the negative sample pair in the negative sample set, it means that there is no sample pair of the classification error in the positive sample set and the negative sample set.
  • the distance of each positive sample pair in the positive sample set is represented by a Euclidean distance
  • the distance of each negative sample pair in the negative sample set is represented by a Euclidean distance
  • other distances may be used. It is indicated that this example cannot be used as a limitation on the way the distance is calculated.
  • the distance corresponding to the maximum distance C point of the positive sample pair in the positive sample set is smaller than the distance corresponding to the minimum distance D point of the negative sample pair in the negative sample set. If there is no crossover portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, then there is no sample pair with the classification error in the positive sample set and the negative sample set.
  • the method when the maximum distance of the positive sample pair in the positive sample set is equal to the minimum distance of the negative sample pair in the negative sample set, when determining the weight distribution of the training sample, the method further includes: maximizing the maximum The mean of the distance from the minimum distance is determined as the mean of the weight distribution of the training samples.
  • the method further includes:
  • the distance corresponding to the absolute value of the difference between the frequency at which the positive sample pair appears and the frequency at which the negative sample pair appears is taken as the mean of the weight distribution of the training sample.
  • the maximum distance of the positive sample pair in the positive sample set is greater than the minimum distance of the negative sample pair in the negative sample set, it means that there is a sample pair of the classification error in the positive sample set and the negative sample set.
  • the distance corresponding to the maximum distance B point of the positive sample pair in the positive sample set is smaller than the distance corresponding to the minimum distance A point of the negative sample pair in the negative sample set. If there is a crossover portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, then there is no sample pair with the classification error in the positive sample set and the negative sample set.
  • a distance corresponding to the distance distribution of the positive sample set and the distance distribution of the negative sample set from the intersection E is taken as the mean of the normal distribution.
  • the absolute value of the difference between the frequency of the positive sample pair and the frequency of occurrence of the negative sample pair is the frequency value F corresponding to the intersection E.
  • the sample pairs corresponding to the distances included in the vicinity of the mean value of the weight distribution of the training samples are classified incorrectly.
  • the weight of the sample pairs corresponding to the distance of the mean of the weight distribution of the training samples is larger, thereby increasing the weight of the sample pairs that increase the classification error.
  • the loss function is associated with the weight distribution of the training sample, and the loss function is established based on the weight distribution of the training sample, which may be increased.
  • the sample pairs corresponding between the distance A and the distance E are sample pairs that are misclassified, and the sample pairs corresponding between the distance B and the distance E are also classified incorrectly.
  • Sample pair Therefore, in the normal distribution, the pair of samples corresponding between the distance A and the distance E and the pair of samples corresponding to the distance B and the distance E have a higher weight than the pair of samples that can be correctly classified.
  • the method further includes:
  • the preset step size is equal to (the maximum distance - minimum distance) / n, and the n is a positive number.
  • the preset step size may also be other forms of step size, and the present invention does not impose any limitation.
  • the iterative termination condition includes, but is not limited to, a preset error.
  • the initial iteration is the initial iteration, and the iterative search is performed based on the preset step step.
  • the distance represented by the current mean ⁇ is calculated, and the frequency of the positive sample pair and the negative sample pair appear. Whether the absolute value of the difference between the frequencies is less than the preset error. If the preset value is less than the preset error, the current average value plus the preset step size is assigned to the current mean value ⁇ , that is, ( ⁇ +step) is assigned to ⁇ , and the determination continues.
  • the search for the mean value is stopped, and the optimal distance value corresponding to the last iteration is output as the mean value of the weight distribution of the training sample.
  • the model expression ability is continuously enhanced, so the weight of the sample pair (ie, the first sample set) of the classification error should also be gradually increased, that is, the normal distribution needs to be reduced (ie, The standard deviation of the weight distribution of the training samples.
  • the normal distribution the smaller the standard deviation, the steeper the normal peak, that is, the closer the weight of the sample pair at the distance indicated by the mean value, so that a sample pair that gradually increases the classification error can be realized (ie, The weight of the first sample set).
  • the standard deviation of the normal distribution can be configured according to the standard deviation of the distance from the sample in the positive sample set.
  • the method further comprises: updating a standard deviation of weight distributions of the training samples in each training process according to a standard deviation of distances between pairs of positive samples in the positive sample set. In this way, the standard deviation in the weight distribution of the training samples gradually decreases with the increase of the number of training times in the model training process, so that the weight of the indistinguishable samples gradually increases, and the expression ability and convergence speed of the model are improved.
  • the present invention acquires a training sample, where the training sample includes a positive sample set and a negative sample set, the positive sample set includes a positive sample pair and the negative sample set includes a negative sample pair; and the positive sample is calculated Concentrating the distance of each positive sample pair and the distance of each negative sample pair in the negative sample set; determining a distance distribution of the positive sample set according to the distance of each positive sample pair in the positive sample set, the positive The distance distribution of the sample set represents a relationship between the occurrence frequency of the positive sample and the distance; determining the distance distribution of the negative sample set according to the distance of each negative sample pair in the negative sample set, the distance distribution of the negative sample set is negative The relationship between the appearance frequency and the distance of the sample; the weight distribution of the training sample is determined based on the distance distribution of the positive sample set and the distance distribution of the negative sample set.
  • the invention can increase the weight of the sample pairs with the wrong classification, and in the subsequent training process, the contribution rate of the sampled errors to the modified model parameters, the improvement of the
  • FIG. 4 is a flow chart of a preferred embodiment of the model training method of the present invention. The order of the steps in the flowchart may be changed according to different requirements, and some steps may be omitted.
  • the electronic device acquires a training sample.
  • the electronic device trains a model parameter by using a loss function and a preset training algorithm based on the training sample, wherein the loss function is associated with a weight distribution of the training sample.
  • the weight distribution of the training samples is obtained by using the sample weight allocation method described in any of the above embodiments. It will not be detailed here.
  • the preset training algorithm includes, but is not limited to: a convolutional neural network algorithm.
  • the loss function increases the contribution rate of the sampled error pair to the target loss by the weight distribution of the training sample.
  • the method further comprises: using the loss function, increasing a contribution rate of the sample error of the classification error to the target loss, thereby improving the contribution rate of the sample error pair to the modified model parameter, and improving the expression ability of the model.
  • the contribution rate makes the model more focused on the classification of wrong samples during the training process, which increases the expression ability and convergence speed of the model.
  • the present invention acquires a training sample, and based on the training sample, trains a model parameter using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training sample.
  • the weight distribution of the training samples is obtained using the sample weight allocation method described in any of the above embodiments.
  • the weight distribution of the training samples is in the process of model training, and the weights of the sample pairs that are misclassified gradually become larger. Therefore, when the model parameters are trained, the loss function can be used to improve the sample of the classification errors.
  • the contribution rate to the modified model parameters and the ability to improve the expression of the model enable the model to focus more on the misclassified samples during the training process, increasing the expression ability and convergence speed of the model, and improving the accuracy of the model parameters. .
  • the face feature expression model is trained using the model training method described in FIG. 4, wherein each positive sample pair in the positive sample set represents a face sample pair representing the same person.
  • the trained face feature expression model is used to extract the features of the image to be detected, so that the accuracy of face recognition can be improved.
  • the to-be-detected picture is obtained, and the feature of the to-be-detected picture is extracted by using the trained face feature expression model, and the face to be detected is subjected to face recognition based on the feature of the picture to be detected.
  • the face feature expression model trained by the present invention can increase the weight of the sample pairs that are misclassified, and reduce the weight of the sample pairs that have been correctly classified, thereby increasing the expression ability and convergence speed of the face feature expression model. Thereby improving the accuracy of face recognition.
  • the sample weight distribution device 11 includes an acquisition module 100, a calculation module 101, and a determination module 102.
  • the unit referred to in the present invention refers to a series of computer program segments that can be executed by the processor of the sample weight distribution device 11 and that can perform a fixed function, which is stored in the memory. In the present embodiment, the functions of the respective units will be described in detail in the subsequent embodiments.
  • the obtaining module 100 acquires a training sample, where the training sample includes a positive sample set and a negative sample set, the positive sample set includes a positive sample pair and the negative sample set includes a negative sample pair.
  • the electronic device configures a training sample set.
  • a part of the samples are first taken out from the configured training sample set for training, and the part of the samples is used as the training sample.
  • the training samples correspond to samples in each mini-batch.
  • the positive sample set comprises one or more positive sample pairs, wherein one of the positive sample pairs represents a sample pair belonging to a same category.
  • the negative sample set includes one or more negative sample pairs.
  • a positive sample pair includes a sample pair of a face, such as a positive sample pair. Two pictures of a human face.
  • the calculation model 101 calculates the distance of each positive sample pair in the positive sample set and the distance of each negative sample pair in the negative sample set.
  • the calculation model 101 calculates the Euclidean distance for each positive sample pair, using the Euclidean distance for each positive sample pair as the distance for each positive sample pair.
  • the calculation model 101 calculates the Euclidean distance for each negative sample pair, and takes the Euclidean distance of each negative sample pair as the distance of each of the negative sample pairs.
  • the expression of the distance of each positive sample pair and the distance of each negative sample pair is not limited to the Euclidean distance, and may be other distance forms, and the present invention does not impose any limitation.
  • the determining module 102 determines a distance distribution of the positive sample set according to a distance of each positive sample pair in the positive sample set, and the distance distribution of the positive sample set represents a relationship between a positive sample pair appearance frequency and a distance.
  • the distance distribution of the positive sample set comprises a plurality of distance points, each distance point corresponding to a positive sample pair appearance frequency.
  • the positive sample set has 100 positive sample pairs, at a distance of 0.2, corresponding to 30 positive sample pairs.
  • the determining module 102 determines a distance distribution of the negative sample set according to a distance of each negative sample pair in the negative sample set, and the distance distribution of the negative sample set represents a relationship between a negative sample pair appearance frequency and a distance.
  • the distance distribution of the negative sample set comprises a plurality of distance points, each distance point corresponding to a negative sample pair appearance frequency.
  • the negative sample set has 100 negative sample pairs, at a distance of 0.5, corresponding to 20 negative sample pairs.
  • the determining module 102 determines a weight distribution of the training samples based on a distance distribution of the positive sample set and a distance distribution of the negative sample set.
  • the present invention when there is no overlapping portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, it indicates that there is no sample pair of the classification error in the positive sample set and the negative sample set.
  • the distance distribution of the positive sample set overlaps with the distance distribution of the negative sample set, it indicates that there is a sample pair of the classification error in the positive sample set and the negative sample set.
  • a sample pair corresponding to the distance of the intersection of the positive sample set and the distance overlap of the distance distribution of the negative sample set represents a sample pair that is misclassified. Therefore, in the subsequent training process, it is necessary to increase the weight of the sample pair of the classification error, so that the contribution rate of the sample of the classification error to the modified model parameter and the contribution rate of the expression ability of the model can be increased.
  • the sample pairs corresponding to the distance between the distance A and the distance B are all samples with incorrect classification. Correct. If the total number of positive sample pairs is 1000, the total number of negative sample pairs is 2000, the positive sample pair corresponding to A is 0.02, and the positive sample corresponding to point A is 20, distance A. The corresponding negative sample pair has a frequency of 0.15, and the negative sample pair corresponding to point A has 300. If the distance of a target sample pair is equal to the distance A, the target sample pair may belong to a positive sample pair or a negative sample pair, and thus the target sample pair may be classified incorrectly.
  • the determining module 102 determines, according to the distance distribution of the positive sample set and the distance distribution of the negative sample set, that the weight distribution of the training sample comprises:
  • the loss function and the training are performed in the subsequent model training process by increasing the weight of the misclassified sample pair in the weight distribution of the training sample, and/or reducing the weight of the correctly classified sample.
  • the weight distribution of the sample is associated, and the loss function is established based on the weight distribution of the training sample, which can increase the contribution of the sample with the wrong classification to the network loss, thereby better correcting the model parameters and improving the expression of the model parameters. ability.
  • the weight distribution of the training samples is a normal distribution.
  • the parameter of the normal distribution is configured to achieve a weighting of a pair of samples that increase the classification error, and/or to reduce the weight of the sample that is correctly classified.
  • the normal distribution represents the relationship between the distance of the pair of samples and the weight.
  • the parameters of the normal distribution include, but are not limited to, mean, standard deviation.
  • the determining module 102 is further configured to: The mean of the maximum distance and the minimum distance is determined as the mean of the weight distribution of the training samples.
  • the maximum distance of the positive sample pair in the positive sample set is smaller than the minimum distance of the negative sample pair in the negative sample set, it means that there is no sample pair of the classification error in the positive sample set and the negative sample set.
  • the distance corresponding to the maximum distance C point of the positive sample pair in the positive sample set is smaller than the distance corresponding to the minimum distance D point of the negative sample pair in the negative sample set. If there is no crossover portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, then there is no sample pair with the classification error in the positive sample set and the negative sample set.
  • the determining module 102 is further configured to: The mean of the maximum distance and the minimum distance is determined as the mean of the weight distribution of the training samples.
  • the method further includes:
  • the distance corresponding to the absolute value of the difference between the frequency at which the positive sample pair appears and the frequency at which the negative sample pair appears is taken as the mean of the weight distribution of the training sample.
  • the maximum distance of the positive sample pair in the positive sample set is greater than the minimum distance of the negative sample pair in the negative sample set, it means that there is a sample pair of the classification error in the positive sample set and the negative sample set.
  • the distance corresponding to the maximum distance B point of the positive sample pair in the positive sample set is smaller than the distance corresponding to the minimum distance A point of the negative sample pair in the negative sample set. If there is a crossover portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, then there is no sample pair with the classification error in the positive sample set and the negative sample set.
  • a distance corresponding to the distance distribution of the positive sample set and the distance distribution of the negative sample set from the intersection E is taken as the mean of the normal distribution.
  • the absolute value of the difference between the frequency of the positive sample pair and the frequency of occurrence of the negative sample pair is the frequency value F corresponding to the intersection E.
  • the sample pairs corresponding to the distances included in the vicinity of the mean value of the weight distribution of the training samples are classified incorrectly.
  • the weight of the sample pairs corresponding to the distance of the mean of the weight distribution of the training samples is larger, thereby increasing the weight of the sample pairs that increase the classification error.
  • the loss function is associated with the weight distribution of the training sample, and the loss function is established based on the weight distribution of the training sample, which may be increased.
  • the sample pairs corresponding between the distance A and the distance E are sample pairs that are misclassified, and the sample pairs corresponding between the distance B and the distance E are also classified incorrectly.
  • Sample pair Therefore, in the normal distribution, the pair of samples corresponding between the distance A and the distance E and the pair of samples corresponding to the distance B and the distance E have a higher weight than the pair of samples that can be correctly classified.
  • the determining module 102 is further configured to:
  • the preset step size is equal to (the maximum distance - minimum distance) / n, and the n is a positive number.
  • the preset step size may also be other forms of step size, and the present invention does not impose any limitation.
  • the iterative termination condition includes, but is not limited to, a preset error.
  • the initial iteration is the initial iteration, and the iterative search is performed based on the preset step step.
  • the distance represented by the current mean ⁇ is calculated, and the frequency of the positive sample pair and the negative sample pair appear. Whether the absolute value of the difference between the frequencies is less than the preset error. If the preset value is less than the preset error, the current average value plus the preset step size is assigned to the current mean value ⁇ , that is, ( ⁇ +step) is assigned to ⁇ , and the determination continues.
  • the search for the mean value is stopped, and the optimal distance value corresponding to the last iteration is output as the mean value of the weight distribution of the training sample.
  • the model expression ability is continuously enhanced, so the weight of the sample pair (ie, the first sample set) of the classification error should also be gradually increased, that is, the normal distribution needs to be reduced (ie, The standard deviation of the weight distribution of the training samples.
  • the normal distribution the smaller the standard deviation, the steeper the normal peak, that is, the closer the weight of the sample pair at the distance indicated by the mean value, so that a sample pair that gradually increases the classification error can be realized (ie, The weight of the first sample set).
  • the standard deviation of the normal distribution can be configured according to the standard deviation of the distance from the sample in the positive sample set.
  • the method further comprises: updating a standard deviation of weight distributions of the training samples in each training process according to a standard deviation of distances between pairs of positive samples in the positive sample set. In this way, the standard deviation in the weight distribution of the training samples gradually decreases with the increase of the number of training times in the model training process, so that the weight of the indistinguishable samples gradually increases, and the expression ability and convergence speed of the model are improved.
  • the present invention acquires a training sample, where the training sample includes a positive sample set and a negative sample set, the positive sample set includes a positive sample pair and the negative sample set includes a negative sample pair; and the positive sample is calculated Concentrating the distance of each positive sample pair and the distance of each negative sample pair in the negative sample set; determining a distance distribution of the positive sample set according to the distance of each positive sample pair in the positive sample set, the positive The distance distribution of the sample set represents a relationship between the occurrence frequency of the positive sample and the distance; determining the distance distribution of the negative sample set according to the distance of each negative sample pair in the negative sample set, the distance distribution of the negative sample set is negative The relationship between the appearance frequency and the distance of the sample; the weight distribution of the training sample is determined based on the distance distribution of the positive sample set and the distance distribution of the negative sample set.
  • the invention can increase the weight of the sample pairs with the wrong classification, and in the subsequent training process, the contribution rate of the sampled errors to the modified model parameters, the improvement of the
  • FIG. 6 is a functional block diagram of a preferred embodiment of the model training device of the present invention.
  • the model training device 61 includes a data acquisition module 600 and the training module 601.
  • the unit referred to in the present invention refers to a series of computer program segments that can be executed by the processor of the model training device 61 and that can perform fixed functions, which are stored in the memory. In the present embodiment, the functions of the respective units will be described in detail in the subsequent embodiments.
  • the data acquisition module 600 acquires training samples.
  • the training module 601 trains model parameters based on the training samples using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training samples.
  • the weight distribution of the training samples is obtained by using the sample weight allocation method described in any of the above embodiments. It will not be detailed here.
  • the preset training algorithm includes, but is not limited to: a convolutional neural network algorithm.
  • the loss function increases the contribution rate of the sampled error pair to the target loss by the weight distribution of the training sample.
  • the training module 601 is further configured to: use the loss function to increase a contribution rate of the sample error of the classification error to the target loss, thereby improving the contribution rate of the sample pair of the classification error to the modified model parameter, and improving the model.
  • the contribution rate of expressive ability enables the model to focus more on the misclassified samples during the training process, increasing the expressive ability and convergence speed of the model.
  • the present invention acquires a training sample, and based on the training sample, trains a model parameter using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training sample.
  • the weight distribution of the training samples is obtained using the sample weight allocation method described in any of the above embodiments.
  • the weight distribution of the training samples is in the process of model training, and the weights of the sample pairs that are misclassified gradually become larger. Therefore, when the model parameters are trained, the loss function can be used to improve the sample of the classification errors.
  • the contribution rate to the modified model parameters and the ability to improve the expression of the model enable the model to focus more on the misclassified samples during the training process, increasing the expression ability and convergence speed of the model, and improving the accuracy of the model parameters. .
  • the above-described integrated unit implemented in the form of a software function module can be stored in a computer readable storage medium.
  • the above software functional modules are stored in a storage medium and include instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to perform the method of each embodiment of the present invention. Part of the steps.
  • the electronic device 3 comprises at least one transmitting device 31, at least one memory 32, at least one processor 33, at least one receiving device 34 and at least one communication bus.
  • the communication bus is used to implement connection communication between these components.
  • the electronic device 3 is a device capable of automatically performing numerical calculation and/or information processing according to an instruction set or stored in advance, and the hardware includes but is not limited to a microprocessor and an application specific integrated circuit (ASIC). ), Field-Programmable Gate Array (FPGA), Digital Signal Processor (DSP), embedded devices, etc.
  • the electronic device 3 may also comprise a network device and/or a user device.
  • the network device includes, but is not limited to, a single network server, a server group composed of multiple network servers, or a cloud computing-based cloud composed of a large number of hosts or network servers, where the cloud computing is distributed computing.
  • a super virtual computer consisting of a group of loosely coupled computers.
  • the electronic device 3 can be, but is not limited to, any electronic product that can interact with a user through a keyboard, a touch pad, or a voice control device, such as a tablet, a smart phone, or a personal digital assistant (Personal Digital Assistant). , PDA), smart wearable devices, camera equipment, monitoring equipment and other terminals.
  • a keyboard e.g., a keyboard
  • a touch pad e.g., a touch pad
  • a voice control device such as a tablet, a smart phone, or a personal digital assistant (Personal Digital Assistant). , PDA), smart wearable devices, camera equipment, monitoring equipment and other terminals.
  • PDA Personal Digital Assistant
  • the network in which the electronic device 3 is located includes, but is not limited to, the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), and the like.
  • the Internet includes, but is not limited to, the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), and the like.
  • VPN virtual private network
  • the receiving device 34 and the transmitting device 31 may be wired transmission ports, or may be wireless devices, for example, including antenna devices, for performing data communication with other devices.
  • the memory 32 is used to store program code.
  • the memory 32 may be a circuit having a storage function, such as a RAM (Random-Access Memory), a FIFO (First In First Out), or the like, which has no physical form in the integrated circuit.
  • the memory 32 may also be a memory having a physical form, such as a memory stick, a TF card (Trans-flash Card), a smart media card, a secure digital card, a flash memory card.
  • Storage devices such as (flash card) and the like.
  • the processor 33 can include one or more microprocessors, digital processors.
  • the processor 33 can call program code stored in the memory 32 to perform related functions.
  • the various units described in FIGS. 5 and/or FIG. 6 are program code stored in the memory 32 and executed by the processor 33 to implement a sample weight distribution method, and/or model training. method.
  • the processor 33 also known as a central processing unit (CPU), is a very large-scale integrated circuit, which is a computing core (Core) and a control unit (Control Unit).
  • the embodiment of the present invention further provides a computer readable storage medium having stored thereon computer instructions, when executed by an electronic device including one or more processors, causing the electronic device to perform the method embodiment as described above Sample weight distribution method.
  • the memory 32 in the electronic device 3 stores a plurality of instructions to implement a sample weight allocation method, and the processor 33 can execute the plurality of instructions to implement:
  • Obtaining a training sample comprising a positive sample set and a negative sample set, the positive sample set comprising a positive sample pair and the negative sample set comprising a negative sample pair; calculating a distance of each positive sample pair in the positive sample set And a distance of each negative sample pair in the negative sample set; determining a distance distribution of the positive sample set according to a distance of each positive sample pair in the positive sample set, the distance distribution of the positive sample set representing a positive sample The relationship between the appearance frequency and the distance; determining the distance distribution of the negative sample set according to the distance of each negative sample pair in the negative sample set, the distance distribution of the negative sample set indicating the relationship between the appearance frequency and the distance of the negative sample pair And determining a weight distribution of the training sample based on a distance distribution of the positive sample set and a distance distribution of the negative sample set.
  • the plurality of instructions corresponding to the sample weight assignment method are stored in the memory 32 in any of the embodiments and are executed by the processor 33 and will not be described in detail herein.
  • the memory 32 in the electronic device 3 stores a plurality of instructions to implement a sample weight allocation method, and the processor 33 can execute the plurality of instructions to: acquire a training sample;
  • the training sample, the model parameter is trained using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training sample, and the weight distribution of the training sample is trained using the model described in any embodiment The method is obtained.
  • a plurality of instructions corresponding to the model training method are stored in the memory 32 in any of the embodiments and executed by the processor 33 and will not be described in detail herein.
  • the integrated circuit of the present invention is installed in the electronic device, so that the electronic device functions to acquire a training sample, the training sample includes a positive sample set and a negative sample set, and the positive sample set includes a positive sample pair And the negative sample set includes a negative sample pair; calculating a distance of each positive sample pair in the positive sample set, and a distance of each negative sample pair in the negative sample set; according to each positive sample pair in the positive sample set a distance, a distance distribution of the positive sample set, the distance distribution of the positive sample set representing a relationship between a frequency of occurrence of a positive sample pair and a distance; determining the negative according to a distance of each negative sample pair in the negative sample set a distance distribution of the sample set, the distance distribution of the negative sample set representing a relationship between the appearance frequency of the negative sample pair and the distance; determining the training sample based on the
  • the functions that can be implemented by the sample weight distribution method in any of the embodiments can be installed in the electronic device by the integrated circuit of the present invention, so that the electronic device can perform the sample weight distribution method in any embodiment.
  • the functions implemented are not detailed here.
  • the above-described characteristic means of the present invention can be implemented by an integrated circuit and control the function of implementing the model training method in any of the above embodiments. That is, the integrated circuit of the present invention is installed in the electronic device, so that the electronic device performs the following functions: acquiring training samples; and training model parameters based on the training samples using a loss function and a preset training algorithm, wherein the loss A function is associated with a weight distribution of the training samples, the weight distribution of the training samples being obtained using a model training method as described in any of the embodiments.
  • the functions that can be implemented by the model training method in any of the embodiments can be installed in the electronic device by the integrated circuit of the present invention, so that the electronic device can be implemented by the model training method in any embodiment. Function, no longer detailed here.
  • the disclosed apparatus may be implemented in other ways.
  • the device embodiments described above are merely illustrative.
  • the division of the unit is only a logical function division.
  • there may be another division manner for example, multiple units or components may be combined or may be Integrate into another system, or some features can be ignored or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be electrical or otherwise.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
  • each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
  • the integrated unit if implemented in the form of a software functional unit and sold or used as a standalone product, may be stored in a computer readable storage medium.
  • the technical solution of the present invention which is essential or contributes to the prior art, or all or part of the technical solution, may be embodied in the form of a software product stored in a storage medium.
  • a number of instructions are included to cause a computer device (which may be a personal computer, server or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention.
  • the foregoing storage medium includes: a U disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk, and the like. .

Abstract

A sample weight allocation method, a model training method, an electronic device, and a storage medium. The sample weight allocation method comprises: calculating the distance of each positive sample pair in a positive sample set and the distance of each negative sample pair in a negative sample set (S11); determining distance distribution of the positive sample set according to the distance of each positive sample pair in the positive sample set, the distance distribution of the positive sample set representing a relation between the frequency of occurrence of positive sample pairs and distances (S12); determining distance distribution of the negative sample set according to the distance of each negative sample pair in the negative sample set, the distance distribution of the negative sample set representing a relation between the frequency of occurrence of negative sample pairs and distances (S13); and determining weight distribution of training samples on the basis of the distance distribution of the positive sample set and the distance distribution of the negative sample set (S14). The sample weight allocation method can increase the weight of misclassified sample pairs, and increase, in a model training process, the contribution of the misclassified samples to target loss, so that model parameters can be well corrected, and the expression ability of the model parameters is improved.

Description

样本权重分配方法、模型训练方法、电子设备及存储介质Sample weight distribution method, model training method, electronic device and storage medium
本申请要求于2017年12月29日提交中国专利局,申请号为201711480906.8、发明名称为“样本权重分配方法、模型训练方法、电子设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application filed on December 29, 2017, the Chinese Patent Office, the application number is 201711480906.8, and the invention name is "sample weight distribution method, model training method, electronic equipment and storage medium". This is incorporated herein by reference.
技术领域Technical field
本发明涉及人工智能领域,尤其涉及一种样本权重分配方法、模型训练方法、电子设备及存储介质。The present invention relates to the field of artificial intelligence, and in particular, to a sample weight distribution method, a model training method, an electronic device, and a storage medium.
背景技术Background technique
在机器学习领域,在模型(例如特征提取模型、人脸特征表达模型等)的训练中损失函数分为两类,第一类是基于分类的度量,由于不是直接对特征进行度量,性能有限;另外一类是直接面向特征度量的端到端的方法,此类方法由于需要挑选到难易程度合适的样本网络才能较好收敛。现有的方法主要通过以下两种方式获取难易程度合适的样本:第一、在模型训练到一定阶段后,根据模型的特征表达,选择一些难度适中的样本,这样的方式操作起来麻烦,并且随着模型的训练,所选择的样本的难以程度发生变化,原有的离线选择的样本不在具有代表性,无法充分表达后续添加的样本的特征。第二、在模型训练的过程中,根据每次训练的模型选择难度适中的样本,虽然这种方法选择的训练样本具有代表性,能有有效的提高模型的表达能力,但是需要的计算资源过大,在实际模型训练中难以实现。In the field of machine learning, loss functions are classified into two categories in the training of models (such as feature extraction models, face feature expression models, etc.). The first category is classification-based metrics. Since the features are not directly measured, the performance is limited. The other is an end-to-end approach to feature metrics directly. Such methods are better able to converge because they need to select a suitable sample network. The existing methods mainly obtain samples with appropriate difficulty levels by the following two methods: First, after the model is trained to a certain stage, according to the characteristic expression of the model, selecting some samples with moderate difficulty, such a method is troublesome to operate, and With the training of the model, the difficulty level of the selected samples changes, and the original offline selected samples are not representative and cannot fully express the characteristics of the subsequently added samples. Second, in the process of model training, select the moderately difficult samples according to the model of each training. Although the training samples selected by this method are representative, they can effectively improve the expression ability of the model, but the required computing resources are Large, difficult to achieve in actual model training.
发明内容Summary of the invention
鉴于以上内容,有必要提供一种样本权重分配方法、模型训练方法、电子设备及存储介质,能增加分类错误的样本对的权重,在模型训练过程中,增大所述分类错误的样本对目标损失的贡献,从而能更好地修正模型参数,提高模 型参数的表达能力。In view of the above, it is necessary to provide a sample weight distribution method, a model training method, an electronic device and a storage medium, which can increase the weight of the sample pairs of the classification error, and increase the sample of the classification error to the target during the model training process. The contribution of loss, so that the model parameters can be better corrected and the expression ability of the model parameters can be improved.
一种样本权重分配方法,所述方法包括:A sample weight distribution method, the method comprising:
获取训练样本,所述训练样本包括正样本集及负样本集,所述正样本集包括正样本对及所述负样本集包括负样本对;Obtaining a training sample, the training sample comprising a positive sample set and a negative sample set, the positive sample set comprising a positive sample pair and the negative sample set comprising a negative sample pair;
计算所述正样本集中每个正样本对的距离,及所述负样本集中每个负样本对的距离;Calculating a distance of each positive sample pair in the positive sample set, and a distance of each negative sample pair in the negative sample set;
根据所述正样本集中每个正样本对的距离,确定所述正样本集的距离分布,所述正样本集的距离分布表示正样本对出现频率与距离的关系;Determining a distance distribution of the positive sample set according to a distance of each positive sample pair in the positive sample set, the distance distribution of the positive sample set indicating a relationship between a frequency of occurrence of a positive sample pair and a distance;
根据所述负样本集中每个负样本对的距离,确定所述负样本集的距离分布,所述负样本集的距离分布表示负样本对出现频率与距离的关系;Determining a distance distribution of the negative sample set according to a distance of each negative sample pair in the negative sample set, the distance distribution of the negative sample set indicating a relationship between a frequency of occurrence of a negative sample pair and a distance;
基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布。And determining a weight distribution of the training sample based on a distance distribution of the positive sample set and a distance distribution of the negative sample set.
根据本发明优选实施例,所述基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布包括:According to a preferred embodiment of the present invention, determining the weight distribution of the training sample based on the distance distribution of the positive sample set and the distance distribution of the negative sample set includes:
基于所述正样本集的距离分布及所述负样本集的距离分布,确定分类错误的第一样本集;Determining a first sample set of the classification error based on the distance distribution of the positive sample set and the distance distribution of the negative sample set;
在所述训练样本的权重分布中,增加所述第一样本集中每个样本对的权重;及/或In the weight distribution of the training samples, increasing the weight of each sample pair in the first sample set; and/or
基于所述正样本集的距离分布及所述负样本集的距离分布,确定分类正确的第二样本集;Determining a correctly classified second sample set based on the distance distribution of the positive sample set and the distance distribution of the negative sample set;
在所述训练样本的权重分布中,减少所述第二样本集中每个样本对的权重。In the weight distribution of the training samples, the weight of each sample pair in the second sample set is reduced.
根据本发明优选实施例,所述训练样本的权重分布为正态分布,当所述正样本集中正样本对的最大距离小于或等于所述负样本集中负样本对的最小距离时,在确定所述训练样本的权重分布时,所述方法还包括:According to a preferred embodiment of the present invention, the weight distribution of the training samples is a normal distribution, and when the maximum distance of the positive sample pairs in the positive sample set is less than or equal to the minimum distance of the negative sample pairs in the negative sample set, When the weight distribution of the training samples is described, the method further includes:
将所述最大距离与所述最小距离的均值确定为所述训练样本的权重分布的均值。The mean of the maximum distance and the minimum distance is determined as the mean of the weight distribution of the training samples.
根据本发明优选实施例,所述训练样本的权重分布为正态分布,当所述正样本集中正样本对的最大距离大于所述负样本集中负样本对的最小距离时,在确定所述训练样本的权重分布时,所述方法还包括:According to a preferred embodiment of the present invention, the weight distribution of the training samples is a normal distribution, and the training is determined when the maximum distance of the positive sample pairs in the positive sample set is greater than the minimum distance of the negative sample pairs in the negative sample set. When the weights of the samples are distributed, the method further includes:
将所述正样本集的距离分布与所述负样本集的距离分布的交叉点对应的距离值作为所述训练样本的权重分布的均值;或And using a distance value corresponding to the intersection of the distance distribution of the positive sample set and the distance distribution of the negative sample set as the mean value of the weight distribution of the training sample; or
将在正样本对出现的频率与负样本对出现的频率的之差的绝对值最小处对应的距离作为所述训练样本的权重分布的均值。The distance corresponding to the absolute value of the difference between the frequency at which the positive sample pair appears and the frequency at which the negative sample pair appears is taken as the mean of the weight distribution of the training sample.
根据本发明优选实施例,在确定所述训练样本的权重分布的均值时,所述方法还包括:According to a preferred embodiment of the present invention, when determining the mean value of the weight distribution of the training samples, the method further includes:
配置预设步长、初始均值及迭代终止条件;Configure preset step size, initial mean value, and iteration termination condition;
基于所述初始均值及所述预设步长,在所述最小距离与最大距离组成的区间内进行迭代搜索满足所述迭代终止条件的最优距离值,在所述最优距离值处,正样本对出现的频率与负样本对出现的频率的之差的绝对值最小。And performing, according to the initial mean value and the preset step size, an iterative search for an optimal distance value satisfying the iterative termination condition in an interval composed of the minimum distance and the maximum distance, where the optimal distance value is positive The absolute value of the difference between the frequency of occurrence of the sample pair and the frequency of occurrence of the negative sample pair is minimal.
根据本发明优选实施例,所述训练样本的权重分布为正态分布,在确定所述训练样本的权重分布时,所述方法还包括:According to a preferred embodiment of the present invention, the weight distribution of the training samples is a normal distribution, and when determining the weight distribution of the training samples, the method further includes:
在每次训练过程中,获取所述正样本集中正样本对之间距离的标准差;Obtaining a standard deviation of the distance between pairs of positive samples in the positive sample set during each training session;
根据所述正样本集中正样本对之间距离的标准差,更新每次训练过程中的所述训练样本的权重分布的标准差。The standard deviation of the weight distribution of the training samples in each training process is updated according to the standard deviation of the distance between the positive sample pairs in the positive sample set.
一种模型训练方法,所述方法包括:A model training method, the method comprising:
获取训练样本;Obtain training samples;
基于所述训练样本,利用损失函数及预设训练算法训练模型参数,其中所述损失函数与所述训练样本的权重分布相关联,所述训练样本的权重分布利用任意实施例中所述的样本权重分配方法得到。Model parameters are trained based on the training samples using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training samples, and the weight distribution of the training samples utilizes samples as described in any embodiment The weight distribution method is obtained.
根据本发明优选实施例,所述方法还包括:According to a preferred embodiment of the present invention, the method further includes:
利用所述损失函数,增加分类错误的样本对目标损失的贡献率。The loss function is used to increase the contribution rate of the sample with the wrong classification to the target loss.
一种电子设备,其特征在于,所述电子设备包括存储器及处理器,所述存储器用于存储至少一个指令,所述处理器用于执行所述至少一个指令以实现如任意实施例中所述的样本权重分配方法,及/或任意实施例中所述的模型训练方法。An electronic device, comprising: a memory and a processor, the memory for storing at least one instruction, the processor for executing the at least one instruction to implement as described in any embodiment A sample weight assignment method, and/or a model training method as described in any embodiment.
一种计算机可读存储介质,所述计算机可读存储介质存储有至少一个指令,所述至少一个指令被处理器执行时实现如任意实施例中所述的样本权重分配方法,及/或任意实施例中所述的模型训练方法。A computer readable storage medium storing at least one instruction, the at least one instruction being executed by a processor to implement a sample weight assignment method as described in any embodiment, and/or any implementation The model training method described in the example.
由以上技术方案可以看出,本发明提供一种样本权重分配方法,所述方法包括:获取训练样本,所述训练样本包括正样本集及负样本集;计算所述正样本集中每个正样本对的距离,及所述负样本集中每个负样本对的距离;根据所述正样本集中每个正样本对的距离,确定所述正样本集的距离分布;根据所述负样本集中每个负样本对的距离,确定所述负样本集的距离分布;基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布。本发明还提供一种模型训练方法、电子设备及存储介质。本发明能增加分类错误的样本对的权重,在模型训练过程中,增大所述分类错误的样本对目标损失的贡献,从而能更好地修正模型参数,提高模型参数的表达能力。As can be seen from the above technical solution, the present invention provides a sample weight allocation method, the method comprising: acquiring a training sample, the training sample comprising a positive sample set and a negative sample set; and calculating each positive sample in the positive sample set a distance of the pair, and a distance of each negative sample pair in the negative sample set; determining a distance distribution of the positive sample set according to a distance of each positive sample pair in the positive sample set; a distance of the negative sample pair, determining a distance distribution of the negative sample set; determining a weight distribution of the training sample based on the distance distribution of the positive sample set and the distance distribution of the negative sample set. The invention also provides a model training method, an electronic device and a storage medium. The invention can increase the weight of the sample pairs with the wrong classification. In the model training process, the contribution of the sample with the wrong classification to the target loss is increased, so that the model parameters can be better corrected and the expression ability of the model parameters can be improved.
附图说明DRAWINGS
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据提供的附图获得其他的附图。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the embodiments or the description of the prior art will be briefly described below. Obviously, the drawings in the following description are only It is an embodiment of the present invention, and those skilled in the art can obtain other drawings according to the provided drawings without any creative work.
图1是本发明样本权重分配方法的较佳实施例的流程图。1 is a flow chart of a preferred embodiment of a sample weighting method of the present invention.
图2是本发明的一个举例中样本的距离分布与权重分布的示意图。2 is a schematic diagram of a distance distribution and a weight distribution of a sample in an example of the present invention.
图3是本发明的一个举例中样本的距离分布的另一个示意图。Figure 3 is another schematic illustration of the distance distribution of a sample in an example of the present invention.
图4是本发明模型训练方法的较佳实施例的流程图。4 is a flow chart of a preferred embodiment of the model training method of the present invention.
图5是本发明样本权重分配装置的较佳实施例的功能模块图。Figure 5 is a functional block diagram of a preferred embodiment of the sample weight distribution device of the present invention.
图6是本发明模型训练装置的较佳实施例的功能模块图。Figure 6 is a functional block diagram of a preferred embodiment of the model training device of the present invention.
图7是本发明至少一个实例中电子设备的较佳实施例的结构示意图。Figure 7 is a block diagram showing a preferred embodiment of an electronic device in at least one example of the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention are clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present invention. It is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts are within the scope of the present invention.
如图1所示,是本发明样本权重分配方法的较佳实施例的流程图。根据不 同的需求,该流程图中步骤的顺序可以改变,某些步骤可以省略。As shown in FIG. 1, it is a flow chart of a preferred embodiment of the sample weight distribution method of the present invention. The order of the steps in the flow chart can be changed according to different requirements, and some steps can be omitted.
S10,电子设备获取训练样本,所述训练样本包括正样本集及负样本集,所述正样本集包括正样本对及所述负样本集包括负样本对。S10. The electronic device acquires a training sample, where the training sample includes a positive sample set and a negative sample set, the positive sample set includes a positive sample pair and the negative sample set includes a negative sample pair.
在本发明的优选实施例中,所述电子设备会配置训练样本集,在模型参数的训练过程中,先从配置的训练样本集中取出一部分样本进行训练,所述一部分样本作为所述训练样本。例如,在所述训练样本对应每个mini-batch中的样本。In a preferred embodiment of the present invention, the electronic device configures a training sample set. In the training process of the model parameters, a part of the samples are first taken out from the configured training sample set for training, and the part of the samples is used as the training sample. For example, the training samples correspond to samples in each mini-batch.
在本发明的优选实施例中,所述正样本集包括一个或者多个正样本对,其中一个所述正样本对表示属于一个同一类别的样本对。所述负样本集包括一个或者多个负样本对。In a preferred embodiment of the invention, the positive sample set comprises one or more positive sample pairs, wherein one of the positive sample pairs represents a sample pair belonging to a same category. The negative sample set includes one or more negative sample pairs.
例如,利用所述训练样本训练人脸特征表达模型,人脸特征表达模型用于后续输入的人脸的特征提取,因此,一个正样本对表示一个人脸的样本对,如一个正样本对包括一个人脸的两张图片。For example, the face feature expression model is trained by using the training sample, and the face feature expression model is used for feature extraction of a face that is subsequently input. Therefore, a positive sample pair includes a sample pair of a face, such as a positive sample pair. Two pictures of a human face.
S11,所述电子设备计算所述正样本集中每个正样本对的距离,及所述负样本集中每个负样本对的距离。S11. The electronic device calculates a distance of each positive sample pair in the positive sample set and a distance of each negative sample pair in the negative sample set.
在本发明的优选实施例中,所述电子设备计算每个正样本对的欧式距离,将每个正样本对的欧式距离作为所述每个正样本对的距离。所述电子设备计算每个负样本对的欧式距离,将每个负样本对的欧式距离作为所述每个负样本对的距离。每个正样本对的距离及每个负样本对的距离的表达形式,并不限于欧式距离,也可以是其他的距离形式,本发明不做任何限制。In a preferred embodiment of the invention, the electronic device calculates the Euclidean distance for each positive sample pair, using the Euclidean distance for each positive sample pair as the distance for each positive sample pair. The electronic device calculates an Euclidean distance for each negative sample pair, and uses the Euclidean distance of each negative sample pair as the distance of each of the negative sample pairs. The expression of the distance of each positive sample pair and the distance of each negative sample pair is not limited to the Euclidean distance, and may be other distance forms, and the present invention does not impose any limitation.
S12,所述电子设备根据所述正样本集中每个正样本对的距离,确定所述正样本集的距离分布,所述正样本集的距离分布表示正样本对出现频率与距离的关系。S12. The electronic device determines a distance distribution of the positive sample set according to a distance of each positive sample pair in the positive sample set, where the distance distribution of the positive sample set represents a relationship between a positive sample pair appearance frequency and a distance.
在本发明的优选实施例中,所述正样本集的距离分布包括多个距离点,每个距离点对应一个正样本对出现频率。例如,所述正样本集有100个正样本对,在距离至为0.2处,对应有30个正样本对。In a preferred embodiment of the invention, the distance distribution of the positive sample set comprises a plurality of distance points, each distance point corresponding to a positive sample pair appearance frequency. For example, the positive sample set has 100 positive sample pairs, at a distance of 0.2, corresponding to 30 positive sample pairs.
S13,所述电子设备根据所述负样本集中每个负样本对的距离,确定所述负样本集的距离分布,所述负样本集的距离分布表示负样本对出现频率与距离的关系。S13. The electronic device determines a distance distribution of the negative sample set according to a distance of each negative sample pair in the negative sample set, and the distance distribution of the negative sample set represents a relationship between a negative sample pair appearance frequency and a distance.
在本发明的优选实施例中,所述负样本集的距离分布包括多个距离点,每个距离点对应一个负样本对出现频率。例如,所述负样本集有100个负样本对,在距离至为0.5处,对应有20个负样本对。In a preferred embodiment of the invention, the distance distribution of the negative sample set comprises a plurality of distance points, each distance point corresponding to a negative sample pair appearance frequency. For example, the negative sample set has 100 negative sample pairs, at a distance of 0.5, corresponding to 20 negative sample pairs.
S14,所述电子设备基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布。S14. The electronic device determines a weight distribution of the training sample based on a distance distribution of the positive sample set and a distance distribution of the negative sample set.
在本发明中,当所述正样本集的距离分布与所述负样本集的距离分布的没有交叉重叠部分时,表示所述正样本集与所述负样本集中不存在分类错误的样本对。当所述正样本集的距离分布与所述负样本集的距离分布的交叉重叠部分,则表示所述正样本集与所述负样本集中存在分类错误的样本对。所述正样本集的距离分布与所述负样本集的距离分布的交叉重叠部分的距离对应的样本对表示分类错误的样本对。因此,在后续的训练过程中,需要增加分类错误的样本对的权重,从而可以增大所述分类错误的样本对对修正模型参数的贡献率、提高模型的表达能力的贡献率。In the present invention, when there is no overlapping portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, it indicates that there is no sample pair of the classification error in the positive sample set and the negative sample set. When the distance distribution of the positive sample set overlaps with the distance distribution of the negative sample set, it indicates that there is a sample pair of the classification error in the positive sample set and the negative sample set. A sample pair corresponding to the distance of the intersection of the positive sample set and the distance overlap of the distance distribution of the negative sample set represents a sample pair that is misclassified. Therefore, in the subsequent training process, it is necessary to increase the weight of the sample pair of the classification error, so that the contribution rate of the sample of the classification error to the modified model parameter and the contribution rate of the expression ability of the model can be increased.
举例而言,如图2所示,一个举例中正样本集的距离分布及所述负样本集的距离分布的示意图,所述正样本集中每个正样本对的距离用欧式距离表示,所述负样本集中每个负样本对的距离用欧式距离表示,当然也可以用其他距离表示,该举例并不能作为对距离计算方式的限制。在距离A与距离B之间的距离对应的样本对都是分类错误的样本对。若正样本对的总数量为1000个,负样本对的总数量为2000个,距离A对应的正样本对出现频率为0.02,在距离A点对应的正样本对数为20个,距离A点对应的负样本对出现频率为0.15,在距离A点对应的负样本对数为300个。若一个目标样本对的距离等于距离A,则所述目标样本对可能属于正样本对,也可能属于负样本对,因此所述目标样本对会出现分类错误的情况。For example, as shown in FIG. 2, a schematic diagram of a distance distribution of a positive sample set and a distance distribution of the negative sample set, wherein the distance of each positive sample pair in the positive sample set is represented by a Euclidean distance, the negative The distance of each negative sample pair in the sample set is represented by the Euclidean distance. Of course, it can also be represented by other distances. This example cannot be used as a limitation on the distance calculation method. The sample pairs corresponding to the distance between the distance A and the distance B are all sample pairs that are misclassified. If the total number of positive sample pairs is 1000, the total number of negative sample pairs is 2000, the positive sample pair corresponding to A is 0.02, and the positive sample corresponding to point A is 20, distance A. The corresponding negative sample pair has a frequency of 0.15, and the negative sample pair corresponding to point A has 300. If the distance of a target sample pair is equal to the distance A, the target sample pair may belong to a positive sample pair or a negative sample pair, and thus the target sample pair may be classified incorrectly.
优选地,所述基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布包括:Preferably, the determining, according to the distance distribution of the positive sample set and the distance distribution of the negative sample set, determining a weight distribution of the training sample includes:
基于所述正样本集的距离分布及所述负样本集的距离分布,确定分类错误的第一样本集;在所述训练样本的权重分布中,增加所述第一样本集中每个样本对的权重;及/或Determining a first sample set of the classification error based on the distance distribution of the positive sample set and the distance distribution of the negative sample set; and increasing each sample in the first sample set in the weight distribution of the training sample Weight of the pair; and/or
基于所述正样本集的距离分布及所述负样本集的距离分布,确定分类正确 的第二样本集;在所述训练样本的权重分布中,减少所述第二样本集中每个样本对的权重。Determining a second sample set that is correctly classified based on a distance distribution of the positive sample set and a distance distribution of the negative sample set; and reducing a sample pair of the second sample set in a weight distribution of the training sample Weights.
在上述实施例中,通过在所述训练样本的权重分布增加分类错误的样本对的权重,及/或减少分类正确的样本的权重,从而在后续的模型训练过程中,损失函数与所述训练样本的权重分布相关联,基于所述训练样本的权重分布建立所述损失函数,可以增大所述分类错误的样本对网络损失的贡献,从而能更好地修正模型参数、提高模型参数的表达能力。In the above embodiment, the loss function and the training are performed in the subsequent model training process by increasing the weight of the misclassified sample pair in the weight distribution of the training sample, and/or reducing the weight of the correctly classified sample. The weight distribution of the sample is associated, and the loss function is established based on the weight distribution of the training sample, which can increase the contribution of the sample with the wrong classification to the network loss, thereby better correcting the model parameters and improving the expression of the model parameters. ability.
优选地,所述训练样本的权重分布为正态分布。所述配置所述正态分布的参数以实现增加分类错误的样本对的权重,及/或减少分类正确的样本的权重。所述正态分布表示样本对的距离与权重的关系。所述正态分布的参数包括,但不限于:均值,标准差。Preferably, the weight distribution of the training samples is a normal distribution. The parameter of the normal distribution is configured to achieve a weighting of a pair of samples that increase the classification error, and/or to reduce the weight of the sample that is correctly classified. The normal distribution represents the relationship between the distance of the pair of samples and the weight. The parameters of the normal distribution include, but are not limited to, mean, standard deviation.
进一步地,当所述正样本集中正样本对的最大距离小于所述负样本集中负样本对的最小距离时,在确定所述训练样本的权重分布时,所述方法还包括:将所述最大距离与所述最小距离的均值确定为所述训练样本的权重分布的均值。当所述正样本集中正样本对的最大距离小于所述负样本集中负样本对的最小距离时,即表示所述正样本集与所述负样本集中不存在分类错误的样本对。Further, when the maximum distance of the positive sample pair in the positive sample set is smaller than the minimum distance of the negative sample pair in the negative sample set, when determining the weight distribution of the training sample, the method further includes: maximizing the maximum The mean of the distance from the minimum distance is determined as the mean of the weight distribution of the training samples. When the maximum distance of the positive sample pair in the positive sample set is smaller than the minimum distance of the negative sample pair in the negative sample set, it means that there is no sample pair of the classification error in the positive sample set and the negative sample set.
举例而言,如图3所示,所述正样本集中每个正样本对的距离用欧式距离表示,所述负样本集中每个负样本对的距离用欧式距离表示,当然也可以用其他距离表示,该举例并不能作为对距离计算方式的限制。所述正样本集中正样本对的最大距离C点对应的距离小于所述负样本集中负样本对的最小距离D点对应的距离。这样所述正样本集的距离分布与所述负样本集的距离分布的没有交叉重叠部分,则所述正样本集与所述负样本集中不存在分类错误的样本对。For example, as shown in FIG. 3, the distance of each positive sample pair in the positive sample set is represented by a Euclidean distance, and the distance of each negative sample pair in the negative sample set is represented by a Euclidean distance, and of course other distances may be used. It is indicated that this example cannot be used as a limitation on the way the distance is calculated. The distance corresponding to the maximum distance C point of the positive sample pair in the positive sample set is smaller than the distance corresponding to the minimum distance D point of the negative sample pair in the negative sample set. If there is no crossover portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, then there is no sample pair with the classification error in the positive sample set and the negative sample set.
进一步地,当所述正样本集中正样本对的最大距离等于所述负样本集中负样本对的最小距离时,在确定所述训练样本的权重分布时,所述方法还包括:将所述最大距离与所述最小距离的均值确定为所述训练样本的权重分布的均值。Further, when the maximum distance of the positive sample pair in the positive sample set is equal to the minimum distance of the negative sample pair in the negative sample set, when determining the weight distribution of the training sample, the method further includes: maximizing the maximum The mean of the distance from the minimum distance is determined as the mean of the weight distribution of the training samples.
进一步地,当所述正样本集中正样本对的最大距离大于所述负样本集中负样本对的最小距离时,在确定所述训练样本的权重分布时,所述方法还包括:Further, when the maximum distance of the positive sample pair in the positive sample set is greater than the minimum distance of the negative sample pair in the negative sample set, when determining the weight distribution of the training sample, the method further includes:
将所述正样本集的距离分布与所述负样本集的距离分布的交叉点对应的距 离值作为所述训练样本的权重分布的均值;或And using a distance value corresponding to the intersection of the distance distribution of the positive sample set and the distance distribution of the negative sample set as the mean value of the weight distribution of the training sample; or
将在正样本对出现的频率与负样本对出现的频率的之差的绝对值最小处对应的距离作为所述训练样本的权重分布的均值。当所述正样本集中正样本对的最大距离大于所述负样本集中负样本对的最小距离时,即表示所述正样本集与所述负样本集中存在分类错误的样本对。The distance corresponding to the absolute value of the difference between the frequency at which the positive sample pair appears and the frequency at which the negative sample pair appears is taken as the mean of the weight distribution of the training sample. When the maximum distance of the positive sample pair in the positive sample set is greater than the minimum distance of the negative sample pair in the negative sample set, it means that there is a sample pair of the classification error in the positive sample set and the negative sample set.
举例而言,如图2所示,所述正样本集中正样本对的最大距离B点对应的距离小于所述负样本集中负样本对的最小距离A点对应的距离。这样所述正样本集的距离分布与所述负样本集的距离分布的有交叉重叠部分,则所述正样本集与所述负样本集中不存在分类错误的样本对。将所述正样本集的距离分布与所述负样本集的距离分布的距交叉点E处对应的距离作为所述正态分布的均值。正样本对出现的频率与负样本对出现的频率的之差的绝对值最小即为所述交叉点E对应的频率值F。For example, as shown in FIG. 2, the distance corresponding to the maximum distance B point of the positive sample pair in the positive sample set is smaller than the distance corresponding to the minimum distance A point of the negative sample pair in the negative sample set. If there is a crossover portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, then there is no sample pair with the classification error in the positive sample set and the negative sample set. A distance corresponding to the distance distribution of the positive sample set and the distance distribution of the negative sample set from the intersection E is taken as the mean of the normal distribution. The absolute value of the difference between the frequency of the positive sample pair and the frequency of occurrence of the negative sample pair is the frequency value F corresponding to the intersection E.
通过上述实施例可知,在以所述训练样本的权重分布的均值为轴,越靠近所述训练样本的权重分布的均值的附近区域所包括的距离对应的样本对,越会分类错误,因此,在所述训练样本的权重分布(即所述正态分布)中,越靠近所述训练样本的权重分布的均值的距离对应的样本对的权重越大,从而实现增加分类错误的样本对的权重,及/或减少分类正确的样本的权重,从而在后续的模型训练过程中,损失函数与所述训练样本的权重分布相关联,基于所述训练样本的权重分布建立所述损失函数,可以增大所述分类错误的样本对网络损失的贡献,从而能更好地修正模型参数、提高模型参数的表达能力。According to the above embodiment, in the average of the weight distribution of the training samples, the sample pairs corresponding to the distances included in the vicinity of the mean value of the weight distribution of the training samples are classified incorrectly. In the weight distribution of the training samples (ie, the normal distribution), the weight of the sample pairs corresponding to the distance of the mean of the weight distribution of the training samples is larger, thereby increasing the weight of the sample pairs that increase the classification error. And/or reducing the weight of the sample with the correct classification, so that in the subsequent model training process, the loss function is associated with the weight distribution of the training sample, and the loss function is established based on the weight distribution of the training sample, which may be increased The contribution of the sample with the wrong classification to the network loss can better correct the model parameters and improve the expression ability of the model parameters.
结合上述图2中的两个图的举例可知,在距离A与距离E之间对应的样本对是分类错误的样本对,及在距离B与距离E之间对应的样本对也是是分类错误的样本对。因此,在正态分布中,所述在距离A与距离E之间对应的样本对及距离B与距离E之间对应的样本对的权重高于能正确分类的样本对的权重。According to the example of the two figures in FIG. 2 above, the sample pairs corresponding between the distance A and the distance E are sample pairs that are misclassified, and the sample pairs corresponding between the distance B and the distance E are also classified incorrectly. Sample pair. Therefore, in the normal distribution, the pair of samples corresponding between the distance A and the distance E and the pair of samples corresponding to the distance B and the distance E have a higher weight than the pair of samples that can be correctly classified.
进一步地,需要在所述最小距离与所述最大距离之间,搜索使正样本对出现的频率与负样本对出现的频率的之差的绝对值最小的最优距离值。优选地,在确定所述训练样本的权重分布的均值时,所述方法还包括:Further, between the minimum distance and the maximum distance, an optimal distance value that minimizes the absolute value of the difference between the frequency of occurrence of the positive sample pair and the frequency of occurrence of the negative sample pair is required. Preferably, when determining the mean value of the weight distribution of the training samples, the method further includes:
配置预设步长、初始均值及迭代终止条件;Configure preset step size, initial mean value, and iteration termination condition;
基于所述初始均值及所述预设步长,在所述最小距离与最大距离组成的区 间内进行迭代搜索满足所述迭代终止条件的最优距离值,在所述最优距离值处,正样本对出现的频率与负样本对出现的频率的之差的绝对值最小。And performing, according to the initial mean value and the preset step size, an iterative search for an optimal distance value satisfying the iterative termination condition in an interval composed of the minimum distance and the maximum distance, where the optimal distance value is positive The absolute value of the difference between the frequency of occurrence of the sample pair and the frequency of occurrence of the negative sample pair is minimal.
进一步地,所述预设步长等于(所述最大距离-最小距离)/n,所述n为正数。当然所述预设步长也可以是其他形式的步长,本发明不做任何限制。Further, the preset step size is equal to (the maximum distance - minimum distance) / n, and the n is a positive number. Of course, the preset step size may also be other forms of step size, and the present invention does not impose any limitation.
进一步地,所述迭代终止条件包括,但不限于:预设误差。Further, the iterative termination condition includes, but is not limited to, a preset error.
具体地,以所述初始均值为初始迭代,基于所述预设步长step进行迭代搜索,在当前迭代中,计算当前均值μ表示的距离处,正样本对出现的频率与负样本对出现的频率的之差的绝对值是否小于预设误差,若小于预设误差,将所述当前均值加上预设步长赋值为所述当前均值μ,即(μ+step)赋值为μ,继续判断正样本对出现的频率与负样本对出现的频率的之差的绝对值是否小于预设误差,直至出现正样本对出现的频率与负样本对出现的频率的之差的绝对值大于预设误差,则停止搜索所述均值,输出最后一次迭代对应的最优距离值作为所述训练样本的权重分布的均值。Specifically, the initial iteration is the initial iteration, and the iterative search is performed based on the preset step step. In the current iteration, the distance represented by the current mean μ is calculated, and the frequency of the positive sample pair and the negative sample pair appear. Whether the absolute value of the difference between the frequencies is less than the preset error. If the preset value is less than the preset error, the current average value plus the preset step size is assigned to the current mean value μ, that is, (μ+step) is assigned to μ, and the determination continues. Whether the absolute value of the difference between the frequency of the positive sample pair and the frequency of the negative sample pair is less than the preset error until the absolute value of the difference between the frequency of the occurrence of the positive sample pair and the frequency of the negative sample pair is greater than the preset error Then, the search for the mean value is stopped, and the optimal distance value corresponding to the last iteration is output as the mean value of the weight distribution of the training sample.
在本发明中,随着模型的训练,模型表达能力不断增强,因此也应当逐渐增加分类错误的样本对(即第一样本集)的权重,即需要减小所述正态分布(即所述训练样本的权重分布)的标准差。对于所述正态分布而言,标准差越小,正态峰越陡峭,即越靠近所述均值表示的距离处的样本对的权重越高,从而可以实现逐渐增加分类错误的样本对(即第一样本集)的权重。In the present invention, as the model is trained, the model expression ability is continuously enhanced, so the weight of the sample pair (ie, the first sample set) of the classification error should also be gradually increased, that is, the normal distribution needs to be reduced (ie, The standard deviation of the weight distribution of the training samples. For the normal distribution, the smaller the standard deviation, the steeper the normal peak, that is, the closer the weight of the sample pair at the distance indicated by the mean value, so that a sample pair that gradually increases the classification error can be realized (ie, The weight of the first sample set).
由于正样本集中的样本对距离的标准差随着模型训练会逐渐较小,因此,可以根据正样本集中的样本对距离的标准差配置所述正态分布的标准差。优选地,所述方法还包括:根据所述正样本集中正样本对之间距离的标准差,更新每次训练过程中的所述训练样本的权重分布的标准差。这样所述训练样本的权重分布中的标准差在模型训练的过程中随着模型训练次数的增多而逐渐较少,从而使得难以区分的样本的权重逐渐变大,提高模型的表达能力和收敛速度。Since the standard deviation of the sample-to-distance in the positive sample set is gradually smaller as the model training, the standard deviation of the normal distribution can be configured according to the standard deviation of the distance from the sample in the positive sample set. Preferably, the method further comprises: updating a standard deviation of weight distributions of the training samples in each training process according to a standard deviation of distances between pairs of positive samples in the positive sample set. In this way, the standard deviation in the weight distribution of the training samples gradually decreases with the increase of the number of training times in the model training process, so that the weight of the indistinguishable samples gradually increases, and the expression ability and convergence speed of the model are improved. .
由以上技术方案可知,本发明获取训练样本,所述训练样本包括正样本集及负样本集,所述正样本集包括正样本对及所述负样本集包括负样本对;计算所述正样本集中每个正样本对的距离,及所述负样本集中每个负样本对的距离;根据所述正样本集中每个正样本对的距离,确定所述正样本集的距离分布,所述正样本集的距离分布表示正样本对出现频率与距离的关系;根据所述负样本 集中每个负样本对的距离,确定所述负样本集的距离分布,所述负样本集的距离分布表示负样本对出现频率与距离的关系;基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布。本发明能增加分类错误的样本对的权重,在后续的训练过程中,从而可以增大所述分类错误的样本对对修正模型参数、提高模型的表达能力的贡献率,提高模型参数的准确度。According to the above technical solution, the present invention acquires a training sample, where the training sample includes a positive sample set and a negative sample set, the positive sample set includes a positive sample pair and the negative sample set includes a negative sample pair; and the positive sample is calculated Concentrating the distance of each positive sample pair and the distance of each negative sample pair in the negative sample set; determining a distance distribution of the positive sample set according to the distance of each positive sample pair in the positive sample set, the positive The distance distribution of the sample set represents a relationship between the occurrence frequency of the positive sample and the distance; determining the distance distribution of the negative sample set according to the distance of each negative sample pair in the negative sample set, the distance distribution of the negative sample set is negative The relationship between the appearance frequency and the distance of the sample; the weight distribution of the training sample is determined based on the distance distribution of the positive sample set and the distance distribution of the negative sample set. The invention can increase the weight of the sample pairs with the wrong classification, and in the subsequent training process, the contribution rate of the sampled errors to the modified model parameters, the improvement of the expression ability of the model can be increased, and the accuracy of the model parameters can be improved. .
如图4所示,是本发明模型训练方法的较佳实施例的流程图。根据不同的需求,该流程图中步骤的顺序可以改变,某些步骤可以省略。4 is a flow chart of a preferred embodiment of the model training method of the present invention. The order of the steps in the flowchart may be changed according to different requirements, and some steps may be omitted.
S40,电子设备获取训练样本。S40. The electronic device acquires a training sample.
S41,所述电子设备基于所述训练样本,利用损失函数及预设训练算法训练模型参数,其中所述损失函数与所述训练样本的权重分布相关联。S41. The electronic device trains a model parameter by using a loss function and a preset training algorithm based on the training sample, wherein the loss function is associated with a weight distribution of the training sample.
优选地,所述训练样本的权重分布利用上述任意实施例中所述的样本权重分配方法得到。此处不再详述。Preferably, the weight distribution of the training samples is obtained by using the sample weight allocation method described in any of the above embodiments. It will not be detailed here.
优选地,所述预设训练算法包括,但不限于:卷积神经网络算法。Preferably, the preset training algorithm includes, but is not limited to: a convolutional neural network algorithm.
在本发明中,所述损失函数通过所述训练样本的权重分布增加分类错误的样本对对目标损失的贡献率。优选地,所述方法还包括:利用所述损失函数,增加分类错误的样本对对目标损失的贡献率,从而提高所述分类错误的样本对对修正模型参数的贡献率、提高模型的表达能力的贡献率,使得模型在训练过程中能够更加专注于分类错误的样本,增加了模型的表达能力和收敛速度。In the present invention, the loss function increases the contribution rate of the sampled error pair to the target loss by the weight distribution of the training sample. Preferably, the method further comprises: using the loss function, increasing a contribution rate of the sample error of the classification error to the target loss, thereby improving the contribution rate of the sample error pair to the modified model parameter, and improving the expression ability of the model. The contribution rate makes the model more focused on the classification of wrong samples during the training process, which increases the expression ability and convergence speed of the model.
由以上技术方案可知,本发明获取训练样本,基于所述训练样本,利用损失函数及预设训练算法训练模型参数,其中所述损失函数与所述训练样本的权重分布相关联。所述训练样本的权重分布利用上述任意实施例中所述的样本权重分配方法得到。本发明中,所述训练样本的权重分布在模型训练的过程中,分类错误的样本对的权重逐渐变大,因此,在训练模型参数时,利用所述损失函数可以提高所述分类错误的样本对对修正模型参数的贡献率、提高模型的表达能力的贡献率,使得模型在训练过程中能够更加专注于分类错误的样本,增加了模型的表达能力和收敛速度,提高了模型参数的准确度。As can be seen from the above technical solution, the present invention acquires a training sample, and based on the training sample, trains a model parameter using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training sample. The weight distribution of the training samples is obtained using the sample weight allocation method described in any of the above embodiments. In the present invention, the weight distribution of the training samples is in the process of model training, and the weights of the sample pairs that are misclassified gradually become larger. Therefore, when the model parameters are trained, the loss function can be used to improve the sample of the classification errors. The contribution rate to the modified model parameters and the ability to improve the expression of the model enable the model to focus more on the misclassified samples during the training process, increasing the expression ability and convergence speed of the model, and improving the accuracy of the model parameters. .
针对上述模型训练的应用场景举例,以下举例只是一个示例,不能作为模 型的限制。For the example of the application scenario of the above model training, the following examples are only an example and cannot be used as a model limitation.
利用图4中描述的模型训练方法来训练人脸特征表达模型,其中正样本集中每个正样本对表示同一个人的人脸样本对。利用训练好的人脸特征表达模型提取待检测图片的特征,从而能提高人脸识别的准确率。The face feature expression model is trained using the model training method described in FIG. 4, wherein each positive sample pair in the positive sample set represents a face sample pair representing the same person. The trained face feature expression model is used to extract the features of the image to be detected, so that the accuracy of face recognition can be improved.
具体地,获取待检测图片,利用所述训练好的人脸特征表达模型提取所述待检测图片的特征,基于所述待检测图片的特征,对所述待检测图片进行人脸识别。Specifically, the to-be-detected picture is obtained, and the feature of the to-be-detected picture is extracted by using the trained face feature expression model, and the face to be detected is subjected to face recognition based on the feature of the picture to be detected.
通过本发明训练的人脸特征表达模型,能通过增加分类错误的样本对的权重值,同时减少已经能正确分类的样本对的权重,从而增加了人脸特征表达模型的表达能力和收敛速度,从而提高人脸识别的准确率。The face feature expression model trained by the present invention can increase the weight of the sample pairs that are misclassified, and reduce the weight of the sample pairs that have been correctly classified, thereby increasing the expression ability and convergence speed of the face feature expression model. Thereby improving the accuracy of face recognition.
如图5所示,本发明样本权重分配装置的较佳实施例的功能模块图。所述样本权重分配装置11包括获取模块100、计算模块101及确定模块102。本发明所称的单元是指一种能够被样本权重分配装置11的处理器所执行并且能够完成固定功能的一系列计算机程序段,其存储在存储器中。在本实施例中,关于各单元的功能将在后续的实施例中详述。As shown in Fig. 5, a functional block diagram of a preferred embodiment of the sample weight distribution device of the present invention. The sample weight distribution device 11 includes an acquisition module 100, a calculation module 101, and a determination module 102. The unit referred to in the present invention refers to a series of computer program segments that can be executed by the processor of the sample weight distribution device 11 and that can perform a fixed function, which is stored in the memory. In the present embodiment, the functions of the respective units will be described in detail in the subsequent embodiments.
所述获取模块100获取训练样本,所述训练样本包括正样本集及负样本集,所述正样本集包括正样本对及所述负样本集包括负样本对。The obtaining module 100 acquires a training sample, where the training sample includes a positive sample set and a negative sample set, the positive sample set includes a positive sample pair and the negative sample set includes a negative sample pair.
在本发明的优选实施例中,所述电子设备会配置训练样本集,在模型参数的训练过程中,先从配置的训练样本集中取出一部分样本进行训练,所述一部分样本作为所述训练样本。例如,在所述训练样本对应每个mini-batch中的样本。In a preferred embodiment of the present invention, the electronic device configures a training sample set. In the training process of the model parameters, a part of the samples are first taken out from the configured training sample set for training, and the part of the samples is used as the training sample. For example, the training samples correspond to samples in each mini-batch.
在本发明的优选实施例中,所述正样本集包括一个或者多个正样本对,其中一个所述正样本对表示属于一个同一类别的样本对。所述负样本集包括一个或者多个负样本对。In a preferred embodiment of the invention, the positive sample set comprises one or more positive sample pairs, wherein one of the positive sample pairs represents a sample pair belonging to a same category. The negative sample set includes one or more negative sample pairs.
例如,利用所述训练样本训练人脸特征表达模型,人脸特征表达模型用于后续输入的人脸的特征提取,因此,一个正样本对表示一个人脸的样本对,如一个正样本对包括一个人脸的两张图片。For example, the face feature expression model is trained by using the training sample, and the face feature expression model is used for feature extraction of a face that is subsequently input. Therefore, a positive sample pair includes a sample pair of a face, such as a positive sample pair. Two pictures of a human face.
所述计算模型101计算所述正样本集中每个正样本对的距离,及所述负样 本集中每个负样本对的距离。The calculation model 101 calculates the distance of each positive sample pair in the positive sample set and the distance of each negative sample pair in the negative sample set.
在本发明的优选实施例中,所述计算模型101计算每个正样本对的欧式距离,将每个正样本对的欧式距离作为所述每个正样本对的距离。所述计算模型101计算每个负样本对的欧式距离,将每个负样本对的欧式距离作为所述每个负样本对的距离。每个正样本对的距离及每个负样本对的距离的表达形式,并不限于欧式距离,也可以是其他的距离形式,本发明不做任何限制。In a preferred embodiment of the invention, the calculation model 101 calculates the Euclidean distance for each positive sample pair, using the Euclidean distance for each positive sample pair as the distance for each positive sample pair. The calculation model 101 calculates the Euclidean distance for each negative sample pair, and takes the Euclidean distance of each negative sample pair as the distance of each of the negative sample pairs. The expression of the distance of each positive sample pair and the distance of each negative sample pair is not limited to the Euclidean distance, and may be other distance forms, and the present invention does not impose any limitation.
所述确定模块102根据所述正样本集中每个正样本对的距离,确定所述正样本集的距离分布,所述正样本集的距离分布表示正样本对出现频率与距离的关系。The determining module 102 determines a distance distribution of the positive sample set according to a distance of each positive sample pair in the positive sample set, and the distance distribution of the positive sample set represents a relationship between a positive sample pair appearance frequency and a distance.
在本发明的优选实施例中,所述正样本集的距离分布包括多个距离点,每个距离点对应一个正样本对出现频率。例如,所述正样本集有100个正样本对,在距离至为0.2处,对应有30个正样本对。In a preferred embodiment of the invention, the distance distribution of the positive sample set comprises a plurality of distance points, each distance point corresponding to a positive sample pair appearance frequency. For example, the positive sample set has 100 positive sample pairs, at a distance of 0.2, corresponding to 30 positive sample pairs.
所述确定模块102根据所述负样本集中每个负样本对的距离,确定所述负样本集的距离分布,所述负样本集的距离分布表示负样本对出现频率与距离的关系。The determining module 102 determines a distance distribution of the negative sample set according to a distance of each negative sample pair in the negative sample set, and the distance distribution of the negative sample set represents a relationship between a negative sample pair appearance frequency and a distance.
在本发明的优选实施例中,所述负样本集的距离分布包括多个距离点,每个距离点对应一个负样本对出现频率。例如,所述负样本集有100个负样本对,在距离至为0.5处,对应有20个负样本对。In a preferred embodiment of the invention, the distance distribution of the negative sample set comprises a plurality of distance points, each distance point corresponding to a negative sample pair appearance frequency. For example, the negative sample set has 100 negative sample pairs, at a distance of 0.5, corresponding to 20 negative sample pairs.
所述确定模块102基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布。The determining module 102 determines a weight distribution of the training samples based on a distance distribution of the positive sample set and a distance distribution of the negative sample set.
在本发明中,当所述正样本集的距离分布与所述负样本集的距离分布的没有交叉重叠部分时,表示所述正样本集与所述负样本集中不存在分类错误的样本对。当所述正样本集的距离分布与所述负样本集的距离分布的交叉重叠部分,则表示所述正样本集与所述负样本集中存在分类错误的样本对。所述正样本集的距离分布与所述负样本集的距离分布的交叉重叠部分的距离对应的样本对表示分类错误的样本对。因此,在后续的训练过程中,需要增加分类错误的样本对的权重,从而可以增大所述分类错误的样本对对修正模型参数的贡献率、提高模型的表达能力的贡献率。In the present invention, when there is no overlapping portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, it indicates that there is no sample pair of the classification error in the positive sample set and the negative sample set. When the distance distribution of the positive sample set overlaps with the distance distribution of the negative sample set, it indicates that there is a sample pair of the classification error in the positive sample set and the negative sample set. A sample pair corresponding to the distance of the intersection of the positive sample set and the distance overlap of the distance distribution of the negative sample set represents a sample pair that is misclassified. Therefore, in the subsequent training process, it is necessary to increase the weight of the sample pair of the classification error, so that the contribution rate of the sample of the classification error to the modified model parameter and the contribution rate of the expression ability of the model can be increased.
举例而言,如图2所示,一个举例中正样本集的距离分布及所述负样本集 的距离分布的示意图,在距离A与距离B之间的距离对应的样本对都是分类错误的样本对。若正样本对的总数量为1000个,负样本对的总数量为2000个,距离A对应的正样本对出现频率为0.02,在距离A点对应的正样本对数为20个,距离A点对应的负样本对出现频率为0.15,在距离A点对应的负样本对数为300个。若一个目标样本对的距离等于距离A,则所述目标样本对可能属于正样本对,也可能属于负样本对,因此所述目标样本对会出现分类错误的情况。For example, as shown in FIG. 2, a schematic diagram of a distance distribution of a positive sample set and a distance distribution of the negative sample set in an example, the sample pairs corresponding to the distance between the distance A and the distance B are all samples with incorrect classification. Correct. If the total number of positive sample pairs is 1000, the total number of negative sample pairs is 2000, the positive sample pair corresponding to A is 0.02, and the positive sample corresponding to point A is 20, distance A. The corresponding negative sample pair has a frequency of 0.15, and the negative sample pair corresponding to point A has 300. If the distance of a target sample pair is equal to the distance A, the target sample pair may belong to a positive sample pair or a negative sample pair, and thus the target sample pair may be classified incorrectly.
优选地,所述确定模块102基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布包括:Preferably, the determining module 102 determines, according to the distance distribution of the positive sample set and the distance distribution of the negative sample set, that the weight distribution of the training sample comprises:
基于所述正样本集的距离分布及所述负样本集的距离分布,确定分类错误的第一样本集;在所述训练样本的权重分布中,增加所述第一样本集中每个样本对的权重;及/或Determining a first sample set of the classification error based on the distance distribution of the positive sample set and the distance distribution of the negative sample set; and increasing each sample in the first sample set in the weight distribution of the training sample Weight of the pair; and/or
基于所述正样本集的距离分布及所述负样本集的距离分布,确定分类正确的第二样本集;在所述训练样本的权重分布中,减少所述第二样本集中每个样本对的权重。Determining a second sample set that is correctly classified based on a distance distribution of the positive sample set and a distance distribution of the negative sample set; and reducing a sample pair of the second sample set in a weight distribution of the training sample Weights.
在上述实施例中,通过在所述训练样本的权重分布增加分类错误的样本对的权重,及/或减少分类正确的样本的权重,从而在后续的模型训练过程中,损失函数与所述训练样本的权重分布相关联,基于所述训练样本的权重分布建立所述损失函数,可以增大所述分类错误的样本对网络损失的贡献,从而能更好地修正模型参数、提高模型参数的表达能力。In the above embodiment, the loss function and the training are performed in the subsequent model training process by increasing the weight of the misclassified sample pair in the weight distribution of the training sample, and/or reducing the weight of the correctly classified sample. The weight distribution of the sample is associated, and the loss function is established based on the weight distribution of the training sample, which can increase the contribution of the sample with the wrong classification to the network loss, thereby better correcting the model parameters and improving the expression of the model parameters. ability.
优选地,所述训练样本的权重分布为正态分布。所述配置所述正态分布的参数以实现增加分类错误的样本对的权重,及/或减少分类正确的样本的权重。所述正态分布表示样本对的距离与权重的关系。所述正态分布的参数包括,但不限于:均值,标准差。Preferably, the weight distribution of the training samples is a normal distribution. The parameter of the normal distribution is configured to achieve a weighting of a pair of samples that increase the classification error, and/or to reduce the weight of the sample that is correctly classified. The normal distribution represents the relationship between the distance of the pair of samples and the weight. The parameters of the normal distribution include, but are not limited to, mean, standard deviation.
进一步地,当所述正样本集中正样本对的最大距离小于所述负样本集中负样本对的最小距离时,在确定所述训练样本的权重分布时,所述确定模块102还用于:将所述最大距离与所述最小距离的均值确定为所述训练样本的权重分布的均值。当所述正样本集中正样本对的最大距离小于所述负样本集中负样本对的最小距离时,即表示所述正样本集与所述负样本集中不存在分类错误的样本对。Further, when the maximum distance of the positive sample pair in the positive sample set is smaller than the minimum distance of the negative sample pair in the negative sample set, when determining the weight distribution of the training sample, the determining module 102 is further configured to: The mean of the maximum distance and the minimum distance is determined as the mean of the weight distribution of the training samples. When the maximum distance of the positive sample pair in the positive sample set is smaller than the minimum distance of the negative sample pair in the negative sample set, it means that there is no sample pair of the classification error in the positive sample set and the negative sample set.
举例而言,如图3所示,所述正样本集中正样本对的最大距离C点对应的距离小于所述负样本集中负样本对的最小距离D点对应的距离。这样所述正样本集的距离分布与所述负样本集的距离分布的没有交叉重叠部分,则所述正样本集与所述负样本集中不存在分类错误的样本对。For example, as shown in FIG. 3, the distance corresponding to the maximum distance C point of the positive sample pair in the positive sample set is smaller than the distance corresponding to the minimum distance D point of the negative sample pair in the negative sample set. If there is no crossover portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, then there is no sample pair with the classification error in the positive sample set and the negative sample set.
进一步地,当所述正样本集中正样本对的最大距离等于所述负样本集中负样本对的最小距离时,在确定所述训练样本的权重分布时,所述确定模块102还用于:将所述最大距离与所述最小距离的均值确定为所述训练样本的权重分布的均值。Further, when the maximum distance of the positive sample pair in the positive sample set is equal to the minimum distance of the negative sample pair in the negative sample set, when determining the weight distribution of the training sample, the determining module 102 is further configured to: The mean of the maximum distance and the minimum distance is determined as the mean of the weight distribution of the training samples.
进一步地,当所述正样本集中正样本对的最大距离大于所述负样本集中负样本对的最小距离时,在确定所述训练样本的权重分布时,所述方法还包括:Further, when the maximum distance of the positive sample pair in the positive sample set is greater than the minimum distance of the negative sample pair in the negative sample set, when determining the weight distribution of the training sample, the method further includes:
将所述正样本集的距离分布与所述负样本集的距离分布的交叉点对应的距离值作为所述训练样本的权重分布的均值;或And using a distance value corresponding to the intersection of the distance distribution of the positive sample set and the distance distribution of the negative sample set as the mean value of the weight distribution of the training sample; or
将在正样本对出现的频率与负样本对出现的频率的之差的绝对值最小处对应的距离作为所述训练样本的权重分布的均值。当所述正样本集中正样本对的最大距离大于所述负样本集中负样本对的最小距离时,即表示所述正样本集与所述负样本集中存在分类错误的样本对。The distance corresponding to the absolute value of the difference between the frequency at which the positive sample pair appears and the frequency at which the negative sample pair appears is taken as the mean of the weight distribution of the training sample. When the maximum distance of the positive sample pair in the positive sample set is greater than the minimum distance of the negative sample pair in the negative sample set, it means that there is a sample pair of the classification error in the positive sample set and the negative sample set.
举例而言,如图2所示,所述正样本集中正样本对的最大距离B点对应的距离小于所述负样本集中负样本对的最小距离A点对应的距离。这样所述正样本集的距离分布与所述负样本集的距离分布的有交叉重叠部分,则所述正样本集与所述负样本集中不存在分类错误的样本对。将所述正样本集的距离分布与所述负样本集的距离分布的距交叉点E处对应的距离作为所述正态分布的均值。正样本对出现的频率与负样本对出现的频率的之差的绝对值最小即为所述交叉点E对应的频率值F。For example, as shown in FIG. 2, the distance corresponding to the maximum distance B point of the positive sample pair in the positive sample set is smaller than the distance corresponding to the minimum distance A point of the negative sample pair in the negative sample set. If there is a crossover portion of the distance distribution of the positive sample set and the distance distribution of the negative sample set, then there is no sample pair with the classification error in the positive sample set and the negative sample set. A distance corresponding to the distance distribution of the positive sample set and the distance distribution of the negative sample set from the intersection E is taken as the mean of the normal distribution. The absolute value of the difference between the frequency of the positive sample pair and the frequency of occurrence of the negative sample pair is the frequency value F corresponding to the intersection E.
通过上述实施例可知,在以所述训练样本的权重分布的均值为轴,越靠近所述训练样本的权重分布的均值的附近区域所包括的距离对应的样本对,越会分类错误,因此,在所述训练样本的权重分布(即所述正态分布)中,越靠近所述训练样本的权重分布的均值的距离对应的样本对的权重越大,从而实现增加分类错误的样本对的权重,及/或减少分类正确的样本的权重,从而在后续的模型训练过程中,损失函数与所述训练样本的权重分布相关联,基于所述训练 样本的权重分布建立所述损失函数,可以增大所述分类错误的样本对网络损失的贡献,从而能更好地修正模型参数、提高模型参数的表达能力。According to the above embodiment, in the average of the weight distribution of the training samples, the sample pairs corresponding to the distances included in the vicinity of the mean value of the weight distribution of the training samples are classified incorrectly. In the weight distribution of the training samples (ie, the normal distribution), the weight of the sample pairs corresponding to the distance of the mean of the weight distribution of the training samples is larger, thereby increasing the weight of the sample pairs that increase the classification error. And/or reducing the weight of the sample with the correct classification, so that in the subsequent model training process, the loss function is associated with the weight distribution of the training sample, and the loss function is established based on the weight distribution of the training sample, which may be increased The contribution of the sample with the wrong classification to the network loss can better correct the model parameters and improve the expression ability of the model parameters.
结合上述图2中的两个图的举例可知,在距离A与距离E之间对应的样本对是分类错误的样本对,及在距离B与距离E之间对应的样本对也是是分类错误的样本对。因此,在正态分布中,所述在距离A与距离E之间对应的样本对及距离B与距离E之间对应的样本对的权重高于能正确分类的样本对的权重。According to the example of the two figures in FIG. 2 above, the sample pairs corresponding between the distance A and the distance E are sample pairs that are misclassified, and the sample pairs corresponding between the distance B and the distance E are also classified incorrectly. Sample pair. Therefore, in the normal distribution, the pair of samples corresponding between the distance A and the distance E and the pair of samples corresponding to the distance B and the distance E have a higher weight than the pair of samples that can be correctly classified.
进一步地,需要在所述最小距离与所述最大距离之间,搜索使正样本对出现的频率与负样本对出现的频率的之差的绝对值最小的最优距离值。优选地,在确定所述训练样本的权重分布的均值时,所述确定模块102还用于:Further, between the minimum distance and the maximum distance, an optimal distance value that minimizes the absolute value of the difference between the frequency of occurrence of the positive sample pair and the frequency of occurrence of the negative sample pair is required. Preferably, when determining the mean value of the weight distribution of the training samples, the determining module 102 is further configured to:
配置预设步长、初始均值及迭代终止条件;Configure preset step size, initial mean value, and iteration termination condition;
基于所述初始均值及所述预设步长,在所述最小距离与最大距离组成的区间内进行迭代搜索满足所述迭代终止条件的最优距离值,在所述最优距离值处,正样本对出现的频率与负样本对出现的频率的之差的绝对值最小。And performing, according to the initial mean value and the preset step size, an iterative search for an optimal distance value satisfying the iterative termination condition in an interval composed of the minimum distance and the maximum distance, where the optimal distance value is positive The absolute value of the difference between the frequency of occurrence of the sample pair and the frequency of occurrence of the negative sample pair is minimal.
进一步地,所述预设步长等于(所述最大距离-最小距离)/n,所述n为正数。当然所述预设步长也可以是其他形式的步长,本发明不做任何限制。Further, the preset step size is equal to (the maximum distance - minimum distance) / n, and the n is a positive number. Of course, the preset step size may also be other forms of step size, and the present invention does not impose any limitation.
进一步地,所述迭代终止条件包括,但不限于:预设误差。Further, the iterative termination condition includes, but is not limited to, a preset error.
具体地,以所述初始均值为初始迭代,基于所述预设步长step进行迭代搜索,在当前迭代中,计算当前均值μ表示的距离处,正样本对出现的频率与负样本对出现的频率的之差的绝对值是否小于预设误差,若小于预设误差,将所述当前均值加上预设步长赋值为所述当前均值μ,即(μ+step)赋值为μ,继续判断正样本对出现的频率与负样本对出现的频率的之差的绝对值是否小于预设误差,直至出现正样本对出现的频率与负样本对出现的频率的之差的绝对值大于预设误差,则停止搜索所述均值,输出最后一次迭代对应的最优距离值作为所述训练样本的权重分布的均值。Specifically, the initial iteration is the initial iteration, and the iterative search is performed based on the preset step step. In the current iteration, the distance represented by the current mean μ is calculated, and the frequency of the positive sample pair and the negative sample pair appear. Whether the absolute value of the difference between the frequencies is less than the preset error. If the preset value is less than the preset error, the current average value plus the preset step size is assigned to the current mean value μ, that is, (μ+step) is assigned to μ, and the determination continues. Whether the absolute value of the difference between the frequency of the positive sample pair and the frequency of the negative sample pair is less than the preset error until the absolute value of the difference between the frequency of the occurrence of the positive sample pair and the frequency of the negative sample pair is greater than the preset error Then, the search for the mean value is stopped, and the optimal distance value corresponding to the last iteration is output as the mean value of the weight distribution of the training sample.
在本发明中,随着模型的训练,模型表达能力不断增强,因此也应当逐渐增加分类错误的样本对(即第一样本集)的权重,即需要减小所述正态分布(即所述训练样本的权重分布)的标准差。对于所述正态分布而言,标准差越小,正态峰越陡峭,即越靠近所述均值表示的距离处的样本对的权重越高,从而可以实现逐渐增加分类错误的样本对(即第一样本集)的权重。In the present invention, as the model is trained, the model expression ability is continuously enhanced, so the weight of the sample pair (ie, the first sample set) of the classification error should also be gradually increased, that is, the normal distribution needs to be reduced (ie, The standard deviation of the weight distribution of the training samples. For the normal distribution, the smaller the standard deviation, the steeper the normal peak, that is, the closer the weight of the sample pair at the distance indicated by the mean value, so that a sample pair that gradually increases the classification error can be realized (ie, The weight of the first sample set).
由于正样本集中的样本对距离的标准差随着模型训练会逐渐较小,因此,可以根据正样本集中的样本对距离的标准差配置所述正态分布的标准差。优选地,所述方法还包括:根据所述正样本集中正样本对之间距离的标准差,更新每次训练过程中的所述训练样本的权重分布的标准差。这样所述训练样本的权重分布中的标准差在模型训练的过程中随着模型训练次数的增多而逐渐较少,从而使得难以区分的样本的权重逐渐变大,提高模型的表达能力和收敛速度。Since the standard deviation of the sample-to-distance in the positive sample set is gradually smaller as the model training, the standard deviation of the normal distribution can be configured according to the standard deviation of the distance from the sample in the positive sample set. Preferably, the method further comprises: updating a standard deviation of weight distributions of the training samples in each training process according to a standard deviation of distances between pairs of positive samples in the positive sample set. In this way, the standard deviation in the weight distribution of the training samples gradually decreases with the increase of the number of training times in the model training process, so that the weight of the indistinguishable samples gradually increases, and the expression ability and convergence speed of the model are improved. .
由以上技术方案可知,本发明获取训练样本,所述训练样本包括正样本集及负样本集,所述正样本集包括正样本对及所述负样本集包括负样本对;计算所述正样本集中每个正样本对的距离,及所述负样本集中每个负样本对的距离;根据所述正样本集中每个正样本对的距离,确定所述正样本集的距离分布,所述正样本集的距离分布表示正样本对出现频率与距离的关系;根据所述负样本集中每个负样本对的距离,确定所述负样本集的距离分布,所述负样本集的距离分布表示负样本对出现频率与距离的关系;基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布。本发明能增加分类错误的样本对的权重,在后续的训练过程中,从而可以增大所述分类错误的样本对对修正模型参数、提高模型的表达能力的贡献率,提高模型参数的准确度。According to the above technical solution, the present invention acquires a training sample, where the training sample includes a positive sample set and a negative sample set, the positive sample set includes a positive sample pair and the negative sample set includes a negative sample pair; and the positive sample is calculated Concentrating the distance of each positive sample pair and the distance of each negative sample pair in the negative sample set; determining a distance distribution of the positive sample set according to the distance of each positive sample pair in the positive sample set, the positive The distance distribution of the sample set represents a relationship between the occurrence frequency of the positive sample and the distance; determining the distance distribution of the negative sample set according to the distance of each negative sample pair in the negative sample set, the distance distribution of the negative sample set is negative The relationship between the appearance frequency and the distance of the sample; the weight distribution of the training sample is determined based on the distance distribution of the positive sample set and the distance distribution of the negative sample set. The invention can increase the weight of the sample pairs with the wrong classification, and in the subsequent training process, the contribution rate of the sampled errors to the modified model parameters, the improvement of the expression ability of the model can be increased, and the accuracy of the model parameters can be improved. .
如图6所示,本发明模型训练装置的较佳实施例的功能模块图。所述模型训练装置61包括数据获取模块600及所述训练模块601。本发明所称的单元是指一种能够被模型训练装置61的处理器所执行并且能够完成固定功能的一系列计算机程序段,其存储在存储器中。在本实施例中,关于各单元的功能将在后续的实施例中详述。Figure 6 is a functional block diagram of a preferred embodiment of the model training device of the present invention. The model training device 61 includes a data acquisition module 600 and the training module 601. The unit referred to in the present invention refers to a series of computer program segments that can be executed by the processor of the model training device 61 and that can perform fixed functions, which are stored in the memory. In the present embodiment, the functions of the respective units will be described in detail in the subsequent embodiments.
所述数据获取模块600获取训练样本。The data acquisition module 600 acquires training samples.
所述训练模块601基于所述训练样本,利用损失函数及预设训练算法训练模型参数,其中所述损失函数与所述训练样本的权重分布相关联。The training module 601 trains model parameters based on the training samples using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training samples.
优选地,所述训练样本的权重分布利用上述任意实施例中所述的样本权重分配方法得到。此处不再详述。Preferably, the weight distribution of the training samples is obtained by using the sample weight allocation method described in any of the above embodiments. It will not be detailed here.
优选地,所述预设训练算法包括,但不限于:卷积神经网络算法。Preferably, the preset training algorithm includes, but is not limited to: a convolutional neural network algorithm.
在本发明中,所述损失函数通过所述训练样本的权重分布增加分类错误的 样本对对目标损失的贡献率。优选地,所述训练模块601还用于:利用所述损失函数,增加分类错误的样本对对目标损失的贡献率,从而提高所述分类错误的样本对对修正模型参数的贡献率、提高模型的表达能力的贡献率,使得模型在训练过程中能够更加专注于分类错误的样本,增加了模型的表达能力和收敛速度。In the present invention, the loss function increases the contribution rate of the sampled error pair to the target loss by the weight distribution of the training sample. Preferably, the training module 601 is further configured to: use the loss function to increase a contribution rate of the sample error of the classification error to the target loss, thereby improving the contribution rate of the sample pair of the classification error to the modified model parameter, and improving the model. The contribution rate of expressive ability enables the model to focus more on the misclassified samples during the training process, increasing the expressive ability and convergence speed of the model.
由以上技术方案可知,本发明获取训练样本,基于所述训练样本,利用损失函数及预设训练算法训练模型参数,其中所述损失函数与所述训练样本的权重分布相关联。所述训练样本的权重分布利用上述任意实施例中所述的样本权重分配方法得到。本发明中,所述训练样本的权重分布在模型训练的过程中,分类错误的样本对的权重逐渐变大,因此,在训练模型参数时,利用所述损失函数可以提高所述分类错误的样本对对修正模型参数的贡献率、提高模型的表达能力的贡献率,使得模型在训练过程中能够更加专注于分类错误的样本,增加了模型的表达能力和收敛速度,提高了模型参数的准确度。As can be seen from the above technical solution, the present invention acquires a training sample, and based on the training sample, trains a model parameter using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training sample. The weight distribution of the training samples is obtained using the sample weight allocation method described in any of the above embodiments. In the present invention, the weight distribution of the training samples is in the process of model training, and the weights of the sample pairs that are misclassified gradually become larger. Therefore, when the model parameters are trained, the loss function can be used to improve the sample of the classification errors. The contribution rate to the modified model parameters and the ability to improve the expression of the model enable the model to focus more on the misclassified samples during the training process, increasing the expression ability and convergence speed of the model, and improving the accuracy of the model parameters. .
上述以软件功能模块的形式实现的集成的单元,可以存储在一个计算机可读取存储介质中。上述软件功能模块存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或处理器(processor)执行本发明每个实施例所述方法的部分步骤。The above-described integrated unit implemented in the form of a software function module can be stored in a computer readable storage medium. The above software functional modules are stored in a storage medium and include instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to perform the method of each embodiment of the present invention. Part of the steps.
如图7所示,所述电子设备3包括至少一个发送装置31、至少一个存储器32、至少一个处理器33、至少一个接收装置34以及至少一个通信总线。其中,所述通信总线用于实现这些组件之间的连接通信。As shown in Fig. 7, the electronic device 3 comprises at least one transmitting device 31, at least one memory 32, at least one processor 33, at least one receiving device 34 and at least one communication bus. Wherein, the communication bus is used to implement connection communication between these components.
所述电子设备3是一种能够按照事先设定或存储的指令,自动进行数值计算和/或信息处理的设备,其硬件包括但不限于微处理器、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程门阵列(Field-Programmable Gate Array,FPGA)、数字处理器(Digital Signal Processor,DSP)、嵌入式设备等。所述电子设备3还可包括网络设备和/或用户设备。其中,所述网络设备包括但不限于单个网络服务器、多个网络服务器组成的服务器组或基于云计算(Cloud Computing)的由大量主机或网络服务器构成的云,其中,云计算是分布式计算的一种,由一群松散耦合的计算机集组成的一个超级虚拟计算 机。The electronic device 3 is a device capable of automatically performing numerical calculation and/or information processing according to an instruction set or stored in advance, and the hardware includes but is not limited to a microprocessor and an application specific integrated circuit (ASIC). ), Field-Programmable Gate Array (FPGA), Digital Signal Processor (DSP), embedded devices, etc. The electronic device 3 may also comprise a network device and/or a user device. The network device includes, but is not limited to, a single network server, a server group composed of multiple network servers, or a cloud computing-based cloud composed of a large number of hosts or network servers, where the cloud computing is distributed computing. A super virtual computer consisting of a group of loosely coupled computers.
所述电子设备3可以是,但不限于任何一种可与用户通过键盘、触摸板或声控设备等方式进行人机交互的电子产品,例如,平板电脑、智能手机、个人数字助理(Personal Digital Assistant,PDA)、智能式穿戴式设备、摄像设备、监控设备等终端。The electronic device 3 can be, but is not limited to, any electronic product that can interact with a user through a keyboard, a touch pad, or a voice control device, such as a tablet, a smart phone, or a personal digital assistant (Personal Digital Assistant). , PDA), smart wearable devices, camera equipment, monitoring equipment and other terminals.
所述电子设备3所处的网络包括,但不限于互联网、广域网、城域网、局域网、虚拟专用网络(Virtual Private Network,VPN)等。The network in which the electronic device 3 is located includes, but is not limited to, the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), and the like.
其中,所述接收装置34和所述发送装置31可以是有线发送端口,也可以为无线设备,例如包括天线装置,用于与其他设备进行数据通信。The receiving device 34 and the transmitting device 31 may be wired transmission ports, or may be wireless devices, for example, including antenna devices, for performing data communication with other devices.
所述存储器32用于存储程序代码。所述存储器32可以是集成电路中没有实物形式的具有存储功能的电路,如RAM(Random-Access Memory,随机存取存储器)、FIFO(First In First Out,)等。或者,所述存储器32也可以是具有实物形式的存储器,如内存条、TF卡(Trans-flash Card)、智能媒体卡(smart media card)、安全数字卡(secure digital card)、快闪存储器卡(flash card)等储存设备等等。The memory 32 is used to store program code. The memory 32 may be a circuit having a storage function, such as a RAM (Random-Access Memory), a FIFO (First In First Out), or the like, which has no physical form in the integrated circuit. Alternatively, the memory 32 may also be a memory having a physical form, such as a memory stick, a TF card (Trans-flash Card), a smart media card, a secure digital card, a flash memory card. Storage devices such as (flash card) and the like.
所述处理器33可以包括一个或者多个微处理器、数字处理器。所述处理器33可调用存储器32中存储的程序代码以执行相关的功能。例如,图5及/图6中所述的各个单元是存储在所述存储器32中的程序代码,并由所述处理器33所执行,以实现一种样本权重分配方法,及/或模型训练方法。所述处理器33又称中央处理器(CPU,Central Processing Unit),是一块超大规模的集成电路,是运算核心(Core)和控制核心(Control Unit)。The processor 33 can include one or more microprocessors, digital processors. The processor 33 can call program code stored in the memory 32 to perform related functions. For example, the various units described in FIGS. 5 and/or FIG. 6 are program code stored in the memory 32 and executed by the processor 33 to implement a sample weight distribution method, and/or model training. method. The processor 33, also known as a central processing unit (CPU), is a very large-scale integrated circuit, which is a computing core (Core) and a control unit (Control Unit).
本发明实施例还提供一种计算机可读存储介质,其上存储有计算机指令,所述指令当被包括一个或多个处理器的电子设备执行时,使电子设备执行如上文方法实施例所述的样本权重分配方法。The embodiment of the present invention further provides a computer readable storage medium having stored thereon computer instructions, when executed by an electronic device including one or more processors, causing the electronic device to perform the method embodiment as described above Sample weight distribution method.
结合图1所示,所述电子设备3中的所述存储器32存储多个指令以实现一种样本权重分配方法,所述处理器33可执行所述多个指令从而实现:As shown in FIG. 1, the memory 32 in the electronic device 3 stores a plurality of instructions to implement a sample weight allocation method, and the processor 33 can execute the plurality of instructions to implement:
获取训练样本,所述训练样本包括正样本集及负样本集,所述正样本集包括正样本对及所述负样本集包括负样本对;计算所述正样本集中每个正样本对 的距离,及所述负样本集中每个负样本对的距离;根据所述正样本集中每个正样本对的距离,确定所述正样本集的距离分布,所述正样本集的距离分布表示正样本对出现频率与距离的关系;根据所述负样本集中每个负样本对的距离,确定所述负样本集的距离分布,所述负样本集的距离分布表示负样本对出现频率与距离的关系;基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布。Obtaining a training sample, the training sample comprising a positive sample set and a negative sample set, the positive sample set comprising a positive sample pair and the negative sample set comprising a negative sample pair; calculating a distance of each positive sample pair in the positive sample set And a distance of each negative sample pair in the negative sample set; determining a distance distribution of the positive sample set according to a distance of each positive sample pair in the positive sample set, the distance distribution of the positive sample set representing a positive sample The relationship between the appearance frequency and the distance; determining the distance distribution of the negative sample set according to the distance of each negative sample pair in the negative sample set, the distance distribution of the negative sample set indicating the relationship between the appearance frequency and the distance of the negative sample pair And determining a weight distribution of the training sample based on a distance distribution of the positive sample set and a distance distribution of the negative sample set.
在任意实施例中所述样本权重分配方法对应的多个指令存储在所述存储器32,并通过所述处理器33来执行,在此不再详述。The plurality of instructions corresponding to the sample weight assignment method are stored in the memory 32 in any of the embodiments and are executed by the processor 33 and will not be described in detail herein.
结合图4所示,所述电子设备3中的所述存储器32存储多个指令以实现一种样本权重分配方法,所述处理器33可执行所述多个指令从而实现:获取训练样本;基于所述训练样本,利用损失函数及预设训练算法训练模型参数,其中所述损失函数与所述训练样本的权重分布相关联,所述训练样本的权重分布利用任意实施例中所述的模型训练方法得到。As shown in FIG. 4, the memory 32 in the electronic device 3 stores a plurality of instructions to implement a sample weight allocation method, and the processor 33 can execute the plurality of instructions to: acquire a training sample; The training sample, the model parameter is trained using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training sample, and the weight distribution of the training sample is trained using the model described in any embodiment The method is obtained.
在任意实施例中所述模型训练方法对应的多个指令存储在所述存储器32,并通过所述处理器33来执行,在此不再详述。A plurality of instructions corresponding to the model training method are stored in the memory 32 in any of the embodiments and executed by the processor 33 and will not be described in detail herein.
以上说明的本发明的特征性的手段可以通过集成电路来实现,并控制实现上述任意实施例中所述样本权重分配方法的功能。即,本发明的集成电路安装于所述电子设备中,使所述电子设备发挥如下功能:获取训练样本,所述训练样本包括正样本集及负样本集,所述正样本集包括正样本对及所述负样本集包括负样本对;计算所述正样本集中每个正样本对的距离,及所述负样本集中每个负样本对的距离;根据所述正样本集中每个正样本对的距离,确定所述正样本集的距离分布,所述正样本集的距离分布表示正样本对出现频率与距离的关系;根据所述负样本集中每个负样本对的距离,确定所述负样本集的距离分布,所述负样本集的距离分布表示负样本对出现频率与距离的关系;基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布。The above-described characteristic means of the present invention can be implemented by an integrated circuit and control the function of implementing the sample weight distribution method in any of the above embodiments. That is, the integrated circuit of the present invention is installed in the electronic device, so that the electronic device functions to acquire a training sample, the training sample includes a positive sample set and a negative sample set, and the positive sample set includes a positive sample pair And the negative sample set includes a negative sample pair; calculating a distance of each positive sample pair in the positive sample set, and a distance of each negative sample pair in the negative sample set; according to each positive sample pair in the positive sample set a distance, a distance distribution of the positive sample set, the distance distribution of the positive sample set representing a relationship between a frequency of occurrence of a positive sample pair and a distance; determining the negative according to a distance of each negative sample pair in the negative sample set a distance distribution of the sample set, the distance distribution of the negative sample set representing a relationship between the appearance frequency of the negative sample pair and the distance; determining the training sample based on the distance distribution of the positive sample set and the distance distribution of the negative sample set Weight distribution.
在任意实施例中所述样本权重分配方法所能实现的功能都能通过本发明的集成电路安装于所述电子设备中,使所述电子设备发挥任意实施例中所述样本 权重分配方法所能实现的功能,在此不再详述。The functions that can be implemented by the sample weight distribution method in any of the embodiments can be installed in the electronic device by the integrated circuit of the present invention, so that the electronic device can perform the sample weight distribution method in any embodiment. The functions implemented are not detailed here.
以上说明的本发明的特征性的手段可以通过集成电路来实现,并控制实现上述任意实施例中所述模型训练方法的功能。即,本发明的集成电路安装于所述电子设备中,使所述电子设备发挥如下功能:获取训练样本;基于所述训练样本,利用损失函数及预设训练算法训练模型参数,其中所述损失函数与所述训练样本的权重分布相关联,所述训练样本的权重分布利用任意实施例中所述的模型训练方法得到。The above-described characteristic means of the present invention can be implemented by an integrated circuit and control the function of implementing the model training method in any of the above embodiments. That is, the integrated circuit of the present invention is installed in the electronic device, so that the electronic device performs the following functions: acquiring training samples; and training model parameters based on the training samples using a loss function and a preset training algorithm, wherein the loss A function is associated with a weight distribution of the training samples, the weight distribution of the training samples being obtained using a model training method as described in any of the embodiments.
在任意实施例中所述模型训练方法所能实现的功能都能通过本发明的集成电路安装于所述电子设备中,使所述电子设备发挥任意实施例中所述模型训练方法所能实现的功能,在此不再详述。The functions that can be implemented by the model training method in any of the embodiments can be installed in the electronic device by the integrated circuit of the present invention, so that the electronic device can be implemented by the model training method in any embodiment. Function, no longer detailed here.
需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本发明并不受所描述的动作顺序的限制,因为依据本发明,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定是本发明所必须的。It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should understand that the present invention is not limited by the described action sequence. Because certain steps may be performed in other sequences or concurrently in accordance with the present invention. In addition, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。In the above embodiments, the descriptions of the various embodiments are different, and the details that are not detailed in a certain embodiment can be referred to the related descriptions of other embodiments.
在本申请所提供的几个实施例中,应该理解到,所揭露的装置,可通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性或其它的形式。In the several embodiments provided herein, it should be understood that the disclosed apparatus may be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the unit is only a logical function division. In actual implementation, there may be another division manner, for example, multiple units or components may be combined or may be Integrate into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be electrical or otherwise.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
另外,在本发明的各个实施例中的各功能单元可以集成在一个处理单元中, 也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可为个人计算机、服务器或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。The integrated unit, if implemented in the form of a software functional unit and sold or used as a standalone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention, which is essential or contributes to the prior art, or all or part of the technical solution, may be embodied in the form of a software product stored in a storage medium. A number of instructions are included to cause a computer device (which may be a personal computer, server or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: a U disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk, and the like. .
以上所述,以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的范围。The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to be limiting; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that The technical solutions described in the embodiments are modified, or some of the technical features are replaced by equivalents; and the modifications or substitutions do not deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims (10)

  1. 一种样本权重分配方法,其中,所述方法包括:A sample weight distribution method, wherein the method comprises:
    获取训练样本,所述训练样本包括正样本集及负样本集,所述正样本集包括正样本对及所述负样本集包括负样本对;Obtaining a training sample, the training sample comprising a positive sample set and a negative sample set, the positive sample set comprising a positive sample pair and the negative sample set comprising a negative sample pair;
    计算所述正样本集中每个正样本对的距离,及所述负样本集中每个负样本对的距离;Calculating a distance of each positive sample pair in the positive sample set, and a distance of each negative sample pair in the negative sample set;
    根据所述正样本集中每个正样本对的距离,确定所述正样本集的距离分布,所述正样本集的距离分布表示正样本对出现频率与距离的关系;Determining a distance distribution of the positive sample set according to a distance of each positive sample pair in the positive sample set, the distance distribution of the positive sample set indicating a relationship between a frequency of occurrence of a positive sample pair and a distance;
    根据所述负样本集中每个负样本对的距离,确定所述负样本集的距离分布,所述负样本集的距离分布表示负样本对出现频率与距离的关系;Determining a distance distribution of the negative sample set according to a distance of each negative sample pair in the negative sample set, the distance distribution of the negative sample set indicating a relationship between a frequency of occurrence of a negative sample pair and a distance;
    基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布。And determining a weight distribution of the training sample based on a distance distribution of the positive sample set and a distance distribution of the negative sample set.
  2. 如权利要求1所述的样本权重分配方法,其中,所述基于所述正样本集的距离分布及所述负样本集的距离分布,确定所述训练样本的权重分布包括:The sample weight allocation method according to claim 1, wherein the determining the weight distribution of the training sample based on the distance distribution of the positive sample set and the distance distribution of the negative sample set comprises:
    基于所述正样本集的距离分布及所述负样本集的距离分布,确定分类错误的第一样本集;Determining a first sample set of the classification error based on the distance distribution of the positive sample set and the distance distribution of the negative sample set;
    在所述训练样本的权重分布中,增加所述第一样本集中每个样本对的权重;及/或In the weight distribution of the training samples, increasing the weight of each sample pair in the first sample set; and/or
    基于所述正样本集的距离分布及所述负样本集的距离分布,确定分类正确的第二样本集;Determining a correctly classified second sample set based on the distance distribution of the positive sample set and the distance distribution of the negative sample set;
    在所述训练样本的权重分布中,减少所述第二样本集中每个样本对的权重。In the weight distribution of the training samples, the weight of each sample pair in the second sample set is reduced.
  3. 如权利要求1所述的样本权重分配方法,其中,所述训练样本的权重分布为正态分布,当所述正样本集中正样本对的最大距离小于或等于所述负样本集中负样本对的最小距离时,在确定所述训练样本的权重分布时,所述方法还包括:The sample weight assignment method according to claim 1, wherein a weight distribution of the training samples is a normal distribution, and a maximum distance of a positive sample pair in the positive sample set is less than or equal to a negative sample pair in the negative sample set. At the minimum distance, when determining the weight distribution of the training sample, the method further includes:
    将所述最大距离与所述最小距离的均值确定为所述训练样本的权重分布的 均值。The mean of the maximum distance and the minimum distance is determined as the mean of the weight distribution of the training samples.
  4. 如权利要求1所述的样本权重分配方法,其中,所述训练样本的权重分布为正态分布,当所述正样本集中正样本对的最大距离大于所述负样本集中负样本对的最小距离时,在确定所述训练样本的权重分布时,所述方法还包括:The sample weight assignment method according to claim 1, wherein a weight distribution of the training samples is a normal distribution, and a maximum distance of a positive sample pair in the positive sample set is greater than a minimum distance of a negative sample pair in the negative sample set When determining the weight distribution of the training sample, the method further includes:
    将所述正样本集的距离分布与所述负样本集的距离分布的交叉点对应的距离值作为所述训练样本的权重分布的均值;或And using a distance value corresponding to the intersection of the distance distribution of the positive sample set and the distance distribution of the negative sample set as the mean value of the weight distribution of the training sample; or
    将在正样本对出现的频率与负样本对出现的频率的之差的绝对值最小处对应的距离作为所述训练样本的权重分布的均值。The distance corresponding to the absolute value of the difference between the frequency at which the positive sample pair appears and the frequency at which the negative sample pair appears is taken as the mean of the weight distribution of the training sample.
  5. 如权利要求4所述的样本权重分配方法,其中,在确定所述训练样本的权重分布的均值时,所述方法还包括:The sample weight allocation method according to claim 4, wherein when determining the mean value of the weight distribution of the training samples, the method further comprises:
    配置预设步长、初始均值及迭代终止条件;Configure preset step size, initial mean value, and iteration termination condition;
    基于所述初始均值及所述预设步长,在所述最小距离与最大距离组成的区间内进行迭代搜索满足所述迭代终止条件的最优距离值,在所述最优距离值处,正样本对出现的频率与负样本对出现的频率的之差的绝对值最小。And performing, according to the initial mean value and the preset step size, an iterative search for an optimal distance value satisfying the iterative termination condition in an interval composed of the minimum distance and the maximum distance, where the optimal distance value is positive The absolute value of the difference between the frequency of occurrence of the sample pair and the frequency of occurrence of the negative sample pair is minimal.
  6. 如权利要求1至5中任一项所述的样本权重分配方法,其中,所述训练样本的权重分布为正态分布,在确定所述训练样本的权重分布时,所述方法还包括:The sample weight distribution method according to any one of claims 1 to 5, wherein the weight distribution of the training sample is a normal distribution, and when determining the weight distribution of the training sample, the method further includes:
    在每次训练过程中,获取所述正样本集中正样本对之间距离的标准差;Obtaining a standard deviation of the distance between pairs of positive samples in the positive sample set during each training session;
    根据所述正样本集中正样本对之间距离的标准差,更新每次训练过程中的所述训练样本的权重分布的标准差。The standard deviation of the weight distribution of the training samples in each training process is updated according to the standard deviation of the distance between the positive sample pairs in the positive sample set.
  7. 一种模型训练方法,其中,所述方法包括:A model training method, wherein the method comprises:
    获取训练样本;Obtain training samples;
    基于所述训练样本,利用损失函数及预设训练算法训练模型参数,其中所述损失函数与所述训练样本的权重分布相关联,所述训练样本的权重分布利用权利要求1至6中任一项所述的样本权重分配方法得到。Model parameters are trained based on the training samples using a loss function and a preset training algorithm, wherein the loss function is associated with a weight distribution of the training samples, and the weight distribution of the training samples utilizes any one of claims 1 to 6. The sample weight distribution method described in the item is obtained.
  8. 如权利要求7中所述的样本训练方法,其中,所述方法还包括:The sample training method according to claim 7, wherein the method further comprises:
    利用所述损失函数,增加分类错误的样本对对目标损失的贡献率。Using the loss function, the contribution rate of the sampled error to the target loss is increased.
  9. 一种电子设备,其中,所述电子设备包括存储器及处理器,所述存储器用于存储至少一个指令,所述处理器用于执行所述至少一个指令以实现如权利要求1至6中任一项所述样本权重分配方法,及/或如权利要求7或8中任一项所述模型训练方法。An electronic device, comprising: a memory for storing at least one instruction, the processor for executing the at least one instruction to implement any one of claims 1 to 6 The sample weight distribution method, and/or the model training method according to any one of claims 7 or 8.
  10. 一种计算机可读存储介质,其中,所述计算机可读存储介质存储有至少一个指令,所述至少一个指令被处理器执行时实现如权利要求1至6中任一项所述样本权重分配方法,及/或如权利要求7或8中任一项所述模型训练方法。A computer readable storage medium, wherein the computer readable storage medium stores at least one instruction, and the at least one instruction is executed by a processor to implement the sample weight distribution method according to any one of claims 1 to 6. And/or the model training method according to any one of claims 7 or 8.
PCT/CN2018/079371 2017-12-29 2018-03-16 Sample weight allocation method, model training method, electronic device, and storage medium WO2019127924A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201711480906.8 2017-12-29
CN201711480906.8A CN108229555B (en) 2017-12-29 2017-12-29 Sample weights distribution method, model training method, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
WO2019127924A1 true WO2019127924A1 (en) 2019-07-04

Family

ID=62647244

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/079371 WO2019127924A1 (en) 2017-12-29 2018-03-16 Sample weight allocation method, model training method, electronic device, and storage medium

Country Status (2)

Country Link
CN (1) CN108229555B (en)
WO (1) WO2019127924A1 (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111198938A (en) * 2019-12-26 2020-05-26 深圳市优必选科技股份有限公司 Sample data processing method, sample data processing device and electronic equipment
CN111310660A (en) * 2020-02-14 2020-06-19 开易(北京)科技有限公司 Target detection false alarm suppression method and device for ADAS scene
CN111353282A (en) * 2020-03-09 2020-06-30 腾讯科技(深圳)有限公司 Model training method, text rewriting method, device and storage medium
CN111915004A (en) * 2020-06-17 2020-11-10 北京迈格威科技有限公司 Neural network training method and device, storage medium and electronic equipment
CN112508130A (en) * 2020-12-25 2021-03-16 商汤集团有限公司 Clustering method and device, electronic equipment and storage medium
CN112801221A (en) * 2021-03-24 2021-05-14 平安科技(深圳)有限公司 Data classification method, device, equipment and storage medium
CN112819085A (en) * 2021-02-10 2021-05-18 中国银联股份有限公司 Model optimization method and device based on machine learning and storage medium
CN113361568A (en) * 2021-05-18 2021-09-07 北京迈格威科技有限公司 Target identification method, device and electronic system
CN113407814A (en) * 2021-06-29 2021-09-17 北京字节跳动网络技术有限公司 Text search method and device, readable medium and electronic equipment

Families Citing this family (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109086207B (en) * 2018-08-02 2023-04-14 平安科技(深圳)有限公司 Page response fault analysis method, computer readable storage medium and terminal device
CN110163053B (en) * 2018-08-02 2021-07-13 腾讯科技(深圳)有限公司 Method and device for generating negative sample for face recognition and computer equipment
CN110084271B (en) * 2019-03-22 2021-08-20 同盾控股有限公司 Method and device for identifying picture category
CN110162995B (en) * 2019-04-22 2023-01-10 创新先进技术有限公司 Method and device for evaluating data contribution degree
CN110309286A (en) * 2019-07-04 2019-10-08 深圳市和合信诺大数据科技有限公司 Improve the method and device of two-way attention machine learning model responsibility
CN110363346A (en) * 2019-07-12 2019-10-22 腾讯科技(北京)有限公司 Clicking rate prediction technique, the training method of prediction model, device and equipment
CN112434839B (en) * 2019-08-26 2023-05-30 电力规划总院有限公司 Distribution transformer heavy overload risk prediction method and electronic equipment
CN110705589A (en) * 2019-09-02 2020-01-17 贝壳技术有限公司 Weight optimization processing method and device for sample characteristics
CN110781922A (en) * 2019-09-27 2020-02-11 北京淇瑀信息科技有限公司 Sample data generation method and device for machine learning model and electronic equipment
CN110837869A (en) * 2019-11-11 2020-02-25 深圳市商汤科技有限公司 Image classification model training method, image processing method and device
CN110856253B (en) * 2019-11-15 2021-03-23 北京三快在线科技有限公司 Positioning method, positioning device, server and storage medium
CN111027442A (en) * 2019-12-03 2020-04-17 腾讯科技(深圳)有限公司 Model training method, recognition method, device and medium for pedestrian re-recognition
CN111507380B (en) * 2020-03-30 2023-10-31 中国平安财产保险股份有限公司 Picture classification method, system, device and storage medium based on clustering
CN113743426A (en) * 2020-05-27 2021-12-03 华为技术有限公司 Training method, device, equipment and computer readable storage medium
CN113378914B (en) * 2021-06-08 2023-06-30 上海壁仞智能科技有限公司 False relevance removing method and device
CN113408804B (en) * 2021-06-24 2023-04-07 广东电网有限责任公司 Electricity stealing behavior detection method, system, terminal equipment and storage medium
CN115858886B (en) * 2022-12-12 2024-02-27 腾讯科技(深圳)有限公司 Data processing method, device, equipment and readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104252627A (en) * 2013-06-28 2014-12-31 广州华多网络科技有限公司 SVM (support vector machine) classifier training sample acquiring method, training method and training system
CN106909981A (en) * 2015-12-23 2017-06-30 阿里巴巴集团控股有限公司 Model training, sample balance method and device and personal credit points-scoring system
CN107273458A (en) * 2017-06-01 2017-10-20 百度在线网络技术(北京)有限公司 Depth model training method and device, image search method and device
CN107292915A (en) * 2017-06-15 2017-10-24 国家新闻出版广电总局广播科学研究院 Method for tracking target based on convolutional neural networks

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107346448B (en) * 2016-05-06 2021-12-21 富士通株式会社 Deep neural network-based recognition device, training device and method
CN106919909B (en) * 2017-02-10 2018-03-27 华中科技大学 The metric learning method and system that a kind of pedestrian identifies again
CN107145827A (en) * 2017-04-01 2017-09-08 浙江大学 Across the video camera pedestrian recognition methods again learnt based on adaptive distance metric

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104252627A (en) * 2013-06-28 2014-12-31 广州华多网络科技有限公司 SVM (support vector machine) classifier training sample acquiring method, training method and training system
CN106909981A (en) * 2015-12-23 2017-06-30 阿里巴巴集团控股有限公司 Model training, sample balance method and device and personal credit points-scoring system
CN107273458A (en) * 2017-06-01 2017-10-20 百度在线网络技术(北京)有限公司 Depth model training method and device, image search method and device
CN107292915A (en) * 2017-06-15 2017-10-24 国家新闻出版广电总局广播科学研究院 Method for tracking target based on convolutional neural networks

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111198938B (en) * 2019-12-26 2023-12-01 深圳市优必选科技股份有限公司 Sample data processing method, sample data processing device and electronic equipment
CN111198938A (en) * 2019-12-26 2020-05-26 深圳市优必选科技股份有限公司 Sample data processing method, sample data processing device and electronic equipment
CN111310660A (en) * 2020-02-14 2020-06-19 开易(北京)科技有限公司 Target detection false alarm suppression method and device for ADAS scene
CN111353282B (en) * 2020-03-09 2023-08-22 腾讯科技(深圳)有限公司 Model training, text rewriting method, device and storage medium
CN111353282A (en) * 2020-03-09 2020-06-30 腾讯科技(深圳)有限公司 Model training method, text rewriting method, device and storage medium
CN111915004A (en) * 2020-06-17 2020-11-10 北京迈格威科技有限公司 Neural network training method and device, storage medium and electronic equipment
CN112508130A (en) * 2020-12-25 2021-03-16 商汤集团有限公司 Clustering method and device, electronic equipment and storage medium
CN112819085A (en) * 2021-02-10 2021-05-18 中国银联股份有限公司 Model optimization method and device based on machine learning and storage medium
CN112819085B (en) * 2021-02-10 2023-10-24 中国银联股份有限公司 Model optimization method, device and storage medium based on machine learning
CN112801221A (en) * 2021-03-24 2021-05-14 平安科技(深圳)有限公司 Data classification method, device, equipment and storage medium
CN112801221B (en) * 2021-03-24 2023-12-22 平安科技(深圳)有限公司 Data classification method, device, equipment and storage medium
CN113361568A (en) * 2021-05-18 2021-09-07 北京迈格威科技有限公司 Target identification method, device and electronic system
CN113407814A (en) * 2021-06-29 2021-09-17 北京字节跳动网络技术有限公司 Text search method and device, readable medium and electronic equipment
CN113407814B (en) * 2021-06-29 2023-06-16 抖音视界有限公司 Text searching method and device, readable medium and electronic equipment

Also Published As

Publication number Publication date
CN108229555A (en) 2018-06-29
CN108229555B (en) 2019-10-25

Similar Documents

Publication Publication Date Title
WO2019127924A1 (en) Sample weight allocation method, model training method, electronic device, and storage medium
WO2020006961A1 (en) Image extraction method and device
WO2019200781A1 (en) Receipt recognition method and device, and storage medium
CN109583332B (en) Face recognition method, face recognition system, medium, and electronic device
CN112801298B (en) Abnormal sample detection method, device, equipment and storage medium
KR20170125720A (en) Recognition apparatus based on deep neural network, training apparatus and methods thereof
JP2022537781A (en) Image recognition method, recognition model training method and related devices and equipment
WO2020253127A1 (en) Facial feature extraction model training method and apparatus, facial feature extraction method and apparatus, device, and storage medium
US11715044B2 (en) Methods and systems for horizontal federated learning using non-IID data
WO2021089013A1 (en) Spatial graph convolutional network training method, electronic device and storage medium
WO2019047703A1 (en) Audio event detection method and device, and computer-readable storage medium
US11380131B2 (en) Method and device for face recognition, storage medium, and electronic device
WO2019200702A1 (en) Descreening system training method and apparatus, descreening method and apparatus, device, and medium
WO2021036309A1 (en) Image recognition method and apparatus, computer apparatus, and storage medium
CN111126347B (en) Human eye state identification method, device, terminal and readable storage medium
US20220139061A1 (en) Model training method and apparatus, keypoint positioning method and apparatus, device and medium
WO2019144710A1 (en) Method and apparatus for determining position of pupil
WO2018059302A1 (en) Text recognition method and device, and storage medium
CN112749685B (en) Video classification method, apparatus and medium
CN110796089A (en) Method and apparatus for training face-changing model
CN115082740B (en) Target detection model training method, target detection device and electronic equipment
US20190108416A1 (en) Methods for more effectively moderating one or more images and devices thereof
CN113627361B (en) Training method and device for face recognition model and computer program product
WO2017097118A1 (en) Text classification processing method and apparatus
CN115170919B (en) Image processing model training and image processing method, device, equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18896975

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS (EPO FORM 1205A DATED 05.10.2020)

122 Ep: pct application non-entry in european phase

Ref document number: 18896975

Country of ref document: EP

Kind code of ref document: A1