Memory-optimized block-based inference method and system for convolutional neural networks
By adopting a block-based inference method in the convolutional neural network, using the calculated features and combining the convolution depth and convolution kernel size to perform multi-layer convolution operations, the high demand for external memory bandwidth in convolutional neural network image processing is solved. solve the problem and achieve the bandwidth reduction effect without increasing the amount of calculation and block register.
Patent Information
- Application Number
- CN202010922472.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2019-10-08
- Filing Date
- 2020-09-04
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2040-09-04
AI Technical Summary
Existing convolutional neural networks require high external memory bandwidth in image processing, and there is a lack of optimization methods that can significantly reduce bandwidth requirements without increasing the amount of calculations and block registers.
Using the block-based inference method, by reusing the calculated features in the forward direction of the block and recalculating the features in the other direction, the input image is divided by combining the convolution depth, block width and convolution kernel size, and multi-layer convolution is performed. The product operation is performed to generate the output block data and the features are temporarily stored in the block register.
Without increasing the amount of calculations and block registers, the bandwidth requirements of external memory are significantly reduced and memory efficiency is improved.
Smart Images

Figure CN112633462B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a block-based inference method and a system thereof, and in particular to a memory-optimized block-based inference method and a system thereof for a convolutional neural network. Background Art
[0002] When using convolutional neural networks in image processing applications, the external memory bandwidth requirement may be quite high, and the use of a block-based inference process can significantly reduce this bandwidth requirement. However, there will be overlapping feature vectors between blocks. Currently, there are two different known processing methods, one is recalculation and the other is reuse. The former will increase the amount of calculation and reduce the output pixel volume, while the latter requires a large number of block registers to store reused feature vectors. It can be seen that there is currently a lack of a memory-optimized block-based inference method and system for convolutional neural networks on the market that can significantly reduce the external memory bandwidth requirement without increasing too much calculation and block registers, so related industry players are all looking for solutions. Summary of the invention
[0003] Therefore, the purpose of the present invention is to provide a memory-optimized block-based inference method and system for a convolutional neural network. When performing block-based inference, the calculated features are reused in the direction of the block forward, and recalculated in the other direction, so that the block-based inference can still significantly reduce the bandwidth requirements of the external memory without increasing too much calculation and block register.
[0004] According to an embodiment of the method style of the present invention, a memory-optimized block-based inference method of a convolutional neural network is provided, which is used to process an input image. The memory-optimized block-based inference method of the convolutional neural network includes a parameter setting step, a segmentation step, a block inference step, and a temporary storage step, wherein the parameter setting step is to set an inference parameter group, and the inference parameter group includes a convolution depth, a block width, a block height, and multiple convolution kernel sizes. The segmentation step is to drive an operation processing unit to divide the input image into multiple input block data according to the convolution depth, block width, block height, and these layers of convolution kernel sizes, and each input block data has an input block size. The block inference step is to drive the operation processing unit to perform multi-layer convolution operations on each input block data to generate output block data. The multi-layer convolution operation includes a first direction data selection step, a second direction data selection step and a convolution operation step, wherein the first direction data selection step is to select a plurality of i-th layer recalculated features along a scanning line direction according to a position of the output block data, and then select an i-th layer recalculated input feature block data according to the position of the output block data and these i-th layer recalculated features, wherein i is one of a plurality of positive integers from 1 to the convolution depth. The second direction data selection step is to select a plurality of i-th layer reused features along a block scanning direction according to the i-th layer recalculated input feature block data, and combine the i-th layer recalculated input feature block data and these i-th layer reused features to generate an i-th layer reused input feature block data. In addition, the convolution operation step is to select multiple i-th layer sub-block input feature groups from the i-th layer reused input feature block data according to the i-th layer convolution kernel size, and then perform a convolution operation on each i-th layer sub-block input feature group and a convolution parameter group to generate an i-th layer sub-block output feature, and combine these i-th layer sub-block output features corresponding to these i-th layer sub-block input feature groups to form an i-th layer output feature block data. The temporary storage step is to drive a block register to temporarily store the i-th layer output feature block data and these i-th layer reused features. The convolution depth, block width and block height are all positive integers, and the i-th layer convolution kernel size is k. Wi ×k Hi , these i-th layer reuse features have a number of reuse features along the block scanning direction, and the number of reuse features is equal to k Hi -1. The block width is represented by B W , the convolution depth is represented by D, and the block height is represented by B H . Input block size equals B W ×B H The output block data has an output block size, and the output block size is equal to (B W -2D)×B HThe i-th layer recalculated input feature block data has the i-th layer recalculated input feature block size, and the i-th layer recalculated input feature block size is equal to (B W -2i+2)×B H The i-th layer reused input feature block data has the i-th layer reused input feature block size, and the i-th layer reused input feature block size is equal to (B W -2i+2)×(B H +2). The i-th layer output feature block data has the i-th layer output feature block size, and the i-th layer output feature block size is equal to (B W -2i)×B H The convolution depth is less than half of the block width.
[0005] Thus, the memory-optimized block-based inference method of the convolutional neural network of the present invention uses different feature calculation methods in different directions, so that the block-based inference can still significantly reduce the bandwidth requirements of the external memory without increasing too much calculation amount and block register.
[0006] Other embodiments of the aforementioned implementation are as follows: When the aforementioned i is equal to 1, the i-th layer recalculates the input feature block data to be equal to each input block data. When i is equal to the convolution depth, the i-th layer output feature block data is equal to the output block data.
[0007] Other embodiments of the aforementioned implementation are as follows: the aforementioned i-th layer recalculated input feature block data has an i-th layer recalculated input feature block size and an i-th layer recalculated input feature block channel number, and the i-th layer output feature block data has an i-th layer output feature block size and an i-th layer output feature block channel number. The i-th layer output feature block size is larger than the i-th layer recalculated input feature block size, and the i-th layer recalculated input feature block channel number is equal to the i-th layer output feature block channel number.
[0008] Other embodiments of the aforementioned implementation are as follows: the aforementioned block scanning direction is perpendicular to the scanning line-wrapping direction, the block width is greater than the block height, and the extension direction of the block height is parallel to the block scanning direction.
[0009] Other embodiments of the aforementioned implementation are as follows: when at least one of the multiple input features of one of the aforementioned i-th layer sub-block input feature groups is located in the outer area of the area where the i-th layer reused input feature block data is located, these input features of this i-th layer sub-block input feature group include multiple outer block features and multiple first inner block features. These outer block features represent calculated features, and these first inner block features represent uncalculated features. Furthermore, when these input features of one of the i-th layer sub-block input feature groups are all located in the inner area of the area where the i-th layer reused input feature block data is located, these input features of this i-th layer sub-block input feature group only include multiple second inner block features. The arrangement order of the area where the i-th layer reused input feature block data is located along the block scanning direction is the outer area and the inner area.
[0010] Other embodiments of the aforementioned implementation are as follows: The aforementioned external block features are stored in a block register, which has a temporary storage space, and the temporary storage space is obtained by calculating the width of the i-th layer recalculated input feature block data, the convolution depth, the number of layers, the number of channels and the i-th layer convolution kernel size. The width of the i-th layer recalculated input feature block data is expressed as B Wi , the convolution depth is represented by D, the number of layers is represented by i, the number of channels is represented by C, and the size of the convolution kernel of the i-th layer is k Wi ×k Hi , the temporary storage space is expressed as LBS and conforms to the following formula:
[0011]
[0012] According to one embodiment of the structural style of the present invention, a memory-optimized block-based inference system of a convolutional neural network is provided, which is used to process an input image. The memory-optimized block-based inference system of the convolutional neural network includes a block register and an operation processing unit, wherein the block register is used to access the i-th layer output feature block data and multiple i-th layer reuse features. The operation processing unit is electrically connected to the block register, and the operation processing unit receives the input image and is configured to implement an operation including the following steps: a parameter setting step, a segmentation step, and a block inference step. The parameter setting step is to set an inference parameter group, and the inference parameter group includes a convolution depth, a block width, a block height, and a multi-layer convolution kernel size. The segmentation step is to divide the input image into multiple input block data according to the convolution depth, the block width, the block height, and the convolution kernel size of these layers, and each input block data has an input block size. In addition, the block inference step is to perform a multi-layer convolution operation on each input block data to generate output block data, and this multi-layer convolution operation includes a first direction data selection step, a second direction data selection step and a convolution operation step. The first direction data selection step is to select a plurality of i-th layer recalculated features along the scanning line direction according to the position of the output block data, and then select the i-th layer recalculated input feature block data according to the position of the output block data and these i-th layer recalculated features, wherein i is one of a plurality of positive integers from 1 to the convolution depth. The second direction data selection step is to select these i-th layer reused features along the block scanning direction according to the i-th layer recalculated input feature block data, and combine the i-th layer recalculated input feature block data and these i-th layer reused features to generate the i-th layer reused input feature block data. The convolution operation step is to select multiple i-th layer sub-block input feature groups from the i-th layer reused input feature block data according to the i-th layer convolution kernel size, and then perform convolution operation on each i-th layer sub-block input feature group and a convolution parameter group to generate the i-th layer sub-block output features, and combine these i-th layer sub-block output features corresponding to these i-th layer sub-block input feature groups to form the i-th layer output feature block data. The convolution depth, block width and block height are all positive integers, and the i-th layer convolution kernel size is k. Wi ×k Hi , these i-th layer reuse features have a number of reuse features along the block scanning direction, and the number of reuse features is equal to k Hi -1. The block width is represented by B W , the convolution depth is represented by D, and the block height is represented by B H . Input block size equals B W ×B H The output block data has an output block size, and the output block size is equal to (B W -2D)×B HThe i-th layer recalculated input feature block data has the i-th layer recalculated input feature block size, and the i-th layer recalculated input feature block size is equal to (B W -2i+2)×B H The i-th layer reused input feature block data has the i-th layer reused input feature block size, and the i-th layer reused input feature block size is equal to (B W -2i+2)×(B H +2). The i-th layer output feature block data has the i-th layer output feature block size, and the i-th layer output feature block size is equal to (B W -2i)×B H The convolution depth is less than half of the block width.
[0013] Thus, the memory-optimized block-based inference system of the convolutional neural network of the present invention uses calculation methods with different features in different directions, so that the block-based inference can still significantly reduce the bandwidth requirements of the external memory without increasing too much calculation amount and block register.
[0014] Other embodiments of the aforementioned implementation are as follows: when the aforementioned i is equal to 1, the i-th layer recalculates the input feature block data to be equal to each input block data. When i is equal to the convolution depth, the i-th layer output feature block data is equal to the output block data.
[0015] Other embodiments of the aforementioned implementation are as follows: the aforementioned i-th layer recalculated input feature block data has an i-th layer recalculated input feature block size and an i-th layer recalculated input feature block channel number, and the i-th layer output feature block data has an i-th layer output feature block size and an i-th layer output feature block channel number. The i-th layer output feature block size is greater than the i-th layer recalculated input feature block size, and the i-th layer recalculated input feature block channel number is equal to the i-th layer output feature block channel number.
[0016] Other embodiments of the aforementioned implementation are as follows: the aforementioned block scanning direction is perpendicular to the scanning line-wrapping direction, the block width is greater than the block height, and the extension direction of the block height is parallel to the block scanning direction.
[0017] Other embodiments of the aforementioned implementation are as follows: when at least one of the multiple input features of one of the aforementioned i-th layer sub-block input feature groups is located in the outer area of the area where the i-th layer reused input feature block data is located, these input features of this i-th layer sub-block input feature group include multiple outer block features and multiple first inner block features. These outer block features represent calculated features, and these first inner block features represent uncalculated features. Furthermore, when these input features of one of the i-th layer sub-block input feature groups are all located in the inner area of the area where the i-th layer reused input feature block data is located, these input features of this i-th layer sub-block input feature group only include multiple second inner block features. The arrangement order of the area where the i-th layer reused input feature block data is located along the block scanning direction is the outer area and the inner area.
[0018] Other embodiments of the aforementioned implementation are as follows: The aforementioned external block features are stored in a block register, and the block register has a temporary storage space, which is obtained by calculating the width of the input feature block data recalculated at the i-th layer, the convolution depth, the number of layers, the number of channels, and the i-th layer convolution kernel size. The width of the input feature block data recalculated at the i-th layer is expressed as B Wi , the convolution depth is represented by D, the number of layers is represented by i, the number of channels is represented by C, and the size of the convolution kernel of the i-th layer is k Wi ×k Hi , the temporary storage space is expressed as LBS and conforms to the following formula:
[0019] BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 1 is a flow chart showing a memory-optimized block-based inference method for a convolutional neural network according to a first embodiment of the present invention;
[0021] Figure 2 It is shown Figure 1 Schematic diagram of the segmentation steps;
[0022] Figure 3 It is shown Figure 1 A three-dimensional schematic diagram of input block data and output block data of a multi-layer convolution operation in a block inference step;
[0023] Figure 4 It is shown Figure 1 A schematic diagram of a first direction data selection step;
[0024] Figure 5 It is shown Figure 1 A schematic diagram of a second direction data selection step;
[0025] Figure 6 It is shown Figure 3A schematic diagram of the first layer reusing the input feature block data;
[0026] Figure 7 is a schematic diagram showing channel shuffling according to a second embodiment of the present invention;
[0027] Figure 8 is a block diagram illustrating a memory-optimized block-based inference system for a convolutional neural network according to a third embodiment of the present invention;
[0028] Fig. 9 is a schematic flow chart showing a multi-layer convolution operation with a 3×3 filter according to a fourth embodiment of the present invention; and
[0029] Fig.10 It is a schematic diagram showing simulation results of recalculation, reuse, and recalculation and reuse according to the present invention.
[0030] Description of reference numerals:
[0031] 100: Memory-optimized block-based inference method for convolutional neural networks
[0032] S02: Parameter setting steps
[0033] S04: Segmentation step
[0034] S06: Block Inference Steps
[0035] S062: First direction data selection step
[0036] S064: Second direction data selection step
[0037] S066: Convolution operation steps
[0038] S08: Temporary storage Step 110: Output image
[0039] 200: Memory-Optimized Block-Based Inference System for Convolutional Neural Networks
[0040] 212: Inference parameter group
[0041] 214: Convolution parameter group
[0042] 220: Block register
[0043] 230: Processing unit
[0044] 232: Convolution Engine
[0045] B W ,W1,W2,W3: Block width
[0046] B H ,H1,H2,H3: Block height
[0047] C1: The number of input feature block channels reused in the i-th layer
[0048] C2: Number of channels of the intermediate feature block in the i-th layer
[0049] C3: Number of channels of the output feature block of the i-th layer
[0050] D: Convolution depth
[0051] D max : Maximum supported convolution depth
[0052] D1: Scan line feed direction
[0053] D2: Block scanning direction
[0054] FC: Recalculate
[0055] FU: Reuse
[0056] FCFU: Recalculate and reuse
[0057] IB: Input block data
[0058] IR: inner area
[0059] k-1: number of reused features
[0060] L1: Layer 1
[0061] L1FC: Layer 1 recalculation features
[0062] L1FC_I: Layer 1 recalculates input feature block data
[0063] L1FU: Layer 1 reuse feature
[0064] L1FU_I: Layer 1 reuses input feature block data
[0065] L1_O: Layer 1 output feature block data
[0066] L2: Layer 2
[0067] L2FC: Layer 2 recomputed features
[0068] L2FC_I: Layer 2 recalculates input feature block data
[0069] L2FU: Layer 2 reuse feature
[0070] L2FU_I: Layer 2 reuses input feature block data L2_O: Layer 2 output feature block data
[0071] L3: Layer 3
[0072] L3FC: Layer 3 recomputed features
[0073] L3FC_I: Layer 3 recalculates input feature block data
[0074] L3FU: Layer 3 reuse feature
[0075] L3FU_I: Layer 3 reuses input feature block data
[0076] L3_O: Layer 3 output feature block data
[0077] LD: Layer D
[0078] LiFU_I: The i-th layer reuses the input feature block data
[0079] Li_M: The intermediate block data of the i-th layer
[0080] Li_O: The i-th layer output feature block data
[0081] NTR: Normalized Throughput Rate
[0082] OB: Output block data
[0083] OR: Outer area
[0084] S: Block buffer size limit
[0085] SBG1, SBG11, SBG12: Layer 1 sub-block input feature group
[0086] SBG2: Layer 2 sub-block input feature group
[0087] SBG3: Layer 3 sub-block input feature group DETAILED DESCRIPTION
[0088] The following will describe multiple embodiments of the present invention with reference to the accompanying drawings. For the purpose of clarity, many practical details will be described together in the following description. However, it should be understood that these practical details should not be used to limit the present invention. That is, in some embodiments of the present invention, these practical details are not necessary. In addition, in order to simplify the drawings, some conventional structures and elements will be shown in the drawings in a simple schematic manner; and repeated elements may be represented by the same number.
[0089] In addition, in this article, when a certain element (or unit or module, etc.) is "connected" to another element, it may refer to that the element is directly connected to another element, or it may refer to that a certain element is indirectly connected to another element, that is, there are other elements between the element and the other element. When it is explicitly stated that a certain element is "directly connected" to another element, it means that there are no other elements between the element and the other element. The terms first, second, third, etc. are only used to describe different elements, and there is no restriction on the elements themselves. Therefore, the first element can also be renamed as the second element. Moreover, the combination of elements / units / circuits in this article is not a generally known, conventional or existing combination in this field. Whether the elements / units / circuits themselves are existing cannot be used to determine whether their combination relationship is easy to be easily completed by those with ordinary knowledge in the technical field.
[0090] See also Figure 1 , Figure 1 1 is a flow chart showing a memory-optimized block-based inference method 100 for a convolutional neural network according to a first embodiment of the present invention. The memory-optimized block-based inference method 100 for a convolutional neural network is used to process an input image to generate an output image, and includes a parameter setting step S02, a segmentation step S04, a block inference step S06, and a temporary storage step S08.
[0091] The parameter setting step S02 is to set an inference parameter set, which includes convolution depth, block width, block height and multiple convolution kernel sizes. The number of layers of these multiple convolution kernel sizes is equal to the convolution depth.
[0092] The segmentation step S04 is to drive the processing unit to divide the input image into a plurality of input block data according to the convolution depth, the block width, the block height and the sizes of the convolution kernels of these layers, and each input block data has an input block size.
[0093] The block inference step S06 is to drive the operation processing unit to perform a multi-layer convolution operation on each input block data to generate output block data, and the multi-layer convolution operation includes a first direction data selection step S062, a second direction data selection step S064 and a convolution operation step S066. The first direction data selection step S062 is to select a plurality of i-th layer recalculated features along the scanning line direction according to the position of the output block data, and then select an i-th layer recalculated input feature block data according to the position of the output block data and these i-th layer recalculated features, wherein i is one of a plurality of positive integers from 1 to the convolution depth. In addition, the second direction data selection step S064 is to select a plurality of i-th layer reused features along the block scanning direction according to the i-th layer recalculated input feature block data, and combine the i-th layer recalculated input feature block data and these i-th layer reused features to generate an i-th layer reused input feature block data. Furthermore, the convolution operation step S066 selects a plurality of i-th layer sub-block input feature groups from the i-th layer reused input feature block data according to the i-th layer convolution kernel size, and then performs a convolution operation on each i-th layer sub-block input feature group and a convolution parameter set to generate an i-th layer sub-block output feature, and combines these i-th layer sub-block output features corresponding to these i-th layer sub-block input feature groups to form an i-th layer output feature block data. The convolution parameter set includes a weight parameter and a bias parameter.
[0094] The temporary storage step S08 is to drive the block buffer bank to temporarily store the i-th layer output feature block data and the i-th layer reuse features.
[0095] Thus, the memory-optimized block-based inference method 100 of the convolutional neural network of the present invention uses different feature calculation methods in different directions, so that the block-based inference can still significantly reduce the bandwidth requirements of the external memory without increasing too much calculation and block register. The details of the above steps will be described below through a more detailed embodiment.
[0096] Please also read Figures 1 to 6 ,in Figure 2 It is shown Figure 1 A schematic diagram of the segmentation step S04; Figure 3 It is shown Figure 1 A three-dimensional schematic diagram of input block data IB and output block data OB of the multi-layer convolution operation of the block inference step S06; Figure 4 It is shown Figure 1 A schematic diagram of the first direction data selection step S062; Figure 5 It is shown Figure 1A schematic diagram of the second direction data selection step S064; and Figure 6 It is shown Figure 3 Schematic diagram of the first layer of the input feature block data L1FU_I being reused. As shown in the figure, this embodiment performs the first direction data selection step S062, the second direction data selection step S064 and the convolution operation step S066 in each layer (i.e., i=1 to D in the i-th layer). Convolution depth D, block width B W and block height B H are all positive integers. The size of the convolution kernel in the i-th layer is k Wi ×k Hi , where k Wi , k Hi are all positive integers. The scanning line direction D1 is the horizontal direction, and the block scanning direction D2 is the vertical direction; in other words, the block scanning direction D2 is perpendicular to the scanning line direction D1. Block width B W Greater than block height B H , and the block height is B H The extension direction is parallel to the block scanning direction D2. The input block size is equal to B W ×B H The output block data OB has an output block size, and the output block size is equal to (B W -2D)×B H The i-th layer recalculated input feature block data has an i-th layer recalculated input feature block size, and the i-th layer recalculated input feature block size is equal to (B W -2i+2)×B H The i-th layer reused input feature block data has an i-th layer reused input feature block size, and the i-th layer reused input feature block size is equal to (B W -2i+2)×(B H +2). The i-th layer output feature block data has an i-th layer output feature block size, and the i-th layer output feature block size is equal to (B W -2i)×B H The i-th layer output feature block data represents the output feature of the i-th layer after the convolution operation is performed, which is used to recalculate the next layer (i+1 layer) of the same block. The convolution depth D is less than the block width B W Furthermore, the i-th layer of reused features has a number of reused features along the block scanning direction D2, and the number of reused features is equal to k Hi-1 (i.e. k-1). The reused features of the i-th layer are reused for the same layer (i-th layer) for the next block. When i is equal to 1, the i-th layer recalculates the input feature block data equal to the input block data IB; when i is equal to the convolution depth D, the i-th layer output feature block data equals the output block data OB.
[0097] exist Figures 3 to 6 In the example, the convolution depth D is 3 and the block width is B. W 10, block height B H is 4, and the size of the convolution kernel of the i-th layer is 3×3, that is, k Wi =k Hi = k and are all 3. The convolution depth D is 3, which means there are 3 layers of convolution operations. Therefore, the multi-layer convolution operation includes the first layer of convolution operation, the second layer of convolution operation, and the third layer of convolution operation (ie, i = 1, 2, and 3).
[0098] The first-layer convolution operation (i=1) includes a first-direction data selection step S062, a second-direction data selection step S064, and a convolution operation step S066. The first-direction data selection step S062 selects six first-layer recalculated features L1FC (i.e., (D-i+1)×(k-1)) along the scanning line direction D1 according to the position of the output block data OB (i.e., the third-layer output feature block data L3_O), and then selects a first-layer recalculated input feature block data L1FC_I according to the position of the output block data OB and these first-layer recalculated features L1FC. This first-layer recalculated input feature block data L1FC_I is equal to the input block data IB, and the input block size of the input block data IB is equal to the first-layer recalculated input feature block size of the first-layer recalculated input feature block data L1FC_I, and both are equal to (B W -2i+2)×B H =(10-2+2)×4=10×4, such as Figure 3 Layer 1 L1, Figure 4 Layer 1 L1 and Figure 6 Furthermore, the second direction data selection step S064 selects two first-layer reused features L1FU along the block scanning direction D2 according to the first-layer recalculated input feature block data L1FC_I, and combines the first-layer recalculated input feature block data L1FC_I and these first-layer reused features L1FU to generate a first-layer reused input feature block data L1FU_I. The first-layer reused input feature block size of the first-layer reused input feature block data L1FU_I is equal to (B W -2i+2)×(B H +2) = (10-2+2) × (4+2) = 10 × 6, such as Figure 3 Layer 1 L1, Figure 5 Layer 1 L1 and Figure 6 In addition, the convolution operation step S066 selects a plurality of first-layer sub-block input feature groups SBG1 (i.e., 3×3 features) from the first-layer reused input feature block data L1FU_I according to the i-th layer convolution kernel size (i.e., 3×3), and then performs a convolution operation on each first-layer sub-block input feature group SBG1 and a convolution parameter group to generate first-layer sub-block output features, and combines these first-layer sub-block output features corresponding to these first-layer sub-block input feature groups SBG1 to form first-layer output feature block data L1_O. The first-layer output feature block size of the first-layer output feature block data L1_O is equal to (B W -2i)×B H =(10-2)×4=8×4, such as Figure 3 and Figure 5 As shown in the first layer L1.
[0099] The second layer convolution operation (i=2) includes a first direction data selection step S062, a second direction data selection step S064 and a convolution operation step S066. The first direction data selection step S062 selects four second layer recalculated features L2FC (i.e. (D-i+1)×(k-1)) along the scanning line feed direction D1 according to the position of the output block data OB (i.e. the third layer output feature block data L3_O), and then selects a second layer recalculated input feature block data L2FC_I according to the position of the output block data OB and these second layer recalculated features L2FC. The second layer recalculated input feature block data L2FC_I is equal to the first layer output feature block data L1_O. The second layer recalculated input feature block size of the second layer recalculated input feature block data L2FC_I is equal to (B W -2i+2)×B H =(10-4+2)×4=8×4, such as Figure 3 and Figure 4 Furthermore, the second direction data selection step S064 selects two second layer reuse features L2FU along the block scanning direction D2 according to the second layer recalculated input feature block data L2FC_I, and combines the second layer recalculated input feature block data L2FC_I and these second layer reuse features L2FU to generate a second layer reuse input feature block data L2FU_I. The second layer reuse input feature block size of the second layer reuse input feature block data L2FU_I is equal to (B W -2i+2)×(B H +2) = (10-4+2) × (4+2) = 8 × 6, such as Figure 3 and Figure 5In addition, the convolution operation step S066 selects a plurality of second-layer sub-block input feature groups SBG2 (i.e., 3×3 features) from the second-layer reused input feature block data L2FU_I according to the i-th layer convolution kernel size (i.e., 3×3), and then performs a convolution operation on each second-layer sub-block input feature group SBG2 and a convolution parameter group to generate second-layer sub-block output features, and combines these second-layer sub-block output features corresponding to these second-layer sub-block input feature groups SBG2 to form second-layer output feature block data L2_O. The second-layer output feature block size of the second-layer output feature block data L2_O is equal to (B W -2i)×B H =(10-4)×4=6×4, such as Figure 3 and Figure 5 As shown in the second layer L2.
[0100] The third-layer convolution operation (i=3) includes a first direction data selection step S062, a second direction data selection step S064 and a convolution operation step S066. The first direction data selection step S062 selects two third-layer recalculated features L3FC (i.e. (D-i+1)×(k-1)) along the scanning line direction D1 according to the position of the output block data OB (i.e. the third-layer output feature block data L3_O), and then selects a third-layer recalculated input feature block data L3FC_I according to the position of the output block data OB and these third-layer recalculated features L3FC. The third-layer recalculated input feature block data L3FC_I is equal to the second-layer output feature block data L2_O. The third-layer recalculated input feature block size of the third-layer recalculated input feature block data L3FC_I is equal to (B W -2i+2)×B H =(10-6+2)×4=6×4, such as Figure 3 and Figure 4 Furthermore, the second direction data selection step S064 selects two third-layer reused features L3FU along the block scanning direction D2 according to the third-layer recalculated input feature block data L3FC_I, and combines the third-layer recalculated input feature block data L3FC_I and these third-layer reused features L3FU to generate a third-layer reused input feature block data L3FU_I. The third-layer reused input feature block size of the third-layer reused input feature block data L3FU_I is equal to (B W -2i+2)×(B H +2) = (10-6+2) × (4+2) = 6 × 6, such as Figure 3 and Figure 5In addition, the convolution operation step S066 selects a plurality of third-layer sub-block input feature groups SBG3 (i.e., 3×3 features) from the third-layer reused input feature block data L3FU_I according to the i-th layer convolution kernel size (i.e., 3×3), and then performs a convolution operation on each third-layer sub-block input feature group SBG3 and a convolution parameter group to generate a third-layer sub-block output feature, and combines these third-layer sub-block output features corresponding to these third-layer sub-block input feature groups SBG3 to form a third-layer output feature block data L3_O. The third-layer output feature block data L3_O is equal to the output block data OB. The third-layer output feature block size of the third-layer output feature block data L3_O is equal to (B W -2i)×B H =(10-6)×4=4×4, and the output block size of the output block data OB is equal to (B W -2D)×B H =(10-6)×4=4×4, such as Figure 3 and Figure 5 As shown in the third layer L3.
[0101] In the memory-optimized block-based inference method 100 of the convolutional neural network of the present invention, when at least one of the multiple input features of an i-th layer sub-block input feature group is located in the outer area of the i-th layer reused input feature block data, the input features of this i-th layer sub-block input feature group include multiple outer block features and multiple first inner block features. The outer block features represent the features that have been calculated in the previous block, and the first inner block features represent the features that have not been calculated in the current block. In addition, when the input features of one of the i-th layer sub-block input feature groups are all located in the inner area of the i-th layer reused input feature block data, the input features of this i-th layer sub-block input feature group only include multiple second inner block features, and the second inner block features represent the features that have not been calculated in the current block. The arrangement order of the i-th layer reused input feature block data along the block scanning direction D2 is the outer area and the inner area. For example Figure 6For example, when 6 of the 9 input features of the 1st-layer sub-block input feature group SBG11 are located in the outer region OR of the 1st-layer reused input feature block data L1FU_I, the 9 input features of this 1st-layer sub-block input feature group SBG11 include 6 outer block features and 3 inner block features. The outer block features represent features that have been calculated and are located in the outer region OR, while the inner block features represent features that have not been calculated and are located in the inner region IR. In addition, when the 9 input features of the 1st-layer sub-block input feature group SBG12 are all located in the inner region IR of the 1st-layer reused input feature block data L1FU_I, the 9 input features of this 1st-layer sub-block input feature group SBG12 only include 9 inner block features, that is, the 9 input features are all inner block features. In addition, the arrangement order of the 1st-layer reused input feature block data L1FU_I along the block scanning direction D2 is the outer region OR and the inner region IR.
[0102] It is also worth mentioning that in the temporary storage step S08, the bottom k Hi -1 line is stored in the block buffer for use by the next block, becoming the LiFU of the next block. For example, after the first layer convolution operation of the block inference step S06 is executed, the temporary storage step S08 is executed, which is to recalculate the bottom k of the input feature block data L1FC_I of the first layer. Hi -1 line is stored in the block buffer for use by the next block, that is, it becomes the first layer reuse feature L1FU of the next block. After the second layer convolution operation of the block inference step S06 is executed, the temporary storage step S08 is executed, which is to recalculate the bottom k of the input feature block data L2FC_I of the second layer. Hi -1 line is stored in the block buffer for use by the next block, that is, it becomes the second layer reuse feature L2FU of the next block. After the third layer convolution operation of the block inference step S06 is executed, the temporary storage step S08 is executed, which is to recalculate the bottom k of the input feature block data L3FC_I of the third layer. Hi -1 line is stored in the block register for use by the next block, that is, it becomes the third layer reuse feature L3FU of the next block. This can greatly reduce the amount of calculation.
[0103] Please also read Figures 1 to 7 ,in Figure 7: is a schematic diagram showing the channel shuffle of the second embodiment of the present invention. The inference process of the present invention can be applied to the operation of channel shuffle, and the i-th layer reuse input feature block data LiFU_I has an i-th layer reuse input feature block size W1×H1 and an i-th layer reuse input feature block channel number C1. The i-th layer intermediate block data Li_M has an i-th layer intermediate feature block size W2×H2 and an i-th layer intermediate feature block channel number C2. The i-th layer output feature block data Li_O has an i-th layer output feature block size W3×H3 and an i-th layer output feature block channel number C3. The i-th layer output feature block size W3×H3 is larger than the i-th layer reuse input feature block size W1×H1, and the i-th layer reuse input feature block size W1×H1 is larger than the i-th layer intermediate feature block size W2×H2. Wherein W1, W2 and W3 are block widths, and H1, H2 and H3 are block heights. In addition, the number of channels C1 of the i-th layer reused input feature blocks is equal to the number of channels C3 of the i-th layer output feature blocks, and the number of channels C2 of the i-th layer intermediate feature blocks is greater than the number of channels C1 of the i-th layer reused input feature blocks. For example, the i-th layer reused input feature block size W1×H1, the i-th layer intermediate feature block size W2×H2, and the i-th layer output feature block size W3×H3 may be 10×10, 8×8, and 16×16, respectively, and the number of channels C1 of the i-th layer reused input feature blocks, the number of channels C2 of the i-th layer intermediate feature blocks, and the number of channels C3 of the i-th layer output feature blocks may be 32, 128, and 32, respectively, but the present invention is not limited thereto.
[0104] Thus, the present invention can realize specific multi-layer convolution operations. When performing block-based inference, the calculated features are reused in the block forward direction (i.e., the block scanning direction D2), and recalculated in the other direction (i.e., the scanning line direction D1). This allows the block-based inference to significantly reduce the bandwidth requirements of the external memory without increasing too much calculation and block registers.
[0105] Please also read Figure 1 , Figure 2 , Figure 8 and Fig. 9 ,in Figure 8 is a block diagram illustrating a memory-optimized block-based inference system 200 for a convolutional neural network according to a third embodiment of the present invention; and Fig. 92 is a flow chart showing a multi-layer convolution operation with a 3×3 filter according to the third embodiment of the present invention. As shown in the figure, the memory-optimized block-based inference system 200 of the convolutional neural network is used to process an input image to generate an output image 110, and includes a block register 220 and an operation processing unit 230. The input block data IB, the inference parameter group 212 and the convolution parameter group 214 are input to the operation processing unit 230, and the output block data OB is output to form the output image 110. The block register 220 is used to access the i-th layer output feature block data and multiple i-th layer reused features, and these two types of storage are area storages at different positions in the block register 220. In addition, the operation processing unit 230 is electrically connected to the block register 220, and the operation processing unit 230 receives the input image and is configured to implement Figure 1 A memory-optimized block-based inference method 100 for a convolutional neural network. The operation processing unit 230 includes a convolution engine 232 (Convolution Engine), which is used to perform convolution operations. The operation processing unit 230 can be a microprocessor, a central processing unit or an image processor, but the present invention is not limited to this. L1, L2 and LD represent the 1st layer, the 2nd layer and the Dth layer respectively, and the 1st layer L1 to the Dth layer LD are all calculated by the convolution engine 232 of the operation processing unit 230. In addition, the block register 220 can store external block features, and the block register 220 has a temporary storage space, which can recalculate the width B of the input feature block data through the i-th layer. Wi , convolution depth D, number of layers i, number of channels C and size of convolution kernel k in the i-th layer Wi ×k Hi The temporary storage space is expressed as LBS (Line Buffer Size) and conforms to the following formula (1):
[0106]
[0107] For example, if each layer (i.e., i=1-D in the i-th layer) performs the first direction data selection step S062, the second direction data selection step S064, and the convolution operation step S066, and k Wi =k Hi = k and are both equal to 3, then the temporary storage space meets the following formula (2):
[0108]
[0109] Thus, the memory-optimized block-based inference system 200 of the convolutional neural network of the present invention uses calculation methods with different features in different directions, so that the block-based inference can still significantly reduce the bandwidth requirements of the external memory for the input block data IB and the output block data OB without increasing too much calculation amount and the block register 220.
[0110] Please also read Figure 1 and Fig.10 ,in Fig.10 It is a schematic diagram showing the comparison results of recalculation (Feature-reComputing; FC), reuse (Feature-reUsing; FU) and the recalculation and reuse (FCFU) of the present invention. The parameter setting condition is that the product value A is set to 64 2 , the size of the output image 110 is 960×540, k Wi =k Hi = k. The product value A is the block width B W With block height B H The multi-layer convolution operation of the present invention has a normalized throughput ratio (NTR), which is calculated by calculating the convolution depth D and the normalized computing ratio (NCR), and the normalized computing ratio is calculated by calculating the block width B. W 、Block height B H , convolution depth D and variable h are calculated. The normalized throughput rate NTR and normalized computing rate NCR of the present invention respectively meet the following equations (3) and (4):
[0111]
[0112] Depend on Fig.10 It can be seen that if there is a block register size limit S for the block register 220, the maximum supported convolution depth D supported by the reuse FU is max It is the shallowest among the three; on the contrary, although recalculating FC can support a wide range of model convolution depths, it requires a higher computational complexity, which leads to a significant reduction in the normalized throughput rate NTR. The recalculation and reuse of FCFU of the present invention can not only support a wider range of model convolution depths than reusing FU, but also provide a better normalized throughput rate NTR than recalculating FC.
[0113] It can be seen from the above embodiments that the present invention has the following advantages: First, the memory-optimized block-based inference method of the convolutional neural network of the present invention uses different feature calculation methods in different directions, so that the block-based inference can significantly reduce the bandwidth requirements of the external memory without increasing too much calculation and block registers. Second, the memory-optimized block-based inference system of the convolutional neural network of the present invention uses different feature calculation methods in different directions, so that the block-based inference can significantly reduce the bandwidth requirements of the external memory without increasing too much calculation and block registers. Third, the recalculation and reuse of the present invention can not only support a wider range of model convolution depths than reuse, but also provide better standardized throughput than recalculation.
[0114] Although the present invention has been disclosed in the above embodiments, it is not intended to limit the present invention. Any person skilled in the art can make various changes and modifications without departing from the concept and scope of the present invention. Therefore, the scope of protection of the present invention shall be based on what is defined in the claims.
Claims
1. A memory-optimized block-based inference method for a convolutional neural network for processing an input image, characterized in that: The memory-optimized block-based inference method for convolutional neural networks includes the following steps: a parameter setting step, which is to set an inference parameter set, wherein the inference parameter set includes a convolution depth, a block width, a block height, and multi-layer convolution kernel sizes; a segmentation step, driving a processing unit to divide the input image into a plurality of input block data according to the convolution depth, the block width, the block height and the multi-layer convolution kernel size, each of the input block data having an input block size; A block inference step is to drive the processing unit to perform a multi-layer convolution operation on each of the input block data to generate an output block data, and the multi-layer convolution operation includes: a first direction data selection step, which is to select a plurality of i-th layer recalculated features along a scanning line direction according to a position of the output block data, and then select an i-th layer recalculated input feature block data according to the position of the output block data and the plurality of i-th layer recalculated features, wherein i is one of a plurality of positive integers from 1 to the convolution depth; a second direction data selection step, selecting a plurality of i-th layer reused features along a block scanning direction according to the i-th layer recalculated input feature block data, and combining the i-th layer recalculated input feature block data and the plurality of i-th layer reused features to generate an i-th layer reused input feature block data; and a convolution operation step, which is to select a plurality of i-th layer sub-block input feature groups from the i-th layer reused input feature block data according to an i-th layer convolution kernel size, and then perform a convolution operation on each of the i-th layer sub-block input feature groups and a convolution parameter set to generate an i-th layer sub-block output feature, and combine the plurality of i-th layer sub-block output features corresponding to the plurality of i-th layer sub-block input feature groups to form an i-th layer output feature block data; as well as A temporary storage step is to drive a block register to temporarily store the i-th layer output feature block data and the plurality of i-th layer reuse features; Among them, the convolution depth, the block width and the block height are all positive integers, and the size of the convolution kernel of the i-th layer is k Wi ×k Hi , the plurality of i-th layer reuse features have a number of reuse features along the block scanning direction, and the number of reuse features is equal to k Hi -1; The block width is denoted as B W , the convolution depth is represented by D, and the block height is represented by B H ; The input block size is equal to B W ×B H ; The output block data has an output block size, and the output block size is equal to (B W -2D)×B H ; The i-th layer recalculated input feature block data has an i-th layer recalculated input feature block size, and the i-th layer recalculated input feature block size is equal to (B W -2i+2)×B H ; The i-th layer of reused input feature block data has an i-th layer of reused input feature block size, and the i-th layer of reused input feature block size is equal to (B W -2i+2)×(B H +2); The i-th layer output feature block data has an i-th layer output feature block size, and the i-th layer output feature block size is equal to (B W -2i)×B H ;and The convolution depth is less than half of the block width.
2. The memory-optimized block-based inference method for a convolutional neural network as claimed in claim 1, wherein: When i is equal to 1, the i-th layer recalculates the input feature block data to be equal to each input block data; and When i is equal to the convolution depth, the i-th layer output feature block data is equal to the output block data.
3. The memory-optimized block-based inference method for a convolutional neural network as claimed in claim 1, wherein: The i-th layer recalculated input feature block data has an i-th layer recalculated input feature block size and an i-th layer recalculated input feature block channel number, the i-th layer output feature block data has an i-th layer output feature block size and an i-th layer output feature block channel number, the i-th layer output feature block size is larger than the i-th layer recalculated input feature block size, and the i-th layer recalculated input feature block channel number is equal to the i-th layer output feature block channel number.
4. The memory-optimized block-based inference method for a convolutional neural network as claimed in claim 1, wherein: The block scanning direction is perpendicular to the scanning line-changing direction, the block width is greater than the block height, and an extension direction of the block height is parallel to the block scanning direction.
5. The memory-optimized block-based inference method for a convolutional neural network as claimed in claim 1, wherein: When at least one of the plurality of input features of one of the i-th layer sub-block input feature groups is located in an outer region of the region where the i-th layer reused input feature block data is located, the plurality of input features of the i-th layer sub-block input feature group comprises a plurality of outer block features and a plurality of first inner block features, the plurality of outer block features represent calculated features, and the plurality of first inner block features represent uncalculated features; When the plurality of input features of one of the i-th layer sub-block input feature groups are all located in an inner region of the region where the i-th layer reused input feature block data is located, the plurality of input features of the one of the i-th layer sub-block input feature groups only include a plurality of second inner block features; and The arrangement order of the region where the i-th layer repeatedly utilizes the input feature block data along the block scanning direction is the outer region and the inner region.
6. The memory-optimized block-based inference method for a convolutional neural network as claimed in claim 5, wherein: The plurality of external block features are stored in the block register, which has a temporary storage space, which is obtained by calculating a width of the input feature block data recalculated by the i-th layer, the convolution depth, the number of layers, the number of channels and the i-th layer convolution kernel size, and the width of the input feature block data recalculated by the i-th layer is expressed as B Wi , the convolution depth is represented by D, the number of layers is represented by i, the number of channels is represented by C, and the size of the convolution kernel of the i-th layer is k Wi ×k Hi , the temporary storage space is represented as LBS and conforms to the following formula:
7. A memory-optimized block-based inference system for a convolutional neural network for processing an input image, characterized in that: The memory-optimized block-based inference system for convolutional neural networks includes: a block register for storing an i-th layer output feature block data and a plurality of i-th layer reuse features; and A processing unit is electrically connected to the block register, the processing unit receives the input image and is configured to perform operations including the following steps: a parameter setting step, which is to set an inference parameter set, wherein the inference parameter set includes a convolution depth, a block width, a block height, and multi-layer convolution kernel sizes; a segmentation step, which divides the input image into a plurality of input block data according to the convolution depth, the block width, the block height and the multi-layer convolution kernel size, each of the input block data having an input block size; and A block inference step is to perform a multi-layer convolution operation on each of the input block data to generate an output block data, and the multi-layer convolution operation includes: a first direction data selection step, which is to select a plurality of i-th layer recalculated features along a scanning line direction according to a position of the output block data, and then select an i-th layer recalculated input feature block data according to the position of the output block data and the plurality of i-th layer recalculated features, wherein i is one of a plurality of positive integers from 1 to the convolution depth; a second direction data selection step, selecting the plurality of i-th layer reused features along a block scanning direction according to the i-th layer recalculated input feature block data, and combining the i-th layer recalculated input feature block data and the plurality of i-th layer reused features to generate an i-th layer reused input feature block data; and a convolution operation step, which is to select a plurality of i-th layer sub-block input feature groups from the i-th layer reused input feature block data according to an i-th layer convolution kernel size, and then perform a convolution operation on each of the i-th layer sub-block input feature groups and a convolution parameter set to generate an i-th layer sub-block output feature, and combine the plurality of i-th layer sub-block output features corresponding to the plurality of i-th layer sub-block input feature groups to form the i-th layer output feature block data; Among them, the convolution depth, the block width and the block height are all positive integers, and the size of the convolution kernel of the i-th layer is k Wi ×k Hi , the plurality of i-th layer reuse features have a number of reuse features along the block scanning direction, and the number of reuse features is equal to k Hi -1; The block width is denoted as B W , the convolution depth is represented by D, and the block height is represented by B H ; The input block size is equal to B W ×B H ; The output block data has an output block size, and the output block size is equal to (B W -2D)×B H ; The i-th layer recalculated input feature block data has an i-th layer recalculated input feature block size, and the i-th layer recalculated input feature block size is equal to (B W -2i+2)×B H ; The i-th layer of reused input feature block data has an i-th layer of reused input feature block size, and the i-th layer of reused input feature block size is equal to (B W -2i+2)×(B H +2); The i-th layer output feature block data has an i-th layer output feature block size, and the i-th layer output feature block size is equal to (B W -2i)×B H ;and The convolution depth is less than half of the block width.
8. The memory-optimized block-based inference system for convolutional neural networks of claim 7, wherein: When i is equal to 1, the i-th layer recalculates the input feature block data to be equal to each input block data; and When i is equal to the convolution depth, the i-th layer output feature block data is equal to the output block data.
9. The memory-optimized block-based inference system for convolutional neural networks of claim 7, wherein: The i-th layer recalculated input feature block data has an i-th layer recalculated input feature block size and an i-th layer recalculated input feature block channel number, the i-th layer output feature block data has an i-th layer output feature block size and an i-th layer output feature block channel number, the i-th layer output feature block size is larger than the i-th layer recalculated input feature block size, and the i-th layer recalculated input feature block channel number is equal to the i-th layer output feature block channel number.
10. The memory-optimized block-based inference system for convolutional neural networks of claim 7, wherein: The block scanning direction is perpendicular to the scanning line-changing direction, the block width is greater than the block height, and an extension direction of the block height is parallel to the block scanning direction.
11. The memory-optimized block-based inference system for convolutional neural networks of claim 7, wherein: When at least one of the plurality of input features of one of the i-th layer sub-block input feature groups is located in an outer region of the region where the i-th layer reused input feature block data is located, the plurality of input features of the i-th layer sub-block input feature group comprises a plurality of outer block features and a plurality of first inner block features, the plurality of outer block features represent calculated features, and the plurality of first inner block features represent uncalculated features; When the plurality of input features of one of the i-th layer sub-block input feature groups are all located in an inner region of the region where the i-th layer reused input feature block data is located, the plurality of input features of the one of the i-th layer sub-block input feature groups only include a plurality of second inner block features; and The arrangement order of the region where the i-th layer repeatedly utilizes the input feature block data along the block scanning direction is the outer region and the inner region.
12. The memory-optimized block-based inference system for convolutional neural networks of claim 11, wherein: The plurality of external block features are stored in the block register, which has a temporary storage space, which is obtained by calculating a width of the input feature block data recalculated by the i-th layer, the convolution depth, the number of layers, the number of channels and the i-th layer convolution kernel size, and the width of the input feature block data recalculated by the i-th layer is expressed as B Wi , the convolution depth is represented by D, the number of layers is represented by i, the number of channels is represented by C, and the size of the convolution kernel of the i-th layer is k Wi ×k Hi , the temporary storage space is represented as LBS and conforms to the following formula:
