Data processing methods and related products

By fixed-point processing of the operation parameters and quantization processing of the neural network model, the problem of high consumption of floating-point computing resources in the low-bit quantization model is solved, achieving resource saving and ensuring prediction accuracy.

CN113222097BActive Publication Date: 2024-09-17SHANGHAI SENSETIME INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010068857.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-01-21
Publication Date
2024-09-17
Estimated Expiration
2040-01-21

AI Technical Summary

Technical Problem

When performing prediction processing tasks, the low-bit quantized neural network model needs to perform a large number of floating point operations, resulting in a large overhead in computing resources and storage resources.

Method used

By obtaining the operating parameters of the neural network model for fixed-point processing, eliminating or reducing floating-point number operations, quantitative processing and clustering technology are used to determine the quantified parameters, and the entire process is fixed-point.

Benefits of technology

Reduce or even eliminate floating-point number operations during the prediction processing of the neural network model, reducing the cost of computing resources and storage resources while ensuring prediction accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113222097B
    Figure CN113222097B
Patent Text Reader

Abstract

The embodiment of the present application discloses the field of artificial intelligence, and in particular, relates to a data processing method and related products in the field of neural network technology, the method comprising: obtaining a first operation parameter required for performing a first operation processing using a neural network model; the first operation processing is obtained based on a network model processing and a first quantization processing performed on at least one network layer including the Lth layer of the neural network model; the first operation parameter is fixed-point processed to obtain a second operation parameter; based on the second operation parameter, the first operation processing is performed on the input data of the at least one network layer to obtain a processing result of the at least one network layer; the data processing device adopts fixed-point numbers to implement the entire process of performing a prediction processing task using a neural network model, which can reduce the overhead of computing resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of neural network technology, and in particular to a data processing method and related products. Background Art

[0002] With the development of neural network technology, neural network quantization technology has emerged, which mainly compresses the weights and activation values ​​(i.e., the output feature maps or input feature maps of each layer) in the neural network (such as convolutional layers and fully connected layers), reduces the bit width of weights, the bit width of activation values, etc., thereby achieving the purpose of compressing the data volume of the neural network model and reducing the computing resource requirements of the neural network model during the prediction process.

[0003] Low-bit quantization is one of the hot areas of current model optimization research. However, in the process of using low-bit quantized neural network models to perform prediction processing tasks, more floating-point operations are usually required, and the computing and storage resources are expensive. Therefore, it is necessary to study new data processing methods to reduce resource overhead. Summary of the invention

[0004] The embodiments of the present application disclose a data processing method and related products.

[0005] In a first aspect, an embodiment of the present application provides a data processing method, the method comprising: obtaining a first operation parameter required to perform a first operation processing using a neural network model; the first operation processing is obtained based on a network model processing and a first quantization processing performed on at least one network layer including the Lth layer of the neural network model, the first operation parameter includes a quantization parameter of the first quantization processing, and L is an integer greater than 0; the first operation parameter is fixed-point processed to obtain a second operation parameter; based on the second operation parameter, the first operation processing is performed on the input data of the at least one network layer to obtain the processing result of the at least one network layer. Optionally, the input data of the at least one network layer is an image to be predicted, or is obtained by processing the image to be predicted by at least one second network layer located before the at least one network layer in the neural network model.

[0006] The quantization processing performed by the Lth layer may be the quantization processing performed by the Lth layer on the activation data output by it. Optionally, the first operation processing is obtained by merging the operation processing performed by the Lth layer and the quantization processing performed by the Lth layer. The second operation parameter does not include floating-point numbers. The Lth layer may be any network layer except the last layer in the neural network model. It should be understood that the data processing device may use a similar method to perform the operation processing and quantization processing performed by each layer in the neural network model. In some embodiments, the data processing device does not need to perform floating-point operations in the entire process of using the neural network model to perform the prediction processing task, that is, the entire process can be fixed-point.

[0007] In an embodiment of the present application, the data processing device can reduce floating-point operations when executing prediction processing tasks using a neural network model, and the overhead of computing resources and storage resources is relatively low.

[0008] In an optional implementation, converting the first operation parameter into a fixed-point number to obtain the second operation parameter includes: expanding each floating-point number included in the first operation parameter by K times to obtain an expanded value, where K is an integer greater than 1; and converting the expanded value into a fixed-point number to obtain the second operation parameter.

[0009] Optionally, the first operation process is a linear operation process, and the calculation formula corresponding to the first operation process is a fraction, and both the numerator and the denominator of the fraction contain floating-point numbers. It can be understood that each floating-point number in the calculation formula corresponding to the first operation process is enlarged K times, and the value calculated by the calculation formula remains unchanged. Because each floating-point number in the first operation parameter is enlarged K times before being converted into a fixed-point number, the accuracy of the first operation process can be guaranteed.

[0010] In this implementation, the floating-point number in the first operation parameter is first expanded by K times, and then the floating-point number expanded by K times is converted into a fixed-point number to ensure the accuracy of the first operation processing.

[0011] In an optional implementation, the first operation processing is obtained by merging the network model processing and the first quantization processing performed by at least two adjacent network layers including the Lth layer.

[0012] In an optional implementation, the quantization parameter is a parameter determined based on a quantization maximum value and a quantization minimum value; the quantization maximum value and the quantization minimum value are obtained by clustering a plurality of numerical values ​​included in the data to be quantized in the Lth layer.

[0013] In this implementation, the distribution of the data to be quantized can be more accurately expressed with a limited quantization order, thereby improving the quantization accuracy.

[0014] In an optional implementation, before obtaining the first operation parameters required to perform the first operation processing using the neural network model, the method also includes: clustering the multiple numerical values ​​included in the data to be quantized in the Lth layer to obtain a clustering result; based on the clustering result, obtaining the quantization maximum value and the quantization minimum value; based on the quantization maximum value and the quantization minimum value, determining the quantization parameter, wherein the quantization parameter is used to quantize the numerical value in the activation data into an integer represented by M bits.

[0015] In this implementation, a maximum quantization value and a minimum quantization value are obtained based on the clustering result, and then a quantization parameter is determined; the quantization parameter can be determined quickly and accurately.

[0016] In an optional implementation, obtaining a quantization maximum value and a quantization minimum value based on the clustering result includes: taking the maximum value of at least two cluster centers included in the clustering result as the quantization maximum value, and taking the minimum value of the at least two cluster centers as the quantization minimum value.

[0017] In this implementation, the quantization maximum value and the quantization minimum value can be accurately and quickly obtained according to the at least two cluster centers included in the clustering result.

[0018] In an optional implementation, the quantization parameter is determined based on the quantization maximum value and the quantization minimum value, including: taking the quantization minimum value as the first item and the quantization maximum value as the last item, to obtain a first arithmetic progression including N numerical values, wherein N is an integer greater than 1; and taking the common factor of the N numerical values ​​contained in the first arithmetic progression as the quantization parameter.

[0019] In this implementation, the common factors of the numerical values ​​contained in the first arithmetic progression are used as quantization parameters, so that the activation data of the Lth layer can be quantized into integers using the quantization parameters.

[0020] In an optional implementation, the method further includes: determining the number of bits M corresponding to the first quantization process based on the distribution discreteness of multiple numerical values ​​included in the data to be quantized.

[0021] In this implementation, the number of bits M corresponding to the quantization process performed at the Lth layer is determined based on the distribution discreteness of multiple values ​​included in the data to be quantized; the number of bits occupied by the quantized data is reduced, thereby saving computing resources.

