Quantization neural network fault tolerance enhancement method based on weight elastic mapping
By calculating the weight perturbation elasticity of the quantized neural network model and determining the weight mapping parameters, the problem of the quantized neural network being vulnerable to bit flip attacks in embedded devices is solved, the fault tolerance is improved and the error rate is reduced, and it is suitable for computers with embedded devices Vision applications.
Patent Information
- Application Number
- CN202410754226.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-06-12
AI Technical Summary
Quantitative neural networks are vulnerable to bit flip attacks in embedded devices, resulting in high error rates. Existing fault-tolerance enhancement technologies are costly and lack universality, and cannot effectively analyze weight perturbation elasticity, resulting in reduced model performance.
By calculating the weight perturbation elasticity of the quantized neural network model, the weight mapping parameters and functions are determined, and weight mapping is performed to limit the numerical range and improve the model's fault tolerance.
The fault tolerance of quantized neural networks is improved, the error rate is reduced, and it is suitable for computer vision applications of embedded devices without adding additional overhead.
Smart Images

Figure CN118586468A
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of network security, and in particular relates to a quantized neural network fault tolerance enhancement method based on weight elastic mapping. Background Art
[0002] Quantized neural networks (QDNN) are deployed in embedded devices, making deep learning widely used in various fields, such as computer vision-based applications. These programs mainly complete the classification task of input samples, that is, for an input image, after inference by the quantitative neural network model, it can output the category it belongs to in a very short time. Errors in quantitative neural networks can cause incalculable consequences and pose a huge threat to human life and property safety.
[0003] Resource-constrained embedded devices lack sufficient resources to ensure the implementation of data integrity checking mechanisms and therefore cannot provide adequate security protection, which is a huge challenge to system security. The inherent fault tolerance of quantized neural networks cannot resist hardware failures. Under more adverse environmental conditions of mobile and embedded systems, the error rate of these devices may be higher due to soft errors caused by manufacturing variability, aging, increased temperature gradients, and radiation. Quantized neural networks are also vulnerable to fault injection techniques, the most typical of which is the bit flip attack (BFA). The progressive search bit flip attack (PBFA) can completely destroy the performance of quantized neural networks with only a few attacks.
[0004] Fault-tolerance enhancement technology is divided into software and hardware levels. Fault-tolerance enhancement technology at the hardware level will bring high hardware costs, and it is difficult to adapt to every hardware device, and it is not universal. Fault-tolerance enhancement technology at the software level can be deployed on different hardware, with lower costs and stronger practicality.
[0005] Existing research reduces the impact of weight disturbances and increases the tolerance threshold of weight errors by limiting the range of weight changes. First, the weight change value is propagated to other weights in its group through averaging operations, and then the average value is clipped to different quantization levels to further reduce the weight changes caused by bit flipping. Finally, training and fine-tuning are performed to improve the accuracy of the model. This shows that limiting the range of weight numerical representation helps improve the fault tolerance of quantized neural network models.
[0006] Then the above method needs to use retraining and fine-tuning, which will bring huge time costs, and the performance of the model will inevitably decline. This is because this method lacks analysis of the elasticity of weight perturbations, and can only use an average method to limit the weight range, but cannot obtain accurate results. Considering that the quantized neural network model has its inherent fault tolerance and can tolerate a certain degree of weight errors, analyzing the elasticity of weight perturbations and limiting the elastic range of weights can effectively improve the fault tolerance of the model. Summary of the invention
[0007] In order to solve the above technical problems, the present invention provides a quantized neural network fault tolerance enhancement method based on weight elastic mapping, which solves the problem that computer vision applications based on quantized neural networks deployed in embedded devices are subject to bit flipping attacks and errors occur.
[0008] The technical solution adopted by the present invention is: a quantized neural network fault tolerance enhancement method based on weight elastic mapping, and the specific steps are as follows:
[0009] S1, select an image dataset to calculate the weight perturbation elasticity of the quantized neural network model;
[0010] S2. Calculate the weight mapping parameters based on the quantization bit width selected in the actual application and the weight perturbation elasticity calculated in step S1;
[0011] S3. Determine a weight mapping function according to the weight disturbance elasticity and the weight mapping parameter;
[0012] S4. During the operation of the network model, the weights are calculated according to the weight mapping function, and the calculated weight parameters are used for reasoning to complete fault tolerance enhancement.
[0013] Furthermore, the step S1 is specifically as follows:
[0014] S11, load the image dataset and quantized neural network model, and confirm the type of image classification task;
[0015] Among them, the types of image classification tasks include: binary classification and multi-classification.
[0016] S12, loading an input data in the image data set, performing model inference, and recording the correct result of the model inference;
[0017] Select an image dataset to input into the quantized neural network model, input one data at a time for inference, calculate the perturbation, add the perturbation to the weight parameters, and record the accumulated perturbation, and repeat the inference of this data until the classification result changes.
[0018] The quantized neural network model is deployed in an embedded device, and its computer vision application is used for the classification task of input samples, that is, for an input image data, after inference by the neural network model, the category to which it should belong is output.
[0019] S13, determine the type of image classification task, if it is a multi-classification task, go to step S14, if it is a binary classification task, go to step S15;
[0020] S14. For each different classification, calculate the classification plane with the closest distance. The calculation expression is as follows:
[0021]
[0022] in, represents the weight parameter in the initial i-th iteration, I represents the classification plane, represents the weight gradient, f represents the inference result, and f i (·) represents the i-th classification result, c represents the correct classification, j represents an incorrect classification, x represents the input data, and b represents the bias parameter.
[0023] S15, calculating weight disturbance;
[0024] Under the binary classification, calculate and record the distance from the weight parameter to the boundary of the binary classification weight space. The expression is as follows:
[0025]
[0026] Among them, ε i represents the perturbation of the i-th iteration, represents the weight gradient, Indicates the classification result.
[0027] Under multiple classifications, the perturbation to classification plane I is calculated and recorded. The expression is as follows:
[0028]
[0029] Among them, f I represents the result of classification under plane I, Represents the corresponding weight gradient.
[0030] S16, the disturbance ε i Add to the weight parameter and update the weight parameter;
[0031] S17, use the updated weight parameters after adding disturbance to perform reasoning again, and compare with the initial correct reasoning result. If the results are consistent, go to step S13; if the results are different, go to step S18;
[0032] S18, accumulating the recorded disturbances Obtain and record the weight perturbation elasticity, and determine whether all the data in the image data set have been inferred. If not, go to step S12 to perform the next data calculation, otherwise go to step S19;
[0033] S19. After inputting all the data in the image data set, the weight perturbation elasticity of each data is calculated, and the minimum value of the weight perturbation elasticity of each layer of weight parameters is taken to obtain the weight perturbation elasticity ε of each layer.
[0034] Furthermore, the step S2 is specifically as follows:
[0035] S21, calculating the quantization bit width range;
[0036] Confirm the quantization bit width to be selected. The expression is as follows:
[0037]
[0038] in, Indicates the weight under the selected quantization bit width, range min Indicates the minimum value of the range, range max Indicates the maximum value of the range.
[0039] S22, confirm the weight elasticity range;
[0040] The weight elasticity range is calculated based on the weight perturbation elasticity and the original weight, and the expression is as follows:
[0041]
[0042] in, represents the weight parameter after mapping, W represents the original correct weight parameter, Represents the tolerable weight.
[0043] S23, calculating two weight mapping parameters required by the weight mapping function;
[0044]
[0045] Among them, λ and μ represent weight mapping parameters.
[0046] Furthermore, the step S3 is specifically as follows:
[0047] The weight perturbation elasticity is obtained, and the weight parameter range for maintaining the accuracy of the model is obtained. The weight mapping function expression is as follows:
[0048]
[0049] After the weight mapping parameters are calculated based on step S2, the weight mapping function expression is rewritten as follows:
[0050]
[0051] Furthermore, the step S4 is specifically as follows:
[0052] S41, calculating the mapped weight based on the weight mapping function obtained in step S3;
[0053] S42, judging whether the mapping result is less than the maximum value of the quantization bit width range, if so, go to step S43, if so, go to step S44;
[0054] S43, the mapping result is truncated and rounded as a weight parameter;
[0055] S44, taking the maximum value of the quantization bit width as a weight parameter;
[0056] S45. Based on the weight parameters obtained in steps S41-S44, reasoning is performed to complete fault tolerance enhancement.
[0057] Beneficial effects of the present invention: The method of the present invention first uses the image data set involved to calculate the weight perturbation elasticity of the quantized neural network model, then calculates the weight mapping parameters based on the selected quantization bit width and weight perturbation elasticity range, and finally determines the weight mapping function according to the weight perturbation elasticity and the weight mapping parameters, and performs weight mapping during the inference process to improve the model's fault tolerance. The method of the present invention uses mapping calculation to limit the numerical range of weights based on the weight perturbation elasticity of the quantized neural network model, thereby avoiding numerical changes, protecting the correctness of the quantized neural network, improving the model's fault tolerance, and achieving fault tolerance enhancement of the neural network. It is suitable for enhancing the fault tolerance of computer vision applications based on quantized neural network models for embedded devices, and does not cause too much additional overhead during operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 The present invention is a flow chart of a method for enhancing fault tolerance of a quantized neural network based on weight elastic mapping.
[0059] Figure 2 The figure is a flow chart of weight perturbation elasticity calculation in an embodiment of the present invention.
[0060] Figure 3 The figure is a flow chart of weight mapping parameter calculation in an embodiment of the present invention.
[0061] Figure 4 The figure is a flow chart of weight mapping function calculation in an embodiment of the present invention. DETAILED DESCRIPTION
[0062] The method of the present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0063] like Figure 1 As shown, a flow chart of a quantized neural network fault tolerance enhancement method based on weight elastic mapping of the present invention, the specific steps are as follows:
[0064] S1, select an image dataset to calculate the weight perturbation elasticity of the quantized neural network model;
[0065] S2. Calculate the weight mapping parameters based on the quantization bit width selected in the actual application and the weight perturbation elasticity calculated in step S1;
[0066] S3. Determine a weight mapping function according to the weight disturbance elasticity and the weight mapping parameter;
[0067] S4. During the operation of the network model, the weights are calculated according to the weight mapping function, and the calculated weight parameters are used for reasoning to complete fault tolerance enhancement.
[0068] Weight perturbation elasticity reflects the inherent fault tolerance of the quantitative neural network model. Within this elastic range, model errors will not affect the final results. Outside this elastic range, errors in weight parameters will lead to errors in the results.
[0069] Calculation of weight perturbation elasticity: Image classification tasks are divided into binary classification and multi-classification. From the perspective of high-dimensional space, they are manifested as different weight space boundaries. The weight parameters are in the correct space. If the perturbation causes them to cross the weight space boundary, the classification result will be wrong. The weight parameters of the model cannot tolerate this disturbance. Therefore, the relationship between the weight parameters and the classification results is established. By calculating the distance from the weight parameters to the weight space boundary, the weight perturbation elasticity can be calculated.
[0070] like Figure 2 As shown, in this embodiment, the step S1 is specifically as follows:
[0071] S11, load the image dataset and quantized neural network model, and confirm the type of image classification task;
[0072] The types of image classification tasks include: binary classification and multi-classification. Binary classification and multi-classification use different weight perturbation elasticity calculation methods.
[0073] S12, loading an input data in the image data set, performing model inference, and recording the correct result of the model inference;
[0074] Select an image dataset to input into the quantized neural network model, input one data at a time for inference, calculate the perturbation, add the perturbation to the weight parameters, and record the accumulated perturbation, and repeat the inference of this data until the classification result changes.
[0075] The quantized neural network model is deployed in an embedded device, and its computer vision application is used for the classification task of input samples, that is, for an input image data, after inference by the neural network model, the category to which it should belong is output.
[0076] S13, determine the type of image classification task, if it is a multi-classification task, go to step S14, if it is a binary classification task, go to step S15;
[0077] S14. For each different classification, calculate the classification plane with the closest distance. The calculation expression is as follows:
[0078]
[0079] in, represents the weight parameter in the initial i-th iteration, I represents the classification plane, represents the weight gradient, f represents the inference result, and f i (·) represents the i-th classification result, c represents the correct classification, j represents an incorrect classification, x represents the input data, and b represents the bias parameter.
[0080] S15, calculating weight disturbance;
[0081] Under the binary classification, calculate and record the distance from the weight parameter to the boundary of the binary classification weight space. The expression is as follows:
[0082]
[0083] Among them, ε i represents the perturbation of the i-th iteration, represents the weight gradient, Indicates the classification result.
[0084] Under multiple classifications, the perturbation to classification plane I is calculated and recorded. The expression is as follows:
[0085]
[0086] Among them, f I represents the result of classification under plane I, Represents the corresponding weight gradient.
[0087] S16, the disturbance ε i Add to the weight parameter and update the weight parameter;
[0088] S17, use the updated weight parameters after adding disturbance to perform reasoning again, and compare with the initial correct reasoning result. If the results are consistent, go to step S13; if the results are different, go to step S18;
[0089] S18, accumulating the recorded disturbances Obtain and record the weight perturbation elasticity, and determine whether all the data in the image data set have been inferred. If not, go to step S12 to perform the next data calculation, otherwise go to step S19;
[0090] S19. After inputting all the data in the image dataset, the weight perturbation elasticity of each data is calculated, and the minimum value of the weight perturbation elasticity of each layer weight parameter (the fine-grainedness of each layer of the network) is taken to obtain the weight perturbation elasticity ε of each layer.
[0091] Weight mapping function calculation: After obtaining the weight perturbation elasticity, the weight parameter range of the model maintaining accuracy can be obtained, so the weight mapping function can be preliminarily established as This involves two parameters λ and μ, which are parameters that determine the range so that the final value is within the elasticity of the weight perturbations.
[0092] like Figure 3 As shown, in this embodiment, the step S2 is specifically as follows:
[0093] S21, calculating the quantization bit width range;
[0094] Confirm the quantization bit width to be selected (the quantization bit width determines the entire representation range of the weight parameter). The expression is as follows:
[0095]
[0096] in, Indicates the weight under the selected quantization bit width, range min Indicates the minimum value of the range, range max Indicates the maximum value of the range.
[0097] S22, confirm the weight elasticity range;
[0098] The weight elasticity range is calculated based on the weight perturbation elasticity and the original weight, and the expression is as follows:
[0099]
[0100] in, represents the weight parameter after mapping, W represents the original correct weight parameter, Represents the tolerable weight.
[0101] S23, calculating two weight mapping parameters required by the weight mapping function;
[0102]
[0103] Among them, λ and μ represent weight mapping parameters.
[0104] In this embodiment, step S3 is specifically as follows:
[0105] The weight perturbation elasticity is obtained, and the weight parameter range for maintaining the accuracy of the model is obtained. The weight mapping function expression is as follows:
[0106]
[0107] After the weight mapping parameters are calculated based on step S2, the weight mapping function expression is rewritten as follows:
[0108]
[0109] like Figure 4 As shown, in this embodiment, the step S4 is specifically as follows:
[0110] S41, calculating the mapped weight based on the weight mapping function obtained in step S3;
[0111] S42, judging whether the mapping result is less than the maximum value of the quantization bit width range, if so, go to step S43, if so, go to step S44;
[0112] S43, the mapping result is truncated and rounded as a weight parameter;
[0113] S44, taking the maximum value of the quantization bit width as a weight parameter;
[0114] S45. Based on the weight parameters obtained in steps S41-S44, reasoning is performed to complete fault tolerance enhancement.
[0115] In summary, the method of the present invention uses mapping calculation to limit the numerical range of weights according to the weight perturbation elasticity of the quantized neural network model, thereby avoiding numerical changes, protecting the correctness of the quantized neural network, improving the fault tolerance of the model, and achieving fault tolerance enhancement of the neural network. It is suitable for enhancing the fault tolerance of computer vision applications based on quantized neural network models for embedded devices, and will not cause too much additional overhead during operation.
[0116] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and should be understood that the scope of protection of the present invention is not limited to such specific statements and embodiments. For those skilled in the art, the present invention may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of the claims of the present invention.
Claims
1. A method for fault tolerance enhancement of quantized neural network based on weight elastic mapping, the specific steps are as follows: S1, select an image dataset to calculate the weight perturbation elasticity of the quantized neural network model; S2. Calculate the weight mapping parameters based on the quantization bit width selected in the actual application and the weight perturbation elasticity calculated in step S1; S3. Determine a weight mapping function according to the weight disturbance elasticity and the weight mapping parameter; S4. During the operation of the network model, the weights are calculated according to the weight mapping function, and the calculated weight parameters are used for reasoning to complete fault tolerance enhancement.
2. According to the method for enhancing fault tolerance of quantized neural network based on weight elastic mapping according to claim 1, it is characterized in that: The step S1 is specifically as follows: S11, load the image dataset and quantized neural network model, and confirm the type of image classification task; Among them, the types of image classification tasks include: binary classification and multi-classification; S12, loading an input data in the image data set, performing model inference, and recording the correct result of the model inference; Select an image dataset to input into the quantized neural network model, input one data at a time for inference, calculate the perturbation, add the perturbation to the weight parameter, and record the accumulated perturbation, and repeat the inference of this data until the classification result changes; The quantized neural network model is deployed in an embedded device, and its computer vision application is used for the classification task of input samples, that is, for an input image data, after inference by the neural network model, the category to which it should belong is output; S13, determine the type of image classification task, if it is a multi-classification task, go to step S14, if it is a binary classification task, go to step S15; S14. For each different classification, calculate the classification plane with the closest distance. The calculation expression is as follows: in, represents the weight parameter in the initial i-th iteration, I represents the classification plane, represents the weight gradient, f represents the inference result, and f i (·) represents the i-th classification result, c represents the correct classification, j represents an incorrect classification, x represents the input data, and b represents the bias parameter; S15, calculating weight disturbance; Under the binary classification, calculate and record the distance from the weight parameter to the boundary of the binary classification weight space. The expression is as follows: Among them, ε i represents the perturbation of the i-th iteration, represents the weight gradient, Indicates the classification result; Under multiple classifications, the perturbation to classification plane I is calculated and recorded. The expression is as follows: Among them, f I represents the result of classification under plane I, Represents the corresponding weight gradient; S16, the disturbance ε i Add to the weight parameter and update the weight parameter; S17, use the updated weight parameters after adding disturbance to perform reasoning again, and compare with the initial correct reasoning result. If the results are consistent, go to step S13; if the results are different, go to step S18; S18, accumulating the recorded disturbances Obtain and record the weight perturbation elasticity, and determine whether all the data in the image data set have been inferred. If not, go to step S12 to perform the next data calculation, otherwise go to step S19; S19. After inputting all the data in the image data set, the weight perturbation elasticity of each data is calculated, and the minimum value of the weight perturbation elasticity of each layer of weight parameters is taken to obtain the weight perturbation elasticity ε of each layer.
3. The method for enhancing fault tolerance of a quantized neural network based on weight elastic mapping according to claim 1, characterized in that: The step S2 is specifically as follows: S21, calculating the quantization bit width range; Confirm the quantization bit width to be selected. The expression is as follows: in, Indicates the weight under the selected quantization bit width, range min Indicates the minimum value of the range, range max Indicates the maximum value of the range; S22, confirm the weight elasticity range; The weight elasticity range is calculated based on the weight perturbation elasticity and the original weight, and the expression is as follows: in, represents the weight parameter after mapping, W represents the original correct weight parameter, represents the tolerable weight; S23, calculating two weight mapping parameters required by the weight mapping function; Among them, λ and μ represent weight mapping parameters.
4. The method for enhancing fault tolerance of a quantized neural network based on weight elastic mapping according to claim 1, characterized in that: The step S3 is specifically as follows: The weight perturbation elasticity is obtained, and the weight parameter range for maintaining the accuracy of the model is obtained. The weight mapping function expression is as follows: After the weight mapping parameters are calculated based on step S2, the weight mapping function expression is rewritten as follows:
5. The method for enhancing fault tolerance of a quantized neural network based on weight elastic mapping according to claim 1, characterized in that: The step S4 is specifically as follows: S41, calculating the mapped weight based on the weight mapping function obtained in step S3; S42, judging whether the mapping result is less than the maximum value of the quantization bit width range, if so, go to step S43, if so, go to step S44; S43, the mapping result is truncated and rounded as a weight parameter; S44, taking the maximum value of the quantization bit width as a weight parameter; S45. Based on the weight parameters obtained in steps S41-S44, reasoning is performed to complete fault tolerance enhancement.
Citation Information
Patent Citations
Neural network model fault tolerance enhancement method based on fine-grained error blocking
CN115860069A
Clustered neural networks
US5155801A
