A method, device, electronic device and storage medium for processing sample characteristics

By obtaining and determining the reference values ​​in the input and output data of the activation function in the neural network model and performing quantitative processing, the problem of low operation efficiency of deep learning algorithm models in mobile terminal devices is solved, and the effect of improving computing speed and reducing resource consumption is achieved.

CN113554147BActive Publication Date: 2025-04-18BEIJING XIAOMI MOBILE SOFTWARE CO LTD +1
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202110460619.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-27
Publication Date
2025-04-18
Estimated Expiration
2041-04-27

AI Technical Summary

Technical Problem

The development of deep learning algorithm models has led to large parameter scale and slow inference speed, especially in mobile terminal devices, which is difficult to run larger models, resulting in slow operation speed and low processing efficiency.

Method used

By acquiring the first reference data in the input data of the activation function in the neural network model, the second reference data corresponding to the first reference data in the output data is determined, and the output data is quantized based on the second reference data.

Benefits of technology

This method can determine the second reference data in a shorter time, improve the computing speed, reduce the consumption of computing resources, and improve the operation efficiency of the neural network model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113554147B_ABST
    Figure CN113554147B_ABST
Patent Text Reader

Abstract

The disclosed embodiment discloses a method for processing sample features, the method comprising: obtaining first reference data from input data of an activation function in a neural network model; wherein the input data comprises feature data of sample features to be input into the activation function; inputting the input data into the activation function to obtain output data of the activation function; determining second reference data corresponding to the first reference data in the output data based on the first reference data; and quantizing the output data based on the second reference data. Compared with the method of obtaining the second reference data from the output data after obtaining the output data without being based on the first reference data, the time for determining the second reference data is shorter and more efficient. The output data is quantized based on the second reference data, so that the computing speed can be improved and the computing resources consumed can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of wireless communication technology but is not limited to the field of wireless communication technology, and in particular to a sample feature processing method, device, electronic device and storage medium. Background Art

[0002] With the development of computer technology, deep learning has been widely used in many fields such as computer vision processing, natural language processing and speech processing. However, deep learning algorithm models are showing a trend of becoming larger and deeper, accompanied by larger parameter scales and slower reasoning speeds.

[0003] In related technologies, the development of deep learning algorithm models will bring huge challenges to the operation of electronic devices, especially mobile terminal devices. Due to the hardware resource limitations of mobile terminal devices, it is difficult for mobile terminal devices to directly run larger deep learning algorithm models, and the running speed is slow and the processing efficiency is low. Summary of the invention

[0004] The embodiments of the present disclosure disclose a method, device, electronic device and storage medium for processing sample features.

[0005] According to a first aspect of an embodiment of the present disclosure, a method for processing sample features is provided, wherein the method comprises:

[0006] Acquire first reference data in input data of an activation function in a neural network model; wherein the input data includes feature data of sample features to be input into the activation function;

[0007] Inputting the input data into the activation function to obtain output data of the activation function;

[0008] Based on the first reference data, determining second reference data in the output data corresponding to the first reference data;

[0009] The output data is quantized based on the second reference data.

[0010] In one embodiment, the first reference data and the output data are acquired simultaneously.

[0011] In one embodiment, after the first reference data is input into the activation function, output data output by the activation function is determined as the second reference data.

[0012] In one embodiment, the first reference data includes:

[0013] The maximum and minimum values ​​in the input data.

[0014] In one embodiment, the activation function is a monotonically increasing function or a monotonically decreasing function.

[0015] In one embodiment, the bit width of the output data is the first bit width; the quantization of the output data based on the second reference data includes: inputting the output data into a quantization mapping function to obtain quantized output data; wherein the quantization mapping function is used to quantize the data from the first bit width to the second bit width; the first bit width is greater than the second bit width; the quantization reference point of the quantization mapping function includes the maximum value and the minimum value in the second reference data. According to a second aspect of an embodiment of the present disclosure, a device for processing sample features is provided, characterized in that the device includes an acquisition module, a determination module and a quantization module; wherein,

[0016] The acquisition module is used to: acquire first reference data from input data of an activation function in a neural network model; wherein the input data includes feature data of sample features to be input into the activation function; input the input data into the activation function to acquire output data of the activation function;

[0017] The determining module is configured to: determine, based on the first reference data, second reference data in the output data corresponding to the first reference data;

[0018] The quantization module is used to quantize the output data based on the second reference data.

[0019] In one embodiment, the acquisition module is further used to: acquire the first reference data and the output data simultaneously.

[0020] In one embodiment, the determining module is further configured to:

[0021] After the first reference data is input into the activation function, output data output by the activation function is determined as the second reference data.

[0022] In one embodiment, the acquisition module is further configured to: the first reference data includes a maximum value and a minimum value in the input data.

[0023] In one embodiment, the acquisition module is further used for the activation function to be a monotonically increasing function or a monotonically decreasing function.

[0024] In one embodiment, the first parameter includes a maximum value and a minimum value in the input data; and the second reference data includes a maximum value and a minimum value in the output data.

[0025] In one embodiment, the bit width of the output data is the first bit width; the quantization module is further used to input the output data into a quantization mapping function to obtain quantized output data; wherein the quantization mapping function is used to quantize the data from the first bit width to the second bit width; the first bit width is greater than the second bit width; the quantization reference point of the quantization mapping function includes the maximum value and the minimum value in the second reference data. .

[0026] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, the electronic device comprising:

[0027] processor;

[0028] a memory for storing instructions executable by the processor;

[0029] The processor is configured to implement the method described in any embodiment of the present disclosure when running the executable instructions.

[0030] According to a fourth aspect of an embodiment of the present disclosure, a computer storage medium is provided, wherein the computer storage medium stores a computer executable program, and when the executable program is executed by a processor, the method described in any embodiment of the present disclosure is implemented.

[0031] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:

[0032] In an embodiment of the present disclosure, first reference data is obtained from input data of an activation function in a neural network model; wherein the input data includes feature data of sample features to be input into the activation function; the input data is input into the activation function to obtain output data of the activation function; based on the first reference data, second reference data corresponding to the first reference data in the output data is determined. Compared with a method of obtaining the second reference data from the output data after obtaining the output data without being based on the first reference data, the time for determining the second reference data is shorter and more efficient. Based on the second reference data, the output data is quantized, so that the computing speed can be improved and the computing resources consumed can be reduced.

[0033] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0035] Figure 1It is a schematic diagram showing a quantization method according to an exemplary embodiment.

[0036] Figure 2 It is a schematic diagram showing a quantization method according to an exemplary embodiment.

[0037] Figure 3 It is a schematic diagram showing a quantization method according to an exemplary embodiment.

[0038] Figure 4 It is a schematic diagram showing a quantization method according to an exemplary embodiment.

[0039] Figure 5 It is a schematic diagram showing a quantization method according to an exemplary embodiment.

[0040] Figure 6 The figure is a flow chart of a method for processing sample features according to an exemplary embodiment.

[0041] Figure 7 The figure is a flow chart of a method for processing sample features according to an exemplary embodiment.

[0042] Figure 8 The figure is a flow chart of a method for processing sample features according to an exemplary embodiment.

[0043] Fig. 9 It is a schematic diagram of a device for processing sample features according to an exemplary embodiment.

[0044] Fig.10 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0045] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of devices and methods consistent with some aspects of the present invention as detailed in the appended claims.

[0046] In order to facilitate the understanding of those skilled in the art, the embodiments of the present disclosure list multiple implementation methods to clearly illustrate the technical solutions of the embodiments of the present disclosure. Of course, those skilled in the art can understand that the multiple embodiments provided by the embodiments of the present disclosure can be executed separately, or can be executed together with the methods of other embodiments of the embodiments of the present disclosure, or can be executed together with some methods in other related technologies separately or in combination; the embodiments of the present disclosure do not limit this.

[0047] In order to facilitate the understanding of any embodiment of the present disclosure, first, the neural network model in deep learning is explained.

[0048] Neural network models contain multiple parameters. During the training process, neural network models with high parameter accuracy will have a large number of matrix operations, which will occupy more computing resources and lead to low efficiency in neural network model training. After the training is completed, the running neural network model will also consume more resources, and the large amount of calculation will usually lead to a long delay, which cannot meet the real-time requirements. Therefore, it is necessary to quantize the parameters of the neural network model and reduce the bit width of the parameters to improve the running speed of the neural network model.

[0049] Model quantization belongs to the category of model compression, and the purpose of model compression is to reduce the memory size of the model and speed up the model reasoning speed. Quantizing the neural network model to be quantized mainly compresses the parameters of the neural network model to be quantized. The compression process uses the floating-point data (for example, 32 bits) that occupies a large memory space and has a higher bit to represent it with integer data (for example, 8 bits) that occupies a smaller memory space and has a lower bit. In this way, the internal calculation of the neural network model to be quantized is performed with a relatively simple numerical type without affecting the accuracy of the quantized neural network model. The calculation speed will be greatly improved and the consumption of computing resources will be greatly reduced.

[0050] In one embodiment, in order to maintain the accuracy requirement, the trained neural network model often needs to be saved in floating point type float32. Model quantization refers to converting the high-precision floating point type float32 value into a low-precision integer representation, such as int8 or int4. See Figure 1 , which converts float32 values ​​to int8 values. Since the ranges of representation are quite different and integers cannot represent decimal ranges, quantization is usually not done through type conversion, but through scaling or affine transformation. See Figure 2 , the upper layer value is the value before quantization, and the lower layer value is the value after quantization. Affine transformation is usually an asymmetric transformation, that is, the mapping point of 0 is not necessarily at 0. For example, Figure 2 The 0 point in the quantized point is at point z.

[0051] The formulas for quantization via affine transformation include:

[0052]

[0053] z=-round(β·s)-2 b-1 ;

[0054]

[0055] x q =quantize(x,b,s,z)=clip(round(s·x+z),-2 b-1 ,2 b-1 -1);

[0056] Where s is the scaling factor, z is the position where the 0 point of float32 is mapped to an integer, α represents the maximum value of the vector, β represents the minimum value of the vector, b is the number of bits represented by the integer, l is the minimum value of the data to be quantized, and u is the maximum value of the data to be quantized.

[0057] Under the condition of 8 bits,

[0058]

[0059] z = -round(β·s)-128;

[0060] z will be rounded to ensure that it can be represented by an integer.

[0061] See also Figure 3 , scaling is a symmetric transformation, and the 0 point is still mapped to the 0 point.

[0062] The formulas for quantization by scaling include:

[0063]

[0064] x q =quantize(x,b,s)=clip(round(s·x),-2 b-1 +1,2 b-1 -1);

[0065] α1 represents the maximum absolute value.

[0066] The above-mentioned affine transformation quantization method and scaling transformation quantization method both require calculation of the maximum and minimum values ​​in the tensor.

[0067] In one embodiment, the tensors in the neural network can be divided into weights and activations. The weights are weight values ​​obtained through training, and the activations are outputs after the activation function. The maximum and minimum values ​​of the weights can be obtained after training. The value of the activation is related to the input.

[0068] In one embodiment, the maximum and minimum activation amounts are calculated in two ways, online or offline. Figure 4 , in the neural network inference process, the required maximum and minimum values ​​are calculated before the quantization operation, and then used for the quantization operation. See Figure 5 In the process of neural network inference, the offline method collects and counts the maximum and minimum activation values ​​of samples in various locations in the network and records them for use in inference. It can be seen that both the online method and the offline method have their own shortcomings. The online method generates extra time to calculate the maximum and minimum values, which will weaken the benefits of quantitative calculation. The maximum and minimum values ​​counted by the offline method deviate from the actual input, which will cause accuracy deviation.

[0069] like Figure 6 As shown, this embodiment provides a method for processing sample features, the method comprising:

[0070] Step 61: Obtain first reference data in input data of an activation function in a neural network model; wherein the input data includes feature data of sample features to be input into the activation function;

[0071] Step 62: input the input data into the activation function to obtain output data of the activation function;

[0072] Step 63: Determine, based on the first reference data, second reference data in the output data corresponding to the first reference data;

[0073] Step 64: quantize the output data based on the second reference data.

[0074] In some embodiments, the method can be applied to a terminal, which may be, but is not limited to, a computer, a mobile phone, a wearable device, a vehicle-mounted terminal, a road side unit (RSU), a smart home terminal, an industrial sensor device and / or a medical device, etc.

[0075] In some embodiments, the neural network model may be a model having at least one of the following functions: image processing function, natural language processing function, and speech processing function. Here, the sample feature may be at least one of the following features: image features of image data samples, text features of text data samples, and speech features of speech data samples. Feature data may be data obtained by extracting features of data samples.

[0076] In one embodiment, the neural network model is an image recognition neural network model. Obtain first reference data from the input data of the activation function in the image recognition neural network model; wherein the input data includes image feature data to be identified of image sample features to be input into the activation function; input the input data into the activation function to obtain output data; determine second reference data corresponding to the first reference data in the output data based on the first reference data; and quantize the output data based on the second reference data. Here, since the second reference data used to quantize the output data is determined based on the first reference data, rather than determined from the output data according to a complex preset algorithm, the operating efficiency of the neural network model can be improved. For example, the first reference data is the maximum and minimum values ​​of the input data, and the second reference data is the maximum and minimum values ​​of the output data. This method can directly obtain the second reference data based on the first reference data after two operations. Compared with the need to determine the second reference data from the output data through data comparison and other algorithms after obtaining the output data, the amount of data operations can be reduced, the operating efficiency of the neural network model can be improved, and the delay can be reduced.

[0077] Here, the output data obtained after the first reference data is input into the activation function may be determined as the second reference data in the output data corresponding to the first reference data.

[0078] In one embodiment, the neural network model includes multiple neuron layers, wherein the neuron layer can be any one of the input layer, output layer and hidden layer in the neural network, or any neuron layer of the hidden layer in the neural network, which is not specifically limited here. Here, the activation function is a function running on the neuron layer, and the activation function is used to map the input of the neuron layer to the output end. In one embodiment, the activation function can be one of the following: sigmoid, relu, gelu and tanh. Here, the sample feature can be the sample feature corresponding to any one of the input layer, output layer or hidden layer.

[0079] In one embodiment, the input data may be data obtained by weighting and summing feature data input into the neuron. After the input data is input into the activation function, the output data may be obtained.

[0080] In one embodiment, the first reference data may include the maximum value and the minimum value in the input data; here, the activation function may be a monotonically increasing or decreasing function, so that the maximum value and the minimum value of the output data can be obtained after the first reference data is input into the activation function. It should be noted that, in one scenario embodiment, before the input data is input into the activation function, the maximum value and the minimum value in the input data have been obtained. That is, before the input data is input into the activation function, the max(x) and min(x) in the input data x have been obtained.

[0081] In one embodiment, the activation function is a monotonically increasing function, and the maximum value of the output data of the activation function can be expressed as:

[0082] max(activation(x))=activation(max(x)).

[0083] Here, the minimum value of the output data of the activation function can be expressed as:

[0084] min(activation(x))=activation(min(x)).

[0085] Wherein, max(x) is the maximum value of the input data; min(x) is the minimum value of the input data; max(activation(x)) is the maximum value of the output data; min(activation(x)) is the minimum value of the output data. It should be noted that when the output data is quantified, it is necessary to perform quantization based on the maximum and minimum values ​​of the output data.

[0086] In one embodiment, the output data is quantized using an affine transformation quantization method or a scaling transformation quantization method. Here, the affine transformation quantization method and the scaling transformation quantization method need to quantize the output data based on the maximum value and the minimum value of the output data.

[0087] In one embodiment, the first reference data is a and b, where a is the maximum value of the input data and b is the minimum value of the input data; after a and b are input into the activation function, output data c and d can be obtained, where c is the maximum value of the output data and d is the minimum value of the output data. In response to the activation function being an increasing function, a corresponds to c one-to-one, and b corresponds to d one-to-one. After c and d are determined, all output data can be quantized based on the affine transformation quantization method or the scaling transformation quantization method.

[0088] In one embodiment, the input data may be sorted according to the size relationship, and after the input data is sorted, the maximum value and the minimum value of the input data are obtained. For example, the input data is sorted in order from large to small, and the first input data after sorting is the maximum value, and the last input data is the minimum value; for another example, the input data is sorted in order from small to large, and the first input data after sorting is the minimum value, and the last input data is the maximum value.

[0089] In one embodiment, adjacent data in the input data may be compared one by one to determine the maximum value and the minimum value. For example, the input data includes a, b, c, d, e, f, g, h, and i, and adjacent data in a, b, c, d, e, f, g, h, and i are compared one by one to determine the maximum value and the minimum value. For example, a and b are compared, and if a is greater than b, then b and c are used for comparison, and so on.

[0090] In one embodiment, the input data is divided into multiple groups, the maximum value and the minimum value in each group are determined respectively, and the maximum value and the minimum value of each group are compared to obtain the maximum value and the minimum value. In this way, the computational complexity of obtaining the maximum value and the minimum value can be reduced.

[0091] For example, the input data includes a, b, c, d, e, f, g, h and i, and the input data is divided into three groups, the first group is a, b and c, the second group is d, e and f, and the third group is g, h and i; the maximum value of the first group is a, and the minimum value is b; the maximum value of the second group is e, and the minimum value is f; the maximum value of the third group is g, and the minimum value is i; compare the sizes of a, b, e, f, g and i, where a is the maximum value and g is the minimum value, then determine that a is the maximum value in the input data and g is the minimum value in the input data. In one embodiment, when quantizing the output data of the activation function, the second reference data is required. The value range of the second reference data can be predetermined, for example, the second reference data is the maximum value and the minimum value. In one embodiment, the value range of the first reference data can be determined according to the value range of the second reference data, for example, the second reference data is the maximum value and the minimum value. If the activation function is a monotonically increasing function or a monotonically decreasing function, the first reference data is also the maximum value and the minimum value. It should be noted that the second reference data may also be any value of a reference point used for quantizing the output data.

[0092] In one embodiment, the output data to be quantized may be a floating point number (e.g., a 32-bit floating point number), and the quantized output data may be an integer, so that it can be represented by an integer that occupies a smaller memory space and has a lower bit (e.g., an 8-bit floating point number).

[0093] In one embodiment, a 32-bit floating point number in the output data may be quantized into a 4-bit integer or an 8-bit integer.

[0094] In one embodiment, the first reference data in the input data of the activation function in the neural network model can be simultaneously obtained and the input data can be input into the activation function to obtain the output data. In this way, after obtaining the output data, the second reference data in the output data corresponding to the first reference data can be quickly determined based on the first reference data. Compared with the need to determine the second reference data from the output data through data comparison and other algorithms after obtaining the output data, the amount of data calculation can be reduced, the operating efficiency of the neural network model can be improved, and the delay can be reduced.

[0095] In one embodiment, the terminal running the neural network model is a multi-core terminal, and the terminal can concurrently obtain first reference data from the input data of the activation function in the neural network model and input the input data into the activation function to obtain output data. In this way, the output data is obtained while the first reference data is obtained. Compared with determining the second reference data from the output data through algorithms such as data comparison after obtaining the output data, the amount of data calculation can be reduced, the operating efficiency of the neural network model can be improved, and the delay can be reduced.

[0096] In one embodiment, when quantizing the output data, the maximum value and the minimum value of the output data need to be used.

[0097] In one embodiment, the terminal obtains the minimum and maximum values ​​in the input data of the activation function in the neural network model; inputs the input data into the activation function to obtain output data; based on the minimum and maximum values ​​in the input data, determines the minimum and maximum values ​​in the output data corresponding to the minimum and maximum values ​​respectively; based on the maximum and minimum values ​​in the output data, quantizes the output data. The activation function may be a monotonically increasing function.

[0098] In an embodiment of the present disclosure, first reference data is obtained from input data of an activation function in a neural network model; wherein the input data includes feature data of sample features to be input into the activation function; the input data is input into the activation function to obtain output data; based on the first reference data, second reference data corresponding to the first reference data in the output data is determined. Compared with the method of obtaining the second reference data from the output data after obtaining the output data without being based on the first reference data, the time for determining the second reference data is shorter and more efficient. Based on the second reference data, the output data is quantized, so that the computing speed can be improved and the computing resources consumed can be reduced.

[0099] It should be noted that those skilled in the art can understand that the method provided in the embodiments of the present disclosure can be executed alone or together with some methods in the embodiments of the present disclosure or some methods in related technologies.

[0100] In one embodiment, the first reference data and the output data are acquired simultaneously.

[0101] In one embodiment, the neural network model is an image recognition neural network model. The multi-core terminal obtains the first reference data in the input data of the activation function in the image recognition neural network model in parallel and inputs the input data into the activation function to obtain output data; wherein the input data includes the image feature data to be identified of the image sample feature to be input into the activation function; based on the first reference data, the second reference data corresponding to the first reference data in the output data is determined; based on the second reference data, the output data is quantified. Here, since the second reference data used to quantize the output data is determined based on the first reference data, rather than determined from the output data according to a complex preset algorithm, the operation efficiency of the neural network model can be improved, and the image can be quickly recognized. For example, the first reference data is the maximum and minimum values ​​of the input data, and the second reference data is the maximum and minimum values ​​of the input data. This method can directly obtain the second reference data based on the first reference data after two operations. Compared with the need to determine the second reference data from the output data through data comparison and other algorithms after obtaining the output data, the amount of data operation can be reduced, the operation efficiency of the neural network model can be improved, and the delay can be reduced.

[0102] In one embodiment, the first reference data may be the maximum value and the minimum value of the input data. The output data may be data obtained after the input data is input into the activation function. The output data includes the maximum value and the minimum value.

[0103] In one embodiment, the first reference data may be obtained by sorting. For example, the input data may be sorted according to size, and after the input data is sorted, the maximum value and the minimum value of the input data are obtained.

[0104] In one embodiment, adjacent data in the input data may be compared one by one to determine the maximum value and the minimum value.

[0105] In one embodiment, the first reference data may be obtained by grouping and then sorting. For example, the input data is divided into multiple groups, the maximum value and the minimum value in each group are determined, and the maximum value and the minimum value of each group are compared to obtain the maximum value and the minimum value.

[0106] Here, since the maximum value, the minimum value and the output data are obtained at the same time, after the output data is obtained, the maximum value and the minimum value can be determined according to the first reference data. Compared with the need to obtain the maximum value and the minimum value of the output data by comparing the sizes after obtaining the output data, the processing delay of the terminal can be reduced and the computing speed of the terminal can be improved.

[0107] It should be noted that those skilled in the art can understand that the method provided in the embodiments of the present disclosure can be executed alone or together with some methods in the embodiments of the present disclosure or some methods in related technologies.

[0108] In the present embodiment, a method for processing sample features is provided, the method comprising: after the first reference data is input into the activation function, the output data output by the activation function is determined as the second reference data. In one embodiment, the first reference data includes a first maximum value and a first minimum value. If the activation function is a monotonically increasing function, the second reference data also includes a second maximum value corresponding to the first maximum value and a second minimum value corresponding to the first minimum value. If the activation function is a monotonically decreasing function, the second reference data also includes a second minimum value corresponding to the first maximum value and a second maximum value corresponding to the first minimum value. It should be noted that, in a scenario embodiment, before the input data is input into the activation function, the maximum value and the minimum value in the input data have been obtained. That is, before the input data is input into the activation function, the max(x) and min(x) in the input data x have been obtained.

[0109] In one embodiment, since the second reference data can be quickly obtained after the first reference data is input into the activation function, after the second reference data is quickly obtained, the neural network model can perform real-time quantization on the output data of the input data of the activation function in the neural network based on the second reference data. For example, each time an output result y is output, y can be quantized using the second reference data. Compared with the method of inputting all input data into the activation function to obtain all output data and then using the second reference data for quantization after sorting all output data to obtain the second reference data, the time for the neural network to perform quantization is saved, making the quantization processing of the neural network more efficient.

[0110] It should be noted that those skilled in the art can understand that the method provided in the embodiments of the present disclosure can be performed alone or together with some methods in the embodiments of the present disclosure or some methods in related technologies. In one embodiment, the first reference data includes the maximum value and the minimum value in the input data.

[0111] like Figure 7 As shown, in this embodiment, a method for processing sample features is provided, wherein the first reference data in the input data of the activation function in the neural network model is obtained, including:

[0112] Step 71: Obtain the maximum and minimum values ​​in the input data of the activation function in the neural network model.

[0113] In one embodiment, the terminal obtains the minimum and maximum values ​​in the input data of the activation function in the neural network model; inputs the input data into the activation function to obtain output data; determines the minimum and maximum values ​​in the output data corresponding to the minimum and maximum values, respectively, based on the minimum and maximum values ​​in the input data; quantizes the output data based on the maximum and minimum values ​​in the output data. Wherein, the activation function is a monotonically increasing function. Since the activation function is a monotonically increasing function, the maximum and minimum values ​​of the output data can be determined according to the minimum value of the input data and the maximum value of the input data.

[0114] In one embodiment, the input data may be sorted according to the size relationship, and after the input data is sorted, the maximum value and the minimum value of the input data are obtained. For example, the input data is sorted in order from large to small, and the first input data after sorting is the maximum value, and the last input data is the minimum value; for another example, the input data is sorted in order from small to large, and the first input data after sorting is the minimum value, and the last input data is the maximum value.

[0115] In one embodiment, adjacent data in the input data may be compared one by one to determine the maximum value and the minimum value. For example, the input data includes a, b, c, d, e, f, g, h, and i, and adjacent data in a, b, c, d, e, f, g, h, and i are compared one by one to determine the maximum value and the minimum value. For example, a and b are compared, and if a is greater than b, then b and c are used for comparison, and so on.

[0116] In one embodiment, the input data is divided into multiple groups, the maximum value and the minimum value in each group are determined respectively, and the maximum value and the minimum value of each group are compared to obtain the maximum value and the minimum value. In this way, the computational complexity of obtaining the maximum value and the minimum value can be reduced.

[0117] For example, the input data includes a, b, c, d, e, f, g, h and i, and the input data is divided into three groups, the first group is a, b and c, the second group is d, e and f, and the third group is g, h and i; the maximum value of the first group is a, and the minimum value is b; the maximum value of the second group is e, and the minimum value is f; the maximum value of the third group is g, and the minimum value is i; compare the sizes of a, b, e, f, g and i, where a is the maximum value and g is the minimum value, then determine that a is the maximum value in the input data and g is the minimum value in the input data.

[0118] It should be noted that those skilled in the art can understand that the method provided in the embodiments of the present disclosure can be executed alone or together with some methods in the embodiments of the present disclosure or some methods in related technologies.

[0119] In one embodiment, the activation function is a monotonically increasing function or a monotonically decreasing function.

[0120] For example, the activation function is a monotonically increasing function. In one embodiment, the activation function may be one of the following: sigmoid, relu, gelu and tanh.

[0121] In one embodiment, the activation function is a monotonically increasing function; the terminal obtains the minimum and maximum values ​​in the input data of the activation function in the neural network model; the input data is input into the activation function to obtain output data; based on the minimum and maximum values ​​in the input data, the minimum and maximum values ​​in the output data corresponding to the minimum and maximum values, respectively, are determined; based on the maximum and minimum values ​​in the output data, the output data is quantized.

[0122] In one embodiment, the activation function is a monotonically decreasing function; the terminal obtains the minimum and maximum values ​​in the input data of the activation function in the neural network model; the input data is input into the activation function to obtain output data; based on the minimum and maximum values ​​in the input data, the maximum and minimum values ​​in the output data corresponding to the minimum and maximum values, respectively, are determined; based on the maximum and minimum values ​​in the output data, the output data is quantized.

[0123] It should be noted that those skilled in the art can understand that the method provided in the embodiments of the present disclosure can be executed alone or together with some methods in the embodiments of the present disclosure or some methods in related technologies.

[0124] like Figure 8 As shown, this embodiment provides a method for processing sample features, wherein the bit width of the output data is the first bit width; the method comprises:

[0125] Step 81: input the output data into a quantization mapping function to obtain quantized output data;

[0126] The quantization mapping function is used to quantize data of a first bit width into data of a second bit width; the first bit width is greater than the second bit width; and the quantization reference point of the quantization mapping function includes the maximum value and the minimum value in the second reference data.

[0127] Here, the second reference data may include the maximum and minimum values ​​output by the activation function. It should be noted that when quantizing data using the quantization mapping function, it is necessary to first obtain at least two quantization reference points in the data, for example, α and β in the above embodiment.

[0128] Here, the first bit width may be the number of bits occupied by the data before being quantized, for example, occupying 32 bits. Here, the second bit width may be the number of bits occupied by the data after being quantized, for example, occupying 8 bits.

[0129] It should be noted that, in some scenario embodiments, the second bit width may also be defined as a quantization bit width. Here, the quantization bit width may be the number of bits occupied by the output data after quantization. For example, if the output data is a 32-bit floating point number, and the quantized output data is an 8-bit integer data, the quantization bit width is 8 bits.

[0130] In one embodiment, the neural network model is a speech recognition neural network model. Obtain first reference data from the input data of the activation function in the speech recognition neural network model; wherein the input data includes speech feature data to be recognized of speech sample features to be input into the activation function; input the input data into the activation function to obtain output data; based on the first reference data, determine second reference data corresponding to the first reference data in the output data; based on the second reference data, quantize the output data using an affine transformation quantization method. Here, since the second reference data used to quantize the output data is determined based on the first reference data, rather than determined from the output data according to a complex preset algorithm, the operating efficiency of the neural network model can be improved. For example, the first reference data is the maximum and minimum values ​​of the input data, and the second reference data is the maximum and minimum values ​​of the input data. This method can directly obtain the second reference data based on the first reference data after two operations. Compared with the need to determine the second reference data from the output data through data comparison and other algorithms after obtaining the output data, and perform quantization processing, this can reduce the amount of data operations, improve the operating efficiency of the neural network model, and reduce latency.

[0131] In one embodiment, the neural network model is a text recognition neural network model. Obtain the first reference data in the input data of the activation function in the text recognition neural network model; wherein the input data includes the text feature data to be recognized of the text sample feature to be input into the activation function; input the input data into the activation function to obtain output data; based on the first reference data, determine the second reference data corresponding to the first reference data in the output data; based on the second reference data, quantize the output data by a scaling transformation quantization method. Here, since the second reference data used to quantize the output data is determined based on the first reference data, rather than determined from the output data according to a complex preset algorithm, the operating efficiency of the neural network model can be improved. For example, the first reference data is the maximum and minimum values ​​of the input data, and the second reference data is the maximum and minimum values ​​of the input data. This method can directly obtain the second reference data based on the first reference data after two operations. Compared with the need to determine the second reference data from the output data through data comparison and other algorithms after obtaining the output data, the amount of data operations can be reduced, the operating efficiency of the neural network model can be improved, and the delay can be reduced. Here, the mapping function is used to quantize the output data to be quantized. Here, different quantization bit widths may correspond to different quantization mapping functions. For example, when the quantization bit width is 4 bits, the corresponding mapping function is the first mapping function; when the quantization bit width is 8 bits, the corresponding mapping function is the second mapping function.