[0022] In an optional implementation, before obtaining the first operation parameters required to perform the first operation processing using the neural network model, the method also includes: determining a first reference value based on weight data of at least one network layer of the neural network model; determining multiple numerical intervals based on the first reference value, each of the multiple numerical intervals corresponding to an integer that can be represented by F bits, where F is an integer greater than 1 and less than 8; based on the multiple numerical intervals, performing a second quantization process on the numerical value in the weight data to obtain an integer represented by F bits.

[0023] In an optional implementation, before determining multiple numerical intervals based on the first reference value, the method also includes: determining the number of bits F for the second quantization processing based on the distribution discreteness of multiple numerical values ​​included in the weight data; determining multiple numerical intervals based on the first reference value includes: determining the multiple numerical intervals based on the first reference value and the number of bits F.

[0024] In this implementation, the number of bits F for quantization processing is determined based on the distribution discreteness of multiple values ​​included in the weight data; the number of bits occupied by the quantized weight data is reduced, thereby saving computing resources.

[0025] In the second aspect, an embodiment of the present application provides a data processing device, including: an acquisition unit, used to acquire a first operation parameter required to perform a first operation processing using a neural network model; the first operation processing is obtained based on the network model processing and the first quantization processing performed on at least one network layer including the Lth layer of the neural network model, and the first operation parameter includes the quantization parameter of the first quantization processing, and L is an integer greater than 0; a conversion unit, used to perform fixed-point processing on the first operation parameter to obtain a second operation parameter; a processing unit, used to perform the first operation processing on the input data of the at least one network layer based on the second operation parameter to obtain the processing result of the at least one network layer. Optionally, the input data of the at least one network layer is the image to be predicted, or is obtained by processing the image to be predicted by at least one second network layer located before the at least one network layer in the neural network model.

[0026] In an optional implementation, the conversion unit is specifically used to expand each floating-point number included in the first operation parameter by K times to obtain an expanded value, where K is an integer greater than 1; and convert the expanded value into a fixed-point number to obtain the second operation parameter.

[0027] In an optional implementation, the first operation processing is obtained by merging the network model processing and the first quantization processing performed by at least two adjacent network layers including the Lth layer.

[0028] In an optional implementation, the quantization parameter is a parameter determined based on a quantization maximum value and a quantization minimum value; the quantization maximum value and the quantization minimum value are obtained by clustering multiple numerical values ​​included in the data to be quantized output by the Lth layer of the neural network model.

[0029] In an optional implementation, the device also includes: a clustering unit, used to cluster the multiple numerical values ​​included in the data to be quantized in the Lth layer to obtain a clustering result; a first determination unit, used to obtain the quantization maximum value and the quantization minimum value based on the clustering result; the first determination unit is also used to determine the quantization parameter based on the quantization maximum value and the quantization minimum value, wherein the quantization parameter is used to quantize the numerical value in the activation data into an integer represented by M bits.

[0030] In an optional implementation, the first determining unit is specifically configured to use the maximum value of at least two cluster centers included in the clustering result as the quantized maximum value, and use the minimum value of the at least two cluster centers as the quantized minimum value.

[0031] In an optional implementation, the first determination unit is specifically used to obtain a first arithmetic progression including N numerical values ​​with the minimum quantization value as the first item and the maximum quantization value as the last item, where N is an integer greater than 1; and use the common factor of the N numerical values ​​contained in the first arithmetic progression as the quantization parameter.

[0032] In an optional implementation, the first determination unit is further configured to determine the number of bits M corresponding to the first quantization process based on a distribution discreteness of a plurality of numerical values ​​included in the data to be quantized.

[0033] In an optional implementation, the device also includes: a second determination unit, which is also used to determine a first reference value based on the weight data of at least one network layer of the neural network model; based on the first reference value, determine multiple numerical intervals, each of the multiple numerical intervals corresponds to an integer that can be represented by F bits, and F is an integer greater than 1 and less than 8; a quantization unit, which is used to perform a second quantization process on the numerical value in the weight data based on the multiple numerical intervals to obtain an integer represented by F bits.

[0034] In an optional implementation, the second determination unit is further used to determine the number of bits F of the second quantization processing based on the distribution discreteness of multiple numerical values ​​included in the weight data; the second determination unit is specifically used to determine the multiple numerical intervals based on the first reference value and the number of bits F.

[0035] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a memory for storing programs; a processor for executing the programs stored in the memory, and when the program is executed, the processor is used to execute the method as described in the first aspect and any optional implementation method.

[0036] In a fourth aspect, an embodiment of the present application provides a chip, which includes a processor and a data interface. The processor reads instructions stored in a memory through the data interface to execute the method of the first aspect and any optional implementation method described above.

[0037] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and the computer program includes program instructions, which, when executed by a processor, enable the processor to execute the method of the above-mentioned first aspect and any optional implementation method.

[0038] In a sixth aspect, an embodiment of the present application provides a computer program product, which includes program instructions, and when the program instructions are executed by a processor, the processor executes the method of the above-mentioned first aspect and any optional implementation method. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the background technology, the drawings required for use in the embodiments of the present application or the background technology will be described below.

[0040] Figure 1 A flow chart of a data processing method provided in an embodiment of the present application;

[0041] Figure 2 A flow chart of another data processing method provided in an embodiment of the present application;

[0042] Figure 3 A flow chart of another data processing method provided in an embodiment of the present application;

[0043] Figure 4 A flow chart of another data processing method provided in an embodiment of the present application;

[0044] Figure 5 A flow chart of another data processing method provided in an embodiment of the present application;

[0045] Figure 6 A flow chart of another data processing method provided in an embodiment of the present application;

[0046] Fig. 7A A schematic diagram of quantified activation data provided in an embodiment of the present application;

[0047] Figure 7B A schematic diagram of activation data quantization reverse provided in an embodiment of the present application;

[0048] Figure 8 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application;

[0049] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0050] Fig.10 A schematic diagram of the structure of a server provided in an embodiment of the present application. DETAILED DESCRIPTION

[0051] The terms "first", "second", and "third" etc. in the specification embodiments and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, including a series of steps or units. Methods, systems, products or equipment are not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment. "And / or" is used to represent the selection of one or all between the two objects connected thereto. For example, "A and / or B" means A, B or A+B.

[0052] In the process of performing prediction processing tasks using a low-bit quantized neural network model, it is usually necessary to perform more floating-point operations, and the overhead of computing resources and storage resources is large. The embodiment of the present application provides a data processing method that can reduce or even eliminate floating-point operations, and has high prediction accuracy. The data processing method provided in the embodiment of the present application can be applied to image text recognition scenarios, video text recognition scenarios, target detection scenarios, etc. The following is a brief introduction to the application of the data processing method provided in the embodiment of the present application in image text recognition scenarios, video text recognition scenarios, and target detection scenarios.

[0053] Image text recognition 1: The terminal device captures an image including one or more characters, performs text recognition on the image, and displays the recognized characters. For example, a user uses a mobile phone to take an image of a sign, and the mobile phone performs text recognition on the image and displays the text on the sign. For another example, a user uses a mobile phone to take an image including a paragraph of English, and the mobile phone performs text recognition on the image and displays the Chinese translation of the English paragraph.

[0054] Image text recognition 2: The terminal device sends the captured image to the server; the server performs text recognition on the image and sends the text recognition result to the terminal device; the terminal device receives and displays the text recognition result. For example, the monitoring equipment on the road captures an image including the license plate number of the vehicle and sends it to the server, which recognizes the license plate number in the image. For another example, a user uses a mobile phone to take an image of a sign and sends the image to the server; the server performs text recognition on the image to obtain a text recognition result, and sends the text recognition result to the terminal device; the terminal device displays the text recognition result.

[0055] Video text recognition 1: The terminal device captures a video and performs text recognition on each frame of the video. For example, a user uses a mobile phone to shoot a video, and multiple frames of the video include at least one character; the mobile phone performs text recognition on each frame of the video, obtains the text recognition result and displays it.

[0056] Video text recognition 2: The terminal device captures a video and sends it to the server; the server performs text recognition on each frame of the video to obtain a text recognition result. For example, a monitoring device on the road captures a video, and at least one frame of the video includes a license plate number; the monitoring device sends the video to the server; the server performs text recognition on each frame of the video to obtain at least one license plate number.

[0057] Target detection scenario: The data processing device extracts the area where the target object is located from the image to be processed. For example, the autonomous driving device extracts the area where pedestrians are located from the collected image.

[0058] In the above scenario, the data processing device can reduce floating-point operations when executing the prediction processing task, thereby saving computing resources and ensuring prediction accuracy.

[0059] See also Figure 1 , Figure 1 A flow chart of a data processing method provided in an embodiment of the present application. Figure 1 As shown, the method may include:

[0060] 101. A data processing device obtains first operation parameters required to perform a first operation process using a neural network model.

[0061] The first operation processing is obtained based on the network model processing and the first quantization processing performed by at least one network layer including the Lth layer of the neural network model, the first operation parameter includes the quantization parameter of the first quantization processing, and the L is an integer greater than 0. The network model processing may include at least one of convolution processing, pooling processing, batch normalization processing, etc., which is not limited in this application. The data processing device may be a terminal device such as a mobile phone, a tablet computer, a wearable device, a laptop computer, a desktop computer, or a server. The first quantization processing may be a quantization processing performed by the data processing device on the activation data obtained by the network model processing performed by at least one network layer including the Lth layer of the neural network model. The activation value (i.e., activation data) of a network layer in the neural network model may refer to the output data (i.e., output feature map) of the network layer, and the quantized output data may be used as the input data (i.e., input feature map) of the next network layer. Optionally, the first operation processing is obtained by merging the network model processing and the first quantization processing performed by the Lth layer. Optionally, the first operation processing is obtained by merging the network model processing and the first quantization processing performed by at least two adjacent network layers including the Lth layer. Optionally, the second operation parameter does not include floating point numbers. The Lth layer can be any network layer except the last layer in the neural network model. It should be understood that the data processing device can perform the network model processing and quantization processing performed by each layer in the neural network model in a similar manner. In some embodiments, the data processing device does not need to perform floating point operations in the entire process of performing the prediction processing task using the neural network model, that is, the entire process can be fixed-point.

[0062] The neural network model can be a deep neural network model, such as any one of a convolutional neural network, a recurrent neural network, a long short-term memory network (Long Short-Term Memory, LSTM), etc., which is not limited in this application. In some embodiments, the neural network model is obtained through training. For example, the neural network model is a prediction model obtained by training using training data. The weights in the neural network model can be unquantized weights, or at least a portion of the weights in the neural network model are quantized. For example, the weights in the neural network model are all quantized into integers represented by less than 8 bits. In some embodiments, the data processing device can obtain the trained neural network model; quantize the weights in the neural network model to obtain a quantized neural network model; and execute based on the quantized neural network model. Figure 1 The method flow in .

[0063] 102. Perform fixed-point processing on the first operation parameter to obtain a second operation parameter.

[0064] Optionally, the first operation parameter is fixed-point processed to obtain an implementation method of the second operation parameter as follows: each floating-point number included in the first operation parameter is enlarged by K times to obtain an enlarged value, where K is an integer greater than 1; the enlarged value is converted into a fixed-point number to obtain the second operation parameter. Optionally, the enlarged value is converted into a fixed-point number to obtain the second operation parameter by rounding the enlarged value into an integer. For example, x is a floating-point number in the first operation parameter, and x is enlarged by K times to obtain x*K; x*K is converted into a fixed-point number to obtain round(x*K). The round function rounds a number to a specified number of digits, and its function formula is: round(number to be rounded, number of digits to be retained). For example, round(3.1415926,2)=3.14, round(3.1415926,3)=3.142. In some embodiments, the round function can be to round a floating-point number into an integer. For example, round(3.1415926, 0) = 3, round(7.76) = 8. It should be understood that the data processing device can convert each floating-point number included in the first operation parameter into a fixed-point number in a similar manner.

[0065] 103. Based on the second operation parameter, perform the first operation on the input data of the at least one network layer to obtain a processing result of the at least one network layer.

[0066] The input data of the at least one network layer is the image to be predicted, or is obtained by processing the image to be predicted by the network layer located before the at least one network layer in the neural network model. For example, the first operation is: Qout = ceil[(x*A+y*BQ / 2) / Q]; the first operation parameters include x, y, Q, A and B, where x, y and Q are all floating point numbers; the second operation parameters include round(x*K), round(y*K)round(Q / 2*K), round(Q*K), A and B; based on the second operation parameters, the first operation is performed as: Out = ceil[(round(x*K)*A+round(y*K)-round(Q / 2*K)) / round(Q*K)]. ceil is a function name used to return the smallest integer greater than or equal to the specified expression. ceil(x) is the smallest integer greater than or equal to x.

[0067] In an embodiment of the present application, the data processing device can reduce floating-point operations when executing prediction processing tasks using a neural network model, and the overhead of computing resources and storage resources is relatively low.

[0068] The above embodiments do not describe in detail the implementation of step 102 and step 103. The following describes the application of step 102 and step 103 in some embodiments.

[0069] Embodiment 1

[0070] The network model processing performed by the Lth layer (Eltwise layer) in the neural network model is: Out = x*A+y*B, where x and y are both floating point numbers, and A and B are two input feature maps of the Eltwise layer; the quantization processing performed by the Lth layer is as follows: Qout = ceil[(Qin-Q / 2) / Q], where Qin represents the activation data output by the Lth layer, that is, the quantized input; Qout represents the quantized activation data, that is, the quantized output, and Q represents the quantization parameter; the first operation processing performed by the Lth layer is: Qout = ceil[(x*A+y*BQ / 2) / Q]. Exemplarily, the data processing device converts the first operation parameter required for the Lth layer to perform the first operation processing into a fixed-point number to obtain a second operation parameter, and the calculation formula corresponding to performing the above-mentioned first operation processing based on the above-mentioned second operation parameter is as follows: Out = ceil[(round(x*K)*A+round(y*K)-round(Q / 2*K)) / round(Q*K)].

[0071] Embodiment 2

[0072] The network model processing (convolution operation) performed by the Lth layer (convolution layer) in the neural network model is: Conv_out = W × A, where W is the weight matrix (weight) of the Lth layer, and A is the input feature map (i.e., activation) of the Lth layer. Assume that the current quantization adopts 2W4A, that is, the bit width of each element in the weight matrix W after quantization is 2 bits, and the bit width of each element in the input feature map A after quantization is 4 bits. W = alpha*B, A = Qparam*M, where B = {-3, -1, 1, 3}, M = {0-shift, 1-shift, ..., 15-shift}, alpha (floating point number) represents the common factor corresponding to the weight matrix, B represents the quantized weight matrix, Qparam (floating point number) represents the common factor corresponding to the input feature map, and M represents the quantized input feature map. Conv_out=W×A=alpha*Qparam*(B×M)=scale*(B*M), so the convolution operation can extract the common factor scale (i.e., alpha*Qparam), and fixed-point convolution operation is performed by B and M during hardware operation. The calculation formula for quantizing the activation data output by the data processing device of the Lth layer is as follows: Qout=ceil[(Qin-Q / 2) / Q], where Q represents the quantization parameter of the Lth layer. It should be understood that the calculation formula for the first operation processing performed by the Lth layer is expressed as follows: Qout=ceil[(scale*(B*M)-Q / 2) / Q]. Exemplarily, the data processing device converts the floating-point numbers in the first operation parameters required for the Lth layer to perform the first operation processing into fixed-point numbers to obtain the second operation parameters, and the calculation formula corresponding to performing the above-mentioned first operation processing based on the above-mentioned second operation parameters is as follows: Qout=ceil[(round(scale*K)*(B*M)-round(Q / 2*K)) / round(Q / 2*K)].

[0073] Embodiment 3

[0074] The network model processing performed by the Lth layer (convolutional layer) in the neural network model is: Conv_out = W × A, where W is the weight matrix (weight) of the Lth layer, A represents the input feature map of the Lth layer, W = alpha * B, A = Qparam * M, alpha (floating point number) represents the common factor corresponding to the weight matrix, B represents the quantized weight matrix, Qparam (floating point number) represents the common factor corresponding to the input feature map, and M represents the quantized input feature map. Conv_out = W × A = alpha * Qparam * (B × M) = scale * (B * M). Assume that part of the network structure in the neural network model is convolution layer (i.e., Lth layer, conv) -> batch normalization layer (i.e., BN layer) -> activation layer (i.e., relu layer), and the network model obtained by merging the operation processing performed by the convolution layer, the operation processing (linear operation) performed by the batch normalization layer, and the operation processing (linear operation) performed by the activation layer is: BNout = scale1*A+bias, scale1 is the floating point number after merging (including alpha, Qparam, etc.), and A is the output result of the convolution layer. Next, BNout is quantized. The quantization function can be: Qout = ceil[(Qin-Q / 2) / Q], Qin is BNout, Q / 2 can be merged into bias, and finally the first operation processing performed by conv->BN->relu can be simplified to: Qout = ceil[(scale1*A+bias) / Q], where scale1, bias and Q are all floating point numbers. Next, the floating point number elimination is performed. Exemplarily, the data processing device converts the floating-point numbers in the first operation parameters required for the Lth layer to perform the first operation processing into fixed-point numbers to obtain second operation parameters, and the corresponding calculation formula for performing the above-mentioned first operation processing based on the above-mentioned second operation parameters is as follows: Qout = ceil[(round(N*scale)*A+round(N*bias)) / round(N*Q)] = ceil[(scale_new*A+bias_new) / Q_n ew], where scale_new, bias_new and Q_new are all fixed-point numbers.

[0075] When the data processing device uses the neural network model to perform prediction processing tasks, floating-point operations will be performed, such as batch normalization, scaling operations, etc. In addition, the quantization process will also introduce floating-point numbers, such as quantization parameters Q, etc. Taking into account the complexity, area, computing resources and other factors of the neural network hardware accelerator implementation, the method provided in the embodiment of the present application can reduce or even eliminate all floating-point parameters and floating-point operations in the neural network model, which can improve computing efficiency.

[0076] Taking the convolutional layer in the neural network model as an example, the following further describes how to achieve full-process fixed-point when using the neural network model to perform prediction processing tasks.

[0077] Figure 2 Another data processing method flow chart provided in the embodiment of the present application. Figure 2 As shown, the method may include:

[0078] 201. The data processing device quantizes the input feature map to be processed in the Lth layer of the neural network model to obtain parameter 2 and matrix 2.

[0079] For example, A represents the input feature map (i.e., activation data) to be processed at the Lth layer, A=Qparam*M, Qparam (floating point number) represents the common factor (corresponding to parameter 2) corresponding to the input feature map (a matrix), and M represents the quantized input feature map, i.e., matrix 2. In practical applications, the data processing device performs Figure 2 Before the method flow in , the weights of the neural network model have been quantized. Figure 2 The parameter 1 in is the common factor corresponding to the weight matrix of the Lth layer, and the matrix 1 is the weight matrix of the Lth layer after quantization. For example, W is the weight matrix of the Lth layer before quantization, W = alpha*B, alpha (floating point number) represents the common factor corresponding to the quantized weight matrix B, and B represents the quantized weight matrix.

[0080] 202. Calculate the product of parameter 1 and parameter 2 to obtain parameter 3.

[0081] 203. Calculate the product of matrix 1 and matrix 2 to obtain matrix 3.

[0082] Step 202 and step 203 can be understood as the steps of performing convolution operation in the Lth layer (ie, the convolution layer).

[0083] 204. Based on parameter 3 and matrix 3, perform target operation processing to obtain the processing result of the Lth layer.

[0084] Optionally, the calculation formula corresponding to the target operation processing is as follows: Qout = ceil[(round(scale*K)*(B*M)-round(Q / 2*K)) / round(Q / 2*K)], where scale represents parameter 3, (B*M) represents matrix 3, and Q represents the quantization parameter of the Lth layer. It should be understood that when the data processing device uses the neural network model to perform the prediction processing task, each layer can perform similar Figure 2 This can reduce the cost of computing and storage resources.

[0085] The implementation of the data processing method in the aforementioned embodiment requires the use of quantization parameters. In practical applications, before the data processing device uses the neural network model to implement the method in the aforementioned embodiment, it is necessary to determine the quantization parameters required for each layer in the neural network model to perform quantization processing and store these quantization parameters. The following takes the Lth layer of the neural network model as an example to introduce how to determine the quantization parameters required for the network layer in the neural network model to perform quantization processing.

[0086] In some embodiments, the quantization parameter is a parameter determined based on a quantization maximum value and a quantization minimum value; the quantization maximum value and the quantization minimum value are obtained by clustering multiple numerical values ​​included in the data to be quantized output by the Lth layer of the neural network model.

[0087] Figure 3 Another data processing method flow chart provided in the embodiment of the present application. The data processing device executes Figure 3 The method flow in can obtain the quantization parameters required for the Lth layer of the neural network model to perform quantization processing, and store the quantization parameters.

[0088] like Figure 3 As shown, the method may include:

[0089] 301. A data processing device obtains the data to be quantized outputted by the Lth layer of a neural network model.

[0090] The data to be quantized includes at least one value represented by M or more bits, L is an integer greater than 0, and M is an integer greater than 1. M can be 6, 8, 12, 16, etc. In practical applications, the data processing device performs Figure 1 Before implementing the prediction processing task in the method flow, you can execute Figure 3 The method flow in the embodiment is used to determine and save the quantization parameters required for each layer of the neural network model to perform quantization processing. Optionally, the above-mentioned data to be quantized is the activation data output by the Lth layer of the above-mentioned neural network model when the data processing device inputs a training sample into the above-mentioned neural network model for prediction processing.

[0091] 302. Cluster multiple values ​​included in the data to be quantified to obtain a clustering result.

[0092] 303. Taking the maximum value of at least two cluster centers included in the clustering result as the quantized maximum value, and taking the minimum value of at least two cluster centers as the quantized minimum value.

