Method for operating a neural network model, readable medium and electronic device

By constructing a lookup table to convert the nonlinear operations of the LRN operator into lookup table entries, the problem that the NPU cannot directly implement nonlinear operations is solved, thus improving the running speed and efficiency of the neural network model.

CN114491167BActive Publication Date: 2026-01-02ARM TECH CHINA CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210100000.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2021-12-31
Filing Date
2022-01-27
Publication Date
2026-01-02
Estimated Expiration
2042-01-27

AI Technical Summary

Technical Problem

Existing neural network processors (NPUs) cannot directly implement nonlinear operations in the Local Response Normalization (LRN) operator, resulting in slow computation speed and high hardware resource consumption, which reduces the running speed of neural network models.

Method used

By constructing a lookup table, the nonlinear operations in the LRN operator are converted into lookup table entries, and the LRN operator is implemented using fixed-point arithmetic, which reduces complex nonlinear operations and improves the operation speed.

Benefits of technology

It reduces hardware resource consumption and improves the running speed and efficiency of neural network models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114491167B_ABST
    Figure CN114491167B_ABST
Patent Text Reader

Abstract

The application relates to the field of artificial intelligence, and discloses a neural network model running method, readable medium and electronic equipment. The method comprises the following steps: detecting a first operation in the process of running a neural network model, the first operation comprising a first operation part, and the first operation part comprising at least one nonlinear operation factor; obtaining first input data of the first operation from a first data matrix; generating first lookup table parameters of the first input data; determining a first index value corresponding to the first lookup table parameters in an index table, obtaining a first lookup table result corresponding to the first index value in the index table, wherein the first lookup table parameters, the first index value and the first lookup table result are fixed-point numbers; and determining an operation result of the first operation part based on the first lookup table result. Thus, the electronic equipment can obtain the fixed-point number operation result of the first operation through linear operation and lookup table when running the first operation, and the speed of running the neural network model of the electronic equipment is improved.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] The present application claims priority to the Chinese patent application No. 202111677116.5, filed on December 31, 2021, and entitled "Running method of neural network model", the whole content of which is incorporated herein by reference. TECHNICAL FIELD

[0002] The present application relates to the field of artificial intelligence, and in particular to a running method of a neural network model, a readable medium and an electronic device. BACKGROUND

[0003] With the rapid development of artificial intelligence (AI), neural network models are increasingly widely used in the field of artificial intelligence. In order to improve the running accuracy of the neural network model, it is usually necessary to normalize the output results of the operators in the neural network model. For example, in the AlexNet network, the output data of the Rectified Linear Unit (ReLU) operator can be normalized by the Local Response Normalization (LRN) operator.

[0004] However, since the LRN operator includes operations such as accumulation, multiplication, division, and exponentiation, and the operation unit used to run the neural network model, such as a Neural-Network Processing Unit (NPU), is a fixed-point operation unit, there is no circuit that can directly implement the non-linear operations such as exponentiation and division in the LRN operator. Instead, the operations of normalizing the output of the ReLU operator by the LRN operator are implemented through iterative solutions, which is slow and occupies a large amount of hardware resources of the NPU, reducing the speed of the electronic device running the neural network model. SUMMARY

[0005] In view of the above, the present application provides a running method of a neural network model, a readable medium and an electronic device.

[0006] In a first aspect, an embodiment of the present application provides a method for running a neural network model, applied to an electronic device, comprising: detecting a first operation in the process of running the neural network model, the first operation comprising a first operation part, wherein the first operation part comprises at least one nonlinear operation factor; obtaining first input data of the first operation from a first data matrix; generating a first lookup table parameter of the first input data; determining a first index value corresponding to the first lookup table parameter in an index table, the floating point number corresponding to the first index value having the same numerical value as the floating point number corresponding to the first lookup table parameter; obtaining a first lookup table result corresponding to the first index value in the index table, wherein the first lookup table parameter and the first index value are fixed point numbers, and the first lookup table result is a fixed point number result obtained by previously taking the first index value as input data of the first operation part; and determining an operation result of the first operation part based on the first lookup table result.

[0007] That is to say, in the process of running the neural network model, if the electronic device detects the first operation, such as the operation of normalizing the first input data by the LRN operator, the electronic device can determine the first lookup table parameter (such as the lookup index value below) corresponding to the first input data, obtain the fixed point number lookup result of the first operation part (such as the lookup table item below) including the nonlinear operation factor in the first operation from the preset index table (such as the lookup table below) based on the first lookup table parameter, and then determine the fixed point number operation result (such as the lookup table result below) of the first operation part according to the lookup result, without performing complex nonlinear operation, thereby reducing the hardware resources occupied by the electronic device in running the neural network model and improving the speed of the electronic device in running the first operation including the nonlinear factor.

[0008] In a possible implementation of the first aspect, the method further comprises: obtaining at least one second input data corresponding to the first input data from at least one second data matrix, and taking an operation result of a first sub-operation including the first input data and the second input data in the first operation part as the first lookup table parameter of the first input data, wherein the first sub-operation only includes linear operation factors, and the row and column of the second input data in the second data matrix are the same as the row and column of the first input data in the first data matrix.

[0009] That is, the operation result of the first operation part varies with the first input data and the second input data, and the index table stores the corresponding result of the first operation part indexed by the result of the sub-operation of the linear operation of the first operation part including the first input data and the second input data, instead of storing the corresponding result of the first operation part for each combination of the first input data and the second input data, thereby reducing the size of the index table, improving the speed of the electronic device in table lookup, and further improving the speed of the electronic device in running the first operation including the nonlinear factor.

[0010] In a possible implementation of the first aspect, the quantization bit number of the first table lookup parameter is M, and the quantization bit number of the index value in the index table is N; and determining the first index value corresponding to the first table lookup parameter in the index table comprises: in the case where M is less than or equal to N, the first index value is an index value equal to the first table lookup parameter in the index table; and in the case where M is greater than N, the first index value is an index value equal to the high N bits of the binary number corresponding to the first table lookup parameter in the index table.

[0011] That is, the quantization bit number of the index value in the index table can be set according to the accuracy requirement of the first operation, in the case where the quantization bit number of the first table lookup parameter is less than or equal to the quantization bit number of the index value, the result corresponding to the index value equal to the first table lookup parameter is directly used as the table lookup result of the first operation part, and in the case where the quantization bit number of the first table lookup parameter is greater than the quantization bit number of the index value, the result corresponding to the index value equal to the high N bits of the first table lookup parameter is used as the table lookup result of the first operation part. Thus, the quantization bit number of the index table can be set according to the accuracy requirement of the first operation, to reduce the size of the index table, improve the table lookup speed, and further improve the speed of the electronic device in running the first operation including the nonlinear factor.

[0012] In a possible implementation of the first aspect, determining the operation result of the first operation based on the first table lookup result comprises: in the case where M is less than or equal to N, using the first table lookup result as the operation result of the first operation part.

[0013] In a possible implementation of the first aspect, determining the operation result of the first operation based on the first table lookup result comprises: in the case where M is greater than N, obtaining a second table lookup result corresponding to a second index value from the index table, based on the second index value obtained by adding 1 to the first index value; determining a difference between the second table lookup result and the first table lookup result, multiplying the difference by the difference between the first table lookup parameter and the first index value, and then right-shifting the product by M-N bits to obtain a correction value; and using the sum of the correction value and the first table lookup result as the operation result of the first operation part.

[0014] That is, in the case that the quantization bit number of the first table lookup parameter is greater than the quantization bit number of the index value, the interpolation table lookup is performed through the above steps, so that the accuracy of the table lookup result can be improved, and the accuracy of the electronic device running the neural network model can be improved.

[0015] In a possible implementation of the first aspect, the first operation further includes a second operation part; and the method further includes: determining the fixed-point number operation result of the first operation based on linear operation of the operation result of the first operation part and the operation result of the second operation part.

[0016] In a possible implementation of the first aspect, the first operation is an operation of normalizing the first input data in the to-be-normalized data set by using an LRN operator, the to-be-normalized data set includes N (N>1) data matrices, and the first operation is defined by the following formula: wherein, is the first input data, and represents data in the xth row and yth column of the ith (1≤i≤N) data matrix in the to-be-normalized data set; is the operation result of the first operation, and represents the normalized result of the first input data ; k, α, β, and n are hyperparameters; the first operation part includes the second operation part includes

[0017] In a possible implementation of the first aspect, the first table lookup parameter is determined according to the following formula: wherein, represents a fixed-point number corresponding to data in the xth row and yth column of the jth (max(0, i-n / 2)≤j≤min(N, i-n / 2)) data matrix in the to-be-normalized data set.

[0018] In a possible implementation of the first aspect, the linear operation based on the operation result of the first operation part and the operation result of the second operation part to determine the fixed-point number operation result of the first operation includes: obtaining a pre-stored scaling coefficient and a shift number from the index table; multiplying the operation result of the first operation part and the fixed-point number corresponding to the first input data, then multiplying the product by the scaling coefficient, and shifting the obtained product to the left by the shift number of bits to obtain the fixed-point number operation result of the first operation.

[0019] That is, in the embodiments of the present application, the fixed-point number table lookup result of the first operation part is obtained through table lookup, the product of the result and the fixed-point number of the input data is multiplied by a pre-set scaling coefficient, and the result of the multiplication is shifted to the left by a pre-set shift number of bits, so that the fixed-point number result of normalizing the first input data by using the LRN operator can be obtained without complex nonlinear operation, thereby improving the speed of the electronic device in operating the neural network model including the LRN operator.

[0020] In a second aspect, the embodiments of the present application provide a readable medium, which comprises instructions, when the instructions are executed by a processor of an electronic device, causing the electronic device to implement the running method of any one of the neural network models provided in the first aspect and various possible implementations of the first aspect.

[0021] In a third aspect, the embodiments of the present application provide an electronic device, which comprises: a memory, configured to store instructions executed by one or more processors of the electronic device; and a processor, which is one of the processors of the electronic device, configured to execute the instructions to cause the electronic device to implement the running method of any one of the neural network models provided in the first aspect and various possible implementations of the first aspect. BRIEF DESCRIPTION OF DRAWINGS

[0022] Figure 1 According to some embodiments of the present application, a structural diagram of a neural network model is shown;

[0023] Figure 2 According to some embodiments of the present application, a schematic diagram of a convolutional layer and an activation layer calculation process of a neural network model 10 is shown;

[0024] Figure 3 According to some embodiments of the present application, a schematic diagram of a lookup table 30 is shown;

[0025] Figure 4 According to some embodiments of the present application, a flowchart of a running method of a neural network model is shown;

[0026] Figure 5 According to some embodiments of the present application, a flowchart of determining a lookup table result according to an index value is shown;

[0027] Figure 6 According to some embodiments of the present application, a process schematic diagram of an interpolation lookup table is shown;

[0028] Figure 7 According to some embodiments of the present application, a structural schematic diagram of an electronic device 100 is shown. DETAILED DESCRIPTION

[0029] The illustrative embodiments of the present application include but are not limited to a running method of a neural network model, a medium and an electronic device.

[0030] In order to more clearly understand the present application, the structure of the neural network model will be described.

[0031] Figure 1 According to some embodiments of the present application, a structural diagram of a neural network model is shown. As shown in FIG. 1, the neural network model 10 comprises an input layer 11, a convolutional layer 12, an activation layer 13, a pooling layer 14, a fully connected layer 15 and an output layer 16.Figure 1 As shown, the neural network model 10 includes an input layer 11, a convolution layer 12, an activation layer 13, a normalization layer 14, a full connection layer 15, and an output layer 16. The convolution layer 12 extracts features of an input image through a plurality of convolution kernels to obtain a plurality of feature matrices; the activation layer 13 is configured to activate each feature matrix, for example, by a ReLU operator to activate each feature matrix to improve the operation speed of the subsequent layer; the normalization layer 14 normalizes the output data of the activation layer 13 by an LRN operator; the full connection layer 15 is configured to classify the input image data, for example, to obtain the probability that the input image belongs to each preset image category; and the output layer 16 is configured 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 maximum probability.

[0032] It can be understood that the structure of the neural network model 10 is only an example, and in other embodiments, the neural network model can be any neural network model including an LRN operator, which is not limited herein.

[0033] It can be understood that in some embodiments, the preset image categories can include landscapes, people, animals, and the like.

[0034] It can be understood that the LRN operator can be defined by the following formula (1).

[0035]

[0036] wherein represents the data of the xth row and yth column of the ith group of input data; represents the data of the xth row and yth column of the ith group of normalized results; N is the number of groups of input data; k, a, b, and n are hyperparameters determined by the neural network model before being deployed to an electronic device, that is, for a neural network model to be run, the hyperparameters k, a, b, and n are known quantities.

[0037] It can be understood that the above hyperparameters k, a, b, and n can also be adjusted according to the actual application scenario, for example, in some embodiments, a / n can be replaced by a hyperparameter, and the embodiments of the present application are not limited.

