An improved LeNet-5 model for CNN hardware acceleration
By improving the LeNet-5 model structure and reducing parameters and complexity, the problem of large computational load of convolutional neural networks in embedded scenarios is solved, the recognition speed is improved, and it is suitable for CNN hardware acceleration.
Patent Information
- Application Number
- CN202011549668.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-24
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-12-24
AI Technical Summary
The existing convolutional neural network structure is not suitable for use in embedded scenarios due to the large amount of data calculation, resulting in slow recognition speed.
By improving the LeNet-5 model structure, reducing the number of parameters and complexity, a multi-layer network structure is adopted, including input layer, convolution layer, pooling layer, activation layer, fully connected layer and output layer, using maximum pooling and The ReLu activation function removes the convolutional layer 5 in the original structure and directly connects the pooling layer output to the fully connected layer to reduce the amount of calculation.
On the premise of ensuring the recognition accuracy, it significantly reduces the calculation amount and complexity of the model, improves the recognition speed of the model, and is suitable for CNN hardware acceleration.
Smart Images

Figure CN112668695B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence, and in particular to an improved LeNet-5 model for CNN hardware acceleration. Background Art
[0002] With the development of embedded machine learning, deploying lightweight neural network models on hardware devices has become one of the important ways to make devices intelligent. For the commonly used CNN model, domestic and foreign scholars have proposed many acceleration schemes for the model on different platforms, such as FPGA (field programmable array), ASIC (application-specific integrated circuit), Soc (system on chip) and GPU (graphics processing unit) and other platforms. Different from the acceleration method on a specific platform, the present invention improves the CNN model structure, strengthens the feature extraction function of the model and reduces the number of parameters, while ensuring the accuracy, effectively reducing the parameter scale and complexity of the CNN model structure. Summary of the invention
[0003] The purpose of the present invention is to solve the problem that the existing convolutional neural network structure has a large amount of data calculation and is not suitable for use in embedded scenarios. An improved LeNet-5 model for CNN hardware acceleration is proposed, which can reduce the model calculation amount and improve the model recognition speed by reducing the model complexity while ensuring the model recognition accuracy.
[0004] The present invention solves the technical problem by adopting the following technical solution:
[0005] An improved LeNet-5 model for CNN hardware acceleration, characterized by comprising an improved LeNet-5 network structure, wherein the improved LeNet-5 network structure is composed of the following parts:
[0006] The improved LeNet-5 network structure is a multi-layer network structure, including an input layer, a convolutional layer, a pooling layer, an activation layer, a fully connected layer, and an output layer. Each layer contains a large number of learnable parameters, wherein the first and third layers are convolutional layers one and three respectively, the second and fourth layers are pooling layers two and four respectively, the sixth layer is a fully connected layer, and the Output is the output layer, wherein the pooling layer adopts the maximum value pooling method, and the activation function uses the ReLu function. After passing through the pooling layer four, the data is directly connected to the fully connected layer, and the fully connected layer uses 147 neurons. The calculation results are activated using the ReLu function, and the output layer Output uses 10 neurons for classification. The entire network structure has a total of 2383 parameters;
[0007] The convolution layer 1 is composed of 6 convolution kernels of size 5*5. The convolution kernel weights are initialized using regularization. The sliding step of the convolution kernel in each convolution operation is 1. If the size of the feature map of the input feature image is 28*28, the image size is 28*28 pixels, and the image depth is 6, the output is 28*28*6.
[0008] The second pooling layer uses a 2*2 filter, which slides from the upper left corner of the image to the lower right corner of the image with a step size of 2, and outputs a 6-channel feature image with a size of 14*14. Since the receptive field size is 2*2 and does not overlap with each other, the output image size of the second pooling layer is only 1 / 4 of the output image size of the first convolutional layer.
[0009] The convolution kernel size of convolution layer 3 is 5*5 pixels and the depth is 6. Three convolution kernels are used in C3, corresponding to three corresponding bias items, and a total of 18 convolution kernels are involved in the convolution process. Since the activation function does not change the output image size and depth, the output feature image size of convolution layer 3 is 14*14 pixels and the depth is 3, that is, 14*14*3.
[0010] Pooling layer 4 is the same as pooling layer 2, with a size of 2*2. The window sliding step is 2, the feature image is filled with zeros at the edges, and the maximum value of the values of every four adjacent areas in the window is taken, that is, the maximum pooling method. The result size of the pooling layer is 7*7 pixels and the depth is 3.
[0011] The advantages of the present invention are as follows: the convolution layer 5 in the original LeNet-5 structure is removed, the data is directly connected to the fully connected layer after passing through the pooling layer 4, the fully connected layer uses 147 neurons, the calculation result is activated by the ReLu function, the output layer Output uses 10 neurons for classification, the entire network structure has a total of 2383 parameters, the improved network structure greatly reduces the amount of calculation, and the difference between the improved network model and LeNet-5 is shown in Table 1.
[0012] Table 1 Comparison between the network structure of this paper and LeNet-5 structure
[0013] BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 This is a schematic diagram of the overall data processing flow of the CNN model of the present invention;
[0015] Figure 2 This is a schematic diagram of the data processing flow of the convolution calculation module of the present invention;
[0016] Figure 3 This is a schematic diagram of the activation layer data processing flow of the present invention;
[0017] Figure 4 This is a schematic diagram of the data processing flow of the maximum pooling module of the present invention;
[0018] Figure 5 The figure is a schematic diagram of the data processing flow of the multiplier required for the fully connected layer of the present invention. DETAILED DESCRIPTION
[0019] As shown in the figure, the specific implementation of the present invention is as follows: an improved LeNet-5 model for CNN hardware acceleration, characterized in that: the improved LeNet-5 network structure is a multi-layer network structure, including an input layer, a convolution layer, a pooling layer, an activation layer, a fully connected layer, and an output layer, each layer contains a large number of learnable parameters, wherein the first layer and the third layer are convolution layers one and three respectively, the second layer and the fourth layer are pooling layers two and four respectively, the sixth layer is a fully connected layer, and the Output is the output layer, wherein the pooling layer adopts the maximum value pooling method, and the activation function uses the ReLu function. After passing through the pooling layer four, the data is directly connected to the fully connected layer, and the fully connected layer uses 147 neurons. The calculation results are activated using the ReLu function, and the output layer Output uses 10 neurons for classification. The entire network structure has a total of 2383 parameters, which reduces the model calculation amount by reducing the model complexity and improves the model recognition speed.
[0020] The improved LeNet-5 model for CNN hardware acceleration is characterized in that the improved LeNet-5 network structure consists of the following parts:
[0021] The convolution layer 1 is composed of 6 convolution kernels of size 5*5. The convolution kernel weights are initialized using regularization. The sliding step of the convolution kernel in each convolution operation is 1. When the size of the feature map of the input feature image is 28*28, the image size is 28*28 pixels, and the image depth is 6, the output is 28*28*6.
[0022] The second pooling layer uses a 2*2 filter, which slides from the upper left corner of the image to the lower right corner of the image with a step size of 2, and outputs a 6-channel feature image with a size of 14*14. Since the receptive field size is 2*2 and they do not overlap with each other, the output image size in the second pooling layer is only 1 / 4 of the output image size in the first convolutional layer.
[0023] The size of the convolution layer 3 is 5*5 pixels and the depth is 6. Three convolution kernels are used in the convolution layer 3, corresponding to three corresponding bias items. A total of 18 convolution kernels are involved in the convolution process. The activation function does not change the output image size and depth. The output feature image size of the convolution layer 3 is 14*14 pixels and the depth is 3, that is, 14*14*3.
[0024] Pooling layer 4 is the same as pooling layer 2, with a size of 2*2. The window sliding step is 2, the feature image is filled with zeros at the edges, and the maximum value of the values of every four adjacent areas in the window is taken, that is, the maximum pooling method. The pooling layer obtains a result size of 7*7 pixels and a depth of 3.
[0025] like Figure 1 As shown, the improved Le-Net model includes input layer, convolution layer, pooling layer, activation layer, fully connected layer, and output layer, and each layer contains a large number of learnable parameters. The specific overall data processing flow of the improved LeNet-5 network structure applied in the CNN hardware model is described below:
[0026] 1. If Figure 2 As shown in the figure, when the image data Data enters the convolution layer 1, the convolution layer 3 shares the same convolution module with the convolution layer 1, and converts the one-dimensional vector into a three-dimensional array in the order of channel number i, row j, and column k, recorded as DataArray[i][j][k]. Assuming that the number of channels of the original image is c and the image size is h*w, then in the case of no padding on the edge, the conversion formula can be expressed as:
[0027] DataArray[i][j][k]=Data[(i*h*w+j*h+k)*8+8-1:(i*h*w+j*h+k)*8]
[0028] If the edge needs to be filled with 0, data 0 needs to be added to the edge of the DataArray array. Assuming the convolution kernel size is a*b, the conversion pseudo code is as follows:
[0029]
[0030] 2. When the LeNet-5 network structure is improved for data processing, 0 is filled at the edge, and the data is converted and saved in DataArrayP[i][j][k]. After filling, the data needs to be preprocessed by convolution. The overlapping parts of each convolution kernel and data are expanded in sequence. The convolution kernel step size is 1. The operation is expanded from the upper left corner of the data. First, the 5*5 convolution kernel coincides with the padded image data in the upper left corner. Then, the 5*5 image data is arranged from the upper left corner to the lower right corner as the parameters for subsequent convolution operations and saved in the parameter ParamArray array. Each parameter occupies 8 bits. After the 5*5 data is traversed and saved in the parameter ParamArray array, the convolution kernel is expanded from the upper left corner. The corner moves to the right to the right edge and then moves down by one step, and then repeatedly moves to the right to the right edge until it traverses to the last position of the lower right corner of the channel. If the input image is multi-channel, the process is that the convolution kernel extracts 5*5 data from the first channel to the last channel, puts them into the ParamArray array, and then the convolution kernel traverses from the upper left corner to the lower right corner in sequence. Each movement is traversed from the upper left corner of the 5*5 data of the first channel to the lower right corner of the 5*5 data of the last channel to save the parameter data; the parameters of the convolution kernel weight are also read in from the upper left corner of the first convolution kernel to the lower right corner of the last convolution kernel. The data are all 8-bit fixed-point numbers. After the convolution data is read in, it needs to be converted into a one-dimensional vector WeightArray in channel order;
[0031] 3. If Figure 2 As shown in the figure, in order to improve the convolution calculation module of the LeNet-5 network structure, after the data conversion in the above steps 1 and 2, the data is sent to the convolution calculation module for calculation. After the convolution kernel weight Weight is multiplied by the corresponding pixel data X, it is added by the addition circuit and the bias item parameter is added, and then sent to the next layer for calculation. In this structure, the data is sent to the convolution calculation module at the same time, and the calculation is completed and output to the next layer at the same time. The output data is 16 bits, but it will be truncated to 8 bits in the process of inputting the next layer;
[0032] 4. If Figure 3 As shown in the figure, in order to improve the activation layer of the LeNet-5 network structure, the activation layer does not need to perform format conversion for the data output by the convolution layer. It only needs to process the data according to the activation function. When the input is a negative value, the output of the activation layer is 0, otherwise, the output is consistent with the input x.
[0033] 5. If Figure 4As shown in the figure, in order to improve the pooling layer of the LeNet-5 network structure, when the data reaches the pooling layer, the input one-dimensional data vector is first converted, and the data is converted into a three-dimensional array DataArray[i][j][k] in the format of channel i, row j, column k. The conversion process is shown in the following formula, where h and w are the height and width of the image size respectively;
[0034] DataArray[i][j][k]=Data[(i*h*w+j*h+k)*8+8-1:(i*h*w+j*h+k)*8]
[0035] After completing the above conversion, the DataArray array is expanded. The expansion process is as follows: first, a 2*2 sliding window is taken, and the upper left corner of the input data is slid to the lower right corner with a step size of 2. When sliding to the right edge, move down two steps and continue to slide from the left edge to the right edge. Repeat this process until the window slides to the lower right corner of the image. In each slide, the data of all channels under the sliding window are saved in the ParamArray array in the order from the upper left corner of the first channel to the lower right corner of the last channel, and then slide in sequence until the lower right corner of the last channel; after the parameter preprocessing is completed, the data is subjected to the maximum pooling operation, and the largest of the four values in the 2*2 area is taken for output each time;
[0036] 6. If Figure 5 As shown, the fully connected layer needs to use a multiplier, that is, in the fully connected layer, the input one-dimensional vector needs to be multiplied by the weight of the fully connected layer. After the corresponding product operation is completed, the bias parameters of each neuron are added;
[0037] 7. The output layer needs to be connected to a softmax classifier for classification. In order to avoid overfitting of the model, during the back propagation process, the network introduces a model complexity index in the loss function, and by weighting the weight parameters, the impact of noise in the training data on model training is weakened. The Dropout technology is used in the data processing process, and 50% of the neurons are randomly discarded in each round of training.
Claims
1. A method for constructing an improved LeNet-5 model for CNN hardware acceleration, characterized in that: The network structure of the improved LeNet-5 model is a multi-layer network structure, including an input layer, a convolution layer, a pooling layer, an activation layer, a fully connected layer, and an output layer. Each layer contains a large number of learnable parameters, wherein the first and third layers are convolution layers one and three respectively, the second and fourth layers are pooling layers two and four respectively, the sixth layer is a fully connected layer, and the Output is the output layer. The pooling layer adopts the maximum value pooling method, and the activation function uses the ReLu function. After passing through the pooling layer four, the data is directly connected to the fully connected layer. The fully connected layers use 147 neurons, and the calculation results are activated using the ReLu function. The output layer Output uses 10 neurons for classification. The entire network structure has a total of 2383 parameters, which reduces the model calculation amount by reducing the model complexity and improves the model recognition speed; The improved LeNet-5 model consists of the following parts: The convolution layer 1 is composed of 6 convolution kernels of size 5*5. The convolution kernel weights are initialized using regularization. The sliding step of the convolution kernel in each convolution operation is 1. When the size of the feature map of the input feature image is 28*28, the image size is 28*28 pixels, and the image depth is 6, the output is 28*28*6. The second pooling layer uses a 2*2 filter, which slides from the upper left corner of the image to the lower right corner of the image with a step size of 2, and outputs a 6-channel feature image with a size of 14*14. Since the receptive field size is 2*2 and they do not overlap with each other, the output image size in the second pooling layer is only 1 / 4 of the output image size in the first convolutional layer. The size of the convolution layer 3 is 5*5 pixels and the depth is 6. Three convolution kernels are used in the convolution layer 3, corresponding to three corresponding bias items. A total of 18 convolution kernels are involved in the convolution process. The activation function does not change the output image size and depth. The output feature image size of the convolution layer 3 is 14*14 pixels and the depth is 3, that is, 14*14*3. Pooling layer 4 is the same as pooling layer 2, with a size of 2*2. The window sliding step is 2, the feature image is filled with zeros at the edges, and the maximum value of the values of every four adjacent areas in the window is taken, that is, the maximum pooling method. The pooling layer obtains a result size of 7*7 pixels and a depth of 3. The specific overall data processing flow of the improved LeNet-5 model applied in the CNN hardware model is as follows: ①. When the image data Data enters the convolution layer 1, the convolution layer 3 shares the same convolution module with the convolution layer 1, and converts the one-dimensional vector into a three-dimensional array in the order of channel number i, row j, and column k, recorded as DataArray[i][j][k]. Assuming that the number of channels of the original image is c and the image size is h*w, then in the case of no padding on the edge, the conversion formula is expressed as: DataArray[i][j][k]=Data[(i*h*w+j*h+k)*8+8-1:(i*h*w+j*h+k)*8] If the edges need to be filled with 0, data 0 needs to be added to the edges of the DataArray array. Assuming the convolution kernel size is a*b, the conversion steps are as follows: Traverse each image channel, as well as the image size h+a and w+b after edge padding; If the row coordinate is less than a / 2 or greater than (h+a) / 2-1, fill it with 0; If the column coordinate is less than b / 2 or greater than (w+b) / 2-1, fill it with 0, otherwise assign the pixel value at the position where the row and column coordinates are shifted by a / 2 and b / 2 respectively to the pixel value before the shift; ② When the improved LeNet-5 model processes data, it fills the edges with 0 and saves the converted data in DataArrayP[i][j][k]. After filling, the data needs to be preprocessed by convolution. The overlapping parts of each convolution kernel and data are expanded in sequence. The convolution kernel step size is 1. The operation is expanded from the upper left corner of the data. First, the 5*5 convolution kernel overlaps with the padded image data in the upper left corner. Then, the 5*5 image data is arranged from the upper left corner to the lower right corner as the parameters for subsequent convolution operations and saved in the parameter ParamArray array. Each parameter occupies 8 bits. After the 5*5 data is traversed and saved in the parameter ParamArray array, the convolution kernel is expanded from the upper left corner to the lower right corner. The corner moves to the right to the right edge and then moves down by one step, and then repeatedly moves to the right to the right edge until it traverses to the last position of the lower right corner of the channel. If the input image is multi-channel, the process is that the convolution kernel extracts 5*5 data from the first channel to the last channel, puts them into the ParamArray array, and then the convolution kernel traverses from the upper left corner to the lower right corner in sequence. Each movement is traversed from the upper left corner of the 5*5 data of the first channel to the lower right corner of the 5*5 data of the last channel to save the parameter data; the parameters of the convolution kernel weight are also read in from the upper left corner of the first convolution kernel to the lower right corner of the last convolution kernel. The data are all 8-bit fixed-point numbers. After the convolution data is read in, it needs to be converted into a one-dimensional vector WeightArray in channel order; ③. After the data conversion in the above steps ① and ②, the data is sent to the convolution calculation module for calculation. After the convolution kernel weight Weight is multiplied by the corresponding pixel data X, it is added by the addition circuit and the bias item parameter is added, and then sent to the next layer for calculation. The data is sent to the convolution calculation module at the same time, and the calculation is completed and output to the next layer at the same time. The output data is 16 bits, but it will be truncated to 8 bits during the input to the next layer; ④. For the data output by the convolution layer, the activation layer does not need to perform format conversion. It only needs to process the data according to the activation function. When the input is a negative value, the output of the activation layer is 0. Otherwise, the output is consistent with the input x. ⑤. When the data reaches the pooling layer, the input one-dimensional data vector is first converted, and the data is converted into a three-dimensional array DataArray[i][j][k] in the format of channel i, row j, column k. The conversion process is shown in the following formula, where h and w are the height and width of the image size respectively; DataArray[i][j][k]=Data[(i*h*w+j*h+k)*8+8-1:(i*h*w+j*h+k)*8] After completing the above conversion, the DataArray array is expanded. The expansion process is as follows: first, a 2*2 sliding window is taken, and the upper left corner of the input data is slid to the lower right corner with a step size of 2. When sliding to the right edge, move down two steps and continue to slide from the left edge to the right edge. Repeat this process until the window slides to the lower right corner of the image. In each slide, the data of all channels under the sliding window are saved in the ParamArray array in the order from the upper left corner of the first channel to the lower right corner of the last channel, and then slide in sequence until the lower right corner of the last channel; after the parameter preprocessing is completed, the data is subjected to the maximum pooling operation, and the largest of the four values in the 2*2 area is taken for output each time; ⑥. In the fully connected layer, the input one-dimensional vector needs to be multiplied by the weight of the fully connected layer. After the corresponding product operation is completed, the bias parameters of each neuron are added; ⑦. The output layer needs to be connected to a softmax classifier for classification. In order to avoid overfitting of the model, during the back-propagation process, a model complexity index is introduced into the loss function. By weighting the weight parameters, the influence of noise in the training data on the model training is weakened. The Dropout technology is used in the data processing process, and 50% of the neurons are randomly discarded in each round of training.