[0093] 304. Determine a first arithmetic progression that has the minimum quantization value as the first item and the maximum quantization value as the last item and includes N values.

[0094] The above N is 2 raised to the Mth power. In some embodiments, before executing step 304, the data processing device may perform the following operation: obtain the number M of bits to be used to quantize the numerical values ​​included in the above data to be quantized. The number of bits M may be preset. For example, the data processing device or other device may pre-store the number of bits to be used to quantize the numerical values ​​included in the above data to be quantized. Accordingly, when it is necessary to determine the quantization parameter, the stored bit is obtained from the memory. In other embodiments, the number of bits M may also be determined based on the data to be quantized. For example, based on the distribution discreteness of multiple numerical values ​​included in the above data to be quantized, the number M of bits to be used to quantize the numerical values ​​included in the above data to be quantized is determined. Alternatively, the number of bits M may also be determined based on other distribution characteristics or parameters of the data to be quantized.

[0095] 305. Use the common factors of each item in the first arithmetic progression as the quantization parameters of the Lth layer of the neural network model, and store the quantization parameters.

[0096] For example, the maximum quantization value (max) is 1.3, the minimum quantization value (min) is -0.2, and M is 4; determine the first arithmetic progression {-0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8. 0.9, 1.0, 1.1, 1.2, 1.3} with -0.2 as the first item and 1.3 as the last item, and include 16 values; extract the common factor 0.1 of each item in the first arithmetic progression as the quantization parameter.

[0097] It can be understood that steps 301 to 305 are a method flow for the data processing device to determine the quantization parameters of the Lth layer in the neural network model. In some embodiments, the quantization parameters of each network layer in the neural network model are different, and the data processing device can use a similar method flow to determine the quantization parameters of each layer in the neural network model, and store the quantization parameters of each layer, so that when the neural network model is used to perform a prediction processing task, the quantization parameters of each layer are used to quantize the feature maps (i.e., activation data) output by each layer.

[0098] The above-mentioned embodiment does not describe the implementation method of determining the number M of bits to be used to quantize the numerical value included in the data to be quantized, which is introduced below.

[0099] Exemplarily, the data processing device determines the number of bits M corresponding to the quantization processing performed by the Lth layer based on the variance of each numerical value included in the above-mentioned data to be quantized; the number of bits M corresponding to the quantization processing performed by the Lth layer is positively correlated with the variance of each numerical value included in the above-mentioned data to be quantized. For example, the data processing device may compare the variance with one or more thresholds to determine the number of bits M, and when the variance of each numerical value included in the data to be quantized is less than a first threshold, the number of bits M corresponding to the quantization processing performed by the Lth layer is determined to be 2; when the variance of each numerical value included in the data to be quantized is not less than the first threshold, the number of bits M corresponding to the quantization processing performed by the Lth layer is determined to be 4. The first threshold may be 0.016, 0.2, 1.2, 10, 100, etc., and is not limited in this application. For another example, multiple segmented intervals may be set. When the variance of each value included in the data to be quantized is less than the second threshold and greater than the third threshold, the data processing device determines that the number of bits M corresponding to the quantization processing performed by the Lth layer is 4; when the variance of each value included in the data to be quantized is not less than the second threshold, the number of bits M corresponding to the quantization processing performed by the Lth layer is determined to be 6; when the variance of each value included in the data to be quantized is not greater than the third threshold, the number of bits M corresponding to the quantization processing performed by the Lth layer is determined to be 2. The third threshold may be 0.016, 0.2, 1.2, etc., and the second threshold may be 10, 25, etc., which are not limited in this application.

[0100] Exemplarily, the data processing device determines the number of bits M corresponding to the quantization processing performed by the Lth layer based on the range of each value included in the data to be quantized; the number of bits M corresponding to the quantization processing performed by the Lth layer is positively correlated with the range of each value included in the data to be quantized. The range of each value included in the data to be quantized is the difference between the maximum value and the minimum value included in the data to be quantized. For example, when the range of each value included in the data to be quantized is less than the fourth threshold, the data processing device determines that the number of bits M corresponding to the quantization processing performed by the Lth layer is 3; when the variance of each value included in the data to be quantized is not less than the fourth threshold, the data processing device determines that the number of bits M corresponding to the quantization processing performed by the Lth layer is 4. The fourth threshold may be 1.2, 10, 100, etc., and is not limited in this application. For another example, when the range of each value included in the data to be quantized is less than the fifth threshold and greater than the sixth threshold, the data processing device determines that the number of bits M corresponding to the Lth layer performing the quantization process is 4; when the range of each value included in the data to be quantized is not less than the fifth threshold, the data processing device determines that the number of bits M corresponding to the Lth layer performing the quantization process is 6; when the range of each value included in the data to be quantized is not greater than the sixth threshold, the data processing device determines that the number of bits M corresponding to the Lth layer performing the quantization process is 2. The sixth threshold may be 0.016, 0.2, 1.2, etc., and the fifth threshold may be 10, 25, etc., which are not limited in this application.

[0101] Exemplarily, the data processing device determines the number of bits M corresponding to the quantization processing performed by the Lth layer based on the standard deviation of each value included in the above-mentioned data to be quantized; the number of bits M corresponding to the quantization processing performed by the Lth layer is positively correlated with the standard deviation of each value included in the above-mentioned data to be quantized. For example, when the standard deviation of each value included in the data to be quantized is less than the seventh threshold, the data processing device determines that the number of bits M corresponding to the quantization processing performed by the Lth layer is 3; when the standard deviation of each value included in the data to be quantized is not less than the seventh threshold, the data processing device determines that the number of bits M corresponding to the quantization processing performed by the Lth layer is 4. The seventh threshold can be 0.04, 0.2, 1.2, 10, etc., and this application does not limit it.

[0102] In this implementation, the data processing device determines the number of bits M corresponding to the quantization processing performed at the Lth layer according to the distribution of each numerical value included in the data to be quantized; it can reduce the bits used for quantization, thereby reducing the computing resources required for predictive processing using the neural network model.

[0103] In some embodiments, the weights in the above neural network model are all quantized weights. In practical applications, the data processing device can also quantize the weights in the trained neural network model to compress the neural network model. The following introduces a scheme for the data processing device to quantize the weights in the trained neural network model.

[0104] Figure 4 Another data processing method flow chart provided in the embodiment of the present application. The data processing device executes Figure 4 The method flow in can quantize the weights in the neural network model. Figure 4 As shown, the method may include:

[0105] 401. Determine a first reference value based on weight data of a neural network model.

[0106] Optionally, based on the weight data of the neural network model, determining the first reference value may be to calculate the average value of each numerical value in the above weight data, and use the average value as the above first reference value. The above weight data includes the weight of at least one network layer of the above neural network model. Exemplarily, the above weight data is the weight of the Lth layer of the above neural network model. Exemplarily, the above weight data includes the weights of at least two network layers of the above neural network model. In some embodiments, the data processing device may quantize the weights of one or more network layers at a time; retrain (i.e., fine-tune) the neural network model while keeping the quantized weights unchanged; then, continue to quantize the weights of one or more network layers that have not been quantized before; and so on to quantize all weights in the neural network model. It can be understood that Figure 4This is an example of quantizing some weights in a neural network model. The data processing device can use a similar method to quantize each network layer in the neural network model.

[0107] 402. Based on the first reference value, determine R numerical intervals.

