A convolutional neural network efficient encoding method, device, and storage medium
Through the run-length coding method, the convolutional neural network's repeated calculations of static image areas are reduced, the calculation speed is improved and the power consumption is reduced, and the problems of large data transmission volume and low speed caused by repeated calculations in the existing technology are solved.
Patent Information
- Application Number
- CN202111585121.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-22
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2041-12-22
AI Technical Summary
When a convolutional neural network processes multiple frames of images, since parts of the first frame image and subsequent frame images are similar or identical, calculations are repeated, which increases the amount of data transmission in the middle layer and reduces the calculation speed, especially in the static image area. Double counting is particularly evident.
The run-length coding method is used to save the specific row and column data of the middle layer as a reference convolution, compare the changes in the subsequent frame image and the first frame image, and only perform convolution operations on areas with large changes to reduce repeated calculations of static areas, and Update the reference convolution when the image shakes or the scene changes.
It greatly reduces the amount of data transmission in the middle layer, improves the calculation speed of the convolutional neural network, reduces power consumption, meets the requirements of real-time response, and reduces repeated calculations of static image areas.
Smart Images

Figure CN114332258B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of processing images using convolutional neural networks, and in particular to a high-efficiency encoding method, device, and storage medium for a convolutional neural network. Background Art
[0002] Convolutional neural networks have been widely used in image recognition. Due to the large amount of calculation, the chip area, price and power consumption are very challenging. In real scenes, the background of many videos shot by cameras is static. If the repeated calculation of convolutional neural networks on image areas that have slightly changed in multiple frames can be reduced, the calculation speed of convolutional neural networks will be greatly improved, the calculation power consumption will be reduced, and the needs of many real-time application scenarios can be met.
[0003] In the prior art, since some areas of the first frame image and the subsequent frame image are similar or identical, repeated calculations result in a huge amount of data transmission in the middle layer of the convolution, while reducing the speed of the convolution operation. Summary of the invention
[0004] In view of the above-mentioned situation that due to the similarity or identity of some areas between the first frame image and the subsequent frame image, repeated calculations lead to a huge amount of data transmission in the convolution intermediate layer, while reducing the speed of the convolution operation. The present invention provides a high-efficiency encoding method, device, and storage medium for a convolutional neural network, which greatly reduces the demand for transmission bandwidth for importing and exporting intermediate layer data, can effectively reduce the repeated calculation of the convolutional neural network on the static image area, and improve the calculation speed of the neural network.
[0005] To achieve the above object, the present invention adopts the following technical solution: an efficient encoding method of a convolutional neural network, comprising the following steps:
[0006] Use the convolutional neural network to calculate the first frame image, select and save the specific row and column data of the middle layer as the reference convolution;
[0007] When the first layer of convolution is calculated for each subsequent frame, it is compared with the reference convolution, and the convolution results of multiple channels with small or unchanged changes are output for run-length encoding;
[0008] When loading input data for computing the next layer of convolution, load the run-length coded region;
[0009] According to whether the input data is a run-length coding area or a non-run-length coding area, specific row and column data of the corresponding intermediate layer are taken out from the reference convolution and / or the non-run-length coding output area of the previous convolution layer to perform convolution operations with different strategies;
[0010] Every time a preset number of frames are generated, specific row and column data of the current convolutional intermediate layer is selected and saved to update the reference convolution, and run-length encoding of each subsequent frame is continued.
[0011] Preferably, the calculating the first frame image by using a convolutional neural network includes:
[0012] Load the first frame image and the convolutional neural network convolution kernel weights;
[0013] Calculate according to the standard convolutional neural network calculation method;
[0014] Select and save specific row and column data of multiple intermediate layers as reference convolution.
[0015] Preferably, the multiple channel convolution result outputs are run-length encoded, including:
[0016] When inputting each subsequent frame image to calculate the first layer of convolution, it is compared with the corresponding row and column convolution output data of the first frame image or the reference convolution;
[0017] If the change is small or no change, the run-length encoding is used to encode the data output by the convolution result of the continuous series. The run-length encoding includes the encoding flag bit + starting position + number of columns. Each additional column is added by +1 on the basis of the number of columns until the current column changes significantly and the run-length encoding is terminated.
[0018] The run-length encoded and non-run-length encoded convolution data are stored in different regions.
[0019] Preferably, the efficient encoding method further comprises:
[0020] When the first layer of convolutional run-length coding is sparse, it is determined that the image is shaking or the scene is switched;
[0021] When calculating the first layer of convolution, calculate the local motion vector and the global motion vector and judge:
[0022] If there is no obvious global motion vector, it is determined that a scene switch occurs, and the process returns to the step of calculating the first frame image with the convolutional neural network to determine the reference convolution;
[0023] If there is an obvious global motion vector, it is determined that the image is shaking, and the position consistent with the global motion vector is obtained and run-length encoding is performed.
[0024] Preferably, the calculating of the local motion vector and the global motion vector comprises:
[0025] When calculating the first layer of convolution, it is compared with the convolution within the range of m*n of the previous frame, and the one with the smallest difference is selected to calculate the local motion vector. If the difference between adjacent motion vectors is small, they are regarded as a group and run-length coded;
[0026] The group with the most pixels is selected, and the motion vector of the group is used as the global motion vector. If the group with the most pixels does not contain more than half of the pixels, it is determined that a scene switch occurs.
[0027] Preferably, when loading input data for calculating the next layer of convolution, loading the run-length coding area includes:
[0028] To calculate the next layer of convolution, first load the run-length coding area, take out the run-length coding of the adjacent rows corresponding to the convolution kernel, and calculate the maximum common row run starting from the current position;
[0029] Ignore and skip the maximum common row run, output the convolution result with the corresponding run-length coding, and place it in the next layer of run-length coding output area.
[0030] Preferably, when loading input data for calculating the next layer of convolution, loading the run-length coding area also includes:
[0031] To calculate the next layer of convolution, first load the run-length coding area and calculate the run-length without common rows;
[0032] When inputting data in the run-length coding region, the specific row and column data of the corresponding intermediate layer will be taken out from the reference convolution;
[0033] When inputting data into a non-run-length coded area, the specific row and column data of the corresponding intermediate layer is taken out from the non-run-length coded output area of the previous layer, and the convolution kernel weights are loaded to perform the convolution operation.
[0034] Preferably, when loading input data for calculating the next layer of convolution, loading the run-length coding area also includes:
[0035] To calculate the next layer of convolution, first load the run-length coding area, including loading the run-length coding of the group of pixels where it is located when there is a global motion vector, which is used to calculate the maximum common row run.
[0036] On the other hand, the present invention also provides an efficient encoding device for a convolutional neural network, comprising one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include instructions for executing the above-mentioned efficient encoding method for a convolutional neural network.
[0037] On the other hand, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-mentioned efficient encoding method for a convolutional neural network.
[0038] Compared with the prior art, the present invention has the following beneficial effects:
[0039] The present invention uses the middle layer data of the convolution of the first frame image as a convolution reference. When calculating the subsequent frame image, run-length compression and decompression are used to process the input and output of the convolution middle layer data, which greatly reduces the transmission amount of the middle layer data. If the local input of the middle layer of the subsequent frame convolution remains unchanged or changes slightly, the convolution operation will not be performed, which greatly improves the average speed of the convolution operation of multiple frames of images.
[0040] The present invention greatly reduces the demand for transmission bandwidth for importing and exporting intermediate layer data between the NPU and the memory, can effectively reduce the repeated calculation of the convolutional neural network on the static image area, improve the calculation speed of the neural network, meet the requirements of real-time response, and greatly reduce power consumption. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solution, the drawings required for use in the implementation will be briefly introduced below. Obviously, the drawings described below are only some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0042] Figure 1 It is a schematic diagram of the structure of the present invention. DETAILED DESCRIPTION
[0043] In order to enable a clear and complete understanding of the technical solution, the present invention is further described in conjunction with the embodiments and drawings. Obviously, the described embodiments are only some embodiments of the present invention, and all other embodiments obtained by technicians in the relevant field without making creative work are within the scope of protection of the present invention.
[0044] like Figure 1 As shown, an efficient encoding method for a convolutional neural network includes the following steps:
[0045] The NPU loads the first frame image and the convolution kernel weights of the convolutional neural network, calculates the first frame image using the standard convolutional neural network calculation method, selects and saves specific row and column data of certain intermediate layers as reference convolution, and uses the intermediate layer data of the convolution of the first frame image as a reference when calculating the subsequent frame image. It uses run-length compression and decompression to process the input and output of the convolution intermediate layer data, which greatly reduces the transmission amount of the intermediate layer data.
[0046] When the first layer of convolution is calculated for each subsequent frame, it will be compared with the reference convolution row by row and column by column, and the convolution results of multiple channels with small or unchanged changes will be run-length encoded. When the first layer of convolution is calculated for each subsequent frame, it will be compared with the convolution output data of the first frame or the reference convolution corresponding rows and columns.
[0047] If the change is small or no change, the run-length encoding is used to encode the data output by the continuous series convolution result. The run-length encoding includes the encoding flag bit + starting position + number of columns. Each additional column is added by 1 on the basis of the number of columns until the current column changes significantly and the run-length encoding ends; the run-length encoded and non-run-length encoded convolution data are stored in different regions. If the local input of the middle layer of the convolution of the subsequent frame remains unchanged or changes slightly, the convolution operation will not be performed, which greatly improves the average speed of the convolution operation of multiple frames of images.
[0048] At this time, when calculating the first layer of convolution, if the run-length coding is sparse, the sparseness of the run-length coding is used to further determine whether the image is shaking or the scene is switching:
[0049] When calculating the first layer of convolution, it is compared with the convolution within the 4×4 range of the previous frame, and the one with the smallest difference is selected to calculate the local motion vector. If the difference between adjacent motion vectors is small, they are regarded as a group and run-length encoding is performed; the group with the most pixels is selected, and the motion vector of the group is used as the global motion vector. If the group with the most pixels does not contain more than half of the pixels, that is, there is no obvious global motion vector, it is judged that a scene switch has occurred. If there is an obvious global motion vector, it is judged that the image is shaking, and the position consistent with the global motion vector is obtained and run-length encoding is performed. If it is judged that the image is shaking, the local motion vector is calculated when calculating the first layer of convolution. After obtaining the global motion vector, the pixels consistent with the global motion vector are effectively run-length encoded, so that the convolution calculation of multiple frames of images can be efficiently processed in the case of image shaking.
[0050] The run-length encoding of the group of pixels obtained according to the motion vector is a valid run-length encoding, which is used to calculate the maximum common run. When calculating the next layer of convolution, the input data of the common run does not need to be loaded, and the convolution operation within the common run does not need to be performed, which effectively reduces the repeated calculation of the convolutional neural network on the image area.
[0051] When there is no obvious global motion vector and it is determined that a scene switch occurs, the reference convolution step determined at the beginning is re-executed.
[0052] To calculate the next layer of convolution, first load the run-length coding area, take out the run-length coding of the adjacent rows corresponding to the convolution kernel, and calculate the maximum common row run starting from the current position; run-length coding includes obtaining the run-length coding of the group of pixels according to the motion vector, ignoring and skipping the maximum common row run, outputting the convolution result with the corresponding run-length coding, and placing the next layer of run-length coding output area.
[0053] When calculating the runs without common rows, data is input according to the run-length coding area and the non-run-length coding area. When data is input in the run-length coding area, the specific row and column data of the corresponding intermediate layer is taken out from the reference convolution; when data is input in the non-run-length coding area, the specific row and column data of the corresponding intermediate layer is taken out from the non-run-length coding output area of the previous layer, and the convolution kernel weights are loaded to perform the convolution operation.
[0054] Every time a preset number of frames are generated, the specific row and column data of the current convolution intermediate layer is selected and saved to update the reference convolution, and the run-length encoding of each subsequent frame is continued. This loop can ensure that each subsequent frame has a strong correlation with the image determined as the reference convolution to reduce repeated calculations.
[0055] In this implementation case, the intermediate layer data of the convolution of the first frame image is used as the convolution reference. When calculating the subsequent frame image, run-length compression and decompression are used to process the input and output of the convolution intermediate layer data, which greatly reduces the transmission volume of the intermediate layer data. If the local input of the intermediate layer of the subsequent frame convolution remains unchanged or changes slightly, the convolution operation will not be performed, which greatly improves the average speed of the convolution operation of multiple frames of images; it greatly reduces the demand for transmission bandwidth for importing and exporting intermediate layer data between the NPU and the memory, can effectively reduce the repeated calculation of the static image area by the convolution neural network, improve the calculation speed of the neural network, meet the requirements of real-time response, and greatly reduce power consumption.
[0056] Implementation case 2:
[0057] A highly efficient encoding device for a convolutional neural network, comprising one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include instructions for executing a highly efficient encoding method for a convolutional neural network, implementing the following steps:
[0058] S100, calculating the first frame image according to a standard convolutional neural network calculation method, and saving multiple layers of intermediate layer data as a reference frame.
[0059] S200, when the second frame image is input to calculate the first layer of convolution, the convolution output data of the corresponding rows and columns of the first frame image are compared at the same time. If the convolution output data of the continuous series is unchanged or changes very little, the convolution output data of the continuous series is run-length encoded using the run-length method.
[0060] S300. When calculating the first layer of convolution for an image, if the run-length coding is sparse, it means that the image is shaking or the scene is switched. When calculating the first layer of convolution, the local motion vector is calculated at the same time, and then the global motion vector is calculated. If there is no obvious global motion vector, it is determined that the scene is switched, and the process jumps to step S100 and executes again. Otherwise, it is determined that the image is shaking, and effective run-length coding can still be performed on the position consistent with the global motion vector.
[0061] S400. If the local convolution inputs are all run-length coded, the remaining common row runs are skipped and no convolution operation is performed, and the result is output using run-length coding. If non-run-length coding exists, the convolution kernel is loaded to perform a standard convolution operation and output the intermediate layer data of non-run-length coding.
[0062] S500, selecting and saving the corresponding intermediate layer convolution output data every several frames to update the reference frame.
[0063] This implementation case reduces the repeated calculation of the convolutional neural network on image areas that have slightly changed in multiple frames of images, which will greatly improve the calculation speed of the convolutional neural network, reduce computing power consumption, and meet the needs of many real-time application scenarios.
[0064] On the other hand, the implementation case also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, it implements an efficient encoding method for a convolutional neural network in the above-mentioned implementation case one.
[0065] The implementation cases described above can be implemented in the form of executable program commands by various computer devices that can be recorded to computer-readable media. Computer-readable media can include program commands, data files, and data structures, alone or in combination. The program commands recorded to the medium can be components specially designed for the present invention, or available to technicians in the relevant fields. Computer-readable recording media include: magnetic media such as hard disks, floppy disks, and tapes; optical media such as CD-ROMs and DVDs; magneto-optical media such as optical disks; hardware devices such as ROM, RAM; and flash memory specifically used to store and execute programs. Program commands include not only machine language codes generated by a compiler, but also high-level codes that can be used by interpreters and the like executed by computing devices. The above-mentioned hardware devices can work more than just as software modules to perform the technical features of the present invention, and they can do the same work in reverse situations.
[0066] The above disclosure is only one or more preferred embodiments of the present invention, which are used to help understand the inventive concept of the technical solution, and is not intended to limit the present invention in other forms. Technical personnel in the relevant field may make other equivalent or customary replacement schemes based on the features defined by the present invention, which still fall within the scope of the present invention.
Claims
1. An efficient encoding method for a convolutional neural network, characterized in that: The following steps are involved: Use the convolutional neural network to calculate the first frame image, select and save the specific row and column data of the middle layer as the reference convolution; When the first layer of convolution is calculated for each subsequent frame image, it is compared with the reference convolution, and the convolution results of multiple channels with small or unchanged changes are output for run-length encoding, including: when inputting each subsequent frame image to calculate the first layer of convolution, it is compared with the corresponding row and column convolution output data of the first frame image or the reference convolution; if the change is very small or there is no change, the data output of the continuous series convolution results is encoded in a run-length manner, and the run-length encoding includes encoding flag bit + starting position + number of columns, and each additional column is added on the basis of the number of columns + 1 value until the run-length encoding is terminated after the continuous series changes significantly; the run-length encoded and non-run-length encoded convolution data are stored in different areas; When loading input data for computing the next layer of convolution, load the run-length coded region; When inputting data according to the run-length coding area and the non-run-length coding area, specific row and column data of the corresponding intermediate layer are taken out from the reference convolution and / or the previous convolution non-run-length coding output area to perform convolution operations of different strategies; Every time a preset number of frames are generated, specific row and column data of the current convolutional intermediate layer is selected and saved to update the reference convolution, and run-length encoding of each subsequent frame is continued.
2. The efficient coding method for a convolutional neural network according to claim 1, characterized in that: The method of calculating the first frame image using a convolutional neural network includes: Load the first frame image and the convolutional neural network convolution kernel weights; Calculate according to the standard convolutional neural network calculation method; Select and save specific row and column data of multiple intermediate layers as reference convolution.
3. The efficient coding method for a convolutional neural network according to claim 1, characterized in that: Also includes: When the first layer of convolutional run-length coding is sparse, it is determined that the image is shaking or the scene is switched; When calculating the first layer of convolution, calculate the local motion vector and the global motion vector and judge: If there is no obvious global motion vector, it is determined that a scene switch occurs, and the process returns to the step of calculating the first frame image with the convolutional neural network to determine the reference convolution; If there is an obvious global motion vector, it is determined that the image is shaking, and the position consistent with the global motion vector is obtained and run-length encoding is performed.
4. The efficient coding method for a convolutional neural network according to claim 3, characterized in that: The calculating of the local motion vector and the global motion vector comprises: When calculating the first layer of convolution, it is compared with the convolution within the m*n range of the previous frame, and the one with the smallest difference is selected to calculate the local motion vector. If the difference between adjacent motion vectors is small, they are regarded as a group and run-length encoding is performed; The group with the most pixels is selected, and the motion vector of the group is used as the global motion vector. If the group with the most pixels does not contain more than half of the pixels, it is determined that a scene switch occurs.
5. The efficient coding method for a convolutional neural network according to claim 1, characterized in that: When loading input data for calculating the next layer of convolution, the run-length coding area is loaded, including: To calculate the next layer of convolution, first load the run-length coding area, take out the run-length coding of the adjacent rows corresponding to the convolution kernel, and calculate the maximum common row run starting from the current position; Ignore and skip the maximum common row run, output the convolution result with the corresponding run-length coding, and place it in the next layer of run-length coding output area.
6. The efficient coding method for a convolutional neural network according to claim 1, characterized in that: When loading input data for calculating the next layer of convolution, loading the run-length coding area also includes: To calculate the next layer of convolution, first load the run-length coding area, including loading the run-length coding of the group of pixels where it is located when there is a global motion vector, which is used to calculate the maximum common row run.
7. The efficient coding method for a convolutional neural network according to claim 1, characterized in that: When inputting data according to the run-length coding area and the non-run-length coding area, specific row and column data of the corresponding intermediate layer are taken out from the reference convolution and / or the previous convolution non-run-length coding output area to perform convolution operations of different strategies, including: To calculate the next layer of convolution, first load the run-length coding area and calculate the run-length without common rows; When inputting data in the run-length coding region, the specific row and column data of the corresponding intermediate layer will be taken out from the reference convolution; When inputting data into a non-run-length coded area, the specific row and column data of the corresponding intermediate layer is taken out from the non-run-length coded output area of the previous layer, and the convolution kernel weights are loaded to perform the convolution operation.
8. An efficient encoding device for a convolutional neural network, comprising one or more processors, a memory, and one or more programs, characterized in that: The one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include instructions for executing an efficient encoding method for a convolutional neural network as described in any one of claims 1-7.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, an efficient encoding method for a convolutional neural network as described in any one of claims 1 to 7 is implemented.