[0132] In one embodiment, the quantization bit width is determined according to the operating environment of the terminal where the neural network model is located. For example, in response to the operating environment supporting 8-bit quantization, the quantization bit width may be 8 bits; in response to the operating environment supporting 4-bit quantization, the quantization bit width may be 4 bits.

[0133] In one embodiment, the output data is stored in the storage area in a 32-bit floating point data format.

[0134] In one embodiment, in response to the operating environment supporting 8-bit quantization, the output data is quantized, including: quantizing the 32-bit output data into 8-bit output data; in response to the operating environment supporting 4-bit quantization, the output data is quantized, including: quantizing the 32-bit output data into 4-bit output data.

[0135] In one embodiment, the bit width threshold is determined according to the information accuracy of the output result.

[0136] In one embodiment, in response to the information accuracy requirement of the output result being less than an accuracy threshold, the quantization bit width is greater than a bit width threshold; in response to the information accuracy requirement of the output result being greater than an accuracy threshold, the quantization bit width is less than a bit width threshold.

[0137] Here, it should be noted that quantizing the data in the neural network model to be quantized is mainly to compress the data of the neural network model to be quantized. The compression process converts the data occupying a larger number of bits (such as 32 bits) in the neural network model to be quantized into data occupying a smaller memory space and fewer bits (such as 8 bits). In this way, without affecting the accuracy of the quantized neural network model, the internal calculation of the neural network model to be quantized uses relatively simple numerical types, the calculation speed will be greatly improved, and the consumption of computing resources will be greatly reduced.

[0138] It should be noted that those skilled in the art can understand that the method provided in the embodiments of the present disclosure can be executed alone or together with some methods in the embodiments of the present disclosure or some methods in related technologies.

[0139] like Fig. 9 As shown, in this embodiment, a sample feature processing device is provided, the device comprising an acquisition module 91, a determination module 92 and a quantification module 93; wherein,

[0140] The acquisition module 91 is used to: acquire first reference data from input data of an activation function in a neural network model; wherein the input data includes feature data of sample features to be input into the activation function; input the input data into the activation function to acquire output data of the activation function;

[0141] The determining module 92 is configured to: determine, based on the first reference data, second reference data in the output data corresponding to the first reference data;

[0142] The quantization module 93 is used to quantize the output data based on the second reference data.

[0143] In one embodiment, the acquisition module 91 is further configured to: acquire the first reference data and the output data simultaneously.

[0144] In one embodiment, the determining module is further configured to:

[0145] After the first reference data is input into the activation function, output data output by the activation function is determined as the second reference data.

[0146] In one embodiment, the acquisition module 91 is further configured to: the first reference data includes a maximum value and a minimum value in the input data.

[0147] In one embodiment, the acquisition module 91 is further configured to enable the activation function to be a monotonically increasing function or a monotonically decreasing function.

[0148] In one embodiment, the first parameter includes a maximum value and a minimum value in the input data; and the second reference data includes a maximum value and a minimum value in the output data.

[0149] In an embodiment, the quantization module 93 is further configured to use the second reference data as a quantization reference point for the output data, and quantize the output data based on a quantization mapping function determined according to a quantization bit width.

[0150] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0151] The present disclosure also provides a communication device, including:

[0152] antenna;

[0153] Memory;

[0154] The processor is connected to the antenna and the memory respectively, and is used to control the antenna to receive and send wireless signals by executing an executable program stored in the memory, and can execute the steps of the wireless network access method provided in any of the above embodiments.

[0155] The communication device provided in this embodiment may be the aforementioned terminal or base station. The terminal may be various types of person-mounted terminals or vehicle-mounted terminals. The base station may be various types of base stations, for example, a 4G base station or a 5G base station.

[0156] The antenna may be various types of antennas, for example, a mobile antenna such as a 3G antenna, a 4G antenna or a 5G antenna; the antenna may also include: a WiFi antenna or a wireless charging antenna, etc.

[0157] The memory may include various types of storage media, which are non-transitory computer storage media that can continue to remember information stored thereon after the communication device loses power.

[0158] The processor may be connected to the antenna and the memory via a bus, etc., and may be used to read an executable program stored in the memory, for example, at least one of the methods shown in any embodiment of the present disclosure.

[0159] An embodiment of the present disclosure also provides a non-temporary computer-readable storage medium, which stores an executable program, wherein when the executable program is executed by a processor, the steps of the wireless network access method provided in any of the aforementioned embodiments are implemented, for example, at least one of the methods shown in any embodiment of the present disclosure.

[0160] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0161] Fig.10 is a block diagram of an electronic device 600 according to an exemplary embodiment. For example, the electronic device 600 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0162] Reference Fig.10 , the electronic device 600 may include one or more of the following components: a processing component 602 , a memory 604 , a power component 606 , a multimedia component 608 , an audio component 610 , an input / output (I / O) interface 612 , a sensor component 614 , and a communication component 616 .

[0163] The processing component 602 generally controls the overall operation of the electronic device 600, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 602 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 602 may include one or more modules to facilitate the interaction between the processing component 602 and other components. For example, the processing component 602 may include a multimedia module to facilitate the interaction between the multimedia component 608 and the processing component 602.