[0108] Each of the R numerical intervals corresponds to an integer that can be represented by F bits, F is an integer greater than 1 and less than 8, and R is an integer greater than 1. Optionally, before executing step 402, the data processing device may perform the following operations: based on the distribution discreteness of the multiple numerical values ​​included in the weight data, determine the number of bits F for quantization processing; the number of bits is positively correlated with the distribution discreteness. For example, if the distribution discreteness of the multiple numerical values ​​included in the weight data is not greater than the first discrete threshold, the number of bits F for quantization processing is determined to be 2; otherwise, the number of bits F for quantization processing is determined to be 4. Based on the first reference value, determining the R numerical intervals can be: based on the first reference value and the number of bits F, determining the R numerical intervals; R is 2 to the Fth power.

[0109] 403. Based on the R numerical intervals, use F bits to quantize the numerical values ​​in the weight data.

[0110] For example, alpha1 is a first reference value, W is any weight in the weight data, and based on the first reference value, the four value intervals determined are as follows:

[0111] When W>=alpha1, W≈alpha1*3 / 2;

[0112] When 0 <W<alpha1,W≈alpha1 / 2;

[0113] When W <= -alpha1, W ≈ alpha1*(-3) / 2;

[0114] When -alpha1 <W<=0,W≈alpha1*(-1) / 2。

[0115] Since alpha1 is a common factor, the quantized values ​​after extracting alpha1 / 2 are 3, 1, -1, -3, so 2 bits can be used to express it. When storing in hardware, -3, -1, 1, 3 can be mapped to 0, 1, 2, 3 through a mapping relationship. In other words, weights greater than alpha1 in the weight data are quantized to the product of alpha1 / 2 and 3; weights greater than 0 and less than alpha1 in the weight data are quantized to the product of alpha1 / 2 and 1; weights less than or equal to -alpha1 in the weight data are quantized to the product of alpha1 / 2 and -3; weights greater than -alpha1 and less than 0 in the weight data are quantized to the product of alpha1 / 2 and -1. The above example is a 2-bit quantization method. The embodiments of the present application also derive 3-bit, 4-bit, 5-bit and other quantization methods. The main idea is to use binary division to divide the quantization order. For 3-bit quantization, the quantization order is further expanded compared to 2-bit. When the weight is greater than 0, alpha1 / 2 and alpha1*3 / 2 are replaced by alpha1 / 4, alpha1*3 / 4, alpha1*5 / 4 and alpha1*7 / 4. When the weight is less than 0, -alpha1 / 2 and -alpha1*3 / 2 are replaced by -alpha1 / 4, -alpha1*3 / 4, -alpha1*5 / 4 and -alpha1*7 / 4. Similarly, 4-bit and higher bit weight quantization also uses binary division to perform a more detailed split of the quantization order. In other words, the data processing device can use different bits to quantize the weights according to the characteristics of the neural network model. In addition, the weights of different layers in the neural network model can be quantized using different bits. For example, the data processing device uses 2 bits to quantize the weights of the first network layer in the neural network model, and uses 4 bits to quantize the weights of the second network layer in the neural network model. Figure 4 The data processing method in can be understood as a low bit weight quantization method.

[0116] The data processing method proposed in the embodiment of the present application can adjust the bit width of the weight (i.e., the bit position of the quantized weight) according to the characteristics of the neural network model, thereby reducing the network performance loss caused by quantization.

[0117] Figure 1 The method flow of a data processing device using a neural network model to perform a prediction processing task is described. Figure 3 The method flow of determining the quantization parameters of each network layer in the neural network model by a data processing device is described. Figure 4 The process of quantizing the weights in a neural network model is described. In some embodiments, the data processing device may first execute Figure 3 and Figure 4The method flow in quantizes the weights in the neural network model and obtains the quantization parameters of each network layer, and then executes Figure 4 The method flow in .

[0118] Figure 5 Another data processing method flow chart provided in the embodiment of the present application. Figure 5 As shown, the method may include:

[0119] 501. The data processing device quantizes some weights in the neural network model.

[0120] The weights in the neural network model can be understood as the weight data in the neural network model.

[0121] 502. The data processing device retrains the neural network model while keeping the quantized weights unchanged.

[0122] Experience shows that most networks are more sensitive to accuracy the closer they are to the input end, so during the retraining (fine tuning) process, layer-by-layer training can be carried out in a back-to-forward order. For example, a neural network model has 50 layers, and fine-tuning can be performed in multiple rounds based on the training convergence situation. For example, in each round, 5 to 10 layers of weights are selected and quantized with low bits, and other layers are fine-tuned with floating point expressions until all layers of the neural network model are quantized with low bits (that is, all weights in the neural network model are quantized), and the retraining process ends.

[0123] 503. Determine whether weight quantization is completed.

[0124] If so, execute step 504; if not, execute step 501. Judging whether weight quantization is completed can be judging whether the difference between the prediction accuracy of the neural network model and the original prediction accuracy is less than the error threshold, and the weights in the above neural network model are all quantized; if so, it is judged that weight quantization is completed, if not, it is judged that weight quantization is not completed. The above original prediction accuracy refers to the prediction accuracy of the above neural network model before the weights in the neural network model are quantized. The error threshold can be 5%, 3%, 1%, etc., which is not limited in this application. The above original prediction accuracy can be 85%, 90%, 95%, etc.

[0125] 504. The data processing device determines the quantization parameters of each network layer in the neural network model.

[0126] 505. The data processing device determines whether the difference between the prediction accuracy of the neural network model and the original prediction accuracy is less than an error threshold when the activation data output by each network layer is quantized using the quantization parameters of each network layer in the process of using the neural network model for prediction processing.

[0127] If yes, go to step 506 ; if no, go to step 504 .

[0128] 506. The data processing device inputs the data to be processed into the neural network model for prediction processing to obtain a prediction result.

[0129] The implementation of step 506 can be found in Figure 1 The data to be processed may be image data, speech data, etc., and the prediction result may be an image processing result, a speech processing result, etc.

[0130] exist Figure 5 In the method flow, the data processing device first quantizes the weights in the neural network model, then determines the quantization parameters of each network layer in the neural network model, and finally uses the obtained neural network model to execute the following Figure 1 In other embodiments, the data processing device may first determine the quantization parameters of each network layer in the neural network model, and then quantize the weights in the neural network model.

[0131] Figure 6 A flowchart of another data processing method provided in an embodiment of the present application. The data processing device executes Figure 6 The method flow in the embodiment can first determine the quantization parameters of each network layer in the neural network model, and then quantize the weights in the neural network model.

[0132] like Figure 6 As shown, the method may include:

[0133] 601. A data processing device determines quantization parameters of some network layers in a neural network model.

[0134] 602. The data processing device retrains the neural network model.

[0135] The data processing device quantizes the activation data output by the partial network layer using the quantization parameters of the partial network layer during the process of retraining the neural network model. For example, the data processing device determines the quantization parameter of the Lth layer of the neural network model, and the data processing device quantizes the activation data of the Lth layer using the quantization parameter during the process of retraining the neural network model. Fig. 7A A schematic diagram of quantized activation data provided in an embodiment of the present application, that is, a schematic diagram of activation data quantization forward. Fig. 7A As shown, activation data in different value intervals are quantized to different values. For example, the value of the activation data that is greater than thr5 and not less than thr6 is quantized to q6. Figure 7B A schematic diagram of activation data quantization reverse provided in an embodiment of the present application.

[0136] 603. Determine whether the determination of the quantization parameter is completed.