[0038] For example, Figure 2 According to some embodiments of the present application, a schematic diagram of the calculation process of the convolution layer 12 and the activation layer 13 in the neural network model 10 is shown. As shown in FIG. 2, the convolution layer 12 extracts features of an input image through a plurality of convolution kernels to obtain a plurality of feature matrices; the activation layer 13 is configured to activate each feature matrix, for example, by a ReLU operator to activate each feature matrix to improve the operation speed of the subsequent layer; the normalization layer 14 normalizes the output data of the activation layer 13 by an LRN operator; the full connection layer 15 is configured to classify the input image data, for example, to obtain the probability that the input image belongs to each preset image category; and the output layer 16 is configured 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 maximum probability. Figure 2As shown, the input image data matrix A is a 9×9 matrix; the convolutional layer 12 includes nine 3×3 convolutional kernels Ki (i = 1, 2, ..., 9), and matrices A and Ki are convolved to obtain nine convolutional results Hi (i = 1, 2, ..., 9); the activation function of the activation layer 13 is the ReLU activation function, which is used to set the elements less than 0 in Hi to 0, resulting in nine sets of data a to be normalized. i (i=1,2,…,9), which is N=9 in formula (1).

[0039] For example, refer to Figure 2 Assuming that after K3 convolution and activation calculations... After K4 convolution and activation calculation After K5 convolution and activation calculation In this way, the data to be normalized can be calculated. Normalized result

[0040] Assume i = 4, x = 1, y = 9, n = 2, k = 2, α = 10 -5 β = 0.75. Based on formula (1), we can obtain:

[0041]

[0042] As can be seen from formula (1), the LRN operator includes operations such as accumulation, multiplication, division, and exponentiation. However, the computing unit used to run the neural network model, such as the NPU, is a fixed-point computing unit and cannot directly implement nonlinear operations such as exponentiation and division in the above operations through hardware. Instead, it achieves the normalization of the output of the ReLU operator by the LRN operator through iterative solution. This is slow and occupies a lot of hardware resources of the NPU, which reduces the speed of running the neural network model of the electronic device.

[0043] To address the aforementioned issues, this application provides a method for operating an LRN operator. By setting the nonlinear operations in the LRN operator as lookup table entries, the LRN operator is equivalent to lookup table entries and data to be normalized. The product, and pre-built for storing based on input data A lookup table that establishes the correspondence between a defined index value and its corresponding lookup item, enabling the NPU to perform operations using the LRN operator. During the normalization process, it can be based on the data to be normalized. Determine the index value for the lookup table, and retrieve the lookup result corresponding to the index value from the lookup table. Then, combine the lookup result with the data to be normalized. Multiplying them together will give you the result. The normalized result of the data. In this way, the NPU does not need to perform complex nonlinear operations, thereby improving the speed of the NPU in performing LRN normalization on data, and thereby improving the running speed of the neural network model.

[0044] It can be understood that the above nonlinear operation (which can also be referred to as a nonlinear operation factor) is an operation that cannot be directly implemented by hardware circuit of the NPU, but needs to be iteratively solved by other linear operations, including but not limited to division, power index, reciprocal, etc. Among them, the linear operation can include multiplication, addition, subtraction, left shift, right shift, etc.

[0045] Specifically, from formula (1), it can be seen that does not change only with the ith group of data, but changes with the max(0, i-n / 2)th group of data to the ith group of data and the min(i+n / 2, N)th group of data, so if the index value of the lookup table is directly taken as , it will cause the lookup table data to be too large, occupy a large storage space, and be not conducive to quickly finding the lookup result of the lookup table item, thereby affecting the running speed of the neural network model. Therefore, in some embodiments, lut_in defined by formula (2) below can be used as the lookup index of the lookup table item, and lut_out defined by formula (3) below can be used as the lookup result of the lookup table item:

[0046]

[0047]

[0048] Therefore, it can be seen from formula (1) to formula (3) that:

[0049]