[0164] The memory 604 is configured to store various types of data to support operations on the device 600. Examples of such data include instructions for any application or method operating on the electronic device 600, contact data, phone book data, messages, pictures, videos, etc. The memory 604 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0165] The power supply component 606 provides power to the various components of the electronic device 600. The power supply component 606 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 600.

[0166] The multimedia component 608 includes a screen that provides an output interface between the electronic device 600 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 608 includes a front camera and / or a rear camera. When the device 600 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and the rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0167] The audio component 610 is configured to output and / or input audio signals. For example, the audio component 610 includes a microphone (MIC), and when the electronic device 600 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 604 or sent via the communication component 616. In some embodiments, the audio component 610 also includes a speaker for outputting audio signals.

[0168] I / O interface 612 provides an interface between processing component 602 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.

[0169] The sensor assembly 614 includes one or more sensors for providing various aspects of status assessment for the electronic device 600. For example, the sensor assembly 614 can detect the open / closed state of the device 600, the relative positioning of the components, such as the display and keypad of the electronic device 600, and the sensor assembly 614 can also detect the position change of the electronic device 600 or a component of the electronic device 600, the presence or absence of contact between the user and the electronic device 600, the orientation or acceleration / deceleration of the electronic device 600, and the temperature change of the electronic device 600. The sensor assembly 614 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 614 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 614 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0170] The communication component 616 is configured to facilitate wired or wireless communication between the electronic device 600 and other devices. The electronic device 600 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 616 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 616 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0171] In an exemplary embodiment, the electronic device 600 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.

[0172] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 604 including instructions, and the instructions can be executed by the processor 820 of the electronic device 600 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0173] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art that are not disclosed in this disclosure. The specification and examples are to be considered exemplary only, and the true scope and spirit of the present invention are indicated by the following claims.

[0174] It should be understood that the present invention is not limited to the exact construction that has been described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.

Claims

1. A method for processing sample features, characterized in that: The method comprises: Acquire first reference data in input data of an activation function in a neural network model; wherein the input data includes feature data of sample features to be input into the activation function; the neural network model is a model having at least one of the following functions: image processing function, natural language processing function and speech processing function; the sample features are at least one of the following features: image features of image data samples, text features of text data samples and speech features of speech data samples; Input the input data into the activation function to obtain output data of the activation function; determine second reference data corresponding to the first reference data in the output data based on the first reference data; the determining the second reference data corresponding to the first reference data in the output data based on the first reference data includes: after inputting the first reference data into the activation function, determining the output data output by the activation function as the second reference data; the first reference data includes the maximum value and the minimum value in the input data, and the activation function is a monotonically increasing function or a monotonically decreasing function; The output data is quantized based on the second reference data.

2. The method according to claim 1, characterized in that: The first reference data and the output data are acquired simultaneously.

3. The method according to claim 1, characterized in that The second reference data includes a maximum value and a minimum value in the output data.

4. The method according to claim 3, characterized in that: The bit width of the output data is the first bit width; and quantizing the output data based on the second reference data includes: Inputting the output data into a quantization mapping function to obtain quantized output data; The quantization mapping function is used to quantize data from a first bit width to a second bit width; the first bit width is greater than the second bit width; and the quantization reference point of the quantization mapping function includes the maximum value and the minimum value in the second reference data.

5. A sample feature processing device, characterized in that: The device comprises an acquisition module, a determination module and a quantification module; wherein, The acquisition module is used to: acquire first reference data from input data of an activation function in a neural network model; wherein the input data includes feature data of sample features to be input into the activation function; input the input data into the activation function to acquire output data of the activation function; the neural network model is a model having at least one of the following functions: image processing function, natural language processing function and speech processing function; the sample features are at least one of the following features: image features of image data samples, text features of text data samples and speech features of speech data samples; The determination module is used to: determine, based on the first reference data, second reference data in the output data corresponding to the first reference data; the determination of the second reference data in the output data corresponding to the first reference data based on the first reference data includes: after the first reference data is input into the activation function, the output data output by the activation function is determined as the second reference data; the first reference data includes the maximum value and the minimum value in the input data, and the activation function is a monotonically increasing function or a monotonically decreasing function; The quantization module is used to quantize the output data based on the second reference data.

6. The device according to claim 5, characterized in that The acquisition module is further used to: acquire the first reference data and the output data simultaneously.

7. The device according to claim 5, characterized in that The second reference data includes a maximum value and a minimum value in the output data.

8. The device according to claim 7, characterized in that The bit width of the output data is the first bit width; the quantization module is also used to: input the output data into a quantization mapping function to obtain quantized output data; wherein the quantization mapping function is used to quantize data from the first bit width to the second bit width; the first bit width is greater than the second bit width; the quantization reference point of the quantization mapping function includes the maximum value and the minimum value in the second reference data.

9. An electronic device, characterized in that: The electronic device comprises: a processor and a memory for storing a computer service that can be run on the processor, wherein the processor implements the method according to any one of claims 1 to 4 when being used to run the computer service.

10. A storage medium, characterized in that: The storage medium contains computer executable instructions, and the computer executable instructions are executed by a processor to implement the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Object type identification method and apparatus, device and storage medium

    CN107516112A

  • Data quantification method and device based on neural network and computer readable storage medium

    CN111008701A

  • Neural network quantification method and system

    CN111178514A

  • Joint neural network model compression method based on channel pruning and quantitative training

    CN111652366A

  • Quantization method and apparatus for neural network model in device

    CN112449703A