[0137] If yes, execute step 604; if no, execute step 601. The determination of whether the determination of the quantization parameters is completed may be to determine whether the difference between the prediction accuracy of the neural network model and the original network accuracy is less than the error threshold, and the quantization parameters of each network layer in the neural network model have been determined; if yes, it is determined that the determination of the quantization parameters is completed; if no, it is determined that the determination of the quantization parameters is not completed.

[0138] 604. The data processing device quantizes a portion of the weights in the neural network model.

[0139] 605. The data processing device retrains the neural network model while keeping the quantized weights unchanged.

[0140] Optionally, the data processing device quantizes the activation data output by each network layer using the quantization parameters of each network layer during the process of retraining the neural network model while keeping the quantized weights unchanged.

[0141] 606. Determine whether weight quantization is completed.

[0142] If yes, execute step 607; if no, execute step 604. Determining whether weight quantization is completed can be to determine whether the difference between the prediction accuracy of the neural network model and the original prediction accuracy is less than the error threshold and the weights in the neural network model are all quantized; if yes, it is determined that weight quantization is completed; if no, it is determined that weight quantization is not completed.

[0143] 607. The data processing device inputs the data to be processed into the neural network model for prediction processing to obtain a prediction result.

[0144] The implementation of step 607 can be found in Figure 1 The data to be processed may be image data, speech data, etc., and the prediction result may be an image processing result, a speech processing result, etc.

[0145] Figure 8 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application. Figure 8 As shown, the data processing device includes:

[0146] An acquisition unit 801 is used to acquire first operation parameters required for performing a first operation process using a neural network model; the first operation process is obtained based on a network model process and a first quantization process performed on at least one network layer including an Lth layer of the neural network model, the first operation parameters include a quantization parameter of the first quantization process, and L is an integer greater than 0;

[0147] The conversion unit 802 is used to perform fixed-point processing on the first operation parameter to obtain a second operation parameter;

[0148] The processing unit 803 is used to perform the first operation processing on the input data of the at least one network layer based on the second operation parameter to obtain the processing result of the at least one network layer; the input data of the at least one network layer is the image to be predicted, or is obtained by processing the image to be predicted by at least one second network layer located before the at least one network layer in the neural network model.

[0149] In an optional implementation, the conversion unit 802 is specifically used to expand each floating-point number included in the above-mentioned first operation parameter by K times to obtain an expanded value, where the above-mentioned K is an integer greater than 1; and convert the above-mentioned expanded value into a fixed-point number to obtain the above-mentioned second operation parameter.

[0150] In an optional implementation, the first operation processing is obtained by merging the network model processing performed by at least two adjacent network layers including the Lth layer and the first quantization processing.

[0151] In an optional implementation, the quantization parameter is a parameter determined based on a quantization maximum value and a quantization minimum value; the quantization maximum value and the quantization minimum value are obtained by clustering multiple numerical values ​​included in the data to be quantized output by the Lth layer of the neural network model.

[0152] In an optional implementation, the above device further includes:

[0153] A clustering unit 804 is used to perform clustering processing on the multiple values ​​included in the data to be quantized outputted by the Lth layer to obtain a clustering result;

[0154] A first determining unit 805 is used to obtain the quantization maximum value and the quantization minimum value based on the clustering result;

[0155] The first determination unit 805 is further used to determine the quantization parameter based on the quantization maximum value and the quantization minimum value, wherein the quantization parameter is used to quantize the numerical value in the activation data of the Lth layer into an integer represented by M bits.

[0156] In an optional implementation, the first determining unit 805 is specifically configured to use the maximum value of at least two cluster centers included in the clustering result as the quantized maximum value, and use the minimum value of the at least two cluster centers as the quantized minimum value.

[0157] In an optional implementation, the first determination unit 805 is specifically used to obtain a first arithmetic progression including N numerical values ​​with the above-mentioned minimum quantization value as the first item and the above-mentioned maximum quantization value as the last item, where the above-mentioned N is an integer greater than 1; and use the common factors of the above-mentioned N numerical values ​​contained in the above-mentioned first arithmetic progression as the above-mentioned quantization parameter.

[0158] In an optional implementation, the first determining unit 805 is further configured to determine the number of bits M corresponding to the first quantization process based on the distribution discreteness of multiple values ​​included in the data to be quantized.

[0159] In an optional implementation, the above device further includes:

[0160] The second determination unit 806 is further configured to determine a first reference value based on the weight data of the neural network model; the weight data includes the weight of at least one network layer of the neural network model; based on the first reference value, determine a plurality of numerical intervals; each of the plurality of numerical intervals corresponds to an integer that can be represented by F bits, and F is an integer greater than 1 and less than 8;

[0161] The quantization unit 807 is used to quantize the values ​​in the first weight data using F bits based on the multiple value intervals. The second determination unit 806 and the first determination unit 805 may be the same unit or different units.

[0162] In an optional implementation, the second determination unit 806 is also used to determine the number of bits F of the quantization processing based on the distribution discreteness of multiple numerical values ​​included in the weight data; the second determination unit is specifically used to determine the multiple numerical intervals based on the first reference value and the bit number F; the multiple numerical intervals are 2 to the power of F numerical intervals.

[0163] It should be understood that the division of the various units of the above data processing device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. For example, the above units can be separately established processing elements, or they can be integrated into the same chip for implementation. In addition, they can also be stored in the storage element of the controller in the form of program code, and called and executed by a certain processing element of the processor. The functions of the above units. In addition, the various units can be integrated together or implemented independently. The processing element here can be an integrated circuit chip with signal processing capabilities. In the implementation process, the steps of the above method or the above units can be completed by hardware integrated logic circuits in the processor element or software instructions. The processing element can be a general-purpose processor, such as a central processing unit (CPU), or one or more integrated circuits configured to implement the above method, such as one or more specific integrated circuits (ASIC), or one or more microprocessors (DSP), or one or more field programmable gate arrays (FPGA).

[0164] Fig. 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig. 9 As shown, the electronic device 90 includes a processor 901, a memory 902 and a communication interface 903; the processor 901, the memory 902 and the communication interface 903 are interconnected via a bus. Fig. 9 The electronic device in the embodiment may be the data processing device in the foregoing embodiment.

[0165] The memory 902 includes, but is not limited to, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), or a portable read-only memory (CDROM), and is used for related instructions and data. The communication interface 903 is used to receive and send data.

[0166] The processor 901 may be one or more central processing units (CPUs). When the processor 901 is a CPU, the CPU may be a single-core CPU or a multi-core CPU. Fig. 9 Specifically, the processor 901 can implement Figure 8 The functions of each unit in it.

[0167] The processor 901 in the electronic device 90 is used to read the program code stored in the memory 902 and execute the data processing method in the above-mentioned embodiment.

[0168] Fig.10 1 is a schematic diagram of the structure of a server 1000 provided in an embodiment of the present application. The server 1000 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 1022 (for example, one or more processors) and a memory 1032, and one or more storage media 1030 (for example, one or more mass storage devices) storing application programs 1042 or data 1044. Among them, the memory 1032 and the storage medium 1030 may be short-term storage or permanent storage. The program stored in the storage medium 1030 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the server. Furthermore, the central processing unit 1022 may be configured to communicate with the storage medium 1030 and execute a series of instruction operations in the storage medium 1030 on the server 1000. The server 1000 may be a data processing device provided in the present application.