[0050] That is to say, based on formula (2) and formula (3), the lookup table item is the part of the LRN operator that includes nonlinear operations The lookup table process is to find the lookup table value lut_out according to the index value lut_in, that is, the value of the aforementioned nonlinear operation part. Therefore, by pre-constructing a lookup table that stores the correspondence between the index value lut_in and the lookup table value lut_out, the electronic device can first determine the index value lut_in according to during the process of normalizing the data by the LRN operator (j takes [max(0, i-n / 2), min(N, i+n / 2)], the index value lut_in is determined, that is, the lookup index value, lut_out is obtained from the lookup table according to lut_in, that is, the lookup result, and finally the product of and the lookup result is calculated to obtain the value of .

[0051] The process of constructing the lookup table based on the above formulas (1) to (4) is introduced below.

[0052] For ease of description, it is defined herein in the embodiments of the present application that X_f represents a floating point number of variable X, X_q represents a fixed point number of variable X, and X_scale represents a scaling factor of quantizing X_f into X_q. Assuming that X_q is a symmetrically quantized n-bit fixed point number, the relationship between X_f, X_scale and X_q can be determined by the following formulas (5) and (6).

[0053]

[0054] X_q = round(X_scale X_f) (6)

[0055] Wherein, max(a) represents the maximum value of a, min(a) represents the minimum value of a, abs(a) represents the absolute value of a, and round(a) represents rounding a to an integer.

[0056] It can be understood that round(a) can also be a function of other functions, for example, floor(a) function, fix(a) function, etc. which retains the integer part and discards the decimal part, and the present application is not limited.

[0057] It can be understood that since the NPU can only perform fixed point operations, the index value and the output in the lookup table should be fixed point numbers, i.e. the index value lut_in_q and the lookup table value lut_out_q. In the process of constructing the lookup table offline, in order to avoid the influence of directly using fixed point operations to determine the lookup table value lut_out_q corresponding to the index value lut_in_q in the construction process on the accuracy of the lookup table, the index value lut_in_q can be first converted into a floating point index value lut_in_f, the floating point lookup table value lut_out_f is obtained based on formula (3), and then the floating point lookup table value lut_out_f is converted into a fixed point lookup table value lut_out_q.

[0058] Specifically, in the process of constructing the lookup table offline, For the case of m-bit fixed point number, it can be known from formula (2) that the value range of the index value lut_in_q is 2m-bit fixed point number. That is, when the index value lut_in_q is a signed number (i.e. a symmetrically quantized fixed point number), the value range of the index value lut_in_q is [-2 2m-1 , …, 2 2m-1 -1]; when the index value lut_in_q is an unsigned number (i.e. a non-symmetrically quantized fixed point number), the value range of the index value lut_in_q is [0, …, 2 2m -1].

[0059] For example, assuming that the output of the above activation layer 13 is It is an 8-bit fixed-point number, and For symmetric quantized signed numbers, The range of the index value lut_in_q is [-32768, 32767].

[0060] First, based on formulas (2) and (6), we can obtain the conversion formula (7) for converting the index value of a fixed-point number to the index value of a floating-point number.

[0061]

[0062] For example, assuming n = 2, and the index value lut_in_q is a decimal fixed point number 25, i.e., binary 00011001, the scaling factor of the data to be normalized. In this case, the floating-point index value lut_in_f can be obtained as the floating-point number 25.

[0063] Therefore, based on formulas (2) and (7), we can obtain the formula for calculating the floating-point lookup value in the lookup table as shown in formula (8).

[0064]

[0065] For example, suppose k = 2, α = 10 -5 With β = 0.75, and the floating-point index value lut_in_f being the aforementioned fixed-point value of 25, the floating-point index value lut_out_f = 0.5945.

[0066] After obtaining the floating-point index value lut_out_f, the maximum and minimum values ​​of the floating-point index value lut_out_f, as well as formulas (5) and (6), can be used to obtain the calculation formula for converting the floating-point lookup table value to the fixed-point lookup table value as shown in formula (9).

[0067]

[0068] For example, if the floating-point index value lut_in_f has a range of [-32768, 32767], and k = 2, α = 10 -5 , β=0.75, the maximum value of the floating-point lookup table value lut_out_f is 0.6800, and the minimum value is 0.5307. Therefore, based on formula (5), it can be known that if the lookup table value lut_out_q is quantized to 8 bits, then the lookup table value scaling factor lut_out_scale=(2 7 -1) / 0.6800 = 186.76.

[0069] From formula (4), we can see that:

[0070]

[0071] Thus, the input data is quantized according to formula (6) The quantized data is normalized according to formula (7) Substituting formula (10) into formula (7) can obtain formula (11) as follows.

[0072]

[0073] The formula (11) can be moved to obtain formula (12) as follows.

[0074]

[0075] The table value lut_out_q can be obtained by table lookup, and the quantized data to be normalized is obtained from the data to be normalized , so that the NPU can quickly pass through the LRN operator by simple fixed-point operation on the data to be normalized by running the neural network model as long as the table lookup is constructed offline.

[0076] In some embodiments, the can be expressed as the product of a fixed-point number and the power of 2, for example, the is converted to qscale x 2 shift , and the qscale (scaling factor) and shift (shift number) are recorded in the lookup table, so that the NPU only needs to calculate the product of the table value lut_out_q and the scaling factor qscale and shift the result to the left by shift bits to obtain the calculation result in the process of calculating the product of and the table value lut_out_q, further improving the speed of the NPU based on the LRN operator to quantize data. For example, in the case where the maximum value of the floating-point table value lut_out_f is 0.6800, the minimum value is 0.5307, , the absolute value of the value range of is [0, 128], the value range of is [0, 87.04], and the normalized result scaling factor is quantized to 8 bits, so that

[0077]

[0078] In some embodiments, 0.0078 can be converted to qscale x 2 shift , for example, 2 -7 ​, i.e. the scaling factor qscale = 1 and the shift number shift = -7. Thus, based on the above data, a look-up table 30 as shown in FIG. 3 can be constructed. As shown in FIG. 3, the look-up table 30 can include the look-up table value lut_out_q corresponding to the index value lut_in_q, and the values of the scaling factor qscale and the shift number shift, i.e. the look-up table result includes the look-up table value lut_out_q, the scaling factor qscale, and the shift number shift. Figure 3 Figure 3

[0079]

[0080]

[0081] In formula (13), "<<" represents left shift operation.

[0082] As can be seen from formula (13), the NPU determines the index value lut_in_q by (j takes an integer in [max(0, i-n / 2), min(N, i+n / 2)]), and obtains the look-up table value lut_out_q, the scaling factor qscale, and the shift number shift from the look-up table according to the index value lut_in_q, and then left shifts the look-up table value lut_out_q multiplied by the scaling factor qscale by shift bits to obtain the fixed-point normalized data normalized_data. Thus, the NPU can obtain the fixed-point normalized data normalized_data by the LRN operator without performing complex nonlinear operations such as division and exponentiation, thereby reducing the hardware resource consumption of the NPU and improving the running speed of the neural network model.

[0083] For example, when the NPU calculates the foregoing , it can determine the index value lut_in_q = 00011001 based on , obtain the look-up table value lut_out_q = 0110 1111 from the look-up table, and then calculate , left shift by -7 bits (i.e. right shift by 7 bits) to obtain

[0084] It can be understood that in some other embodiments, the look-up table 30 can also be stored in other data forms, such as a graph, an array, etc., and the storage form of the look-up table 30 is not limited in the embodiments of the present application.

[0085] It can be understood that in some other embodiments, the look-up table 30 can also be stored in other data forms, such as a graph, an array, etc., and the storage form of the look-up table 30 is not limited in the embodiments of the present application. ​​​​Conversion operations to other fixed-point items, and the fixed-point items as a computing item, not limited in the application.

[0086] The technical scheme of the embodiments of the present application is introduced below in combination with the neural network model 10 and the construction process of the aforementioned lookup table.

[0087] Figure 4 According to some embodiments of the present application, a flowchart of a neural network model running method is shown. The execution subject of the flowchart is an electronic device, such as a server, a terminal, a mobile phone, a tablet computer, a personal computer, a wearable device, etc. Figure 4 As shown in the figure, the flowchart includes the following steps:

[0088] S401: Detecting the LRN operator operation in the neural network model 10.

[0089] That is, in the process of running the neural network model 10, if the LRN operator operation is detected, the method provided in the embodiments of the present application is used to perform operation on the data to be normalized through the LRN operator.

[0090] For example, in the process of running the neural network model 10, after the input image is preprocessed through the input layer 11 to generate the image data matrix, and the image data matrix is convolved through the convolution layer 12, the output result H i of the convolution layer 12 is activated through the ReLU activation function to obtain the data matrix a i , after the data matrix a i , when the normalization layer 14 is run, the LRN operator operation can be detected, triggering the neural network model running method provided in the embodiments of the present application, the specific process of which will be described below, and will not be described here.

[0091] S402: According to the data to be normalized, determining the lookup table index value of the data to be normalized.

[0092] The electronic device determines the lookup table index of the data to be normalized according to the data to be normalized and the hyperparameters of the LRN operator.

[0093] For example, in some embodiments, the data to be normalized can be an element in the output matrix a i after the ReLU activation function. Wherein, The i in the element corresponds to the convolution result H i of the convolution kernel k i , and (x, y) represents the element located in the xth row and yth column in the matrix a i .

[0094] For example, assuming that the hyperparameter n of the LRN operator of the neural network model 10 is 2, if the element to be normalized is the element in the 9th column of the 1st row of the output matrix a of the ReLU activation function, i.e. 4 Referring to Figure 2 , , the value of the element in the 9th column of the 1st row of the output matrix a is 4, according to formula (1), the element in the 9th column of the 1st row of the output matrix a 3 The element in the 9th column of the 1st row of the output matrix a 5 The element in the 9th column of the 1st row of the output matrix a

[0095]

[0096] It can be understood that is only an example of the element to be normalized, and for other elements to be normalized, the electronic device can determine the corresponding lookup index value by using a similar method, which will not be described here.

[0097] S403: obtaining the lookup result of the lookup table item from the lookup table based on the lookup index value.

[0098] That is, the electronic device obtains the fixed-point number of the lookup value lut_out_q, the scaling coefficient qscale, and the shift number shift from the lookup table (for example, the aforementioned lookup table 30) based on the lookup index value, for example, the aforementioned index value lut_in_q. That is, the lookup result can include the fixed-point number of the lookup value lut_out_q, the scaling coefficient qscale, and the shift number shift

[0099] For example, for the case where the index value lut_in_q corresponding to the element to be normalized in step S402 is 25, the electronic device can obtain the corresponding lookup value lut_out_q, scaling coefficient qscale, and shift number shift from the lookup table according to the index value.

[0100] It can be understood that, in some embodiments, in order to save the length of the lookup table and reduce the storage space occupied by the lookup table, the number of bits of the lookup table (the value range of the index value) can be lower than the index value lut_in_q. In order to improve the accuracy of the lookup result, the lookup value lut_out_q corresponding to the index value lut_in_q can be obtained by interpolation lookup.

[0101] Specifically, Figure 5 According to some embodiments of the present application, a flowchart for determining the lookup value lut_out_q according to the index value lut_in_q is shown. The execution subject of the flowchart is an electronic device. As Figure 5 ​​​​As shown, the flow includes the following steps.

[0102] S403A: determining the value range of the lookup table index value of the to-be-normalized data determined in step S402 and the value range of the index value of the stored preset lookup table.

[0103] For example, in some embodiments, the value range of the lookup table index value can be determined according to the number of binary digits of the lookup table index value, and the value range of the index value of the lookup table can be determined according to the number of binary digits of the index value of the lookup table.

[0104] Specifically, it is assumed that the number of binary digits of the lookup table index value lut_in_q is n1, and the number of binary digits of the index value in the lookup table is n2. The electronic device can determine the number of binary digits of the index value in the stored lookup table, determine the number of binary digits n2 of the index value of the lookup table, for example, it is assumed that the binary digits of a certain index value are 00011001, which indicates that the number of binary digits of the index value of the lookup table is 8. In addition, after the electronic device determines the lookup table index value lut_in_q, it can determine the number n1 of binary digits of the lookup table index value lut_in_q, for example, when the index value lut_in_q = 0000011001, n1 = 10.

[0105] It can be understood that in other embodiments, the electronic device can use other ways to determine the value range of the lookup table index value and the value range of the index value of the lookup table, which are not limited in the present application.

[0106] S403B: determining whether the value range of the lookup table index value is greater than the value range of the index value of the lookup table. If yes, it indicates that the lookup table index value can not exist in the index value of the lookup table, and step S403C is entered for interpolation lookup table; otherwise, it indicates that the lookup table index value exists in the index value of the lookup table, and step S403D is entered.

[0107] For example, in some embodiments, the electronic device can determine whether the value range of the lookup table index value is greater than the value range of the index value of the lookup table by judging whether the number of binary digits of the lookup table index value is greater than the number of binary digits of the index value in the lookup table, that is, in the case where the number of binary digits of the lookup table index value is greater than the number of binary digits of the index value of the lookup table, it is determined that the value range of the lookup table index value is greater than the value range of the index value of the lookup table.

[0108] For example, if the number of binary bits n1 of the lookup table index value lut_in_q is 10 bits and the number of binary bits n2 of the index value in the lookup table is 8 bits, that is, n1 is greater than n2, the electronic device needs to perform interpolation lookup table. For another example, if the number of binary bits n1 of the lookup table index value lut_in_q is 10 bits and the number of binary bits n2 of the index value in the lookup table is 16 bits, that is, n1 is less than n2, the electronic device does not need to perform interpolation lookup table, but can directly find the corresponding lookup table value lut_out_q from the lookup table according to the lookup table index value lut_in_q.

[0109] It can be understood that the method for the electronic device to determine whether the number of binary bits n1 of the lookup table index value lut_in_q is greater than the number of binary bits n2 of the index value in the lookup table can be to directly compare the sizes of n1 and n2, or to determine the sizes of n1 and n2 by judging whether the difference between n1 and n2 is greater than 0, which is not limited in the present application.

[0110] S403C: Determine the interpolation bit number.

[0111] For example, in some embodiments, the interpolation bit number can be the difference between the number of binary bits n1 of the lookup table index value lut_in_q and the number of binary bits n2 of the index value in the lookup table, that is, the interpolation bit number is n3=n1-n2. For example, if the number of binary bits n1 of the lookup table index value lut_in_q is 10 bits and the number of binary bits n2 of the index value in the lookup table is 8 bits, the electronic device can determine that the interpolation bit number of the index value lut_in_q is 2 bits.

[0112] It can be understood that in another embodiment, the interpolation bit number n3 can also be the number of binary bits n2 of the index value in the lookup table, which is not limited in the present application.

[0113] S403D: Directly find the lookup table value corresponding to the lookup table index value from the lookup table according to the lookup table index value.

[0114] In the case that the value range of the lookup table index value lut_in_q is smaller than the value range of the index value in the lookup table, the electronic device can directly obtain the corresponding lookup table value lut_out_q from the lookup table according to the lookup table index value lut_in_q. For example, if the number of binary bits n1 of the lookup table index value lut_in_q is 8 bits and the number of binary bits n2 of the index value in the lookup table is 16 bits, that is, n1 is less than n2, the electronic device does not need to perform interpolation lookup table, but can directly find the corresponding lookup table value lut_out_q from the lookup table according to the lookup table index value lut_in_q.

[0115] S403E: Determine the lookup table value according to the interpolation bit number and the lookup table index value.

[0116] In the case that the number of binary bits of the table lookup index value n1 exceeds the number of binary bits of the index value in the lookup table n2, the electronic device can determine the first lookup table result lut_out_st1 corresponding to the reference index lut_in_st1 and the second lookup table result lut_out_st2 corresponding to the reference index plus one lut_in_st2 (i.e., lut_in_st2 = lut_in_st1 + 1) from the lookup table according to the table lookup index value lut_in_q, so that the electronic device can determine that the value of the table lookup value lut_out_q of the table lookup index value lut_in_q is between the first lookup table result lut_out_st1 and the second lookup table result lut_out_st2. Then, the electronic device can determine the correction value e according to the interpolation bit number n3, the difference between the table lookup index value and the reference index, the first lookup table result lut_out_st1 and the second lookup table result lut_out_st2. The table lookup value lut_out_q corresponding to the table lookup index value lut_in_q is the sum of the first lookup table result lut_out_st1 and the correction value e.

[0117] For example, Figure 6 According to some embodiments of the present application, a process diagram of interpolation lookup table is shown. The electronic device can obtain the reference index value 00 0000 11 by right shifting the table lookup index value 00 0000 1101 by 2 bits, so that the corresponding first lookup table result lut_out_st1 can be determined from the lookup table according to the reference index value 00 0000 11. Then, the electronic device can determine the corresponding second lookup table result lut_out_st2 from the lookup table according to the index value 00 0000 100 obtained by adding one to the reference index value lut_in_st1. According to the difference d between the table lookup index value and the reference index value and the interpolation bit number n3, the electronic device can calculate the correction value e corresponding to the value. The table lookup value lut_out_q is the sum of the first lookup table result lut_out_st1 and the correction value e.

[0118] Specifically, referring to Figure 6 , the electronic device first obtains 00000011 by right shifting the table lookup index value 00 0000 1101 by 2 bits, and then obtains 00 0000 1100 by left shifting 0000 0011 by 2 bits, so that the difference d between 00 0000 1101 and 00 0000 1100 is 00 0000 0001. According to the difference d and 2 n3, which is the ratio of the correction value e and the difference between the second lookup table result and the first lookup table result, so that the ratio is multiplied by the difference between the second lookup table result and the first lookup table result to obtain the correction value e. In order to quickly calculate and avoid the division process of the ratio from occupying the computing resources of the electronic device, the ratio can be determined by shifting, and the correction value e is determined based on the ratio.

[0119] In some embodiments, the difference between the lookup table index value and the reference index value can be determined by the following formula (15).

[0120] d = lut_in_q - (lut_in_q » n3 « n3) (15)

[0121] In formula (15), “<<” represents left shift operation, and “>>” represents right shift operation. Then the correction value e can be determined by the following formula (16).

[0122] e = (lut_out_st2 - lut_out_st1) x d » n3 (16)

[0123] In formula (16), “>>” represents right shift operation.

[0124] Wherein, e represents the correction value, lut_out_st2 is the second lookup table result determined from the lookup table by the index value obtained by adding one to the reference index value, lut_out_st1 is the first lookup table result determined from the lookup table by the reference index value, d is the difference between the lookup table index value and the reference index value, and n3 is the interpolation bit number.

[0125] After the correction value e is determined, the electronic device can add the first lookup table result lut_out_st1 and the correction value e to obtain the lookup table value lut_out_q of the lookup table index value lut_in_q, that is, after the first lookup table result lut_out_st1 and the correction value e are determined, the lookup table value lut_out_q can be determined by the following formula (17).

[0126] lut_out_q = lut_out_st1 + e (17)

[0127] S404: Determine the normalization result of the to-be-normalized data based on the to-be-normalized data and the lookup table result.

[0128] That is, the electronic device obtains the normalization result of the to-be-normalized data based on the lookup table value lut_out_q obtained by the lookup table, the scaling coefficient qscale, the shift number shift, and the fixed-point to-be-normalized data and the aforementioned formula (13).

[0129] For example, the element to be normalized is In this case, the electronic device obtains the corresponding lookup value lut_out_q, scaling factor qscale, and shift value from the lookup table based on the lookup index value lut_in_q obtained in step S402, and can then calculate the element to be normalized based on formula (13). The normalization result is obtained. According to formula (13), the element to be normalized can be calculated. The normalization result: retrieve lut_out_q = 0110 1111 from the lookup table, and then calculate... Shift left by -7 bits (i.e., right by 7 bits) to get

[0130] It is understandable that other elements to be normalized can obtain corresponding normalization results through similar methods, which will not be elaborated in this application.

[0131] It is understandable that after the electronic device normalizes the nine data matrices of the activation layer 13 through the normalization layer 14, the normalization result can be transmitted to the fully connected layer 15 to determine the probability that the input image data is divided into each preset image category, and the preset image category with the highest probability is determined as the type of input image data. For example, after the electronic device determines that the probability of the input image being a landscape is 1 / 5, the probability of the input image being a person is 1 / 5, and the probability of the input image being an animal is 3 / 5, it can compare the probability of the input image being different types, thereby determining the animal type with the highest probability as the output result.

[0132] Using the method provided in the embodiments of this application, the electronic device adjusts the data to be normalized. (j is an integer in [max(0, in / 2), min(N, i+n / 2)]) Determine the index value lut_in_q, and obtain the lookup value lut_out_q and the shift value shift from the lookup table based on the index value lut_in_q. Multiplying by the scaling factor qscale and shifting left by shift bits yields the result obtained using the LRN operator. Normalizing fixed-point numbers eliminates the need for complex nonlinear operations such as division and exponentiation, reducing the hardware resource consumption of electronic devices and thus improving the running speed of neural network models.

[0133] The following is combined Figure 1 Neural network model 10 and Figure 2 The calculation process of convolutional layer 12 and activation layer 13 is described in detail, outlining the steps taken by the electronic device to determine the data to be normalized.

[0134] Before introducing the calculation process of the neural network model 10, the calculation process of convolution is introduced. Assuming that the size of the matrix A is M x M, the size of the convolution kernel K is N x N, and the convolution step is k, the convolution result H of the matrix A and the convolution kernel K can be expressed as:

[0135]

[0136] In the formula (18), H(m, n) is the element of the mth row and the nth column of the matrix H; m, n satisfy the following relationship:

[0137]

[0138] Wherein is the floor operation, that is is the largest integer less than X. Since M-N < M and k is a positive integer, it can be seen that That is to say, the size of the convolution result H is always less than or equal to the size of the matrix A.

[0139] In order to ensure that the size of the matrix corresponding to the convolution result is the same as the size of the input data, and avoid losing the data characteristics of the edge of the picture data matrix, it is common to fill the rows with values of 0 before the first row and after the last row of the input matrix, and fill the rows or columns with values of 0 before the first column and after the last column of the input matrix, that is, fill the rows or columns with values of 0 around the input matrix. Assuming that the number of rows or columns filled with values of 0 around the input matrix A is P, at this time, the size of the input matrix A becomes (M+2P) x (M+2P). At this time, m, n in formula (1) satisfy the following relationship:

[0140]

[0141] Let The value of P can be calculated.

[0142] Assuming that the image data matrix A is a 9 x 9 matrix (that is, M is 9), the matrix A and the convolution kernel Ki (i is from 1 to 9) are respectively convolved to obtain 9 feature images H1 to H9.

[0143] Assuming that the image data matrix A is:

[0144]

[0145] The convolution kernel K3 is:

[0146]

[0147] It can be understood that under the assumption that the size of the feature matrix H is the same as the size of the initial image data matrix A, the value of P is 1 can be calculated under the condition that the size of the convolution kernel K3 is 3 x 3 (that is, N is 3).

[0148] Thus, the result H3 of the convolution of the matrix A and the convolution kernel K3 with a sliding step of 1 can be represented as:

[0149]

[0150]

[0151] Similarly, the feature matrix H4 after the convolution of the matrix A and the convolution kernel K4 can be represented as:

[0152]

[0153] The feature matrix H5 after the convolution of the matrix A and the convolution kernel K4 can be represented as:

[0154]

[0155] It can be understood that the convolution calculation process of the image data matrix A and other convolution kernels is similar, which is not described herein.

[0156] It can be understood that the image data matrix A in the above embodiments is only exemplary.

[0157] After completing the convolution calculation of the convolution layer 12, the electronic device continues to run the activation layer 13 in the neural network model 10 to activate the feature matrix H1 to the feature matrix H9, for example, by ReLU operator to activate the feature matrix H1 to the feature matrix H9 to improve the operation speed of the subsequent layer. Taking the activation of the foregoing feature matrix H3, the feature matrix H4 and the feature matrix H5 by the ReLU operator as an example, the ReLU operator sets the elements less than 0 in the feature matrix to 0, that is, the H3, H4 and H5 after the ReLU activation become as follows: 3 4 5

[0158]

[0159] It can be understood that the activation process of the activation layer 13 to other matrices is similar, which is not described herein.

[0160] After running the activation layer 13 of the neural network model 10, the electronic device continues to run the normalization layer 14, and detects the LRN operator when running the normalization layer 14, so that the electronic device normalizes the output data of the activation layer 13 as the normalization data. That is, the above activated matrix a 1 to the matrix a 9 are normalization data. The electronic device can normalize the normalization data according to the normalization formula: Figure 4 ​​​The method shown normalizes the to-be-normalized data to obtain normalized data, and then obtains, by the full connection layer 15 based on the normalized data, probabilities that the input image corresponding to the image data matrix A belongs to each preset image category, and determines the preset image category with the largest probability as the category of the input image. For example, after the electronic device determines, by the full connection layer 15, that the probability that the input image is of the landscape type is 1 / 5, the probability that the input image is of the person type is 1 / 5, and the probability that the input image is of the animal type is 3 / 5, the electronic device can determine the animal as the category of the input image.

[0161] It can be understood that the running method of the neural network model provided in the embodiments of the present application can be applied to any electronic device capable of running the neural network model, including but not limited to a mobile phone, a wearable device (such as a smart watch), a tablet computer, a desktop computer, a laptop computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) / virtual reality (VR) device, and the like, and the embodiments of the present application are not limited thereto. In order to facilitate understanding of the technical solutions of the embodiments of the present application, the structure of the electronic device 100 to which the running method of the neural network model provided in the embodiments of the present application is applicable is described by taking the electronic device 100 as an example.

