Feature processing method, medium, device and program product in neural network model
By dividing and sampling candidate areas in the neural network model, and using multiplication and shift operations to represent operation factors, the division operation problem in the RoiAlign operator is solved and the operating efficiency of electronic equipment is improved.
Patent Information
- Application Number
- CN202210227374.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-08
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2042-03-08
AI Technical Summary
In the existing neural network model, the division operation of the RoiAlign operator causes the operation speed to be slow and consumes a large amount of hardware resources, affecting the operating efficiency of electronic equipment.
By dividing and sampling the candidate area, multiplication and shift operations are used to represent the operation factors, avoiding division operations, and directly calculating the coordinates and feature values of the sampling points, thereby generating a fixed-size output feature map.
While ensuring the accuracy of calculations, it reduces the amount of calculations and hardware resource usage, and improves the speed of electronic devices running neural network models.
Smart Images

Figure CN114611685B
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a feature processing method, medium, device and program product in a neural network model. Background Art
[0002] With the rapid development of artificial intelligence (AI), neural network models are increasingly used in the field of artificial intelligence. In order to improve the running speed of the neural network model, it is usually necessary to perform regional feature aggregation on the output feature map of the operator in the neural network model to obtain a feature map of a fixed size. For example, in the Faster-RCNN network, the output feature map of the backbone network can be mapped to a fixed-size feature map by the RoiAlign operator through the candidate box mapping.
[0003] However, since the RoiAlign operator includes operations such as accumulation, multiplication, and division, and the computing unit used to run the neural network model, such as the neural network processor (NPU), is a fixed-point computing unit, there is no circuit that can directly implement nonlinear operations such as division in the RoiAlign operator. Instead, it is implemented through iterative solution, which is slow and occupies a large amount of hardware resources of the NPU, reducing the speed at which electronic devices run neural network models. Summary of the invention
[0004] In view of this, embodiments of the present application provide a feature processing method, medium, device and program product in a neural network model.
[0005] In a first aspect, an embodiment of the present application provides a feature processing method in a neural network model, which is applied to an electronic device, including:
[0006] Determine a candidate region in the processing object, and perform a target operation on the candidate region, wherein the target operation is used to convert an input feature map in the candidate region into an output feature map of a fixed size;
[0007] Determine the input feature map corresponding to the target operation and the coordinate data of the candidate area;
[0008] Dividing the candidate region according to a pre-stored output parameter to obtain a plurality of sub-regions; wherein the output parameter is used to determine the size of the output feature map;
[0009] Sampling each of the sub-regions respectively to obtain at least one sampling point corresponding to each of the sub-regions;
[0010] Amplifying the coordinate data of the candidate area;
[0011] Determine the coordinate data of each sampling point corresponding to each sub-region based on the coordinate data of the candidate region after the enlargement processing, the first operation factor and the second operation factor; wherein the first operation factor and the second operation factor are both represented in the form of multiplication and shift;
[0012] Based on the input feature map and the coordinate data of each sampling point corresponding to each sub-region, respectively determine the feature value of each sampling point corresponding to each sub-region;
[0013] Based on the feature values of each sampling point corresponding to each of the sub-regions, an output feature map corresponding to the candidate region is determined.
[0014] It can be understood that when an electronic device is running a neural network model, if a target operation of converting an input feature map in a candidate area into an output feature map of a fixed size is detected, such as an operation of generating a fixed-size feature map based on a candidate box mapping through a RoiAlign operator, the candidate area can be first divided and sampled, and the coordinate data of the candidate area can be enlarged in advance. Based on the enlarged coordinate data and the first operation factor and the second operation factor represented in the form of multiplication and shift, the coordinate data of each sampling point corresponding to each sub-area in the candidate area is calculated, and then the corresponding eigenvalue is determined according to the coordinate data of each sampling point, thereby determining the output feature map corresponding to the candidate area. In the subsequent operation process, there is no need to enlarge the operation result, and the division operation is avoided. While ensuring the operation accuracy, the amount of operation is reduced, the hardware resources occupied by the electronic device when running the neural network model containing the target operation are reduced, and the speed at which the electronic device runs the neural network model containing the target operation is improved.
[0015] In a possible implementation of the first aspect, the enlarging the coordinate data of the candidate area includes: enlarging the coordinate data of the candidate area by 2 shift , where shift is an integer greater than zero.
[0016] In a possible implementation of the first aspect above, the coordinate data of the candidate area includes horizontal coordinate data and vertical coordinate data;
[0017] The step of determining the coordinate data of each sampling point corresponding to each sub-region based on the coordinate data of the candidate region after the enlargement processing, the first operation factor and the second operation factor includes:
[0018] For the coordinate data in each direction of the horizontal coordinate data and the vertical coordinate data, respectively, obtain the first operation factor corresponding to the coordinate data stored in advance;
[0019] Acquire the target sampling parameters corresponding to the direction of the coordinate data stored in advance;
[0020] Determine a second operation factor corresponding to the coordinate data according to the target sampling parameter;
[0021] Based on the coordinate data after the magnification processing and the first operation factor and the second operation factor corresponding to the coordinate data, the coordinate data of each sampling point corresponding to each sub-area in the corresponding direction is calculated.
[0022] In a possible implementation of the first aspect, determining the second operation factor corresponding to the coordinate data according to the target sampling parameter includes:
[0023] Determining whether the target sampling parameter is greater than zero;
[0024] When the target sampling parameter is greater than zero, obtaining a second operation factor corresponding to the pre-stored coordinate data;
[0025] When the target sampling parameter is equal to zero, generating a target table lookup parameter of the target sampling parameter;
[0026] Obtain a target table lookup result corresponding to the target table lookup parameter in the lookup table;
[0027] Based on the target table lookup result and the first operation factor corresponding to the coordinate data, a second operation factor corresponding to the coordinate data is determined.
[0028] In a possible implementation of the first aspect, generating the target table lookup parameter of the target sampling parameter includes: calculating the target table lookup parameter based on the coordinate data after the magnification process and the corresponding first operation factor.
[0029] In a possible implementation of the first aspect, determining the feature values of the sampling points corresponding to the sub-regions based on the input feature map and the coordinate data of the sampling points corresponding to the sub-regions includes:
[0030] For each sampling point, based on the coordinate data of the sampling point, determine the coordinate data of a plurality of grid points in the input feature map that are closest to the sampling point;
[0031] Determine a feature value of each of the grid points based on the input feature map and the coordinate data of each of the grid points;
[0032] A bilinear difference operation is performed based on the coordinate data and the eigenvalues of each of the grid points to obtain the eigenvalues corresponding to the sampling points.
[0033] In a possible implementation of the first aspect, determining the output feature map corresponding to the candidate region based on the feature values of each sampling point corresponding to each sub-region includes:
[0034] Acquire pre-stored transverse sampling parameters and longitudinal sampling parameters;
[0035] Determine a third operation factor according to the horizontal sampling parameter and the vertical sampling parameter;
[0036] For each sub-region, respectively, based on the characteristic values of each sampling point corresponding to the sub-region and the third operation factor, calculate the characteristic value corresponding to the sub-region;
[0037] Based on the feature values corresponding to each of the sub-regions, an output feature map of the candidate region is generated.
[0038] In a possible implementation of the first aspect, determining the third operation factor according to the horizontal sampling parameter and the vertical sampling parameter includes:
[0039] respectively determining whether the horizontal sampling parameter and the vertical sampling parameter are greater than zero;
[0040] When the horizontal sampling parameter and the vertical sampling parameter are both greater than zero, obtaining a pre-stored third operation factor;
[0041] When the horizontal sampling parameter and / or the vertical sampling parameter is equal to zero, generating a first table lookup parameter of the horizontal sampling parameter, and / or generating a second table lookup parameter of the vertical sampling parameter;
[0042] Obtaining a first table lookup result corresponding to the first table lookup parameter in a lookup table, and / or obtaining a second table lookup result corresponding to the second table lookup parameter in the lookup table;
[0043] The third operation factor is determined based on the first table lookup result and / or the second table lookup result.
[0044] It can be understood that the method provided in the embodiment of the present application is compatible with the case where the sampling parameter is zero, and has better adaptability. In addition, when the sampling parameter is zero, the division operation during online calculation is avoided by looking up the table, thereby further accelerating the calculation speed of the online calculation process while ensuring the calculation accuracy.
[0045] In a second aspect, an embodiment of the present application provides a readable medium, which contains instructions. When the instructions are executed by a processor of an electronic device, the electronic device implements the feature processing method in any one of the neural network models provided by the first aspect and various possible implementations of the first aspect.
[0046] In a third aspect, the present application provides an electronic device comprising: a memory for storing instructions executed by one or more processors of the electronic device; and a processor, which is one of the processors of the electronic device, for running the instructions to enable the electronic device to implement the feature processing method in the neural network model of any one of the first aspect and various possible implementations of the first aspect.
[0047] In a fourth aspect, an embodiment of the present application provides a computer program product, which includes instructions for implementing the feature processing method in a neural network model provided by the first aspect and any one of the various possible implementations of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 According to some embodiments of the present application, a schematic diagram of a neural network model is shown;
[0049] Figure 2 According to some embodiments of the present application, a schematic diagram of the operation process of the RoiAlign operator is shown;
[0050] Figure 3 According to some embodiments of the present application, a schematic diagram of area division is shown;
[0051] Figure 4 According to some embodiments of the present application, a flow chart of a feature processing method in a neural network model is shown;
[0052] Figure 5 According to some embodiments of the present application, a flow chart for calculating abscissa data is shown;
[0053] Figure 6 According to some other embodiments of the present application, a flow chart for calculating characteristic values is shown;
[0054] Figure 7 According to some embodiments of the present application, a structural schematic diagram of a feature processing device in a neural network model is shown;
[0055] Figure 8 According to some embodiments of the present application, a schematic structural diagram of an electronic device is shown. DETAILED DESCRIPTION
[0056] The illustrative embodiments of the present application include but are not limited to a feature processing method, medium and electronic device in a neural network model. The embodiments of the present application will be further described in detail below in conjunction with the accompanying drawings.
[0057] In order to understand the present application more clearly, the structure of the neural network model is now explained.
[0058] Figure 1 According to some embodiments of the present application, a schematic diagram of the structure of a neural network model is shown. Figure 1 As shown, the neural network model 10 includes an input layer 11, a convolution layer 12, an activation layer 13, a pooling layer 14, a fully connected layer 15 and an output layer 16. Among them, the convolution layer 12 extracts features of the input image through multiple convolution kernels to obtain multiple feature maps; the activation layer 13 is used to activate each feature map to improve the operation speed of the subsequent layer; the pooling layer 14 converts the output feature map of the activation layer 13 into a feature map of a fixed size through the RoiAlign operator; the fully connected layer 15 is used to classify the input image data, for example, to obtain the probability that the input image belongs to each preset image category; the output layer 16 is used to output the category of the input image, for example, to determine the category of the input image as the preset image category with the largest probability.
[0059] It can be understood that in some embodiments, the preset image categories may include: landscape, person, animal, etc.
[0060] It can be understood that the structure of the neural network model 10 is only an example. In other embodiments, the neural network model can be any neural network model that includes a RoiAlign operator, which is not limited here.
[0061] It can be understood that the input data of the RoiAlign operator may include coordinate data of the candidate region and an input feature map. Figure 2 According to some embodiments of the present application, a schematic diagram of the operation process of the RoiAlign operator is shown. Figure 2 As shown, the operation process of the RoiAlign operator may include:
[0062] S201: Divide the candidate region into multiple sub-regions according to the output parameter, sample each sub-region according to the sampling parameter, and obtain at least one sampling point corresponding to each sub-region.
[0063] The output parameter and the sampling parameter are defined by the RoiAlign operator, the output parameter is used to determine the size of the output feature map of the RoiAlign operator, and the sampling parameter is used to determine the number of sampling points.
[0064] In some embodiments, the output parameter may include a horizontal output parameter and a vertical output parameter, and the size of the output feature map of the RoiAlign operator may be determined according to the horizontal output parameter and the vertical output parameter. Specifically, the candidate region may be divided into [horizontal output parameter*vertical output parameter] sub-regions according to the horizontal output parameter and the vertical output parameter, and the sizes of the obtained multiple sub-regions are all the same.
[0065] For example, assuming that the output parameters are [out_h, out_w] = [3, 3], Figure 3 As shown, it can be determined that the size of the output feature map is 3*3, that is, the candidate area can be divided into 9 sub-areas.
[0066] In some embodiments, the sampling parameters may also include a horizontal sampling parameter and a vertical sampling parameter, indicating the number of horizontal and vertical samplings in the sub-area. Specifically, each sub-area may be divided into [horizontal sampling parameter*vertical sampling parameter] cells according to the horizontal sampling parameter and the vertical sampling parameter, and the center point of each cell is used as the sampling point.
[0067] For example, assuming that the sampling parameters are [sample_h, sample_w] = [2, 2], Figure 3 As shown, each sub-region can be divided into 4 cells, and the center point of each cell is used as a sampling point.
[0068] S202: Calculate the coordinates of each sampling point using the input coordinate data of the candidate area.
[0069] It can be understood that the calculation formula of the horizontal coordinate data x of each sampling point is as follows:
[0070] x_f=x1+w_step_size*out_w_idx+sample_w_idx*w_bin_size+0.5*w_bin_size (1)
[0071] roi_width=x2-x1 (2)
[0072]
[0073]
[0074] Among them, x1, x2 are the starting and ending coordinates of the candidate region Roi in the x direction; out_w_idx∈[0,out_w), indicates the number of the sub-region where the sampling point is located in the x direction; out_w is the output parameter in the x direction, indicating the width of the output feature map; sample_w_idx∈[0,sample_w), indicates the number of the sampling point in the corresponding sub-region in the x direction, sample_w is the sampling parameter in the x direction, indicating the number of samples in each out_w direction. If sample_w is defined as 0 in the RoiAlign operator, then sample_w takes the value of ceil(w_step_size). Similarly, when calculating the ordinate data, if sample_h is defined as 0, then sample_h takes the value of ceil(h_step_size).
[0075] Substituting formulas (2), (3), and (4) into formula (1), we can obtain:
[0076]
[0077] After the above formula is sorted out, the calculation formula of the horizontal coordinate data of the sampling point is obtained (5):
[0078]
[0079] Similarly, the calculation formula (6) for the ordinate data of the sampling point can be obtained:
[0080]
[0081] S203: Calculate the characteristic value of each sampling point through bilinear interpolation based on the coordinate data of each sampling point.
[0082] In some embodiments, the coordinate data of multiple grid points closest to the sampling point in the input feature map of the RoiAlign operator can be determined based on the coordinate data of the sampling point, and then the eigenvalue of each grid point can be determined using the coordinate data of each grid point as an index. Finally, based on the coordinate data and eigenvalue of each grid point, the eigenvalue of the sampling point is calculated by bilinear interpolation.
[0083] It can be understood that the calculation formula of the eigenvalue of each sampling point is as follows:
[0084] f(x,y)=dx2*dy2*fm(x_left,y_top)+dx1*dy2*fm(x_right,y_top)+dx2*dy1*fm(x_left,y_bottom)+dx1*dy1*fm(x_right,y_bottom) (7)
[0085] x_left=floor(x),x_right=x_left+1
[0086] y_top=floor(y),y_bottom=y_top+1
[0087] dx1=x-x_left,dx2=1-dx1
[0088] dy1=y-y_top,dy2=1-dy1
[0089] Among them, fm(a,b) represents the eigenvalue corresponding to the point (a,b), and floor(a) is a function that retains the integer part and discards the decimal part.
[0090] S204: Determine an output feature map corresponding to the candidate region based on the feature values of each sampling point corresponding to each of the sub-regions.
[0091] In some embodiments, the average of the feature values of each sampling point corresponding to each sub-region may be used as the feature value corresponding to the sub-region, and the output feature map of the RoiAlign operator may be generated according to each sub-region and its corresponding feature value.
[0092] It can be understood that the calculation formula of the eigenvalue of each sub-region is as follows:
[0093]
[0094] where out h,w Represents the eigenvalue of the sub-region, h∈[0,out_h),w∈[0,out_w).
[0095] The following introduces the quantization process of the RoiAlign operator.
[0096] The quantization of the sampling point coordinates of the RoiAlign operator is the key to the quantization of the operator. The accuracy of its quantization directly determines the eigenvalues of the selected grid points, thereby determining the quantization accuracy of the result after bilinear interpolation.
[0097] First, the quantization process of the above formulas (5) and (6) is introduced.
[0098] For ease of description, it is defined here that in the embodiment of the present application, x_f represents the floating point number of the variable x, x_q represents the fixed point number of the variable x, and x_s represents the scaling factor of x_f quantized to x_q. Assuming that x_q is a symmetrically quantized n-bit fixed point number, the relationship between x_f, x_s and x_q can be determined by the following formulas (9) and (10).
[0099]
[0100] x_q=round(x_f*x_s) (10)
[0101] Among them, max(a) means to find the maximum value of a, min(a) means to find the minimum value of a, abs(a) means to find the absolute value of a, round(a) means to round a to the nearest integer, and n is the number of quantization bits.
[0102] It can be understood that the method provided in the embodiment of the present application supports multiple quantization bit numbers, that is, the quantization bit number n can be set according to actual needs, for example, it can be 8 bits, 16 bits, etc.
[0103] It can be understood that round(a) can also be a function of other functions, for example, it can be a floor(a) function or a fix(a) function that retains the integer part and discards the decimal part, and the embodiments of the present application are not limited to this.
[0104] It can be understood that since the NPU can only perform fixed-point operations, when calculating the coordinates of each sampling point, the operation factors in the calculation formula need to be quantized into fixed-point numbers.
[0105] Zoom in on the coordinate data of the candidate area 2 shift , where shift is an integer greater than zero. The value of shift can be configured according to actual needs, for example, it can be set to 10, which is not limited in the embodiments of the present application.
[0106] It can be understood that the coordinate data of the candidate area is enlarged before the calculation, so as to avoid further enlargement of the calculation results in the subsequent calculation process, reduce the amount of calculation in the feature processing process, and improve the operating speed of the electronic device while ensuring the calculation accuracy.
[0107] According to formulas (5) and (10), we can obtain:
[0108]
[0109] That is, we get:
[0110]
[0111] Among them, x1_q represents the fixed-point number of variable x1 (data after enlargement processing), roi_width_q=x2_q-x1_q, and x2_q represents the fixed-point number of variable x2 (data after enlargement processing).
[0112] From formula (11), we can see that except for the two division factors, all others can be directly calculated using fixed-point numbers. In order to avoid division, we can convert division into integer multiplication and shift, that is, and Expressed as qscale*2 qshift In the form of, qscale, qshift are both integers. At this time, formula (11) is quantized as:
[0113] x_q*2 shift =x1_q+(roi_width_q*out_w_idx*qscale_1<<qshift_1)+((2*sample_w_idx+1)*roi_width_q*qscale_2<<qshift_2) (12)
[0114] In formula (12), “<<” indicates a left shift operation, and the scaling factor and the shift number (qscale_1, qshift_1) indicate the first operation factor. The scaling factor and shift number (qscale_2, qshift_2) represent the second operation factor. After the NPU determines roi_widt*_q according to x2_q-x1_q and determines out_w_idx and sample_w_idx according to the current sampling point, the horizontal coordinate data of each sampling point can be calculated by formula (12) without performing a division operation, thereby reducing the hardware resource consumption of the NPU and improving the running speed of the neural network model.
[0115] It can be understood that since out_w is a hyperparameter of the neural network model and out_w>0, the first operation factor can be Convert to qscale_1*2 qshift_1 The scaling factor and the shift number (qscale_1, qshift_1) are stored in advance so that they can be directly obtained when the horizontal coordinate data of each sampling point is calculated online.
[0116] It can be understood that the second operation factor The value of is related to the horizontal output parameter sample_w and can be determined according to the value of sample_w. Since there are special cases for the value of sample_w, the second operation factor needs to be processed separately.
[0117] It can be understood that when sample_w>0 in the RoiAlign operator definition, the second operation factor can be Convert to qscale_2*2 qshift_2 The scaling factor and the shift number (qscale_2, qshift_2) are stored in advance and directly obtained when the horizontal coordinate data of each sampling point is calculated online.
[0118] It can be understood that when sample_w=0 in the definition of RoiAlign operator, it needs to be obtained according to sample_w=ceil(w_step_size) in the online stage. In order to speed up the calculation speed in the online stage, it can be obtained by looking up the table The corresponding scaling factor and the shift number are then combined with the first operation factor to calculate the corresponding second operation factor.
[0119] The following describes the process of building a lookup table.
[0120] Since the value of sample_h may be equal to 0 in the calculation process of the ordinate data of the sampling point, it is also necessary to calculate it in the online stage according to sample_h = ceil (h_step_size). The value of is then combined with the corresponding first operation factor to calculate the corresponding second operation factor.
[0121] because Then the maximum value of roi_width is the width of the feature map, so the value range of w_step_size is because Then the maximum value of roi_height is the height of the feature map, so the value range of h_step_size is To make a unified lookup table, the size of the lookup table can be set to That is, only Just make a lookup table in the form of lut_size group (qscale, qshift).
[0122] It can be understood that when calculating the horizontal coordinate data of the sampling point in the online stage, it can be based on The table lookup parameter of the horizontal sampling parameter sample_w is calculated, and the corresponding table lookup result (qscale_w, qshift_w) is obtained from the lookup table with the table lookup parameter as the index, and then the scaling coefficient qscale_w corresponding to the table lookup result is multiplied by the scaling coefficient qscale_1 of the first operation factor to obtain the scaling coefficient qscale_2 of the corresponding second operation factor, and the shift number qshift_w corresponding to the table lookup result is added to the shift number qshift_1 of the first operation factor to obtain the corresponding shift number qshift_2 of the second operation factor. The calculation of the ordinate data of the sampling point in the online stage is similar to the calculation of the abscissa data, and the embodiments of the present application are not repeated here.
[0123] From formula (12), we can see that all x_q are magnified by 2shift Therefore, dx1, dx2, dy1, dy2 in formula (7) are all magnified by 2 shift .
[0124] Quantifying formula (8) yields the following formula:
[0125]
[0126] Right now
[0127]
[0128] For formula (13), we can It is recorded as the third operation factor. In order to avoid division, the third operation factor can be replaced by integer multiplication and shift, that is, total_scale is expressed as qscale*2 qshift In the form of, qscale, qshift are both integers. The fixed-point number f(x,y) of the eigenvalues of each sampling point corresponding to each sub-region i The linear operation of the sum ... h,w _q. At this time, formula (13) is quantized as:
[0129]
[0130] Among them, "<<" indicates a left shift operation, and ">>" indicates a right shift operation. Since the third operation factor is related to the horizontal sampling parameter and the vertical sampling parameter, and there is a case where sample_w and / or sample_h is 0 in the RoiAlign operator definition, the third operation factor also needs to be processed separately.
[0131] (1) When sample_w≠0, sample_h≠0, the third operation factor total_scale can be expressed as integer multiplication and shift, that is, the third operation factor total_scale is expressed as qscale_3*2 qshift_3 The scaling factor and the shift number (qscale_3, qshift_3) are stored in advance and directly obtained during online calculation.
[0132] (2) When sample_w = 0, the third operation factor You can Partially expressed as integer multiplication and shift, Expressed as qscale_4*2 qshift_4, and pre-store the scaling factor and shift number (qscale_4, qshift_4) and directly obtain them during online calculation. Some of them can be obtained by looking up the table (qscale_w, qshift_w), and qscale_w*2 qshift_w With qscale_4*2 qshift_4 Multiply to get the third operation factor qscale_3*2 qshift_3 .
[0133] (3) When sample_h = 0, the third operation factor You can Partially expressed as integer multiplication and shift, Expressed as qscale_4*2 qshift_4 , and pre-store the scaling factor and shift number (qscale_4, qshift_4) and directly obtain them during online calculation. Some of them can be obtained by looking up the table (qscale_h, qshift_h), and qscale_h*2 qshift_h With qscale_4*2 qshift_4 Multiply to get the third operation factor qscale_3*2 qshift_3 .
[0134] (4) When sample_w = 0, sample_h = 0, the third operation factor You can Partially expressed as integer multiplication and shift, Expressed as qscale_4*2 qshift_4 , and pre-store the scaling factor and shift number (qscale_4, qshift_4) and directly obtain them during online calculation. Partial and Some can be obtained by looking up the table (qscale_w, qshift_w) and (qscale_h, qshift_h), and qscale_w*2 qshift_w With qscale_h*2 qshift_h Multiply, and then add qscale_4*2 qshift_4 Multiply to get the third operation factor qscale_3*2 qshift_3 .
[0135] The following introduces the feature processing method in the neural network model provided in the embodiment of the present application.
[0136] Figure 4 According to some embodiments of the present application, a schematic diagram of a process flow of a feature processing method in a neural network model is shown. The execution subject of the process is an electronic device, such as Figure 4 As shown, the process includes the following steps:
[0137] S401: Determine a candidate region in a processing object, and perform a target operation on the candidate region, wherein the target operation is used to convert an input feature map in the candidate region into an output feature map of a fixed size.
[0138] When the electronic device is running the neural network model, if the operation of the RoiAlign operator is detected, the target operation is performed on the candidate area through the RoiAlign operator through the method provided in the embodiment of the present application to convert the input feature map within the candidate area into an output feature map of a fixed size.
[0139] In an embodiment of the present application, the processing object may be a processing object of the neural network model, such as an image, etc.; the candidate area may be generated by other operators in the neural network model.
[0140] For example, when the electronic device is running the neural network model 10, the RoiAlign operator can be detected when running the pooling layer 14, triggering the feature processing method in the neural network model provided in the embodiment of the present application.
[0141] S402: Determine the input feature map corresponding to the target operation and the coordinate data of the candidate area.
[0142] In the embodiment of the present application, the input feature map and the coordinate data of the candidate area are generated by other operators in the neural network model.
[0143] S403: Divide the candidate region according to pre-stored output parameters to obtain multiple sub-regions; wherein the output parameters are used to determine the size of the output feature map.
[0144] In an embodiment of the present application, the output parameter is a hyperparameter of the neural network model, which is determined by the neural network model before being deployed on an electronic device. That is to say, for a neural network model to be run, the output parameter is a known quantity.
[0145] In some embodiments, the electronic device may divide the candidate area equally so that the sizes of the obtained multiple sub-areas are the same.
[0146] In some embodiments, the output parameters may include a horizontal output parameter and a vertical output parameter, and the size of the output feature map may be determined according to the horizontal output parameter and the vertical output parameter.
[0147] For example, assuming that the output parameters are [out_h, out_w] = [3, 3], Figure 3 As shown, the size of the output feature map can be determined to be 3*3, that is, the candidate area can be divided into 9 sub-areas.
[0148] S404: Sampling each of the sub-regions respectively to obtain at least one sampling point corresponding to each of the sub-regions respectively.
[0149] In the embodiment of the present application, the electronic device can sample each of the sub-areas according to the sampling parameters defined by the neural network model. The sampling parameters can also include horizontal sampling parameters and vertical sampling parameters, indicating the number of points sampled horizontally and vertically in the sub-areas.
[0150] For example, assuming that the sampling parameters are [sample_h, sample_w] = [2, 2], Figure 3 As shown, each sub-region can be divided into 4 cells, and the center point of each cell is used as a sampling point.
[0151] S405: Enlarging the coordinate data of the candidate area.
[0152] In the embodiment of the present application, the coordinate data of the candidate region may include horizontal coordinate data and vertical coordinate data. For example, the coordinate data of the candidate region may be expressed as Roi=[y1, x1, y2, x2]. The electronic device may enlarge the coordinate data of the candidate region by 2 shift , and obtain the coordinate data [y1, x1, y2, x2] after magnification processing, where shift is an integer greater than zero. The value of shift can be configured according to actual needs, for example, it can be set to 10, and the embodiment of the present application is not limited to this.
[0153] It can be understood that the coordinate data of the candidate area is enlarged before the calculation, so as to avoid further enlargement of the calculation results in the subsequent calculation process, reduce the amount of calculation in the feature processing process, and improve the operating speed of the electronic device while ensuring the calculation accuracy.
[0154] S406: Determine the coordinate data of each sampling point corresponding to each sub-region based on the coordinate data of the candidate region after the enlargement processing, the first operation factor and the second operation factor; wherein the first operation factor and the second operation factor are both represented in the form of multiplication and shift.
[0155] In the embodiment of the present application, determining the coordinate data of each sampling point corresponding to each sub-region based on the coordinate data of the candidate region after the enlargement processing, the first operation factor and the second operation factor may include:
[0156] For the coordinate data in each direction of the horizontal coordinate data and the vertical coordinate data, respectively, obtain the first operation factor corresponding to the coordinate data stored in advance;
[0157] Acquire the target sampling parameters corresponding to the direction of the coordinate data stored in advance;
[0158] Determine a second operation factor corresponding to the coordinate data according to the target sampling parameter;
[0159] Based on the coordinate data after the magnification processing and the first operation factor and the second operation factor corresponding to the coordinate data, the coordinate data of each sampling point corresponding to each sub-area in the corresponding direction is calculated.
[0160] For example, when calculating the horizontal coordinate data of each sampling point, the scaling coefficient and the shift number (qscale_1, qshift_1) corresponding to the first operation factor corresponding to the pre-stored horizontal coordinate data can be obtained, and then the horizontal sampling parameters can be obtained. The scaling coefficient and the shift number (qscale_2, qshift_2) corresponding to the second operation factor corresponding to the horizontal coordinate data are determined according to the horizontal sampling parameters. Then, roi_widt*_q is calculated based on the fixed-point number of the coordinate data of x1 and x2 after the amplification processing, and out_w_idx and sample_w_idx are determined according to the current sampling point. Finally, the horizontal coordinate data can be calculated by formula (12).
[0161] In some embodiments, determining the second operation factor corresponding to the coordinate data according to the target sampling parameter may include:
[0162] Determining whether the target sampling parameter is greater than zero;
[0163] When the target sampling parameter is greater than zero, obtaining a second operation factor corresponding to the pre-stored coordinate data;
[0164] When the target sampling parameter is equal to zero, generating a target table lookup parameter of the target sampling parameter;
[0165] Obtain a target table lookup result corresponding to the target table lookup parameter in the lookup table;
[0166] Based on the target table lookup result and the first operation factor corresponding to the coordinate data, a second operation factor corresponding to the coordinate data is determined.
[0167] In some embodiments, generating the target table lookup parameter of the target sampling parameter may include:
[0168] The target table lookup parameter is calculated based on the enlarged coordinate data and its corresponding first operation factor.
[0169] Specifically, when calculating the horizontal coordinate data of each sampling point, such as Figure 5 As shown, the horizontal sampling parameter sample_w (i.e., the target sampling parameter) in the direction corresponding to the horizontal coordinate data can be obtained, and it is determined whether the horizontal sampling parameter sample_w is greater than zero. If the horizontal sampling parameter sample_w is greater than zero, the scaling factor and the shift number (qscale_2, qshift_2) corresponding to the second operation factor corresponding to the pre-stored horizontal coordinate data can be obtained, and the horizontal coordinate data of each sampling point can be calculated according to formula (12). If the horizontal sampling parameter sample_w is equal to zero, the scaling factor and the shift number (qscale_2, qshift_2) corresponding to the second operation factor can be calculated by looking up a table.
[0170] Specifically, Figure 5 As shown, if the horizontal sampling parameter sample_w is equal to zero, it can be calculated according to The target table lookup parameter tmp of the horizontal sampling parameter sample_w is calculated, where "<<" indicates a left shift operation and ">>" indicates a right shift operation. Then, using tmp as the index, the corresponding table lookup result (qscale_w, qshift_w) is obtained from the pre-established lookup table. Finally, based on the table lookup result (qscale_w, qshift_w) and the scaling factor and shift number (qscale_1, qshift_1) corresponding to the first operation factor, the scaling factor and shift number (qscale_2, qshift_2) corresponding to the second operation factor can be determined, where qscale_2 = qscale_1*qscale_w, qshift_2 = qshift_1+qshift_w. In other words, when the obtained horizontal sampling parameter sample_w is equal to zero, the horizontal coordinate data of each sampling point can be calculated according to the following formula:
[0171] x_q*2 shift =x1_q+(roi_width_q*out_w_idx*qscale_1<<qshift_1)+((2*sample_w_idx+1)*roi_width_q*qscale_w*qscale_1<<(qshift_w+qshift_1)) (15)
[0172] Here, "<<" indicates a left shift operation. It should be noted that the method for calculating the ordinate data of each sampling point in the embodiment of the present application is similar to the method for calculating the abscissa data, and the embodiment of the present application will not be repeated here.
[0173] It can be understood that the method provided in the embodiment of the present application represents division as integer multiplication and shift when calculating the coordinate data of each sampling point, thereby avoiding division operations in the online calculation process, reducing the amount of calculation while ensuring the calculation accuracy, reducing the hardware resources occupied by the electronic device when running the neural network model, and improving the speed at which the electronic device runs the neural network model.
[0174] It can be understood that the method provided in the embodiment of the present application is compatible with the case where the sampling parameter is zero, and has better adaptability. In addition, when the sampling parameter is zero, the division operation during online calculation is avoided by looking up the table, thereby further accelerating the calculation speed of the online calculation process while ensuring the calculation accuracy.
[0175] S407: Based on the input feature map and the coordinate data of each sampling point corresponding to each sub-region, respectively determine the feature value of each sampling point corresponding to each sub-region.
[0176] In the embodiment of the present application, determining the feature values of each sampling point corresponding to each sub-region based on the input feature map and the coordinate data of each sampling point corresponding to each sub-region may include:
[0177] For each sampling point, based on the coordinate data of the sampling point, determine the coordinate data of a plurality of grid points in the input feature map that are closest to the sampling point;
[0178] Determine a feature value of each of the grid points based on the input feature map and the coordinate data of each of the grid points;
[0179] A bilinear difference operation is performed based on the coordinate data and the eigenvalues of each of the grid points to obtain the eigenvalues corresponding to the sampling points.
[0180] In the embodiment of the present application, the number of grid points can be set to 4, and bilinear interpolation can be performed through the coordinate data and eigenvalues of the 4 grid points to obtain the eigenvalues of the corresponding sampling points. It should be noted that the calculation method of bilinear interpolation is a prior art and will not be repeated in the embodiment of the present application.
[0181] Specifically, we can first calculate the values of x_left, x_right, y_top, and y_bottom based on the coordinates of the sampling points x_q and y_q:
[0182] x_left=x_q>>shift,x_right=x_left+1
[0183] y_top=y_q>>shift,y_bottom=y_top+1
[0184] Among them, ">>" represents a right shift operation, and the coordinate data (x_left, y_top), (x_left, y_bottom), (x_right, y_top) and (x_right, y_bottom) of the four grid points closest to the sampling point in the input feature map can be determined according to the values of x_left, x_right, y_top, and y_bottom.
[0185] S408: Determine an output feature map corresponding to the candidate region based on the feature values of each sampling point corresponding to each of the sub-regions.
[0186] In the embodiment of the present application, determining the output feature map corresponding to the candidate region based on the feature values of each sampling point corresponding to each sub-region may include:
[0187] Acquire pre-stored transverse sampling parameters and longitudinal sampling parameters;
[0188] Determine a third operation factor according to the horizontal sampling parameter and the vertical sampling parameter;
[0189] For each sub-region, respectively, based on the characteristic values of each sampling point corresponding to the sub-region and the third operation factor, calculate the characteristic value corresponding to the sub-region;
[0190] Based on the feature values corresponding to each of the sub-regions, an output feature map of the candidate region is generated.
[0191] Specifically, when determining the characteristic value f(x,y) of each sampling point corresponding to a sub-region i Afterwards, the pre-stored horizontal sampling parameter sample_w and the vertical sampling parameter sample_h can be obtained, and the scaling coefficient and the shift number (qscal_3, qshift_3) corresponding to the third operation factor can be determined according to the horizontal sampling parameter sample_w and the vertical sampling parameter sample_h, and then the characteristic value of the sub-area is calculated according to formula (14).
[0192] In some embodiments, the sum of the fixed-point numbers of sample_h*sample_w eigenvalues can be first obtained. Denoted as linear_out, the eigenvalue of the sub-region is calculated according to the following formula:
[0193] out h,w _q=linear_out*qscale_3<<qshift_3>>(2*shift)
[0194] Among them, “<<” represents a left shift operation, and ">>" represents a right shift operation.
[0195] In some embodiments, determining the third operation factor according to the transverse sampling parameter and the longitudinal sampling parameter may include:
[0196] respectively determining whether the horizontal sampling parameter and the vertical sampling parameter are greater than zero;
[0197] When the horizontal sampling parameter and the vertical sampling parameter are both greater than zero, obtaining a pre-stored third operation factor;
[0198] When the horizontal sampling parameter and / or the vertical sampling parameter is equal to zero, generating a first table lookup parameter of the horizontal sampling parameter, and / or generating a second table lookup parameter of the vertical sampling parameter;
[0199] Obtaining a first table lookup result corresponding to the first table lookup parameter in a lookup table, and / or obtaining a second table lookup result corresponding to the second table lookup parameter in the lookup table;
[0200] The third operation factor is determined based on the first table lookup result and / or the second table lookup result.
[0201] Specifically, when calculating the eigenvalues corresponding to each sub-region, such as Figure 6 As shown, the horizontal sampling parameter sample_w and the vertical sampling parameter sample_h can be obtained, and it is determined whether the horizontal sampling parameter sample_w and the vertical sampling parameter sample_h are greater than zero. If the horizontal sampling parameter sample_w and the vertical sampling parameter sample_h are both greater than zero, then the scaling coefficient and the shift number (qscale_3, qshift_3) corresponding to the pre-stored third operation factor can be obtained, and the characteristic value of each sub-area can be calculated according to formula (14). If at least one of the obtained horizontal sampling parameter sample_w and the vertical sampling parameter sample_h is equal to zero, then the scaling coefficient and the shift number (qscale_3, qshift_3) corresponding to the third operation factor can be calculated by looking up a table.
[0202] Specifically, Figure 6 As shown, when only sample_w=0, it can be based on The first table lookup parameter of the horizontal sampling parameter sample_w is calculated, where (qscale_1, qshift_1) is The corresponding scaling factor and shift number are obtained, and then tmp is used as the index to obtain the corresponding first lookup result from the pre-established lookup table. Since the lookup table is Therefore, multiplying the first table lookup result by 2 can obtain The corresponding scaling factor and shift number (scale_w, qshift_w) of the part are calculated according to (qscale_w, qshift_w) and the pre-stored The scaling factor and shift number (qscale_4, qshift_4) corresponding to the part can determine the scaling factor and shift number (qscale_3, qshift_3) corresponding to the third operation factor, where qscale_3 = qscale_4*qscale_w, qshift_3 = qshift_4+qshift_w. In other words, when the obtained horizontal sampling parameter sample_w is equal to zero and the vertical sampling parameter sample_h is not equal to zero, the eigenvalues corresponding to each sub-region can be calculated according to the following formula:
[0203] out h,w _q=linear_out*qscale_4*qscale_w<<(qshift_4+qshift_w)>>(2*shift)<<1 (16)
[0204] Among them, “<<” represents a left shift operation, and ">>" represents a right shift operation.
[0205] Specifically, when only sample_h=0, it is similar to sample_w=0, and the embodiment of the present application is not described again here.
[0206] Specifically, Figure 6 As shown, when sample_w=0, sample_h=0, the The first table lookup parameter of the horizontal sampling parameter sample_w is calculated and obtained according to The second table lookup parameter of the longitudinal sampling parameter sample_h is calculated, where (qscale_1, qshift_1) is The corresponding scaling factor and shift number, (qscale_1′,qshift_1′) are The corresponding scaling factor and shift number are obtained by using tmp and tmp′ as indexes to obtain the corresponding first and second lookup results from the pre-established lookup table. Since the lookup table is Therefore, the first table lookup result and the second table lookup result are multiplied by 2 to obtain The corresponding scaling factor and shift number (qscale_w, qshift_w) and The corresponding scaling factor and shift number (qscale_h, qshift_h) of the part are finally calculated according to (qscale_w, qshift_w), (qscale_h, qshift_h) and the pre-stored The values of the part (qscale_4, qshift_4) can determine the scaling factor and shift number (qscale_3, qshift_3) corresponding to the third operation factor, where qscale_3 = qscale_4*qscale_w*qscale_h, qshift_3 = qshift_4+qshift_w+qshift_h. In other words, when the obtained horizontal sampling parameter sample_w and vertical sampling parameter sample_h are both equal to zero, the eigenvalues corresponding to each sub-region can be calculated according to the following formula:
[0207] out h,w _q=linear_out*qscale_4*qscale_w*qscale_h<<(qshift_4+qshift_w+qshift_h)>>(2*shift)<<2 (17)
[0208] Among them, “<<” represents a left shift operation, and ">>" represents a right shift operation.
[0209] It can be understood that the method provided in the embodiment of the present application is compatible with the case where the sampling parameter is zero, and has better adaptability. In addition, when the sampling parameter is zero, the division operation during online calculation is avoided by looking up the table, thereby further accelerating the calculation speed of the online calculation process while ensuring the calculation accuracy.
[0210] To summarize, when an electronic device is running a neural network model, if a target operation is detected that converts an input feature map in a candidate area into an output feature map of a fixed size, such as an operation that generates a fixed-size feature map based on a candidate box mapping through a RoiAlign operator, the candidate area can be divided and sampled first, and the coordinate data of the candidate area can be enlarged in advance. Based on the enlarged coordinate data and the first operation factor and the second operation factor represented in the form of multiplication and shift, the coordinate data of each sampling point corresponding to each sub-area in the candidate area is calculated, and then the corresponding eigenvalue is determined according to the coordinate data of each sampling point, thereby determining the output feature map corresponding to the candidate area. In subsequent operations, there is no need to enlarge the operation results, and the division operation is avoided. While ensuring the operation accuracy, the amount of operation is reduced, the hardware resources occupied by the electronic device when running the neural network model containing the target operation are reduced, and the speed at which the electronic device runs the neural network model containing the target operation is improved.
[0211] Figure 7 According to some embodiments of the present application, a schematic diagram of the structure of a feature processing device 700 in a neural network model is shown, and the device 700 is arranged in an electronic device, such as Figure 7 As shown, the device 700 may include:
[0212] A candidate region determination module 710 is used to determine a candidate region in a processing object and perform a target operation on the candidate region, wherein the target operation is used to convert an input feature map in the candidate region into an output feature map of a fixed size;
[0213] An input data determination module 720, used to determine the input feature map corresponding to the target operation and the coordinate data of the candidate area;
[0214] A region division module 730 is used to divide the candidate region according to a pre-stored output parameter to obtain a plurality of sub-regions; wherein the output parameter is used to determine the size of the output feature map;
[0215] A sampling module 740 is used to sample each of the sub-regions to obtain at least one sampling point corresponding to each of the sub-regions;
[0216] A magnification module 750 is used to magnify the coordinate data of the candidate area;
[0217] A coordinate data determination module 760, configured to determine the coordinate data of each sampling point corresponding to each sub-region based on the coordinate data of the candidate region after the enlargement processing, a first operation factor and a second operation factor; wherein the first operation factor and the second operation factor are both represented in the form of multiplication and shift;
[0218] A feature value determination module 770, configured to determine the feature values of each sampling point corresponding to each sub-region based on the input feature map and the coordinate data of each sampling point corresponding to each sub-region;
[0219] The feature map determination module 780 is used to determine the output feature map corresponding to the candidate area based on the feature values of each sampling point corresponding to each sub-area.
[0220] It should be noted that the device provided in the above embodiment, when implementing its functions, only uses the division of the above functional modules as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device provided in the above embodiment and the corresponding method embodiment belong to the same concept, and the specific implementation process is detailed in the corresponding method embodiment, which will not be repeated here.
[0221] The feature processing method in the neural network model provided in the embodiment of the present application can be applied to any electronic device that can run a neural network model, including but not limited to mobile phones, wearable devices (such as smart watches, etc.), tablet computers, desktops, laptops, handheld computers, notebook computers, ultra-mobile personal computers (ultra-mobile personal computers, UMPC), netbooks, as well as cellular phones, personal digital assistants (personal digital assistants, PDAs), augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) devices, etc., and the embodiment of the present application does not limit it. To facilitate understanding of the technical solution of the embodiment of the present application, the electronic device 100 is taken as an example to illustrate the structure of the electronic device to which the feature processing method in the neural network model provided in the embodiment of the present application is applicable.
[0222] Figure 8 According to some embodiments of the present application, a schematic diagram of the structure of an electronic device 100 is shown. Figure 8 As shown, the electronic device 100 includes one or more processors 101, a system memory 102, a non-volatile memory (NVM) 103, a communication interface 104, an input / output (I / O) device 105, and a system control logic 106 for coupling the processor 101, the system memory 102, the non-volatile memory 103, the communication interface 104 and the input / output (I / O) device 105. Among them:
[0223] The processor 101 may include one or more processing units, for example, a central processing unit CPU (Central Processing Unit), a graphics processor GPU (Graphics Processing Unit), a digital signal processor DSP (Digital Signal Processor), a microprocessor MCU (Micro-programmed Control Unit), an AI (Artificial Intelligence) processor or a programmable logic device FPGA (Field Programmable Gate Array), a neural network processor (Neural-network Processing Unit, NPU), etc. The processing module or processing circuit may include one or more single-core or multi-core processors. In some embodiments, the NPU can be used to run instructions corresponding to the feature processing method in the neural network model provided in the embodiments of the present application.
[0224] The system memory 102 is a volatile memory, such as a random-access memory (RAM), a double data rate synchronous dynamic random access memory (DDR SDRAM), etc. The system memory is used to temporarily store data and / or instructions. For example, in some embodiments, the system memory 102 can be used to store the above-mentioned lookup table.
[0225] The non-volatile memory 103 may include one or more tangible, non-transitory computer-readable media for storing data and / or instructions. In some embodiments, the non-volatile memory 103 may include any suitable non-volatile memory such as flash memory and / or any suitable non-volatile storage device, such as a hard disk drive (HDD), a compact disc (CD), a digital versatile disc (DVD), a solid-state drive (SSD), etc. In some embodiments, the non-volatile memory 103 may also be a removable storage medium, such as a secure digital (SD) memory card, etc. In other embodiments, the non-volatile memory 103 may be used to store the above-mentioned lookup table.
[0226] In particular, the system memory 102 and the non-volatile memory 103 may respectively include: a temporary copy and a permanent copy of the instruction 107. The instruction 107 may include: when executed by at least one of the processors 101, the electronic device 100 implements the feature processing method in the neural network model provided in each embodiment of the present application.
[0227] The communication interface 104 may include a transceiver for providing a wired or wireless communication interface for the electronic device 100, and then communicating with any other suitable device through one or more networks. In some embodiments, the communication interface 104 may be integrated into other components of the electronic device 100, for example, the communication interface 104 may be integrated into the processor 101. In some embodiments, the electronic device 100 may communicate with other devices through the communication interface 104, for example, the electronic device 100 may obtain a neural network model and a lookup table corresponding to the neural network model from other electronic devices through the communication interface 104.
[0228] The input / output (I / O) device 105 may include input devices such as a keyboard, a mouse, etc., and output devices such as a display, etc. A user may interact with the electronic device 100 via the input / output (I / O) device 105 .
[0229] System control logic 106 may include any suitable interface controller to provide any suitable interface with other modules of electronic device 100. For example, in some embodiments, system control logic 106 may include one or more memory controllers to provide interfaces to system memory 102 and non-volatile memory 103.
[0230] In some embodiments, at least one of the processors 101 may be packaged together with the logic of one or more controllers for the system control logic 106 to form a system in package (SiP). In other embodiments, at least one of the processors 101 may also be integrated with the logic of one or more controllers for the system control logic 106 on the same chip to form a system-on-chip (SoC).
[0231] Understandably, Figure 8 The structure of the electronic device 100 shown is only an example. In other embodiments, the electronic device 100 may include more or fewer components than shown, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0232] The various embodiments of the mechanism disclosed in the present application can be implemented in hardware, software, firmware or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device and at least one output device.
[0233] Program code can be applied to input instructions to perform the functions described in this application and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, a processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.
[0234] Program code can be implemented with high-level programming language or object-oriented programming language to communicate with the processing system. When necessary, program code can also be implemented with assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any specific programming language. In either case, the language can be a compiled language or an interpreted language.
[0235] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, instructions may be distributed over a network or through other computer-readable media. Therefore, machine-readable media may include any mechanism for storing or transmitting information in a machine (e.g., computer) readable form, including, but not limited to, floppy disks, optical disks, optical disks, read-only memories (CD-ROMs), magneto-optical disks, read-only memories (ROM), random access memories (RAM), erasable programmable read-only memories (EPROM), electrically erasable programmable read-only memories (EEPROM), magnetic cards or optical cards, flash memory, or tangible machine-readable memories for transmitting information (e.g., carrier waves, infrared signal digital signals, etc.) using the Internet in electrical, optical, acoustic, or other forms of propagation signals. Accordingly, machine-readable media include any type of machine-readable media suitable for storing or transmitting electronic instructions or information in a form readable by a machine (eg, a computer).
[0236] In the accompanying drawings, some structural or method features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be required. Instead, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. In addition, the inclusion of structural or method features in a particular figure does not mean that such features are required in all embodiments, and in some embodiments, these features may not be included or may be combined with other features.
[0237] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation method of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed by the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned device embodiments of the present application do not introduce units / modules that are not closely related to solving the technical problems proposed by the present application, which does not mean that there are no other units / modules in the above-mentioned device embodiments.
[0238] It should be noted that in the examples and description of this patent, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, an element defined by the sentence "comprises one" does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0239] Although the present application has been illustrated and described with reference to certain preferred embodiments thereof, it will be apparent to those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present application.
Claims
1. A feature processing method in a neural network model, applied to electronic equipment, characterized in that: include: Determine a candidate region in the processing object, and perform a target operation on the candidate region, wherein the target operation is used to convert an input feature map in the candidate region into an output feature map of a fixed size; Determine the input feature map corresponding to the target operation and the coordinate data of the candidate area; Dividing the candidate region according to pre-stored output parameters to obtain a plurality of sub-regions, wherein the output parameters are used to determine the size of the output feature map, and the output parameters include a horizontal output parameter and a vertical output parameter; Sampling each of the sub-regions according to a sampling parameter to obtain at least one sampling point corresponding to each of the sub-regions, wherein the sampling parameter includes a horizontal sampling parameter and a vertical sampling parameter, the horizontal sampling parameter represents the number of points sampled in the horizontal direction of the sub-region, and the vertical sampling parameter represents the number of points sampled in the vertical direction of the sub-region; Amplifying the coordinate data of the candidate area; Determine the coordinate data of each sampling point corresponding to each sub-region based on the coordinate data of the candidate region after the enlargement processing, the first operation factor and the second operation factor, wherein the first operation factor and the second operation factor are both expressed in the form of multiplication and shift, and the coordinate data of the candidate region includes horizontal coordinate data and vertical coordinate data; Based on the input feature map and the coordinate data of each sampling point corresponding to each sub-region, respectively determine the feature value of each sampling point corresponding to each sub-region; Determine an output feature map corresponding to the candidate region based on the feature values of each sampling point corresponding to each of the sub-regions; and: Corresponding to the horizontal coordinate data, the first operation factor represents the reciprocal of the horizontal output parameter, and the second operation factor represents the reciprocal of 2 times the product of the horizontal output parameter and the horizontal sampling parameter; Corresponding to the longitudinal coordinate data, the first operational factor represents the inverse of the longitudinal output parameter, and the second operational factor represents the inverse of 2 times the product of the longitudinal output parameter and the longitudinal sampling parameter.
2. The method according to claim 1, characterized in that The enlarging the coordinate data of the candidate area includes: Enlarge the coordinate data of the candidate area by 2 shift , where shift is an integer greater than zero.
3. The method according to claim 1, characterized in that The step of determining the coordinate data of each sampling point corresponding to each sub-region based on the coordinate data of the candidate region after the enlargement processing, the first operation factor and the second operation factor includes: For the coordinate data in each direction of the horizontal coordinate data and the vertical coordinate data, respectively, obtain the first operation factor corresponding to the coordinate data stored in advance; Acquire the target sampling parameters corresponding to the direction of the coordinate data stored in advance; Determine a second operation factor corresponding to the coordinate data according to the target sampling parameter; Based on the coordinate data after the magnification processing and the first operation factor and the second operation factor corresponding to the coordinate data, the coordinate data of each sampling point corresponding to each sub-area in the corresponding direction is calculated.
4. The method according to claim 3, characterized in that The determining, according to the target sampling parameter, a second operation factor corresponding to the coordinate data comprises: Determining whether the target sampling parameter is greater than zero; When the target sampling parameter is greater than zero, obtaining a second operation factor corresponding to the pre-stored coordinate data; When the target sampling parameter is equal to zero, generating a target table lookup parameter of the target sampling parameter; Obtain a target table lookup result corresponding to the target table lookup parameter in the lookup table; Based on the target table lookup result and the first operation factor corresponding to the coordinate data, a second operation factor corresponding to the coordinate data is determined.
5. The method according to claim 4, characterized in that The generating of the target table lookup parameter of the target sampling parameter comprises: The target table lookup parameter is calculated based on the enlarged coordinate data and its corresponding first operation factor.
6. The method according to claim 1, characterized in that The step of determining the feature values of the sampling points corresponding to the sub-regions based on the input feature map and the coordinate data of the sampling points corresponding to the sub-regions comprises: For each sampling point, based on the coordinate data of the sampling point, determine the coordinate data of a plurality of grid points in the input feature map that are closest to the sampling point; Determine a feature value of each of the grid points based on the input feature map and the coordinate data of each of the grid points; A bilinear difference operation is performed based on the coordinate data and the eigenvalues of each of the grid points to obtain the eigenvalues corresponding to the sampling points.
7. The method according to claim 1, characterized in that The step of determining an output feature map corresponding to the candidate region based on the feature values of each sampling point corresponding to each sub-region comprises: Determine a third operation factor according to the horizontal sampling parameter and the vertical sampling parameter; For each sub-region, respectively, based on the characteristic values of each sampling point corresponding to the sub-region and the third operation factor, calculate the characteristic value corresponding to the sub-region; Based on the feature values corresponding to each of the sub-regions, generating an output feature map of the candidate region; Furthermore, determining the third operation factor according to the horizontal sampling parameter and the vertical sampling parameter includes: respectively determining whether the horizontal sampling parameter and the vertical sampling parameter are greater than zero; When the horizontal sampling parameter and the vertical sampling parameter are both greater than zero, obtaining a pre-stored third operation factor; When the horizontal sampling parameter and / or the vertical sampling parameter is equal to zero, generating a first table lookup parameter of the horizontal sampling parameter, and / or generating a second table lookup parameter of the vertical sampling parameter; Obtaining a first table lookup result corresponding to the first table lookup parameter in a lookup table, and / or obtaining a second table lookup result corresponding to the second table lookup parameter in the lookup table; The third operation factor is determined based on the first table lookup result and / or the second table lookup result.
8. A readable medium, characterized in that The readable medium contains instructions, which, when executed by a processor of an electronic device, enable the electronic device to implement the feature processing method in the neural network model described in any one of claims 1-7.
9. An electronic device, characterized in that: include: a memory for storing instructions to be executed by one or more processors of the electronic device; And a processor, which is one of the processors of the electronic device, is used to run the instructions to enable the electronic device to implement the feature processing method in the neural network model described in any one of claims 1-7.
10. A computer program product, characterized in that The computer program product comprises instructions for implementing the feature processing method in the neural network model according to any one of claims 1 to 7.
Citation Information
Patent Citations
Design method for convolutional neural network processor supporting multiple precisions
CN108564168A
Fine image recognition
CN109284749A
Method and apparatus with neural network performing deconvolution
CN109754064A
Artificial neural network adjustment method and device
CN110413255A
Computing device for neural network operation and integrated circuit board card thereof
CN111027691A
