Embedded neural network binarization quantization method and related equipment
By initializing the quantified parameter calculation and optimization of the convolutional layer input, output and weight of the neural network model, and converting them into integers for calculation, the problems of small application range and performance degradation of the existing binarization method are solved, and embedding is achieved. Efficient calculation and high-precision deployment on the formula side.
Patent Information
- Application Number
- CN202410861490.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-29
AI Technical Summary
The binary quantization method of the existing neural network model has the problems of small application range and significant performance decline. It lacks adaptive optimization of quantization parameters and a binarization method suitable for 0 and +1, and when deployed on the embedded side, Inverse quantization calculation performance is poor.
By selecting the image as the calibration set, the initial quantization parameters of the convolution layer input, output and weight are calculated, the weight quantization parameters are optimized, converted into integers for calculation, and the convolution operation is performed based on the converted parameters to obtain inverse quantization. Calculate the result.
It effectively reduces the information loss caused by integer reasoning, improves the computing performance of the neural network model on the embedded side, reduces the calculation amount and storage consumption of the model, and improves the calculation accuracy.
Smart Images

Figure CN118862979A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of neural network model calculation, and specifically relates to an embedded neural network binarization quantization method and related equipment. Background Art
[0002] The data type of the neural network algorithm is floating point. In order to deploy the neural network algorithm on an embedded device with limited computing resources and achieve efficient computing, the floating point neural network model needs to be quantized into an integer network. Binarized neural network quantizes the activation / weight of the neural network to 1 bit, that is, converts the activation / weight to -1(0) or +1, which can greatly reduce the storage and computing resource requirements of the neural network model and has important application prospects in the end-side inference scenario with limited computing resources. The existing binary quantization method of the neural network model has the following problems:
[0003] (1) When the activation / weight is quantized to 1 bit, the quantization parameters of the binary neural network are calculated by taking the average of the absolute values. The quantization parameters cannot be adaptively optimized. The existing dynamic parameter generation method is only for the activation layer parameters of the binary neural network, and lacks an automatic adjustment method for the quantization parameters.
[0004] (2) Existing binarization methods are only applicable to binarizing data into -1 and +1, and lack methods for binarizing data into 0 and +1, which limits the application scope of binarization neural networks;
[0005] (3) Existing methods focus on how to train binary networks. When deployed on the embedded side, they only migrate from 8-bit inverse quantization calculation process to 1-bit, resulting in a significant drop in performance. There is a lack of effective methods for integer inference binary models on the embedded side. Summary of the invention
[0006] The present invention provides an embedded neural network binarization quantization method and related equipment, which solves the problem that the existing binarization method has a small application range and causes a significant decrease in performance.
[0007] To achieve the above object, the present invention provides the following technical solutions:
[0008] An embedded neural network binarization quantization method, comprising:
[0009] Select several images as the calibration set as the input of the convolution layer and obtain the output of the convolution layer;
[0010] Calculate the initialization quantization parameters for the convolution layer input, output and weights;
[0011] Optimize the initialization weight quantization parameters;
[0012] The convolution layer input is converted into an integer according to the convolution layer input quantization parameter, the weight is converted into an integer according to the optimized weight quantization parameter, the dequantization calculation parameter is obtained according to the initialized convolution layer input quantization parameter, the output quantization parameter and the optimized weight quantization parameter, convolution is performed based on the convolution layer input converted to integer and the convolution layer weight to obtain the calculation result, and then the dequantization calculation is performed according to the calculation result to obtain the final output.
[0013] Preferably, the initialization quantization parameter calculation for the convolution layer input and output is specifically performed as follows:
[0014] The maximum value threshold of the convolution layer input is obtained as max in , the minimum input threshold is min in , the maximum output threshold is max out , the minimum output threshold is min out , if max and min are both positive, set min = 0; if max and min are both negative, set max = 0, and calculate the initial quantization parameters s for input and output in , D in 、s out , D out ;
[0015] bw in 、bw out are the bit widths of input and output respectively;
[0016] Calculate the initial quantization parameters s for input and output in , D in 、s out , D out The process is:
[0017] bw in When it is not 1,
[0018] bw in =1, when it is binarized to -1 and +1, s in = the average of the absolute values of the input data;
[0019] bw in =1, when it is converted to 0 and +1, s in = the average of the positive values of the input data;
[0020] bw in When it is not 1,
[0021] bw in =1, D in =0;
[0022] bw outWhen it is not 1,
[0023] bw out =1, when it is binarized to -1 and +1, s out = the average value of the absolute value of the output data;
[0024] bw out =1, when it is converted to 0 and +1, s out = the average value of the positive values of the output data;
[0025] bw out When it is not 1,
[0026] bw out =1, D out =0 (13).
[0027] Preferably, the weight initialization quantization parameter calculation is specifically as follows:
[0028] The maximum absolute value of the weight is taken as the threshold, and the quantization parameter s of the weight is calculated. w , bw w is the bit width of the weight;
[0029] When bww is not 1,
[0030] bw w =1, when it is binarized to -1 and +1, s w = average of the absolute values of weights;
[0031] bw w =1, when it is converted to 0 and +1, s w =The average value of the positive weights.
[0032] Preferably, the optimization of the initialization weight quantization parameter is specifically as follows:
[0033]
[0034] Among them, ceil is the upward rounding function, s in is the input quantization parameter, s out is the output quantization parameter, s w is the quantization parameter of the weight.
[0035] Preferably, the convolutional layer input and convolutional layer weights are converted to integers as follows:
[0036] For floating point input float According to the input threshold, the floating-point input and weight are converted into integer input in Integerand weight w Integer , where MAX is the maximum value operation and MIN is the minimum value operation;
[0037] bw in When not 1: input float =MAX(MIN(input float , max in ), min in );
[0038] bw in When not 1:
[0039] bw in =1, or
[0040] bw w When not 1:
[0041] bw w =1, or
[0042] Preferably, the dequantization calculation parameters are obtained according to the initialized convolution layer input quantization parameter, output quantization parameter and optimized weight quantization parameter:
[0043] The inverse quantization calculation parameters include shift parameters, multiplication parameters and addition parameters. The calculation methods of shift parameters, multiplication parameters and addition parameters are as follows:
[0044]
[0045]
[0046] The floating-point bias of the convolutional layer float Convert to add parameters and modify bias float Bias new float;
[0047] Bias_new_float = bias float +D in ·∑w float ;
[0048]
[0049] Among them, ∑w float To sum the convolution kernels in units of output channels, that is, to calculate as many ∑w as there are output channels float value;
[0050] Among them, s in is the input quantization parameter, s out is the output quantization parameter, s w is the quantization parameter of the optimized weight, MAX is the maximum value operation, and MIN is the minimum value operation.
[0051] Preferably, convolution is performed based on the convolution layer input converted to integer and the convolution layer weight to obtain a calculation result, and then a dequantization calculation is performed based on the calculation result to obtain the final output, which is specifically:
[0052]
[0053] Among them, Integer is the convolution layer input converted to integer, w Integer The convolutional layer output converted to integer;
[0054] bw out When it is not 1,
[0055] bw out =1, or
[0056] An embedded neural network binarization quantization system, comprising:
[0057] Input module: used to select several images as calibration sets, as input of the convolution layer, and obtain the output of the convolution layer;
[0058] Initialization quantization parameter calculation module: used to calculate the initialization quantization parameters of the convolution layer input, output and weight;
[0059] Optimization module: used to optimize the initialized weight quantization parameters;
[0060] Integer calculation module: used to convert the convolution layer input and convolution layer weights into integers, obtain the dequantization calculation parameters according to the initialized convolution layer input quantization parameters, output quantization parameters and optimized weight quantization parameters, perform convolution based on the convolution layer input and convolution layer weights converted to integers to obtain the calculation results, and then perform dequantization calculation based on the calculation results to obtain the final output.
[0061] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of an embedded neural network binarization quantization method are implemented.
[0062] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of an embedded neural network binarization quantization method.
[0063] Compared with the prior art, the present invention has the following beneficial effects: the present invention proposes an embedded neural network binarization quantization method, by selecting several images as calibration sets as the input of the convolution layer, and obtaining the output of the convolution layer, the convolution layer input, output and weight are initialized and quantized parameter calculations are performed, the initialized weight quantization parameters are optimized and adaptively adjusted, and finally, through integer and inference calculations, the information loss caused by integer inference is effectively reduced, and the computing performance of the neural network model on the embedded end is improved. Under the premise of limited computing resources, the computing accuracy of the neural network model after deployment can be effectively improved while reducing the model calculation amount, parameter scale and storage consumption, so that the neural network model can be quickly and conveniently deployed and implemented on the resource-constrained embedded end, which is of great significance to the engineering implementation of the neural network algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 This is a flow chart of an embedded neural network binarization quantization method of the present invention;
[0065] Figure 2 This is a block diagram of an embedded neural network binarization quantization system of the present invention;
[0066] Figure 3 is the initial quantization parameter of the convolutional layer of the present invention;
[0067] Figure 4 It is the quantization parameter of the convolution layer after being optimized according to the method proposed in the present invention. DETAILED DESCRIPTION
[0068] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0069] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0070] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0071] Artificial intelligence technology with convolutional neural networks as its core has made breakthroughs in many fields and has great application potential in the field of edge computing. However, the computational complexity and data volume of such artificial intelligence algorithms are huge. Taking the mainstream VGG16 convolutional neural network model as an example, the inference of this model requires 154.7G multiplication and accumulation operations and 196.85M comparison operations. However, the computing resources of edge computing platforms such as aerospace are limited. For example, the main frequency of the radiation-resistant instruction set chip AT697E developed by the European Space Agency for military edge computing applications is only 100MHz, and the processing power is 100MIPS / 25MFLOPS, which cannot meet the rapid deployment requirements of edge intelligent algorithms. In order to deploy neural network algorithms on embedded devices with limited computing resources and achieve efficient computing, it is necessary to quantize floating-point neural network models into integer networks. Binary Neural Network (BNN) refers to quantizing the activation and weight of the neural network to 1 bit width, that is, converting the activation and weight to -1 (0) or +1. Binary neural networks can significantly reduce the storage and computing resource requirements of neural network models. They have important application prospects in edge reasoning scenarios with limited computing resources and are one of the important research directions for the future development of the field of artificial intelligence.
[0072] Since the binary neural network was proposed in 2016, although it has made great progress, it still faces problems such as large performance loss, poor generalization, and how to coordinate the design of software and hardware. The performance degradation of binary neural networks is mainly caused by the limited representation ability and discreteness of binarization. There is serious information loss in the process of forward calculation and reverse gradient propagation. The existing neural network binarization methods have poor robustness and cannot adapt to different neural network model structures, hardware resource limitations and computing task requirements, especially for high-precision or difficult computing tasks. It is difficult to meet the accuracy requirements and cannot be effectively promoted to embedded devices. The limited representation ability of binarization causes the calculation accuracy of binary neural networks on the embedded side to decrease, resulting in a large performance gap between it and the floating-point neural network of the same structure, which affects the deployment on resource-constrained platforms. In view of the problems of reduced calculation accuracy and poor robustness of existing neural network binarization methods on the embedded side, a high-precision neural network model binarization quantization method is proposed. Through the adaptive optimization of binarization quantization parameters, the neural network model can reduce memory usage and computational complexity on the embedded side while greatly improving the calculation accuracy.
[0073] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings.
[0074] like Figure 1 As shown, the present invention provides an embedded neural network binarization quantization method, comprising:
[0075] S101 selects a number of images as a calibration set as an input of a convolutional layer, and obtains an output of the convolutional layer;
[0076] S102 performs initialization quantization parameter calculation on the convolution layer input, output and weight;
[0077] S103 optimizes the initialized weight quantization parameters;
[0078] S104 converts the convolution layer input and the convolution layer weight into integers, obtains inverse quantization calculation parameters according to the initialized convolution layer input quantization parameters, output quantization parameters and optimized weight quantization parameters, performs convolution based on the convolution layer input and the convolution layer weight converted to integers to obtain calculation results, and then performs inverse quantization calculation based on the calculation results to obtain the final output.
[0079] Specifically apply the method to the system, such as Figure 2 As shown in the figure. The system can quantize the input / weight of the operators of the convolutional layer and the fully connected layer, which have huge computational complexity, by 1 bit, and perform binary integer inference calculation to obtain the output. The calculation method of the fully connected layer is similar to that of the convolutional layer. Taking the convolutional layer as an example, the calculation principle of the binary system is explained.
[0080] The input and output of all operators in this system adopt asymmetric quantization mapping, with quantization parameters s and D. The formula of asymmetric quantization mapping is:
[0081] r=sQ+D (1)
[0082] Among them, r is a floating point real value, Q is a quantized integer value, and s and D are quantization parameters.
[0083] The weights of the convolutional layer use a symmetric mapping, that is, D = 0, which means that the weights have only one quantization parameter s.
[0084] The calculation principle of the floating-point convolution layer is:
[0085] ∑(input float ·w float )+bias float =out float (2)
[0086] Among them, input float is the input of the convolutional layer, w floatis the weight of the convolutional layer, bias float is the bias of the convolutional layer, out float is the output of the convolutional layer. All the above data types are floating point types.
[0087] According to the calculation principle of the floating-point convolution layer shown in formula (2), combined with the quantization mapping method shown in formula (1), the calculation principle of the binarization of the convolution layer is derived as follows:
[0088]
[0089] Among them, s w is the quantization parameter of the weight, s in , D in is the quantization parameter of the convolution layer input, s out , D out is the quantization parameter of the convolutional layer output, and n is the shift parameter during the convolutional layer inference process.
[0090] According to formula (3), the binary quantization deployment method of the convolution layer can be obtained, that is, the calculation process of the binary quantization system of the neural network model is as follows:
[0091] 1) Initial quantization parameter module
[0092] ① Calculation of initial input and output quantization parameters
[0093] Select several images as the calibration set as the input of the convolution layer. The maximum value threshold of the convolution layer input is max in , the minimum input threshold is min in , the maximum output threshold is max out , the minimum output threshold is min out If max and min are both positive, set min = 0; if max and min are both negative, set max = 0. Calculate the initial quantization parameters s of the input and output according to formulas (4) to (13) in , D in 、s out , D out .bw in 、bw out They are the bit widths of input and output respectively, and can be positive integers such as 1, 2, 4, 8, etc.
[0094] bw in When it is not 1,
[0095] bw in =1, when it is binarized to -1 and +1, s in = Average of the absolute values of the input data (5)
[0096] bwin =1, when it is converted to 0 and +1, s in = Average of the positive values of the input data (6)
[0097] bw in When it is not 1,
[0098] bw in =1, D in =0 (8)
[0099] bw out When it is not 1,
[0100] bw out =1, when it is binarized to -1 and +1, s out = Average value of the absolute value of the output data (10)
[0101] bw out =1, when it is converted to 0 and +1, s out = Average value of positive output data (111)
[0102] bw out When it is not 1,
[0103]
[0104] bw out =1, D out =0 (13)
[0105] ②Calculation of initial weight quantization parameters
[0106] The maximum value of the absolute value of the weight is obtained as the threshold th, and the quantization parameter s of the weight is calculated according to formulas (14) to (16): w .bw w is the bit width of the weight, which can be a positive integer such as 1, 2, 4, 8, etc.
[0107] bw w When it is not 1,
[0108] bw w =1, when it is binarized to -1 and +1, s w = Average of the absolute values of the weights (15)
[0109] bw w =1, when it is converted to 0 and +1, s w = Average of positive weights (16)
[0110] 2) Quantization parameter adaptive optimization module
[0111] Round is a rounding function. Since there is a rounding operation in the calculation process of the multiplication parameter, in order to make the multiplication parameter To minimize the rounding loss caused by the round operation, is an integer. The quantization parameter adaptive optimization method designed by the present invention is shown in formula (17), and the quantization parameter s of the weight is w Adaptive fine-tuning optimization is performed to avoid rounding losses of multiplication parameters.
[0112]
[0113] Among them, ceil is the upward rounding function.
[0114] 3) Integer reasoning calculation module
[0115] ①Convert the floating-point input and weights of the convolutional layer into integers
[0116] For floating point input float The input is truncated according to the threshold, as shown in formula (18), and then the floating-point input and weight are converted into integer input according to formulas (19) to (22) Integer and weight w Integer In formula (18), MAX is the maximum value operation, and MIN is the minimum value operation.
[0117] bw in When not 1: input float =MAX(MIN(input float , max in ), min in ) (18)
[0118] bw in When not 1:
[0119] bw in =1, or
[0120]
[0121] bw w When not 1:
[0122] bw w =1, or
[0123] ②Calculate shift parameters, multiplication parameters, and addition parameters for integer reasoning
[0124]
[0125] The floating-point bias of the convolutional layer float Convert to add parameters and modify bias float The Bias_new_float method simplifies the process of calculating and adding parameters during convolutional layer reasoning, thereby accelerating the reasoning speed of the convolutional layer and achieving rapid deployment of the convolutional layer.
[0126] Bias_new_float = bias float +D in ·∑w float (25)
[0127]
[0128] Among them, ∑w float To sum the convolution kernels in units of output channels, that is, to calculate as many ∑w as there are output channels float value.
[0129] The shift parameter n is a 9-bit signed integer value with a value range of -256 to 255;
[0130] The multiplication parameter MUL is a 7-bit positive integer, ranging from 0 to 127;
[0131] The ADD parameter is a 40-bit signed integer value.
[0132] ③Perform convolution and dequantization calculations to obtain output
[0133] The result of the integer convolution multiplication and accumulation ∑(in Integer ·w Integer ) performs the dequantization calculation in the order of multiplication, addition, and shift, as shown in formula (27), and obtains the integer value out output by the convolution layer Integer Then, the output is truncated according to formulas (28) to (29) to obtain the final output result.
[0134]
[0135] bw out When it is not 1,
[0136]
[0137] bw out =1, or
[0138]
[0139] Taking the Xilinx ZCU102 embedded development board as an example, this paper explains how to build a neural network binary quantization system. The neural network model used in this embodiment is the VGG16 classification model, the data set is Cifar10, and the performance evaluation index of the neural network model after being deployed on the embedded development board is Top-1 accuracy. The input bit width bw of the convolution layer Conv_26 of the neural network model is in =2, bw w =1,bw out = 8. Convolutional layer Con v The weight of _26 is quantized to 0 and 1. This embodiment illustrates the effect of the invention from two aspects: the result of numerical calculation and the classification accuracy of the model.
[0140] (1) No adaptive optimization of quantization parameters
[0141] Select several images from the Cifar10 dataset as input, and use formulas (4) to (16) to obtain the quantization parameters of the input, output, and weight first channel as follows: Figure 3 As shown, s in =4.2001948, D in =8.4003897,s out =0.0153713, D out =-0.2613127, s w =0.0656578.
[0142] According to formula (23), the shift parameter can be obtained
[0143] If the quantization parameter is not optimized, then multiply the parameter
[0144] Since the integer convolution multiplication and accumulation ∑(in Integer ·w Integer ) is calculated as -320. When -320 is multiplied by the multiplication parameter, -320×71.7636=-22964.352 is approximated to -320×72=-23040, resulting in a numerical error of 76. The classification accuracy of the model Top-1 is 70.4%.
[0145] (2) Adaptive optimization of quantization parameters
[0146] According to the method proposed in the present invention, the binary quantization parameter of the weight is adaptively optimized, and the quantization parameter of the weight is optimized as follows according to formula (17): As shown in Figure (3).
[0147] After optimizing the quantization parameters, multiply the parameters At this time, the numerical error caused by round is 0, and the classification accuracy of the model Top-1 is improved from 70.4% to 77.3%.
[0148] The deployment of artificial intelligence algorithms represented by neural network models on embedded platforms is an important development trend in the future. Lightweight binary neural networks have the advantages of strong generalization, noise resistance, low computing and storage costs, and have important application value in the development of low-power, miniaturized intelligent unmanned systems. Existing binary methods cannot adapt to different neural network model structures, hardware resource limitations, and computing task requirements, especially for computing tasks with high or difficult precision requirements, and it is difficult to meet the precision requirements. The neural network model binarization quantization method proposed in the present invention can be applied to the lightweight deployment of algorithms for embedded intelligent computing platforms, to construct a high-precision neural network model binarization system, to reduce the performance loss of the neural network during the binarization process, and to promote the application of binary neural networks in embedded devices.
[0149] A terminal device is provided in one embodiment of the present invention. The terminal device of this embodiment includes: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor executes the computer program, the functions of the modules / units in the above-mentioned device embodiments are implemented.
[0150] The computer program may be divided into one or more modules / units, and the one or more modules / units are stored in the memory and executed by the processor to accomplish the present invention.
[0151] The terminal device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The terminal device may include, but is not limited to, a processor and a memory.
[0152] The processor can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0153] The memory may be used to store the computer programs and / or modules, and the processor implements various functions of the terminal device by running or executing the computer programs and / or modules stored in the memory and calling the data stored in the memory.
[0154] If the module / unit integrated in the terminal device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0155] Although the embodiments of the present invention are described above in conjunction with the accompanying drawings, the present invention is not limited to the above-mentioned specific embodiments and application fields, and the above-mentioned specific embodiments are only illustrative and instructive, rather than restrictive. Under the guidance of the specification, a person skilled in the art can also make many forms without departing from the scope of protection of the claims of the present invention, all of which belong to the scope of protection of the present invention.
Claims
1. An embedded neural network binarization quantization method, characterized in that: include: Select several images as the calibration set as the input of the convolution layer and obtain the output of the convolution layer; Calculate the initialization quantization parameters for the convolution layer input, output and weights; Optimize the initialization weight quantization parameters; The convolution layer input is converted into an integer according to the convolution layer input quantization parameter, the weight is converted into an integer according to the optimized weight quantization parameter, the dequantization calculation parameter is obtained according to the initialized convolution layer input quantization parameter, the output quantization parameter and the optimized weight quantization parameter, convolution is performed based on the convolution layer input converted to integer and the convolution layer weight to obtain the calculation result, and then the dequantization calculation is performed according to the calculation result to obtain the final output.
2. The embedded neural network binarization quantization method according to claim 1, characterized in that: The calculation of initialization quantization parameters for convolution layer input and output is as follows: The maximum value threshold of the convolution layer input is obtained as max in , the minimum input threshold is min in , the maximum output threshold is max out , the minimum output threshold is min out , if max and min are both positive, set min = 0; if max and min are both negative, set max = 0, and calculate the initial quantization parameters s for input and output in , D in 、s out , D out ; bw in 、bw out are the bit widths of input and output respectively; Calculate the initial quantization parameters s for input and output in , D in 、s out , D out The process is: bw in When it is not 1, bw in =1, when it is binarized to -1 and +1, s in = the average of the absolute values of the input data; bw in =1, when it is converted to 0 and +1, s in = the average of the positive values of the input data; bw in When it is not 1, bw in =1, D in =0; bw out When it is not 1, bw out =1, when it is binarized to -1 and +1, s out = the average value of the absolute value of the output data; bw out =1, when it is converted to 0 and +1, s out = the average value of the positive values of the output data; bw out When it is not 1, bw out =1, D out =0.
3. The embedded neural network binarization quantization method according to claim 1, characterized in that: The calculation of the initialization quantization parameters for the weights is as follows: The maximum absolute value of the weight is taken as the threshold, and the quantization parameter s of the weight is calculated. w , bw w is the bit width of the weight; bw w When it is not 1, bw w =1, when it is binarized to -1 and +1, s w = average of the absolute values of weights; bw w =1, when it is converted to 0 and +1, s w =The average value of the positive weights.
4. The embedded neural network binarization quantization method according to claim 1, characterized in that: The optimization of the initialization weight quantization parameters is as follows: Among them, ceil is the upward rounding function, s in is the input quantization parameter, s out is the output quantization parameter, S w is the quantization parameter of the weight.
5. The embedded neural network binarization quantization method according to claim 1, characterized in that: Convert the convolutional layer input and convolutional layer weights to integers as follows: For floating point input float According to the input threshold, the floating-point input and weight are converted into integer input in Integer and weight w Integer , where MAX is the maximum value operation and MIN is the minimum value operation; bw in When not 1: input float =MAX(MIN(input float , max in ), min in ); bw in When not 1: bw in =1, or bw w When not 1: bw w =1, or 6. The embedded neural network binarization quantization method according to claim 1, characterized in that: The dequantization calculation parameters obtained according to the initialized convolution layer input quantization parameters, output quantization parameters and optimized weight quantization parameters are as follows: The inverse quantization calculation parameters include shift parameters, multiplication parameters and addition parameters. The calculation methods of shift parameters, multiplication parameters and addition parameters are as follows: The floating-point bias of the convolutional layer float Convert to add parameters and modify bias float Bias_new_float; Bias_new_float=bias float +D in ·∑w float ; Among them, ∑w float To sum the convolution kernels in units of output channels, that is, to calculate as many ∑w as there are output channels float value; Among them, s in is the input quantization parameter, s out is the output quantization parameter, s w is the quantization parameter of the optimized weight, MAX is the maximum value operation, and MIN is the minimum value operation.
7. The embedded neural network binarization quantization method according to claim 6, characterized in that: The convolution is performed based on the convolution layer input converted to integer and the convolution layer weight to obtain the calculation result, and then the dequantization calculation is performed based on the calculation result to obtain the final output: Among them, Integer is the convolution layer input converted to integer, w Integer The convolutional layer output converted to integer; bw out When it is not 1, bw out =1, or 8. An embedded neural network binarization quantization system, characterized in that: include: Input module: used to select several images as calibration sets, as input of the convolution layer, and obtain the output of the convolution layer; Initialization quantization parameter calculation module: used to calculate the initialization quantization parameters of the convolution layer input, output and weight; Optimization module: used to optimize the initialized weight quantization parameters; Integer calculation module: used to convert the convolution layer input and convolution layer weights into integers, obtain the dequantization calculation parameters according to the initialized convolution layer input quantization parameters, output quantization parameters and optimized weight quantization parameters, perform convolution based on the convolution layer input and convolution layer weights converted to integers to obtain the calculation results, and then perform dequantization calculation based on the calculation results to obtain the final output.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the embedded neural network binarization quantization method as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of an embedded neural network binarization quantization method as described in any one of claims 1 to 7 are implemented.