[0162] Further, Figure 7 According to some embodiments of the present application, a structural schematic diagram of an electronic device 100 is shown. As shown in the figure, Figure 7 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 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:

[0163] The processor 101 can include one or more processing units, e.g., can include a processing module or processing circuitry of a central processing unit (CPU), a graphics processing unit (GPU), a digital signal processor (DSP), a micro-programmed control unit (MCU), an artificial intelligence (AI) processor, or a programmable logic device (FPGA), a neural-network processing unit (NPU), etc. The processing circuitry can include one or more single-core or multi-core processors. In some embodiments, the NPU can be used to run instructions corresponding to the running method of the neural network model provided by the embodiments of the present application.

[0164] The system memory 102 is a volatile memory, e.g., 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, e.g., in some embodiments, the system memory 102 can be used to store the above lookup table 30.

[0165] The non-volatile memory 103 can include one or more tangible, non-transitory computer-readable media for storing data and / or instructions. In some embodiments, the non-volatile memory 103 can include any suitable non-volatile memory and / or any suitable non-volatile storage device, e.g., a flash memory, 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 can also be a removable storage medium, e.g., a secure digital (SD) memory card, etc. In other embodiments, the non-volatile memory 103 can be used to store the above lookup table 30.

[0166] In particular, system memory 102 and non-volatile memory 103 can include, respectively, a temporary copy and a permanent copy of instructions 107. Instructions 107 can include instructions that, when executed by at least one of processors 101, cause electronic device 100 to implement a method of running a neural network model according to embodiments of the present application.

