A cosine convolutional neural network quantization method, application and system
Through the quantization method based on KL divergence and cosine lookup table, the parameters of the cosine convolutional neural network are quantized layer by layer, solving the problem of difficulty in deploying deep convolutional neural networks, and a significant reduction in parameter storage space and efficient operation of the model in an edge computing environment are achieved.
Patent Information
- Application Number
- CN202210505572.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-10
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2042-05-10
AI Technical Summary
The existing convolutional neural network is difficult to deploy, especially the deep convolutional neural networks, due to the huge number of parameters, it is difficult to deploy in mobile phones or edge computing units. The existing quantization methods are not designed for cosine convolutional networks, resulting in less obvious compression of parameter space after quantization.
The cosine convolutional neural network quantization method based on KL divergence and cosine lookup table is adopted to quantify the parameters of the cosine convolutional neural network layer by layer, reduce the network calculation amount and improve the calculation efficiency.
Quantifying the floating-point data format parameters of cosine convolutional neural networks into signed integer data format parameters with low bit widths greatly reduces parameter storage space, reduces the system's operating power consumption and bandwidth requirements, improves the model's memory access efficiency, and enables the model to run efficiently in low-power on-chip systems and edge computing units.
Smart Images

Figure CN114861884B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a cosine convolutional neural network quantization method, application and system based on KL divergence and cosine lookup table, belonging to the technical field of neural network and artificial intelligence. Background Art
[0002] Deep neural network is a new type of end-to-end deep learning model that can automatically learn and extract features. In particular, deep convolutional neural network (CNN) is increasingly being applied to the fields of computer vision and signal processing. Compared with the method of combining manually designed and extracted time-frequency domain features with classical classifiers, deep neural network is better at automatically learning and integrating features from raw signals. At present, the application research of deep neural network mainly focuses on exploring and optimizing different network structures, but the change of network structure actually has limited improvement on the accuracy and robustness of classification and recognition results, and the existing convolution module does not contain prior knowledge, the training process is slow and prone to overfitting. Therefore, using cosine convolution kernel instead of conventional convolution kernel can learn periodic features and improve the generalization ability of convolutional neural network by reducing the parameter scale. Deep convolutional neural network usually has more than a dozen or even dozens of convolution layers, with a large number of parameters. Storing them in 32-bit floating point numbers will take up a lot of memory space, making it impossible to port them to mobile phones or edge computing units for deployment. The current solution to the difficulty in deploying convolutional neural networks is to quantize the network parameters at a low bit width. However, the existing quantization method is not designed for cosine convolutional networks, which makes the space compression of the quantized parameters not obvious and cannot meet the needs of actual applications. Summary of the invention
[0003] In view of the shortcomings of the prior art, the present invention proposes a cosine convolutional neural network parameter quantization method. Based on the cosine lookup table and KL divergence, all parameters of the cosine convolutional neural network are quantized to low-bit width integers to reduce the amount of network calculation and improve the network calculation efficiency.
[0004] The present invention also provides an application of a quantized cosine convolutional neural network in electroencephalogram signal classification and a cosine convolutional neural network parameter quantization system. SUMMARY OF THE INVENTION
[0006] A cosine convolution neural network quantization circuit and parameter quantization method, including a floating-point parameter pool, a cosine convolution parameter quantization calculation module, a cosine convolution operation unit and a quantization parameter pool. The trained cosine convolution neural network parameters are sent to the floating-point parameter pool; the cosine convolution parameter quantization calculation module reads the floating-point parameters from the floating-point parameter pool layer by layer based on the cosine lookup table and KL divergence, performs layer-by-layer quantization to obtain low-bit-width quantization parameters; the quantized parameters replace the floating-point parameters to form a quantized cosine convolution neural network, thereby reducing the amount of calculation of the cosine convolution neural network.
[0007] Terminology explanation:
[0008] 1. Quantization: The process of mapping a set of parameters to another value range through mathematical transformation. Usually, linear mapping is used to achieve the mapping transformation. The original value of the parameter is usually a floating point number, while the quantized parameter value is generally an integer.
[0009] 2. Dequantization: The process of transforming the quantized parameters back to the original value range of the group of parameters according to the previous quantization process. The goal of dequantization is to make the dequantized parameters as equal as possible to the values of the original floating-point parameters to reduce the precision loss caused by quantization.
[0010] 3. Training: Input a set of data into the neural network, compare the output result with the label corresponding to this set of data and calculate the error, obtain the gradient value of each parameter through the back propagation algorithm and update it.
[0011] 4. Cosine convolutional neural network: A convolutional neural network whose convolution kernel is modulated by the cosine function Acos(ωx), where the amplitude A and angular velocity ω are two learnable parameters of each convolution kernel, and x is an arithmetic sequence with an interval of 1, which is monotonically increasing and the number of its elements is consistent with the length of the convolution kernel.
[0012] 5. Fully connected layer: The fully connected layer contains a floating-point parameter weight matrix P, which does not participate in the quantization process.
[0013] The technical solution of the present invention is as follows:
[0014] A cosine convolutional neural network quantization method comprises the following steps:
[0015] 1) Train a model with N l The cosine convolutional neural network with 1 cosine convolutional layer is constructed. The parameter values of the trained cosine convolutional neural network are counted. The maximum value of the angular velocity parameter ω in all layers of the cosine convolutional neural network is found, and its quantization scale S is calculated. ω : Among them, BW ω is the quantization bit width of the angular velocity parameter ω, |·| max is the maximum absolute value of the angular velocity parameter ω;
[0016] 2) Take a part of the training data as the quantization correction data set X c , calculate the quantization scale of the input data
[0017] 3) Calculate the quantization scale S of the quantized cosine lookup table Ω ;
[0018] 4) Initialize the quantized cosine lookup table Among them, k is the convolution kernel length set by the cosine convolutional neural network; The jth row and mth column in is initialized to: Among them, cos(·) is the cosine function;
[0019] 5) Start quantizing each cosine convolution layer layer by layer, starting from l=1 and performing the following loop iteration:
[0020] a) Fusion N l Layer cosine convolution layer and its associated batch normalization layer;
[0021] b) Quantify the Nth l All angular velocity parameters of the cosine convolution layer: Among them, |·| is the absolute value of the parameter, and [·] is the rounding function;
[0022] c) Find the Nth l Layer cosine convolution layer amplitude parameter A l The maximum value of and calculate the quantization scale Where BW A is the quantization bit width of the amplitude parameter;
[0023] d) Quantify the Nth l Amplitude parameters of the cosine convolution layer:
[0024] e) Calculate the activation quantization scale according to the adaptive quantization threshold setting algorithm based on KL divergence
[0025] f) Calculate the Nth l Quantization factor M of the output of the cosine convolution layer l :
[0026] g) Update the Nth l The bias term B of the cosine convolution layer l :
[0027] h) If l = N l , the iteration ends, jumps out of the loop and goes to step 6), otherwise, let l increase by 1 and return to step a);
[0028] 6) Calculate the dequantization factor corresponding to the last cosine convolution layer
[0029] 7) The obtained quantized cosine convolutional neural network weight parameters include M l , B l 、M deQ Stored in the quantization parameter pool as the weight of the quantized cosine convolutional neural network, l = 1, 2, ..., N l .
[0030] Further preferably, in step 2), Among them, BW act Quantization bit width of the cosine convolutional neural network activation value.
[0031] Further preferably, in step 3), Among them, BW Ω is the quantization bit width of the cosine lookup table.
[0032] Preferably, in step 5), the first cosine convolution layer and the batch normalization layer associated with it are fused, and the implementation steps are: updating the amplitude parameter and bias parameters in, and μ B are the variance and mean obtained by the batch normalization layer in the cosine convolutional neural network during the training phase, ε is a decimal designed to prevent the variance from being zero, β and γ are the normalization bias parameter and normalization scaling parameter learned by the batch normalization layer during the training phase, respectively.
[0033] More preferably, ε=10 -5 .
[0034] According to the preferred embodiment of the present invention, in step 5), the activation quantization scale is calculated according to the adaptive quantization threshold setting algorithm based on KL divergence The implementation steps include:
[0035] ①Quantize the calibration data set X c Send it to the cosine convolutional neural network and get the Nth l The activation value of the cosine convolution layer;
[0036] ② Take the absolute value of the activation value in step ① and divide its value range into N H There are equal interval areas, and the width of each interval area is W H , calculate the number of parameters in each interval area and obtain the parameter distribution histogram H;
[0037] ③From The following loop iterations begin:
[0038] i) Take the first i values of the parameter distribution histogram H and set them as H * , and normalize these values to between 0 and 1;
[0039] j) H * The domain of the quantized Let
[0040] k) By filling zeros, Expand to integers between 0 and i-1 and normalize them to between 0 and 1, set
[0041] 1) Calculation and H * The KL divergence value D between KL , the calculation formula is shown in formula (I)
[0042]
[0043] m) If i = N H , the iteration ends, jumps out of the loop and enters step ④, otherwise, let i increase by 1 and return to step i);
[0044] ④Find the minimum KL divergence value calculated in step ③ and its corresponding loop index n H ;
[0045] ⑤n H With W H The product of is the optimal threshold T optimal ; At the same time, the activation quantization scale is calculated:
[0046] More preferably, N H =2048.
[0047] According to the preferred embodiment of the present invention, in step ①, the Nth cosine convolutional neural network is calculated. l The steps to implement the activation value of the cosine convolution layer include:
[0048] A. Quantize and correct the data set X for the cosine convolutional neural network input c Each data sample in ;
[0049] B. Calculate the activation value of each cosine convolution layer layer by layer, from N k =1 to start the following loop iteration:
[0050] n) Calculate the Nth k Quantized activation output of the cosine convolution layer As input to the next layer:
[0051]
[0052] In formula (II), is the i-th value output by the cosine convolution layer, For N k -The i+mth value in the activation output of the 1st cosine convolution layer, and The Nth k The amplitude parameter and angular velocity parameter of the cosine convolution layer, * is the convolution operator; is the cosine kernel function;
[0053] o) If N k =N l , then the iteration ends, jumps out of the loop and enters step ⑧, otherwise, let N k Add 1 and return to step ⑦;
[0054] ⑧ Output cosine convolutional neural network Nth l Activation output value of the cosine convolution layer
[0055] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of a cosine convolutional neural network quantization method when executing the computer program.
[0056] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of a cosine convolutional neural network quantization method.
[0057] A method for classifying EEG signals by using a cosine convolutional neural network quantization method is used for N l The quantized cosine convolutional neural network with 1 cosine convolutional layer includes:
[0058] Step 1: Convert the original EEG signal data X S Input quantized cosine convolutional neural network;
[0059] Step 2: Quantify X S Get the quantized raw EEG signal data
[0060] Step 3: Starting from l=1, perform the following loop iterations:
[0061] p) Calculate the i-th value of the cosine convolution layer output after the l-th layer quantization through formula (III)
[0062]
[0063] In formula (III), is the i-th value output by the cosine convolution layer after the l-th layer quantization, is the i+mth value in the activation output of the cosine convolution layer after quantization of the l-1th layer, and * is the convolution operator;
[0064] q) Dequantize and requantize get
[0065] r) If l = N l , the iteration ends, jumps out of the loop and goes to step 4; otherwise, let l increase by 1 and return to step p);
[0066] Step 4: Dequantize the Nth l Cosine convolution layer, get the output value in floating point format
[0067] Step 5: Flattened into a one-dimensional feature vector, sent to the fully connected layer, and the weight matrix P in the fully connected layer is used to transform Mapped to have N c The characteristic vector R of elements is shown in formula (IV):
[0068]
[0069] The probability corresponding to each EEG signal category is calculated through the softmax function, and the index corresponding to the maximum probability is selected as the output, that is, the category of the EEG signal required.
[0070] A cosine convolution neural network parameter quantization system, comprising a floating point parameter pool, a cosine convolution parameter quantization calculation module, a cosine convolution operation unit and a quantization parameter pool;
[0071] The parameters of the trained cosine convolutional neural network are sent to the floating-point parameter pool; the cosine convolution parameter quantization calculation module reads the floating-point parameters from the floating-point parameter pool layer by layer based on the cosine lookup table and KL divergence, and quantizes them layer by layer to obtain low-bit-width quantization parameters; the cosine convolution operation unit is used to calculate the activation value in the adaptive quantization threshold setting algorithm based on KL divergence; all quantized parameters after layer-by-layer quantization are stored in the quantization parameter pool to replace the parameters in the floating-point parameter pool; the parameters after quantization replace the floating-point parameters to form a quantized cosine convolutional neural network, thereby reducing the computational complexity of the cosine convolutional neural network.
[0072] The beneficial effects of the present invention are:
[0073] Quantizing the floating-point data format parameters of the cosine convolutional neural network into low-bit-width signed integer data format parameters for storage can greatly reduce the parameter storage space of the deep cosine convolutional neural network, reduce the system's operating power consumption and bandwidth requirements, improve the model's memory access efficiency, and enable the model to run efficiently in low-power on-chip systems and edge computing units. In addition, the present invention uses KL divergence to adaptively evaluate the quantization scale parameters of each cosine convolutional layer, so that the model can guarantee the performance of the model without fine-tuning training. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] Figure 1 It is a structural schematic diagram of the cosine convolutional neural network parameter quantization system of the present invention;
[0075] Figure 2 It is a schematic diagram of the process of the cosine convolutional neural network quantization method of the present invention; DETAILED DESCRIPTION
[0076] The present invention is further described below with reference to the accompanying drawings and examples, but the present invention is not limited thereto;
[0077] Example 1
[0078] A cosine convolutional neural network quantization method, such as Figure 2 As shown, the steps include:
[0079] 1) Train a model with N l = 8 cosine convolutional layers, each with a convolution kernel length of k = 5, statistically analyze the parameter values of the trained cosine convolutional neural network, find the maximum value of the angular velocity parameter ω in all layers of the cosine convolutional neural network, and calculate its quantization scale S ω : Among them, BW ω =8 is the quantization bit width of the angular velocity parameter ω, |·| max is the maximum absolute value of the angular velocity parameter ω;
[0080] 2) Take a part of the training data as the quantization correction data set X c , calculate the quantization scale of the input data
[0081] 3) Calculate the quantization scale S of the quantized cosine lookup table Ω ;
[0082] 4) Initialize the quantized cosine lookup table Among them, k is the convolution kernel length set by the cosine convolutional neural network; The jth row and mth column in is initialized to: Among them, cos(·) is the cosine function;
[0083] 5) Start quantizing each cosine convolution layer layer by layer, starting from l=1 and performing the following loop iteration:
[0084] a) Fusion N l Layer cosine convolution layer and its associated batch normalization layer;
[0085] b) Quantify the Nth l All angular velocity parameters of the cosine convolution layer: Among them, |·| is the absolute value of the parameter, and [·] is the rounding function;
[0086] c) Find the Nth l Layer cosine convolution layer amplitude parameter A l The maximum value of and calculate the quantization scale Where BW A is the quantization bit width of the amplitude parameter;
[0087] d) Quantify the Nth l Amplitude parameters of the cosine convolution layer:
[0088] e) Calculate the activation quantization scale according to the adaptive quantization threshold setting algorithm based on KL divergence
[0089] f) Calculate the Nth l Quantization factor M of the output of the cosine convolution layer l :
[0090] g) Update the Nth l The bias term B of the cosine convolution layer l :
[0091] h) If l = N l , the iteration ends, jumps out of the loop and goes to step 6), otherwise, let l increase by 1 and return to step a);
[0092] 6) Calculate the dequantization factor corresponding to the last cosine convolution layer
[0093] 7) The obtained quantized cosine convolutional neural network weight parameters include M l , B l 、M deQ Stored in the quantization parameter pool as the weight of the quantized cosine convolutional neural network, l = 1, 2, ..., N l .
[0094] Example 2
[0095] The cosine convolutional neural network quantization method according to embodiment 1 is different in that:
[0096] In step 2), Among them, BW act =8 is the quantization bit width of the activation value of the cosine convolutional neural network.
[0097] In step 3), Among them, BW Ω =8 is the quantization bit width of the cosine lookup table.
[0098] In step 5), the lth cosine convolution layer and the batch normalization layer associated with it are fused. The implementation steps are: Update the amplitude parameter and bias parameters in, and μ B is the variance and mean obtained by the batch normalization layer in the cosine convolutional neural network during the training phase, ε is a decimal designed to prevent the variance from being zero, ε = 10 -5 β and γ are the normalization bias parameter and normalization scaling parameter learned by the batch normalization layer during the training phase, respectively.
[0099] In step 5), the activation quantization scale is calculated according to the adaptive quantization threshold setting algorithm based on KL divergence The implementation steps include:
[0100] ①Quantize the calibration data set X c Send it to the cosine convolutional neural network and get the Nth l The activation value of the cosine convolution layer;
[0101] ② Take the absolute value of the activation value in step ① and divide its value range into N H = 2048 equally spaced regions, assuming that the width of each spaced region is W H , calculate the number of parameters in each interval area and obtain the parameter distribution histogram H; there are N H values, representing the number of parameters in each interval area;
[0102] ③From The following loop iterations begin:
[0103] i) Take the first i values of the parameter distribution histogram H and set them as H * , and normalize these values to between 0 and 1;
[0104] j) H * The domain of the quantized Let
[0105] k) By filling zeros, Expand to integers between 0 and i-1 and normalize them to between 0 and 1, set
[0106]
[0107] 1) Calculation and H * The KL divergence value D between KL , the calculation formula is shown in formula (I)
[0108]
[0109] m) If i = N H , the iteration ends, jumps out of the loop and enters step ④, otherwise, let i increase by 1 and return to step i);
[0110] ④Find the minimum KL divergence value calculated in step ③ and its corresponding loop index n H ;
[0111] ⑤n H With W H The product of is the optimal threshold T optimal ; At the same time, the activation quantization scale is calculated:
[0112] In step ①, calculate the Nth cosine convolutional neural network l The steps to implement the activation value of the cosine convolution layer include:
[0113] A. Quantize and correct the data set X for the cosine convolutional neural network input c Each data sample in ;
[0114] B. Calculate the activation value of each cosine convolution layer layer by layer, from N k =1 to start the following loop iteration:
[0115] n) Calculate the Nth k Quantized activation output of the cosine convolution layer As input to the next layer:
[0116]
[0117] In formula (II), is the i-th value output by the cosine convolution layer, For N k -The i+mth value in the activation output of the 1st cosine convolution layer, and The Nth k The amplitude parameter and angular velocity parameter of the cosine convolution layer, * is the convolution operator;
[0118] is the cosine kernel function;
[0119] o) If N k =N l , then the iteration ends, jumps out of the loop and enters step ⑧, otherwise, let N k Add 1 and return to step ⑦;
[0120] C. Output cosine convolutional neural network Nth l Activation output value of the cosine convolution layer
[0121] Example 3
[0122] A computer device includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the cosine convolutional neural network quantization method described in embodiment 1 or 2 are implemented.
[0123] Example 4
[0124] A computer-readable storage medium having a computer program stored thereon, which implements the steps of the cosine convolutional neural network quantization method described in Example 1 or 2 when the computer program is executed by a processor.
[0125] Example 5
[0126] A method for implementing the classification of EEG signals by the cosine convolutional neural network quantization method described in Example 1 or 2, for a l = A quantized cosine convolutional neural network with 8 cosine convolutional layers, including:
[0127] Step 1: Convert the original EEG signal data X S Input quantized cosine convolutional neural network, sampling frequency is 256Hz, duration is 1 second;
[0128] Step 2: Quantify X S Get the quantized raw EEG signal data
[0129] Step 3: Starting from l=1, perform the following loop iterations:
[0130] p) Calculate the i-th value of the cosine convolution layer output after the l-th layer quantization through formula (III)
[0131]
[0132] In formula (III), is the i-th value output by the cosine convolution layer after the l-th layer quantization, is the i+mth value in the activation output of the cosine convolution layer after quantization of the l-1th layer, and * is the convolution operator;
[0133] q) Dequantize and requantize get
[0134] r) If l = N l , the iteration ends, jumps out of the loop and goes to step 4; otherwise, let l increase by 1 and return to step p);
[0135] Step 4: Dequantize the Nth l Cosine convolution layer, get the output value in floating point format
[0136] Step 5: Flattened into a one-dimensional feature vector, sent to the fully connected layer, and the weight matrix P in the fully connected layer is used to transform Mapped to have N c = The eigenvector R of 2 elements, as shown in formula (IV):
[0137]
[0138] The probability corresponding to each EEG signal category is calculated by the softmax function, and the index corresponding to the maximum probability is selected as the output, that is, the category of the EEG signal to be taken. The classification results of the quantized cosine convolution model on the Bonn epilepsy EEG database are shown in Table 1; Table 1 shows the average accuracy results of the ten-fold cross validation of the cosine convolution network under different quantization bit widths.
[0139] Table 1
[0140]
[0141] The first line in Table 1 is the classification result of the cosine convolution network with floating-point parameters; the second line is the quantization bit width BW ω , BW Ω , BW A , BW act When the quantization bit width is set to 12, 8, 8, and 8 respectively, the classification accuracy of the model under the convolution kernel length k = 5 and k = 33. It can be seen that under this quantization bit width setting, the quantized cosine convolution network with a convolution kernel length of 5 is 0.33% more accurate than the unquantized cosine convolution network; the third line is the quantization bit width BW ω , BW Ω , BW A , BW actWhen the kernel length is set to 16, 8, 8, and 8 respectively, the classification accuracy of the model under the convolution kernel length k = 5 and k = 33. It can be seen that under this quantization bit width setting, the quantized cosine convolution network with a convolution kernel length of 5 is 0.67% more accurate than the unquantized cosine convolution network. This proves that the cosine convolution quantization method can not only reduce the memory consumption of parameters, but also improve the model performance. At the same time, the quantized cosine convolution neural network can also be applied to other time series signal classification tasks.
[0142] Example 6
[0143] A cosine convolutional neural network parameter quantization system, such as Figure 1 As shown, it includes a floating point parameter pool, a cosine convolution parameter quantization calculation module, a cosine convolution operation unit and a quantization parameter pool;
[0144] The parameters of the trained cosine convolutional neural network are sent to the floating-point parameter pool; the cosine convolution parameter quantization calculation module reads the floating-point parameters from the floating-point parameter pool layer by layer based on the cosine lookup table and KL divergence, and quantizes them layer by layer to obtain low-bit-width quantization parameters; the cosine convolution operation unit is used to calculate the activation value in the adaptive quantization threshold setting algorithm based on KL divergence; all quantized parameters after layer-by-layer quantization are stored in the quantization parameter pool to replace the parameters in the floating-point parameter pool; the parameters after quantization replace the floating-point parameters to form a quantized cosine convolutional neural network, thereby reducing the computational complexity of the cosine convolutional neural network.
Claims
1. A method for classifying EEG signals by using a cosine convolutional neural network quantization method, characterized in that: For including N l The quantized cosine convolutional neural network with 1 cosine convolutional layer includes: Step 1: Convert the original EEG signal data X S Input quantized cosine convolutional neural network; Step 2: Quantify X S Get the quantized raw EEG signal data Step 3: Starting from l=1, perform the following loop iterations: p) Calculate the i-th value of the cosine convolution layer output after the l-th layer quantization through formula (III) In formula (III), is the i-th value output by the cosine convolution layer after the l-th layer quantization, is the i+mth value in the activation output of the cosine convolution layer after quantization of the l-1th layer, and * is the convolution operator; q) Dequantize and requantize get r) If l = N l , the iteration ends, jumps out of the loop and goes to step 4; otherwise, let l be increased by 1 and return to step p); Step 4: Dequantize the Nth l Cosine convolution layer, get the output value in floating point format Step 5: Flattened into a one-dimensional feature vector, sent to the fully connected layer, and the weight matrix P in the fully connected layer is used to transform Mapped to have N c The characteristic vector R of elements is shown in formula (IV): The probability corresponding to each EEG signal category is calculated through the softmax function, and the index corresponding to the maximum probability is selected as the output, that is, the category of the EEG signal required; The cosine convolutional neural network quantization method comprises the following steps: 1) Train a model with N l The cosine convolutional neural network with 1 cosine convolutional layer is constructed. The parameter values of the trained cosine convolutional neural network are counted. The maximum value of the angular velocity parameter ω in all layers of the cosine convolutional neural network is found, and its quantization scale S is calculated. ω : Among them, BW ω is the quantization bit width of the angular velocity parameter ω, |·| max is the maximum absolute value of the angular velocity parameter ω; 2) Take a part of the training data as the quantization correction data set X c , calculate the input data quantization scale 3) Calculate the quantization scale S of the quantized cosine lookup table Ω ; 4) Initialize the quantized cosine lookup table Among them, k is the convolution kernel length set by the cosine convolutional neural network; The jth row and mth column in is initialized to: Among them, cos(·) is the cosine function; 5) Start quantizing each cosine convolution layer layer by layer, starting from l=1 and performing the following loop iteration: a) Fusion N l Layer cosine convolution layer and its associated batch normalization layer; b) Quantify the Nth l All angular velocity parameters of the cosine convolution layer: Among them, |·| is the absolute value of the parameter, and [·] is the rounding function; c) Find the Nth l Layer cosine convolution layer amplitude parameter A l The maximum value of and calculate the quantization scale Where BW A is the quantization bit width of the amplitude parameter; d) Quantify the Nth l Amplitude parameters of the cosine convolution layer: e) Calculate the activation quantization scale according to the adaptive quantization threshold setting algorithm based on KL divergence f) Calculate the Nth l Quantization factor M of the output of the cosine convolution layer l : g) Update the Nth l The bias term B of the cosine convolution layer l : h) If l = N l , the iteration ends, jumps out of the loop and goes to step 6), otherwise, let l increase by 1 and return to step a); 6) Calculate the dequantization factor corresponding to the last cosine convolution layer 7) The obtained quantized cosine convolutional neural network weight parameters include M l , B l 、M deQ Stored in the quantization parameter pool as the weight of the quantized cosine convolutional neural network, l = 1, 2, ..., N l .
2. The method for classifying electroencephalogram signals by using a cosine convolutional neural network quantization method according to claim 1, characterized in that: In step 2), Among them, BW act Quantization bit width of the cosine convolutional neural network activation value.
3. The method for classifying EEG signals by using a cosine convolutional neural network quantization method according to claim 1, characterized in that: In step 3), Among them, BW Ω is the quantization bit width of the cosine lookup table.
4. The method for classifying EEG signals by using a cosine convolutional neural network quantization method according to claim 1, characterized in that: In step 5), the lth cosine convolution layer and the batch normalization layer associated with it are fused. The implementation steps are: Update the amplitude parameter and bias parameters in, and μ B is the variance and mean obtained by the batch normalization layer in the cosine convolutional neural network during the training phase, ε is a decimal designed to prevent the variance from being zero, β and γ are the normalization bias parameter and normalization scaling parameter learned by the batch normalization layer during the training phase, respectively; More preferably, ε=10 -5 .
5. The method for classifying electroencephalogram signals by using a cosine convolutional neural network quantization method according to claim 1, characterized in that: In step 5), the activation quantization scale is calculated according to the adaptive quantization threshold setting algorithm based on KL divergence The implementation steps include: ①Quantize the calibration data set X c Send it to the cosine convolutional neural network and get the Nth l The activation value of the cosine convolution layer; ② Take the absolute value of the activation value in step ① and divide its value range into N H There are equal interval areas, and the width of each interval area is W H , calculate the number of parameters in each interval area and obtain the parameter distribution histogram H; ③From The following loop iterations begin: i) Take the first i values of the parameter distribution histogram H and set them as H * , and normalize these values to between 0 and 1; j) H * The domain of the quantized Let k) By filling zeros, Expand to integers between 0 and i-1 and normalize them to between 0 and 1, set 1) Calculation and H * The KL divergence value D between KL , the calculation formula is shown in formula (I) m) If i = N H , the iteration ends, jumps out of the loop and enters step ④, otherwise, let i increase by 1 and return to step i); ④Find the minimum KL divergence value calculated in step ③ and its corresponding loop index n H ; ⑤n H With W H The product of is the optimal threshold T optimal ; At the same time, the activation quantization scale is calculated: More preferably, N H =2048.
6. The method for classifying EEG signals by using a cosine convolutional neural network quantization method according to claim 5, characterized in that: In step ①, calculate the Nth cosine convolutional neural network l The steps to implement the activation value of the cosine convolution layer include: A. Quantize and correct the data set X for the cosine convolutional neural network input c Each data sample in ; B. Calculate the activation value of each cosine convolution layer layer by layer, from N k =1 to start the following loop iteration: n) Calculate the Nth k Quantized activation output of the cosine convolution layer As input to the next layer: In formula (II), is the i-th value output by the cosine convolution layer, For N k -The i+mth value in the activation output of the 1st cosine convolution layer, and The Nth k The amplitude parameter and angular velocity parameter of the cosine convolution layer, * is the convolution operator; is the cosine kernel function; o) If N k =N l , then the iteration ends, jumps out of the loop and enters step ②, otherwise, let N k Add 1 and return to step ①; C. Output cosine convolutional neural network Nth l Activation output value of the cosine convolution layer 7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of a method for classifying EEG signals by using a cosine convolutional neural network quantization method as described in any one of claims 1 to 6 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of a method for classifying EEG signals by using a cosine convolutional neural network quantization method as described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Artificial neural network quantification method and device
CN112200275A
Convolutional neural network quantification method for automatically sensing weight distribution in reinforcement learning
CN112733964A