[0169] The server 1000 may also include one or more power supplies 1026, one or more wired or wireless network interfaces 1050, one or more input and output interfaces 1058, and / or one or more operating systems 1041, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0170] The steps performed by the data processing device in the above embodiment can be based on the Fig.10 Specifically, the central processor 1022 can implement Figure 8 The functions of each unit in it.

[0171] In an embodiment of the present application, a computer-readable storage medium is provided. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the data processing method provided in the above embodiment is implemented.

[0172] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A method for processing image data, video data or target detection scene data, It is characterized in that include: Acquire a first operation parameter required to perform a first operation process using a neural network model; The first operation processing is obtained based on the network model processing and the first quantization processing performed on at least one network layer including the Lth layer of the neural network model, the first operation parameter includes the quantization parameter of the first quantization processing, and L is an integer greater than 0; Performing fixed-point processing on the first operation parameter to obtain a second operation parameter; Based on the second operation parameter, perform the first operation processing on the input data of the at least one network layer to obtain a processing result of the at least one network layer; Before obtaining the first operation parameter required for performing the first operation processing using the neural network model, the method further includes: Determining a first reference value based on weight data of at least one network layer of the neural network model; Based on the first reference value, determine a plurality of numerical intervals, each of the plurality of numerical intervals corresponding to an integer that can be represented by F bits, where F is an integer greater than 1 and less than 8; Based on the multiple numerical intervals, a second quantization process is performed on the numerical values ​​in the weight data to obtain an integer represented by F bits.

2. The method according to claim 1, It is characterized in that The converting the first operation parameter into a fixed-point number to obtain a second operation parameter comprises: Expand each floating-point number included in the first operation parameter by K times to obtain an expanded value, where K is an integer greater than 1; The expanded value is converted into a fixed-point number to obtain the second operation parameter.

3. The method according to claim 1 or 2, It is characterized in that The first operation processing is obtained by merging the network model processing and the first quantization processing performed by at least two adjacent network layers including the Lth layer.

4. The method according to claim 1, It is characterized in that The quantization parameter is a parameter determined based on a maximum quantization value and a minimum quantization value; the maximum quantization value and the minimum quantization value are obtained by clustering a plurality of numerical values ​​included in the data to be quantized in the Lth layer.

5. The method according to claim 4, It is characterized in that Before obtaining the first operation parameter required for performing the first operation processing using the neural network model, the method further includes: Performing clustering processing on a plurality of values ​​included in the data to be quantized in the Lth layer to obtain a clustering result; Based on the clustering result, obtaining the quantization maximum value and the quantization minimum value; Based on the quantization maximum value and the quantization minimum value, the quantization parameter is determined, wherein the quantization parameter is used to quantize the numerical value in the activation data into an integer represented by M bits.

6. The method according to claim 5, It is characterized in that The obtaining of the maximum quantization value and the minimum quantization value based on the clustering result includes: The maximum value of at least two cluster centers included in the clustering result is used as the quantized maximum value, and the minimum value of the at least two cluster centers is used as the quantized minimum value.

7. The method according to claim 5 or 6, It is characterized in that The determining the quantization parameter based on the quantization maximum value and the quantization minimum value includes: Taking the minimum quantization value as the first item and the maximum quantization value as the last item, a first arithmetic progression including N values ​​is obtained, where N is an integer greater than 1; The common factor of the N numerical values ​​included in the first arithmetic progression is used as the quantization parameter.

8. The method according to claim 5 or 6, It is characterized in that The method further comprises: The number of bits M corresponding to the first quantization process is determined based on the distribution discreteness of multiple values ​​included in the data to be quantized.

9. The method according to claim 1, It is characterized in that Before determining a plurality of numerical value intervals based on the first reference value, the method further includes: Determining the number of bits F of the second quantization processing based on the distribution discreteness of multiple values ​​included in the weight data; The determining a plurality of numerical intervals based on the first reference value comprises: Based on the first reference value and the number of bits F, the plurality of numerical value intervals are determined.

10. A device for processing image data, video data or target detection scene data, It is characterized in that include: An acquisition unit, used to acquire a first operation parameter required to perform a first operation process using a neural network model; The first operation processing is obtained based on the network model processing and the first quantization processing performed on at least one network layer including the Lth layer of the neural network model, the first operation parameter includes the quantization parameter of the first quantization processing, and L is an integer greater than 0; A conversion unit, used for performing fixed-point processing on the first operation parameter to obtain a second operation parameter; a processing unit, configured to perform the first operation processing on the input data of the at least one network layer based on the second operation parameter, to obtain a processing result of the at least one network layer; The device also includes: The second determining unit is further used to determine a first reference value based on weight data of at least one network layer of the neural network model; based on the first reference value, determine a plurality of numerical intervals, each of the plurality of numerical intervals corresponds to an integer that can be represented by F bits, and F is an integer greater than 1 and less than 8; The quantization unit is used to perform a second quantization process on the numerical values ​​in the weight data based on the multiple numerical intervals to obtain an integer represented by F bits.

11. The device according to claim 10, It is characterized in that The conversion unit is specifically used to expand each floating-point number included in the first operation parameter by K times to obtain an expanded value, where K is an integer greater than 1; and convert the expanded value into a fixed-point number to obtain the second operation parameter.

12. The device according to claim 10 or 11, It is characterized in that The first operation processing is obtained by merging the network model processing and the first quantization processing performed by at least two adjacent network layers including the Lth layer.

13. The device according to claim 10, It is characterized in that The quantization parameter is a parameter determined based on a quantization maximum value and a quantization minimum value; the quantization maximum value and the quantization minimum value are obtained by clustering a plurality of numerical values ​​included in the data to be quantized outputted by the Lth layer of the neural network model.

14. The device according to claim 13, It is characterized in that The device also includes: A clustering unit, used for performing clustering processing on a plurality of values ​​included in the data to be quantized in the Lth layer to obtain a clustering result; A first determining unit, configured to obtain the quantization maximum value and the quantization minimum value based on the clustering result; The first determination unit is further used to determine the quantization parameter based on the quantization maximum value and the quantization minimum value, wherein the quantization parameter is used to quantize the numerical value in the activation data into an integer represented by M bits.

15. The device according to claim 14, It is characterized in that The first determining unit is specifically configured to use a maximum value of at least two cluster centers included in the clustering result as the quantized maximum value, and use a minimum value of the at least two cluster centers as the quantized minimum value.

16. The device according to claim 14 or 15, It is characterized in that The first determining unit is specifically configured to obtain a first arithmetic progression including N values, with the minimum quantization value as the first item and the maximum quantization value as the last item, where N is an integer greater than 1; The common factor of the N numerical values ​​included in the first arithmetic progression is used as the quantization parameter.

17. The device according to claim 14 or 15, It is characterized in that The first determining unit is further configured to determine the number of bits M corresponding to the first quantization process based on the distribution discreteness of multiple numerical values ​​included in the data to be quantized.

18. The device according to claim 10, It is characterized in that The second determining unit is further configured to determine the number of bits F of the second quantization processing based on the distribution discreteness of the multiple values ​​included in the weight data; The second determination unit is specifically configured to determine the multiple numerical value intervals based on the first reference value and the number of bits F.

19. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor executes the method according to any one of claims 1 to 9.

20. An electronic device, It is characterized in that include: Memory, used to store programs; A processor, configured to execute the program stored in the memory; when the program is executed, the processor is configured to execute the method according to any one of claims 1 to 9.

21. A chip, It is characterized in that include: A processor and a data interface, wherein the processor reads instructions stored in a memory through the data interface to execute the method according to any one of claims 1 to 9.