[0167] Communication interface 104 can include a transceiver to provide electronic device 100 with a wired or wireless communication interface to communicate with any other suitable device over one or more networks. In some embodiments, communication interface 104 can be integrated with other components of electronic device 100, e.g., communication interface 104 can be integrated with processors 101. In some embodiments, electronic device 100 can communicate with other devices through communication interface 104, e.g., electronic device 100 can obtain a neural network model and a lookup table 30 corresponding to the neural network model from other electronic devices through communication interface 104.

[0168] Input / output (I / O) device 105 can include input devices such as a keyboard, a mouse, etc., and output devices such as a display, etc., through which a user can interact with electronic device 100.

[0169] System control logic 106 can include any suitable interface controllers to provide any suitable interfaces to other modules of electronic device 100. For example, in some embodiments, system control logic 106 can include one or more memory controllers to provide an interface to connect to system memory 102 and non-volatile memory 103.

[0170] In some embodiments, at least one of processors 101 can be packaged together with logic for one or more controllers of system control logic 106 to form a system in package (SiP). In other embodiments, at least one of processors 101 can also be integrated on the same chip with logic for one or more controllers of system control logic 106 to form a system-on-chip (SoC).

[0171] It can be appreciated that, Figure 7 The structure of electronic device 100 shown is only an example, and in other embodiments, electronic device 100 can include more or fewer components than shown, or combine some components, or split some components, or different arrangement of components. The components shown can be implemented in hardware, software, or a combination of software and hardware.

