Method and apparatus for training image processing model
By using the WSAM scheme to perform multiple rounds of iterative training on the image processing model and updating parameters with weighted summation, the overfitting problem is solved, and the generalization performance and accuracy of the model are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
- Filing Date
- 2023-07-18
- Publication Date
- 2026-04-17
AI Technical Summary
Existing image processing models are prone to overfitting during training, resulting in poor generalization performance and low accuracy of image processing results.
The Weighted Sharpness-aware Minimization (WSAM) scheme is adopted. Through multiple rounds of iterative training of the image processing model, the first training gradient and sharpness gradient are determined using the current batch of image samples, and then weighted summation is performed to update the model parameters, thereby improving the generalization performance of the model.
It effectively improves the generalization performance and prediction accuracy of image processing models, reduces overfitting, and enhances the overall performance of the models.
Smart Images

Figure CN116882478B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of image processing technology, and more particularly to a training method and apparatus for an image processing model, and a training method and apparatus for a prediction model. Background Technology
[0002] Computer vision (CV) is a simulation of biological vision using computers and related equipment. Its main task is to process acquired images or videos to obtain three-dimensional information about the corresponding scene, just as humans and many other organisms do every day. CV-related technologies are already ubiquitous in our lives, such as facial recognition and gesture recognition in smart devices, as well as the detection and segmentation of target objects in images, and the location and tracking of target objects in videos, and so on.
[0003] Generally, depending on the specific CV task (such as face recognition), image samples (such as face images) are collected to train a machine learning model (such as a face recognition model) to perform that CV task.
[0004] Therefore, we propose to improve the training method of image processing models in order to enhance their generalization ability and improve the accuracy of image processing results. Summary of the Invention
[0005] This specification describes a training method and apparatus for an image processing model, and a training method and apparatus for a prediction model, which can effectively improve the generalization performance of the model.
[0006] According to a first aspect, a training method for an image processing model is provided, involving multiple rounds of iterative training of the image processing model, wherein any round of iterative training includes: using current batch image samples, determining a first training gradient of the image processing model at its current first model parameters; based on the first training gradient, determining the parameter change amount that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius; determining a second training gradient of the image processing model at a second model parameter, the second model parameter being obtained based on the first model parameter offset by the parameter change amount; performing a weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient to obtain a third training gradient; and updating the first model parameters based on a preset learning rate and the third training gradient.
[0007] In one embodiment, determining the first training gradient of the image processing model at its current first model parameters using the current batch of image samples includes: inputting each image sample in the current batch of image samples into the image processing model to obtain the corresponding image processing result, and using the image processing result, the sample label corresponding to the image sample, and the first model parameters as the first input of a preset gradient calculation formula to obtain the corresponding first gradient; and calculating the average value of the first gradient corresponding to the current batch of image samples as the first training gradient.
[0008] In one specific embodiment, determining the second training gradient of the image processing model at the second model parameters includes: for each image sample, using the image processing result, the sample label, and the second model parameters as the second input of the preset gradient calculation formula to obtain the corresponding second gradient; and calculating the average value of the second gradient corresponding to the current batch of image samples as the second training gradient.
[0009] In one embodiment, based on the first training gradient, determining the parameter change amount that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius includes: calculating the product between the preset radius and the unit vector of the first training gradient as the parameter change amount.
[0010] In one embodiment, based on the first training gradient, determining the parameter change amount that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius includes: calculating the first training gradient and the ratio between the magnitude of the first training gradient and the sum of the numerically stable terms; and calculating the product between the ratio and the preset radius as the parameter change amount.
[0011] In one embodiment, the third training gradient is obtained by weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient, including: using pre-set weights to weighted summation of the first training gradient and the gradient difference to obtain the third training gradient.
[0012] In one embodiment, the current training epoch is the t-th training epoch; wherein, the third training gradient is obtained by weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient, including: weighted summation of the first training gradient determined in the current t-th training epoch and the t-1 first training gradients obtained in the previous t-1 training epochs, and the difference, to obtain the third training gradient.
[0013] In a specific embodiment, obtaining the third training gradient includes: inputting the t first training gradients corresponding to t training rounds into a preset first function and a second function respectively to obtain a first vector and a second matrix; summing the product between the first vector and the second matrix and the result of weighting the gradient difference using preset weighting coefficients to obtain the third training gradient.
[0014] In one embodiment, the current training epoch is the t-th training epoch; updating the first model parameters based on the preset learning rate and the third training gradient includes: inputting the t third training gradients corresponding to the t training epochs into the preset first function and the second function respectively to obtain the first vector and the second matrix; using the first model parameters minus the preset learning rate and the product between the first vector and the second matrix as the updated first model parameters.
[0015] In one embodiment, updating the first model parameters based on a preset learning rate and the third training gradient includes: subtracting the product between the preset learning rate and the third training gradient from the first model parameters to obtain the updated first model parameters.
[0016] According to a second aspect, a method for training a prediction model is provided, wherein the prediction model is used to perform a prediction task; the method involves multiple rounds of iterative training of the prediction model, wherein any round of iterative training includes: using the current batch of training samples, determining a first training gradient of the prediction model at its current first model parameters; based on the first training gradient, determining the parameter change amount that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius; determining a second training gradient of the prediction model at a second model parameter, the second model parameter being obtained based on the first model parameter offset by the parameter change amount; performing a weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient to obtain a third training gradient; and updating the first model parameters based on a preset learning rate and the third training gradient.
[0017] In one embodiment, the prediction model is used to make predictions for a business object, which is text or audio.
[0018] In one embodiment, the prediction model is used to make predictions for a business object, which is a user, a product, or an event.
[0019] According to a third aspect, a training apparatus for an image processing model is provided. This training apparatus performs iterative training in any one round of multi-round iterative training of the image processing model using the following units: a first gradient determination unit configured to determine a first training gradient of the image processing model at its current first model parameters using current batch image samples; a parameter change determination unit configured to determine, based on the first training gradient, the parameter change that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius; a second gradient determination unit configured to determine a second training gradient of the image processing model at second model parameters, the second model parameters being obtained based on the first model parameters offset by the parameter change; a third gradient determination unit configured to perform a weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient to obtain a third training gradient; and a parameter update unit configured to update the first model parameters based on a preset learning rate and the third training gradient.
[0020] According to a fourth aspect, a training apparatus for a prediction model is provided, wherein the prediction model is used to perform a prediction task; the training apparatus performs any one of the iterations in a multi-round iterative training of the prediction model through the following units: a first gradient determination unit configured to determine a first training gradient of the prediction model at its current first model parameters using the current batch of training samples; a parameter change determination unit configured to determine, based on the first training gradient, the parameter change that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius; a second gradient determination unit configured to determine a second training gradient of the prediction model at a second model parameter, the second model parameter being obtained based on the first model parameter offset by the parameter change; a third gradient determination unit configured to perform a weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient to obtain a third training gradient; and a parameter update unit configured to update the first model parameters based on a preset learning rate and the third training gradient.
[0021] According to a fifth aspect, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method provided in the first or second aspect.
[0022] According to a sixth aspect, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements the method provided in the first or second aspect.
[0023] By using the methods and apparatus disclosed in the embodiments of this specification, the generalization performance of the trained model can be effectively improved, and the accuracy of the model prediction can be increased. Attached Figure Description
[0024] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1 This is a schematic diagram of the implementation architecture of the WSAM solution disclosed in the embodiments of this specification;
[0026] Figure 2 This is a schematic diagram of the training method for the image processing model disclosed in the embodiments of this specification;
[0027] Figure 3 This is a schematic diagram of the training method for the prediction model disclosed in the embodiments of this specification;
[0028] Figure 4 This is a schematic diagram of the training device structure for the image processing model disclosed in the embodiments of this specification.
[0029] Figure 5 This is a schematic diagram of the training device structure for the prediction model disclosed in the embodiments of this specification. Detailed Implementation
[0030] The solution provided in this specification will now be described with reference to the accompanying drawings.
[0031] As mentioned earlier, the industry utilizes machine learning techniques to build models for performing image processing tasks. Generally, the larger the number of parameters in an image processing model, the better its predictive performance. However, an excessive number of parameters can easily lead to overfitting. The image processing model will try to "memorize" the data instead of "understand" it, resulting in poor generalization performance and low accuracy in the image processing results.
[0032] Recent research indicates that the generalization performance of image processing models is related to the flatness of the training loss at its minimum; a smaller flatness value of the loss helps achieve a lower generalization error. To explore a flatter minimum loss value, Sharpness-Aware Minimization (SAM) defines the sharpness of the loss function L at the model parameters w:
[0033]
[0034] However, It can only be used to find flat regions in the loss function but not to find the minimum value, causing the model to converge to a certain point but the loss is still relatively large. Therefore, SAM adopts... That is, L SAM (w) is used as the loss function.
[0035] SAM is an optimization problem that minimizes the maximum value. It is necessary to first determine the maximum value of L(w+δ)-L(w) under the constraint ||δ||≤ρ, that is, to calculate the value in equation (1). Then minimize
[0036] Specifically, for The calculation is performed by performing a first-order Taylor expansion of L(w+δ) at w, to determine δ* that makes L(w+δ)-L(w) approach the maximum value.
[0037]
[0038] Furthermore, SAM calculates L SAM The approximate gradient of (w) is used to optimize the parameter w, where the approximate gradient is calculated as follows:
[0039]
[0040] It should be noted that the approximation in formula (3) is for the purpose of accelerating computation. Other gradient-based optimizers (referred to as basic optimizers in this paper) can be incorporated into the general framework of SAM. In Algorithm 1 illustrated in Table 1, by adjusting φ t and ψ t To adjust m accordingly t and B t This allows different basic optimizers to be applied in SAM, such as S... GD S GD M and A DA M, see Table 2 for details.
[0041] Table 1
[0042]
[0043] Table 2: Different m t and B t The underlying optimizer
[0044]
[0045] It should be noted that for the fourth row of Algorithm 1 shown in Table 1, you can also refer to the above formula (2). The addition of the numerical stability term ∈ is to prevent the denominator from being zero. For the fifth row of Algorithm 1 shown in Table 1, you can also refer to the above formula (3).
[0046] Observation and analysis of SAM show that the loss function used by SAM is It gives the sharpness of the loss function The original value L(w) has the same weights. Therefore, an improved scheme is proposed, named Weighted Sharpness-aware Minimization (WASM). In WASM, sharpness is treated as a regularization term, assigning different weights to the original loss function value and sharpness. This allows the loss function to freely control convergence to a point where the sharpness is smaller or the original loss function value is smaller. Simultaneously, weight decoupling is employed to ensure the regularization term accurately reflects the sharpness of the current step, thereby improving generalization.
[0047] Figure 1 This is a schematic diagram illustrating the implementation architecture of the WSAM solution disclosed in the embodiments of this specification. Figure 1 As shown, by using a batch of image samples sampled from the image sample set, the first training gradient corresponding to the original loss and the second training gradient corresponding to the sharpness of the image processing model are determined. Then, the first training gradient and the second training gradient are weighted and summed to obtain the third training gradient, and the model parameters of the image processing model are updated using the third training gradient.
[0048] Below, in conjunction with Table 3 and Figure 2 This describes the specific implementation steps of the WSAM scheme. Specifically, Table 3 shows an exemplary framework for the WSAM optimizer.
[0049] Table 3
[0050]
[0051] Figure 2 This is a schematic diagram of the training method for the image processing model disclosed in the embodiments of this specification. It should be understood that the image processing model can be implemented using neural network algorithms, such as Convolutional Neural Networks (CNN) or Deep Neural Networks (DNN), etc.; in addition, the execution entity of the method can be any device, server, platform, or device cluster with computing and processing capabilities.
[0052] The method involves iteratively training an image processing model through multiple rounds (hereinafter referred to as T rounds), wherein any round of iterative training includes Figure 2 The following steps are shown in the figure:
[0053] Step S210: Using the current batch of image samples, determine the first training gradient of the image processing model at its current first model parameters; Step S220: Based on the first training gradient, determine the parameter change amount that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius; Step S230: Determine the second training gradient of the image processing model at the second model parameters, wherein the second model parameters are obtained based on the first model parameters offset by the parameter change amount; Step S240: Perform a weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient to obtain a third training gradient; Step S250: Update the first model parameters based on the preset learning rate and the third training gradient.
[0054] The steps above are explained in detail below:
[0055] First, in step S210, the current batch of image samples is used. Determine the image processing model in its current first model parameter w t The first training gradient at the location It should be noted that the subscript t indicates the number of iterations in the current iteration; the terms "first" in the first model parameter and the first training gradient, as well as "second" and similar terms elsewhere in the text, are used to distinguish similar things and do not have any other limiting function such as ranking.
[0056] Current batch of image samples From image sample set The image sample set is obtained through sampling, which can employ methods such as hierarchical sampling or sampling with replacement. For example, the image sample set can be pre-sampled. Perform T sampling operations to obtain T batches of image samples. Accordingly, in this step, based on the current iteration t, the image sample of the t-th batch can be obtained as the current batch image sample.
[0057] Image samples and their corresponding labels are adapted to the business scenario. Generally speaking, the sample labels for image samples can include image category labels, or bounding boxes or masks of target objects in the image. More specifically, for example, in a face recognition scenario, the image sample can be a face image, and its corresponding sample label can be an identity identifier. As another example, in a vehicle damage assessment scenario, the image sample can be a vehicle damage image, and its corresponding label can include the vehicle damage category and the bounding box indicating the damaged area.
[0058] In one embodiment, for each image sample x in the current batch of image samples... k First, input it into the image processing model to obtain the corresponding image processing result h. w (x k ), then the image sample x k Image processing results h w (x k ), Sample label y k and the first model parameter w t As the first input to the gradient calculation formula, the corresponding first gradient is obtained. Or simply called
[0059] It is understandable that the above gradient calculation formula can be derived based on the selected loss function, such as the cross-entropy loss function or the mean squared error loss function. The loss function is used to calculate based on the image processing result h. w (x k ) and sample label y k Determine the training loss l(h) w (x k ),y k ).
[0060] Furthermore, the image samples in the current batch can be calculated. The corresponding first gradient The average value is used as the first training gradient. This can be recorded as:
[0061]
[0062] In formula (4), This indicates the sample size of the current batch of image samples.
[0063] From the above, the first training gradient can be calculated. For example, see also row 3 of Algorithm 2 shown in Table 3.
[0064] In step S220, based on the first training gradient Determine the first model parameter w t Within a neighborhood centered at a given point and with a preset radius ρ, the parameter change δ that causes the maximum change in the current training loss. t That is, to calculate:
[0065] δ t =argmax(L(w t +δ)-L(w t )), where ||δ||≤ρ (5)
[0066] For δ t In one embodiment, the calculation can be performed with reference to the above formula (2), and correspondingly:
[0067]
[0068] In another embodiment, a numerically stable term ∈ can be added to the denominator of formula (6) to prevent the denominator from being zero, thus ensuring the usability of the calculation result. See formula (7) below for details, or see also [other examples].
[0069] The fourth row of Algorithm 2 is shown in Table 3.
[0070]
[0071] It should be understood that the numerically stable term ∈ is a hyperparameter, whose value is set manually and takes a small value, such as 10. -12 In addition, the neighborhood radius ρ can be pre-set manually, for example, ρ = 0.05.
[0072] The parameter change δ can be determined from the above. t .
[0073] In step S230, the image processing model is determined in the second model parameter w. t +δ t The second training gradient g at the location t The second model parameter w t +δ t Based on the first model parameter w t The change in offset parameter δ t And thus obtained.
[0074] In one embodiment, for each image sample x in the current batch of image samples... k The image processing result h w (x k ), Sample label y k Second model parameter w t +δt As the second input to the above gradient calculation formula, the corresponding second gradient is obtained.
[0075] Furthermore, the image samples in the current batch can be calculated. The corresponding second gradient The average value is used as the second training gradient g. t This can be recorded as:
[0076]
[0077] From the above, the second training gradient g can be calculated. t For example, see also row 5 of Algorithm 2 shown in Table 3.
[0078] Step S240, for the first training gradient and the second training gradient g t Subtract the first training gradient gradient difference We perform a weighted summation to obtain the third training gradient g′. t .
[0079] We might as well use the first training gradient and gradient difference The corresponding weighting coefficients are denoted as η1 and η2, respectively. Specifically, the pre-set η1 and η2 can be used to adjust the first training gradient. and gradient difference We perform a weighted summation to obtain the third training gradient g′. t .
[0080] In one embodiment, η1 and η2 can be adjusted and selected separately by the operator; for example, η1 = 1 and η2 = 0.85. In another embodiment, η1 and η2 can be set in association; for example, the value of η2 can be set first, and then the value of η1 can be determined according to an expression with η2 as the independent variable and η1 as the dependent variable. For example, the expression is η1 = 0.5 + η2.
[0081] On the other hand, it is possible to adapt existing basic optimizers (such as S...) GD Describe this step from the perspective of (etc.).
[0082] Referring to row 6 of Algorithm 2 in Table 3, the first training gradient determined in the current t-th training epoch and the t-1 first training gradients obtained in the previous t-1 training epochs can be used as... Input function sequence The t-th pair of functions φ t and ψ t The first vector is obtained respectively. Second matrix Thus, by adjusting φ t and ψ t To adjust accordingly and It allows the application of different base optimizers in WASM, such as S GD S GD M and A DA For M, please refer to Table 2 above.
[0083] Furthermore, referring to row 7 of Algorithm 2 in Table 3, the corresponding information is as follows:
[0084]
[0085] In the After expansion, it can be observed that it includes at least the training gradient. The weighted terms. Additionally... γ∈[0,1), this is because the range of η2 is [0,+∞). When setting the value of η2, it would be difficult to directly adjust η2 for observation. Therefore, it is proposed to express η2 equivalently as... This allows for direct adjustment of γ within the range [0,1), effectively simplifying the adjustment and observation process. In fact, through continuous adjustment of the value of γ, it was found that the prediction performance of the WSAM scheme is less sensitive to the value of γ. When using different γ values, the WSAM scheme maintains a relatively stable high-performance range. The default γ value can be 0.9.
[0086] Based on an example, applying S in WASM GD As the basic optimizer, at this point... and The functional expression can be found in Table 2, and Algorithm 2 of WASM in Table 3 is further refined into Algorithm 3 in Table 4 below.
[0087] Table 4
[0088]
[0089] It should be noted that this step employs a weight separation (or weight decoupling) technique, meaning that the sharpness term... Instead of being integrated into the basic optimizer for calculating gradients and updating parameters, the regularization term is calculated separately. In this way, the regularization term simply reflects the sharpness of the current step without adding any additional information. For comparison, Algorithm 4 in Table 5 below shows a WSAM scheme that uses weight coupling instead of weight separation. It should be noted that unless otherwise emphasized, the WSAM scheme (or optimizer) mentioned in this paper refers to the WSAM scheme (or optimizer) that uses weight separation.
[0090] Table 5
[0091]
[0092] Assuming that S is used in the weighted coupled WSAM scheme GD With M as the base optimizer, the regularization term in this scheme is an exponentially increasing sharpness moving average. In contrast, the WSAM scheme, which employs weight separation technology, further improves the model's generalization performance.
[0093] From the above, we can obtain the third training gradient g′. t .
[0094] In step S250, based on the preset learning rate α t and the third training gradient g′ t Update the first model parameter w t .
[0095] It should be understood that the learning rate used in each iteration can be the same or different. For example, this step can use the following formula for w. t Update:
[0096] w t+1 =w t -α t *g′ t (10)
[0097] Therefore, it is possible to control the current model parameters w of the image processing model. t Update it. Furthermore, by adopting... Figure 2 The method shown performs multiple rounds of iterative updates on the image processing model until the model reaches the convergence criterion, thus obtaining a well-trained image processing model.
[0098] This specification also provides experimental data demonstrating the effectiveness of the WSAM scheme in the embodiments. Table 6 below shows the top-1 error rate of the maximum probability prediction results, involving ResNet18 and WRN-28-10 as image processing models, Cifar10 and Cifar100 as image datasets, and S... GD M, SAM, ESAM, GSAM, and WSAM are used as optimizers. Vanilla in Table 6 represents the standard training without sharpness perception.
[0099] Table 6
[0100]
[0101] According to the experimental error rate statistics in Table 6, the error rate of the WSAM scheme is consistently the lowest. This indicates that the WSAM scheme can effectively improve the generalization and prediction accuracy of the image processing model.
[0102] It should also be noted that the WSAM scheme without weight separation, i.e., weight coupling, is also a new proposal from the applicant. In the weight coupling WSAM scheme, in step S230, h can be calculated using the formula in line 6 of the algorithm 4 above. t , as the third training gradient g′ t It's important to understand that the formula in line 6 can be derived from the first training gradient. and gradient difference This is derived from a weighted summation transformation. Furthermore, in step S240, lines 7-8 of Algorithm 4 above can be used to update the first model parameters w. t Specifically, first, assign t third training gradients {h1,...,h} corresponding to t training epochs. t Enter the preset first function φ respectively. t Second function ψ t In this context, the first vector m is obtained. t Second matrix B t Then use the first model parameter w t Subtract the preset learning rate α t The first vector m t Second matrix B t The product between them is used as the updated first model parameter w. t+1 .
[0103] The above mainly introduces the application of the WSAM optimizer in image processing scenarios for model training. In fact, it can also be applied to other business scenarios, such as text prediction. Therefore, this specification also discloses a method for training a prediction model. Specifically, Figure 3 This is a schematic diagram of the training method for the prediction model disclosed in the embodiments of this specification, wherein the prediction model is used to perform the prediction task. It should be understood that the prediction model can be implemented using any neural network algorithm, such as CNN or DNN; in addition, the execution entity of the method can be any device, server, platform or device cluster with computing and processing capabilities.
[0104] Figure 3 The method shown involves training a prediction model through multiple rounds of iterations, where any one round of iterations includes the following steps:
[0105] Step S310: Using the current batch of training samples, determine the first training gradient of the prediction model at its current first model parameters; Step S320: Based on the first training gradient, determine the parameter change amount that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius; Step S330: Determine the second training gradient of the prediction model at the second model parameters, wherein the second model parameters are obtained based on the first model parameters offset by the parameter change amount; Step S340: Perform a weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient to obtain a third training gradient; Step S350: Update the first model parameters based on the preset learning rate and the third training gradient.
[0106] The steps above are explained in detail below:
[0107] First, in step S310, the first training gradient of the prediction model at its current first model parameters is determined using the current batch of training samples.
[0108] In one implementation, the prediction model is used to make predictions for business objects, and the current batch of training samples is obtained by sampling a training sample set constructed for the business objects.
[0109] In one embodiment, the business object is text; correspondingly, the training sample set is a text set, the prediction model is a text processing model, and each text in the text set has a corresponding text label, such as a text classification label. In a specific embodiment, the text is the text content of a user's evaluation of a product on an e-commerce platform. In this case, the text classification label can be a positive evaluation, a neutral evaluation, or a negative evaluation.
[0110] In another embodiment, the business object is audio; correspondingly, the training sample set is an audio set, the prediction model is an audio processing model, and each audio track in the audio set has a corresponding audio tag, such as an audio category tag. Furthermore, in a voiceprint recognition scenario, each audio track can be a recording of a user's speech, and the audio tag can be the user's identity identifier.
[0111] On the other hand, in one embodiment, the business object is the user; correspondingly, the training sample set is the user dataset, the prediction model is the user prediction model, and each user sample in the user dataset has a corresponding user category label. It should be noted that all user-related data mentioned in this document were collected after the user confirmed and authorized the data. Furthermore, in a risk control scenario, each user sample can include the user's static attributes (such as address, IP address, etc.) and the user's dynamic behavioral characteristics. Dynamic behavioral characteristics include network behavioral characteristics, such as social activity, daily login frequency on online platforms, daily transaction count, and daily payment amount. Correspondingly, user labels can be user risk labels, for example, risky or risk-free, or low-risk or high-risk.
[0112] In another embodiment, the business object is a product, and correspondingly, the training sample set is a product dataset, the prediction model is a product prediction model, and each product sample in the product dataset has a corresponding product category label.
[0113] In another embodiment, the business object is an event; correspondingly, the training sample set is an event dataset, the prediction model is an event prediction model, and each event sample in the event dataset has a corresponding event category label. In a specific embodiment, the event can be a network-based transaction event, payment event, or login event, etc. In one example, the event characteristics of a transaction event include IP address, transaction amount, transacting party information, transaction frequency, etc., and the event label of the transaction event is normal transaction or risky transaction.
[0114] It should be noted that the description of step S310 can also be found in the description of step S210.
[0115] Then, for the description of steps S320, S330, S340 and S350, please refer to the foregoing introduction of steps S220, S230, S240 and S250, which will not be repeated here.
[0116] In summary, the training method for the prediction model disclosed in the embodiments of this specification can effectively improve the generalization performance of the trained prediction model and increase the accuracy of the model's predictions.
[0117] Corresponding to the training methods described above, the embodiments of this specification also disclose training devices. Figure 4 This is a schematic diagram of the training device structure for the image processing model disclosed in the embodiments of this specification. This training device is used to perform any one of the iterations in a multi-round iterative training of the image processing model. Figure 4 As shown, the training device 400 includes the following units:
[0118] The first gradient determination unit 410 is configured to determine the first training gradient of the image processing model at its current first model parameters using the current batch of image samples. The parameter change determination unit 420 is configured to determine, based on the first training gradient, the parameter change that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius. The second gradient determination unit 430 is configured to determine the second training gradient of the image processing model at the second model parameters, where the second model parameters are obtained based on the first model parameters offset by the parameter change. The third gradient determination unit 440 is configured to perform a weighted summation of the first training gradient and the gradient difference between the second and first training gradients to obtain a third training gradient. The parameter update unit 450 is configured to update the first model parameters based on a preset learning rate and the third training gradient.
[0119] In one embodiment, the first gradient determination unit 410 is specifically configured to: input each image sample in the current batch of image samples into the image processing model to obtain the corresponding image processing result, and use the image processing result, the sample label corresponding to the image sample, and the first model parameters as the first input of the preset gradient calculation formula to obtain the corresponding first gradient; calculate the average value of the first gradient corresponding to the current batch of image samples as the first training gradient.
[0120] In a specific embodiment, the second gradient determination unit 430 is specifically configured to: for each image sample, use the image processing result, the sample label and the second model parameters as the second input of the preset gradient calculation formula to obtain the corresponding second gradient; calculate the average value of the second gradient corresponding to the current batch of image samples as the second training gradient.
[0121] In one embodiment, the parameter change determination unit 420 is specifically configured to: calculate the product between the preset radius and the unit vector of the first training gradient as the parameter change.
[0122] In one embodiment, the parameter change determination unit 420 is specifically configured to: calculate the first training gradient and the ratio between the magnitude of the first training gradient and the sum of the numerical stability terms; calculate the product between the ratio and the preset radius as the parameter change.
[0123] In one embodiment, the third gradient determination unit 440 is specifically configured to: use pre-set weights to perform a weighted summation of the first training gradient and the gradient difference to obtain the third training gradient.
[0124] In one embodiment, the current training round is the t-th training round; the third gradient determination unit 440 is specifically configured to: perform a weighted summation of the first training gradient determined in the current t-th training round, the t-1 first training gradients obtained in the previous t-1 training rounds, and the difference, to obtain the third training gradient.
[0125] In a specific embodiment, the third gradient determination unit 440 is further configured to: input the t first training gradients corresponding to t training rounds into a preset first function and a second function respectively to obtain a first vector and a second matrix; sum the product between the first vector and the second matrix and the result of weighting the gradient difference using preset weighting coefficients to obtain the third training gradient.
[0126] In one embodiment, the current training round is the t-th training round; the parameter update unit 450 is specifically configured as follows: the t third training gradients corresponding to the t training rounds are respectively input into the preset first function and the second function to obtain the first vector and the second matrix; the first model parameters are used to subtract the preset learning rate and the product between the first vector and the second matrix as the updated first model parameters.
[0127] In one embodiment, the parameter update unit 450 is specifically configured to: use the first model parameters minus the product between the preset learning rate and the third training gradient as the updated first model parameters.
[0128] Figure 5 This is a schematic diagram of the training device structure for the prediction model disclosed in the embodiments of this specification, wherein the prediction model is used to perform a prediction task, and the training device is used to perform any one of the multiple iterations of training on the prediction model. Figure 5 As shown, the training device 500 includes:
[0129] The first gradient determination unit 510 is configured to determine the first training gradient of the prediction model at its current first model parameters using the current batch of training samples. The parameter change determination unit 520 is configured to determine, based on the first training gradient, the parameter change that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius. The second gradient determination unit 530 is configured to determine the second training gradient of the prediction model at the second model parameters, where the second model parameters are obtained based on the first model parameters offset by the parameter change. The third gradient determination unit 540 is configured to perform a weighted summation of the first training gradient and the gradient difference between the second and first training gradients to obtain a third training gradient. The parameter update unit 550 is configured to update the first model parameters based on a preset learning rate and the third training gradient.
[0130] In one embodiment, the prediction model is used to make predictions for a business object, which is text or audio.
[0131] In one embodiment, the prediction model is used to make predictions for a business object, which is a user, a product, or an event.
[0132] In one embodiment, the first gradient determination unit 510 is specifically configured to: input each training sample in the current batch of training samples into the prediction model to obtain the corresponding prediction result, and use the prediction result, the sample label corresponding to the training sample, and the first model parameters as the first input of the preset gradient calculation formula to obtain the corresponding first gradient; calculate the average value of the first gradient corresponding to the current batch of training samples as the first training gradient.
[0133] In a specific embodiment, the second gradient determination unit 530 is specifically configured to: for each training sample, use the prediction result, the sample label and the second model parameters as the second input of the preset gradient calculation formula to obtain the corresponding second gradient; calculate the average value of the second gradient corresponding to the current batch of training samples as the second training gradient.
[0134] In one embodiment, the parameter change determination unit 520 is specifically configured to: calculate the product between the preset radius and the unit vector of the first training gradient as the parameter change.
[0135] In one embodiment, the parameter change determination unit 520 is specifically configured to: calculate the first training gradient and the ratio between the magnitude of the first training gradient and the sum of the numerical stability terms; calculate the product between the ratio and the preset radius as the parameter change.
[0136] In one embodiment, the third gradient determination unit 540 is specifically configured to: use pre-set weights to perform a weighted summation of the first training gradient and the gradient difference to obtain the third training gradient.
[0137] In one embodiment, the current training round is the t-th training round; the third gradient determination unit 440 is specifically configured to: perform a weighted summation of the first training gradient determined in the current t-th training round, the t-1 first training gradients obtained in the previous t-1 training rounds, and the difference, to obtain the third training gradient.
[0138] In a specific embodiment, the third gradient determination unit 540 is further configured to: input the t first training gradients corresponding to t training rounds into a preset first function and a second function respectively to obtain a first vector and a second matrix; sum the product between the first vector and the second matrix and the result of weighting the gradient difference using preset weighting coefficients to obtain the third training gradient.
[0139] In one embodiment, the current training round is the t-th training round; the parameter update unit 450 is specifically configured as follows: the t third training gradients corresponding to the t training rounds are respectively input into the preset first function and the second function to obtain the first vector and the second matrix; the first model parameters are used to subtract the preset learning rate and the product between the first vector and the second matrix as the updated first model parameters.
[0140] In one embodiment, the parameter update unit 550 is specifically configured to: subtract the product between the preset learning rate and the third training gradient from the first model parameters to obtain the updated first model parameters.
[0141] According to another embodiment, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed in a computer, causes the computer to perform a combination Figure 2 or Figure 3 The method described.
[0142] According to another embodiment, a computing device is also provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it implements a combination... Figure 2 or Figure 3 The method described.
[0143] Those skilled in the art will recognize that, in one or more of the examples above, the functions described in this invention can be implemented using hardware, software, firmware, or any combination thereof. When implemented in software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium.
[0144] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solution of the present invention should be included within the scope of protection of the present invention.
Claims
1. A training method for an image processing model, involving multiple rounds of iterative training of the image processing model, wherein any round of iterative training includes: Using the current batch of image samples, the first training gradient of the image processing model at its current first model parameters is determined, specifically including: inputting each image sample into the image processing model to obtain the corresponding image processing result, and determining the first training gradient based on the image processing result, the corresponding sample label, and the first model parameters; Based on the first training gradient, determine the parameter change amount that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius. Determine the second training gradient of the image processing model at the second model parameters, the second model parameters being obtained based on the first model parameters offset by the parameter change; The third training gradient is obtained by weighted summing of the first training gradient and the gradient difference between the second training gradient and the first training gradient. The parameters of the first model are updated based on the preset learning rate and the third training gradient.
2. The method according to claim 1, wherein, Determining the first training gradient based on the image processing results and corresponding sample labels, as well as the first model parameters, includes: The image processing result, the corresponding sample label, and the first model parameters are used as the first input to the preset gradient calculation formula to obtain the corresponding first gradient. Calculate the average value of the first gradient corresponding to the current batch of image samples, and use it as the first training gradient.
3. The method according to claim 2, wherein, Determining the second training gradient of the image processing model at the second model parameters includes: For each image sample, the image processing result, the sample label, and the second model parameters are used as the second input to the preset gradient calculation formula to obtain the corresponding second gradient; Calculate the average value of the second gradient corresponding to the current batch of image samples, and use it as the second training gradient.
4. The method according to claim 1, wherein, Based on the first training gradient, determine the parameter change amount that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius, including: The product between the preset radius and the unit vector of the first training gradient is calculated as the parameter change.
5. The method according to claim 1, wherein, Based on the first training gradient, determine the parameter change amount that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius, including: Calculate the first training gradient, and the ratio of the magnitude of the first training gradient to the sum of the values of the numerically stable terms; Calculate the product between the ratio and the preset radius, and use it as the parameter change.
6. The method according to claim 1, wherein, The third training gradient is obtained by weighted summing of the first training gradient and the gradient difference between the second and first training gradients, including: Using pre-set weights, the first training gradient and the gradient difference are weighted and summed to obtain the third training gradient.
7. The method according to claim 1, wherein, The current training epoch is the t-th training epoch; wherein, the third training gradient is obtained by weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient, including: The third training gradient is obtained by weighted summing of the first training gradient determined in the current t-th training round, the t-1 first training gradients obtained in the previous t-1 training rounds, and the difference.
8. The method according to claim 7, wherein, The third training gradient is obtained by: Input the t first training gradients corresponding to the t training rounds into the preset first function and second function respectively to obtain the first vector and the second matrix; The third training gradient is obtained by summing the product between the first vector and the second matrix, and the result of weighting the gradient difference using preset weighting coefficients.
9. The method according to claim 1, wherein, The current training round is the t-th training round; Based on the preset learning rate and the third training gradient, the parameters of the first model are updated, including: Input the t third training gradients corresponding to the t training rounds into the preset first function and second function respectively to obtain the first vector and the second matrix; The first model parameters are updated by subtracting the preset learning rate, the product of the first vector and the second matrix from the first model parameters.
10. The method according to claim 1, wherein, Based on the preset learning rate and the third training gradient, the parameters of the first model are updated, including: The first model parameters are updated by subtracting the product between the preset learning rate and the third training gradient from the first model parameters.
11. A method for training a prediction model, wherein the prediction model is used to perform a prediction task for a business object, said business object being text or audio; The method involves multiple rounds of iterative training of the prediction model, wherein any round of iterative training includes: Using the current batch of training samples, the first training gradient of the prediction model at its current first model parameters is determined, specifically including: inputting each training sample into the prediction model to obtain the corresponding prediction result, and determining the first training gradient based on the prediction result, the corresponding sample label, and the first model parameters. Based on the first training gradient, determine the parameter change amount that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius. Determine the second training gradient of the prediction model at the second model parameters, the second model parameters being obtained based on the first model parameters offset by the parameter change; The third training gradient is obtained by weighted summing of the first training gradient and the gradient difference between the second training gradient and the first training gradient. The parameters of the first model are updated based on the preset learning rate and the third training gradient.
12. A training apparatus for an image processing model, the training apparatus performing any one of the iterations in a multi-round iterative training of the image processing model via the following units: The first gradient determination unit is configured to determine the first training gradient of the image processing model at its current first model parameters using the current batch of image samples, specifically including: Each image sample is input into the image processing model to obtain the corresponding image processing result. The first training gradient is determined based on the image processing result, the corresponding sample label, and the first model parameters. The parameter change determination unit is configured to determine, based on the first training gradient, the parameter change that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius. The second gradient determination unit is configured to determine the second training gradient of the image processing model at the second model parameters, wherein the second model parameters are obtained based on the first model parameters offset by the parameter change amount; The third gradient determination unit is configured to perform a weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient to obtain the third training gradient. The parameter update unit is configured to update the parameters of the first model based on the preset learning rate and the third training gradient.
13. A training apparatus for a prediction model, wherein the prediction model is used to perform a prediction task for a business object, said business object being text or audio; the training apparatus performs any one round of iterative training in a multi-round iterative training of the prediction model through the following units: The first gradient determination unit is configured to determine the first training gradient of the prediction model at its current first model parameters using the current batch of training samples, specifically including: Each training sample is input into the prediction model to obtain the corresponding prediction result, and the first training gradient is determined based on the prediction result, the corresponding sample label, and the first model parameters. The parameter change determination unit is configured to determine, based on the first training gradient, the parameter change that causes the maximum change in the current training loss within a neighborhood centered on the first model parameters and having a preset radius. The second gradient determination unit is configured to determine the second training gradient of the prediction model at the second model parameters, wherein the second model parameters are obtained based on the first model parameters offset by the parameter change amount; The third gradient determination unit is configured to perform a weighted summation of the first training gradient and the gradient difference between the second training gradient and the first training gradient to obtain the third training gradient. The parameter update unit is configured to update the parameters of the first model based on the preset learning rate and the third training gradient.
14. A computer-readable storage medium having a computer program stored thereon, wherein, When the computer program is executed in the computer, it causes the computer to perform the method according to any one of claims 1-11.
15. A computing device comprising a memory and a processor, wherein, The memory stores executable code, and when the processor executes the executable code, it implements the method of any one of claims 1-11.
Citation Information
Patent Citations
Training method and device of service prediction system
CN113902473A
Non-independent identically distributed federal learning performance optimization method based on local model offset
CN116011585A