[0172] Embodiments of the mechanisms disclosed herein can be implemented in hardware, software, firmware, or any combination thereof. Embodiments of the application can be implemented as computer programs or program code executing on programmable systems comprising 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.

[0173] Program code can be applied to input instructions to perform the functions described herein and generate output information. The output information can be applied to one or more output devices, in known fashion. For purposes of this application, a processing system includes any system that has a processor, such as, for example; a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.

[0174] The program code can be implemented in a high level procedural or object oriented programming language to communicate with a processing system. The program code can be implemented in assembly or machine language, if desired. In fact, the mechanisms described herein are not limited in scope to any particular programming language. In any case, the language can be a compiled or interpreted language.

[0175] In some cases, the disclosed embodiments can be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments can also be implemented as instructions carried by or stored on a transitory or non-transitory machine-readable (e.g., computer-readable) medium, which can be read and executed by one or more processors. For example, the instructions can be distributed over the network or by other computer readable media. Thus, a machine-readable medium can include any mechanism for storing or transmitting information in a form readable by a machine (e.g., a computer), including without limitation, floppy diskettes, optical disks, optical fiber, Read Only Memory (ROM), Random Access Memory (RAM), Erasable Programmable Read Only Memory (EPROM), Electrically Erasable Programmable Read Only Memory (EEPROM), magnetic or optical cards, flash memory, or any other suitable device. Accordingly, a machine-readable medium includes any medium that is capable of storing or transmitting electronic instructions or information that can be used to program a computer to perform any of the methods described above.

[0176] In the drawings, some of the structural or methodological features can be shown in particular arrangements and / or orders. However, it should be understood that such particular arrangements and / or orders can not be required. Instead, these features can be arranged in a different manner and / or order than shown in the illustrative figures, in some embodiments. Additionally, inclusion of a structural or methodological feature in a particular figure is not meant to imply that such feature is required in all embodiments, and in some embodiments, these features can not be included or can be combined with other features.

[0177] It should be noted that each unit / module mentioned in the embodiments of the present application is a logical unit / module, in physical, one logical unit / module can be one physical unit / module, or a part of a physical unit / module, or be realized in a combination of multiple physical unit / modules, and the physical realization of the logical unit / module itself is not the most important, the combination of the functions realized by the logical unit / module is the key to solve the technical problems proposed in the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned each device embodiment of the present application does not introduce the unit / module which is not closely related to solving the technical problems proposed in the present application, which does not mean that the above-mentioned device embodiment does not have other units / modules.

[0178] It has to be understood that in the examples and in the description of the patent, the terms "comprises", "comprising", "includes" or any other variant thereof are intended to cover non-exclusive inclusions, such that processes, methods, articles, or apparatuses that comprise a list of elements are not limited to those elements, but can include other elements not expressly listed or inherent to such processes, methods, articles, or apparatuses. Without further limitation, an element preceded by "comprises a" does not, without more constraints, foreclose the existence of additional identical elements in the process, method, article, or apparatus that comprises the recited element.

[0179] While the application has been illustrated and described in relation to certain preferred embodiments thereof, it will be appreciated that various changes in form and detail can be made therein without departing from the spirit and scope of the application.

Claims

1. A method for operating a neural network model, applied to electronic devices, characterized in that, The method is applied to image classification, and an index table is stored in the electronic device, the index table comprising a corresponding relationship between an index value and a table lookup result, and the method comprises the following steps: In the process of running the neural network model, a first operation is detected, and the first operation comprises a first operation part, wherein the first operation is an operation of normalizing first input data in a to-be-normalized data set by using an LRN operator, the to-be-normalized data set comprises N data matrices, N≥1, and the first operation is defined by the following formula: wherein, is the first input data, representing data in the xth row and yth column in the ith data matrix in the data set to be normalized, 1≤i≤N; is the operation result of the first operation, representing the normalized result of the first input data ; k, a, b, n are hyperparameters; the first operation part comprises From the first data matrix, the first input data of the first operation is obtained; A first table lookup parameter of the first input data is generated; The first table lookup parameter is determined according to the following formula: wherein, represents the fixed-point number corresponding to the data in the xth row and yth column in the jth data matrix in the data set to be normalized, max(0, i-n / 2)≤j≤min(N, i+n / 2); A first index value corresponding to the first table lookup parameter in the index value of the index table is determined, and a floating-point number corresponding to the first index value is the same as the floating-point number value corresponding to the first table lookup parameter; A first table lookup result corresponding to the first index value in the table lookup result of the index table is obtained, wherein the first table lookup parameter and the first index value are fixed-point numbers, and the first table lookup result is a fixed-point number result calculated by taking the first index value as input data of the first operation part in advance; The operation result of the first operation part is determined based on the first table lookup result.

2. The method of claim 1, wherein, The generation of the first table lookup parameter of the first input data comprises: At least one second input data corresponding to the first input data is obtained from at least one second data matrix, and the operation result of a first sub-operation comprising the first input data and the second input data in the first operation part is taken as the first table lookup parameter of the first input data, wherein the first sub-operation only comprises a linear operation factor, and the row and column of the second input data in the second data matrix are the same as the row and column of the first input data in the first data matrix.

3. The method of claim 1, wherein, The quantization bit number of the first table lookup parameter is M, and the quantization bit number of the index value in the index table is N; and The determination of the first index value corresponding to the first table lookup parameter in the index value of the index table comprises: In the case that M is less than or equal to N, the first index value is an index value equal to the first table lookup parameter in the index table; In the case that M is greater than N, the first index value is an index value equal to the high N bits of the binary number corresponding to the first table lookup parameter in the index table.

4. The method of claim 3, wherein, The determination of the first index value corresponding to the first table lookup parameter in the index value of the index table comprises: In the case that M is less than or equal to N, the first table lookup result is taken as the operation result of the first operation part.

5. The method of claim 3, wherein, The determination of the first index value corresponding to the first table lookup parameter in the index value of the index table comprises: In the case that M is greater than N, a second index value obtained by adding 1 to the first index value is used to obtain a second table lookup result corresponding to the second index value from the index table; determining a difference between the second table lookup result and the first table lookup result, and multiplying the difference by a difference between the first table lookup parameter and the first index value and then right shifting the result by M-N bits to obtain a correction value; adding the correction value and the first table lookup result to obtain a result of the first operation.

6. The method according to any one of claims 1 to 5, characterized in that, The first operation further includes a second operation part; and the method further includes: determining a fixed-point number operation result of the first operation based on a linear operation of a result of the first operation part and a result of the second operation part.

7. The method of claim 6, wherein, The second operation section includes 8. The method of claim 7, wherein, The determining a fixed-point number operation result of the first operation based on a linear operation of a result of the first operation part and a result of the second operation part includes: obtaining a pre-stored scaling coefficient and a shift number from the index table; multiplying the result of the first operation part and a fixed-point number corresponding to the first input data, then multiplying the result by the scaling coefficient, and left shifting the product by the shift number to obtain the fixed-point number operation result of the first operation.

9. A readable medium characterized by The readable medium contains instructions, which, when executed by a processor of an electronic device, cause the electronic device to implement the running method of the neural network model of any one of claims 1 to 8.

10. An electronic device, comprising: comprise: a memory configured to store instructions for execution by one or more processors of an electronic device; and a processor, which is one of the processors of the electronic device, configured to execute the instructions to cause the electronic device to implement the running method of the neural network model of any one of claims 1 to 8.

Citation Information

Patent Citations

  • FPGA circuit and method for realizing softmax function calculation

    CN109308520A

  • A method of operating a hardware accelerator, a hardware accelerator and a neutral network device

    CN113407747A