WO2021073638A1 - 运行神经网络模型的方法、装置和计算机设备 - Google Patents

运行神经网络模型的方法、装置和计算机设备 Download PDF

Info

Publication number
WO2021073638A1
WO2021073638A1 PCT/CN2020/121896 CN2020121896W WO2021073638A1 WO 2021073638 A1 WO2021073638 A1 WO 2021073638A1 CN 2020121896 W CN2020121896 W CN 2020121896W WO 2021073638 A1 WO2021073638 A1 WO 2021073638A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
weight parameter
processing
winograd
parameter data
Prior art date
Application number
PCT/CN2020/121896
Other languages
English (en)
French (fr)
Inventor
何占盈
郑淼
何雷骏
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2021073638A1 publication Critical patent/WO2021073638A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/06Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons
    • G06N3/063Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons using electronic means

Definitions

  • This application relates to the field of artificial intelligence technology, in particular to a method, device and computer equipment for running a neural network model.
  • a neural network model can be composed of multiple network layers. Typical network layers can include Convolution (Conv), Pooling (Pooling), Full Connection (FC), and so on. Different types of network layers involve different types of operations. For convolutional layers, convolution operations need to be performed based on input data and weight parameters. The specific operation process of the convolution operation is relatively cumbersome, and many times of multiplication and accumulation operations are required to perform the convolution operation. In practical applications, a single convolutional layer needs to perform millions or even tens of millions of times of accumulation and multiplication operations. The running speed of a single convolutional layer is already relatively slow, and the neural network model generally includes multiple convolutional layers. The running speed of the network model is extremely slow.
  • a method for running a neural network model including:
  • the quantized input data and weight parameter data are processed by winograd, so that the processed input data and weight parameter data are convenient for convolution operation in the device, and the operation of the current convolution layer is improved.
  • Speed can ultimately achieve the goal of improving the running speed of the entire neural network model.
  • the requirements for hardware (such as multipliers) used to support the calculation of the data to be calculated can be reduced, which is beneficial to reducing the power consumption of the hardware and Hardware volume.
  • the weight parameter data processed by winograd is fixed-point data with a signed bit
  • the reducing the number of data bits of the weight parameter data processed by winograd includes:
  • any data bit in the highest preset number of data bits is 1, then the sign bit in the weight parameter data processed by winograd and all but the highest preset number of data bits are reserved. For other data bits, the values of the data bits other than the highest preset number of data bits are all set to 1, and the weight parameter data after the reduction is obtained.
  • the memory unit used to store the weight parameter data processed by winograd can be configured in advance.
  • a memory unit with 8-bit data as an integer part and 2-bit data as a decimal part can be configured to store the weight parameter data processed by winograd. After the winograd process, even if the result is actually 12-digit data with a decimal point, the 12-digit data with a decimal point will overflow in the above-mentioned memory unit, and finally only the lowest 8 digits of the integer part and the decimal part will be retained. Numerical value.
  • the overall neural network model is extremely complex and the number of weight parameter data for calculation is numerous, so the integer part is directly discarded. Except for the sign bit, the numerical value on the highest 2 digits is convolved through the weight parameter data after the reduction, and it has little effect on the accuracy of the final output data of the neural network model.
  • the number of data bits of the weight parameter data to be calculated is reduced to the same as the number of data bits of the input data to be calculated.
  • the hardware requirements for supporting the data to be calculated for calculation will also be reduced, which is beneficial to reducing the power consumption and hardware volume of the hardware.
  • the weight parameter data after reduction is fixed-point data with a sign bit
  • the performing quantization processing on the weight parameter data after the reduction includes:
  • the performing inverse quantization processing on the intermediate output data includes:
  • the fixed-point weight parameter data can be enlarged by a product factor in the quantization process.
  • the quantization factor can be obtained, and the quantization factor can be divided by the product factor to obtain the transformed
  • the intermediate output data is inversely quantized to maintain the consistency of the output results.
  • the determining a product factor based on the number of decimal places includes:
  • the number of decimal places in the weight parameter data is x, and 2 to the power of x can be determined as the multiplication factor.
  • the quantization factor is a quantization factor used in the process of quantizing the initial weight parameter data.
  • the quantization factor used in the quantization process of the initial weight parameter data can be s w
  • the transformed quantization factor s w can be
  • the input data and weight parameter data of the current convolutional layer are 8-bit integer data respectively, and the input data to be calculated is 10-bit integer data, and the winograd process
  • the integer part of the subsequent weight parameter data is 10 digits and the decimal part is 2 digits
  • the weight parameter data to be calculated is 10-digit integer data.
  • the input data and weight parameter data of the current convolutional layer of 8-bit integer type can be quantized data by the user, or data obtained after quantization processing by the system provided by this application. These data are in a relatively common format. , It is easy to realize based on the existing technology, which reduces the development cost.
  • the performing a convolution operation based on the input data to be calculated and the weight parameter data to be calculated includes:
  • the control multiply accumulator performs a convolution operation based on the input data to be calculated and the weight parameter data to be calculated, wherein the multiply accumulator is a multiply accumulator that supports 10-bit integer data to perform a convolution operation.
  • the method before obtaining the input data and weight parameter data of the current convolutional layer, the method further includes:
  • the obtaining the input data and weight parameter data of the current convolutional layer includes:
  • the input data and weight parameter data of the current convolutional layer are quantized data, and the input data and weights of the current convolutional layer can be directly modified.
  • the parameter data is processed by winograd. If the user does not over-process the input data and weight parameter data of the current convolution layer, the input data and weight parameter data of the current convolution layer are floating-point data, and the initial input The data and the initial weight parameter data are quantified and then processed by winograd.
  • the method further includes:
  • the performing quantization processing on the initial input data includes:
  • quantization processing configuration information is configuration information used to indicate a convolution operation in the integer domain, perform quantization processing on the initial input data
  • the performing quantization processing on the initial weight parameter data includes:
  • quantization processing configuration information is configuration information used to indicate a convolution operation in the integer domain, perform quantization processing on the initial weight parameter data
  • the performing quantization processing on the weight parameter data after the reduction includes:
  • quantization processing configuration information is the configuration information used to indicate the convolution operation in the integer domain, then perform quantization processing on the reduced weight parameter data;
  • the performing inverse quantization processing on the intermediate output data includes:
  • the quantization processing configuration information is configuration information used to instruct the convolution operation in the integer domain, inverse quantization processing is performed on the intermediate output data.
  • the user can configure the quantization process.
  • the user can choose whether to quantize the input data and weight parameter data, or the user can choose to perform convolution operations in the floating-point domain or in the integer domain. Through the user's configuration, you can flexibly choose whether to quantify the data used in the convolution operation.
  • the method further includes:
  • the performing winograd processing on the input data includes:
  • winograd processing configuration information is configuration information for instructing winograd processing, perform winograd processing on the input data
  • the performing winograd processing on the weight parameter data includes:
  • winograd processing configuration information is configuration information for instructing to perform winograd processing, perform winograd processing on the weight parameter data
  • the performing winograd result transformation processing on the intermediate output data after the inverse quantization processing includes:
  • winograd processing configuration information is configuration information for instructing to perform winograd processing, then perform winograd result transformation processing on the intermediate output data after the inverse quantization processing.
  • the user can configure the winograd processing process, and the user can choose whether to perform winograd processing on input data and weight parameter data. Through the user's configuration, you can flexibly choose whether to perform winograd processing on the data used in the convolution operation.
  • the size of the weight parameter data is 3 ⁇ 3, and the step parameter used in the convolution operation is 1;
  • the performing winograd processing on the input data includes:
  • the performing winograd processing on the weight parameter data includes:
  • the performing winograd result transformation processing on the intermediate output data after the inverse quantization processing includes:
  • the first conversion matrix is The second conversion matrix is The third conversion matrix is
  • the more cumbersome convolution operation can be replaced by the relatively simple convolution operation by equivalent replacement to reduce the number of multiplication operations during the convolution operation.
  • the operation results obtained by the more cumbersome convolution operation or the simpler convolution operation are consistent.
  • a device for running a neural network model includes at least one circuit for implementing the method for running a neural network model provided by the first aspect.
  • a computer device which includes a processor and the device for running a neural network model provided in the second aspect.
  • a computer-readable storage medium including instructions, which when the computer-readable storage medium runs on a computer device, cause the computer device to execute the above-mentioned first aspect.
  • a computer program product containing instructions, which when the computer program product runs on a computer device, causes the computer device to execute the method described in the first aspect.
  • the quantized input data and weight parameter data are processed by winograd, so that the processed input data and weight parameter data are convenient for convolution operation in the device, and the operation of the current convolution layer is improved.
  • Speed can ultimately achieve the goal of improving the running speed of the entire neural network model.
  • Fig. 1 is a schematic diagram showing the structure of a computer device according to an exemplary embodiment
  • Fig. 2 is a schematic structural diagram of a neural network processor according to an exemplary embodiment
  • Fig. 3 is a schematic flowchart of a method for running a neural network model according to an exemplary embodiment
  • Fig. 4 is a schematic diagram of performing winograd processing on input data according to an exemplary embodiment
  • Fig. 5 is a schematic diagram showing performing winograd processing on weight parameter data according to an exemplary embodiment
  • Fig. 6 is a schematic diagram showing a flow of winograd processing according to an exemplary embodiment
  • Fig. 7 is a schematic flow chart showing a method for running a neural network model according to an exemplary embodiment
  • Fig. 8 is a schematic structural diagram showing a device for running a neural network model according to an exemplary embodiment
  • Fig. 9 is a schematic diagram showing the structure of a computer device according to an exemplary embodiment.
  • the embodiment of the present application provides a method for running a neural network model, and the method can be implemented by a computer device.
  • a schematic diagram of a structure of a computer device is shown in FIG. 1.
  • the computer device may be provided with a processor (Central Processing Unit, CPU), a neural network processor, and a memory (Memory).
  • the processor and the neural network processor can be located in the same system on chip (System on Chip, SoC), and the processor, neural network processor and memory can be electrically connected through the AXI (Advanced eXtensible Interface, a bus protocol) bus .
  • the processor can control the neural network processor to start arithmetic processing through the AXI bus.
  • the neural network processor When the neural network processor receives the control instruction sent by the processor for instructing to start the arithmetic processing, it can read the image data and weight parameter data from the memory. In the neural network processor, arithmetic processing is performed based on the image data and the weight parameter data. After the neural network processor completes the arithmetic processing, it obtains the output data and writes the output data back to the Memory through the AXI bus. The neural network processor can also send to the processor instruction information for instructing the completion of the arithmetic processing.
  • the method for running a neural network model provided by the embodiment of the application can be implemented in the neural network processor provided in the above-mentioned computer device.
  • the neural network processor can be used as a single electrical component or integrated into the SoC chip. Or it can be integrated into a special application integrated circuit (Application Specific Integrated Circuit, ASIC) chip.
  • Computer equipment can be smart phones, video monitors, vehicle-mounted smart terminals, and so on.
  • the structure of the neural network processor provided by the embodiments of the present application can be seen in Figure 2.
  • the neural network processor may include a core calculation engine, a data buffer (Buffer), a parameter buffer, a dedicated linear processor engine, an output control module, and a control Module.
  • the core calculation engine is used to perform related calculations on the convolutional layer and the fully connected layer in the neural network model, and send the calculation results to the output control module.
  • the data buffer is used to store data (such as image data input by the user) that needs to be used in the calculation process, and the data buffer can send the stored data to the core calculation engine or the dedicated linear processor engine.
  • the parameter buffer is used to store the weight parameter data that needs to be used in the calculation process, and send the stored weight parameter data to the core calculation engine or the dedicated linear processor engine.
  • the dedicated linear processing engine is used to perform related operations on the network layers other than the convolutional layer and the fully connected layer in the neural network model, and send the calculation results to the output control module.
  • the output control module is used to receive the calculation results and send the calculation results to the Memory through the AXI bus.
  • the control module is used to control the above-mentioned core calculation engine, data buffer, parameter buffer, dedicated linear processor engine, output control module, etc. to perform orderly operation.
  • Image data can be recognized by computer equipment equipped with a neural network processor. Recognizing different image data in different fields has different meanings, but all can rely on computer equipment to complete the process of recognizing image data.
  • the trained neural network model is pre-stored in the computer equipment, and the image data can be recognized through the trained neural network model. In the process of recognizing the image data by the trained neural network model, it is necessary to run the neural network in the computer equipment Network model.
  • the embodiments of the present application take the field of video surveillance as an example for description, and the situation in other fields is similar, and examples are not given one by one.
  • the principle of the winograd algorithm is to reduce the number of multiplications by equivalent replacement for the convolution operation to save operation time while keeping the output result unchanged.
  • the input data d in the convolution operation is converted into an n*n matrix through the transformation matrix B, and the weight parameter data g is also converted into an n*n matrix through the transformation matrix G. Then, the two n*n matrices after the conversion are dot-producted to obtain intermediate output data, and the intermediate output data is converted through the conversion matrix A to obtain the same output data as the above-mentioned convolution operation.
  • the convolution operation with the same size and step size of the weight parameter data corresponds to the same set of conversion matrices A, B, and G when the winograd process is performed.
  • An exemplary embodiment of the present application provides a method for running a neural network model. As shown in FIG. 3, the processing flow of the method may include the following steps:
  • Step S301 Obtain input data and weight parameter data of the current convolutional layer.
  • users can install a video monitor at home.
  • the video monitor can record the environment video at home in real time, and the video monitor can identify each video frame in the environment video. . After the person image is recognized in any video frame, the recognition result can be pushed to the terminal bound to the user.
  • Input a video frame to the neural network model.
  • the neural network model recognizes whether there is a character image in the video frame. If there is a character image, the neural network model also needs to mark the position of the character image in the video frame. This process can be in the neural network Completed in the processor.
  • the video monitor records a video frame and stores the video frame in Memory.
  • the processor sends a control instruction for instructing to start arithmetic processing to the neural network processor, and the neural network processor reads the video frame from the Memory.
  • the video frame can be used as the input data of the first network layer of the neural network model, that is, the input layer, and the input data is processed through the first network layer to obtain the output data of the first network layer.
  • the output data of the previous network layer can be used as the input data of the next network layer.
  • the neural network model may include multiple network layers, and the multiple network layers may include an input layer, a convolutional layer, a pooling layer, a fully connected layer, an output layer, and so on. It can be judged whether the current network layer is a convolutional layer. If the current network layer is a convolutional layer, the output data of the previous network layer of the current convolutional layer will be used as the input data of the current convolutional layer.
  • the weight parameter data of the current convolutional layer can be obtained.
  • the method provided in the embodiment of the present application may further include: acquiring initial input data and initial weight parameter data of the current convolutional layer.
  • Step S301 includes: performing quantization processing on the initial input data to obtain the input data of the current convolutional layer; performing quantization processing on the initial weight parameter data to obtain the weight parameter data of the current convolution layer.
  • the user can input the initial input data and initial weight parameter data of the current convolutional layer, and the computer device can receive the input initial input data and initial weight parameter data of the current convolutional layer. If the user performs over-processing on the initial input data and initial weight parameter data in advance (at this time, the initial input data and initial weight parameter data can be 8-bit integer data), the initial input data and initial weight parameter data can be directly used as The input data and weight parameter data of the current convolutional layer are processed for subsequent operations.
  • the initial input data and initial weight parameter data are floating-point data, and the initial input data can be quantized to obtain the input of the current convolutional layer Data, the initial weight parameter data is quantized to obtain the weight parameter data of the current convolutional layer, and subsequent calculation processing is performed based on the quantized input data and the weight parameter data.
  • the foregoing process can be implemented by any of several circuits in the computer equipment's CPU, graphics processing unit (GPU), ASIC chip, and field programmable logic gate array (Field Programmable Gate Array, FPGA).
  • the CPU or GPU can obtain the initial input data and initial weight parameter data of the current convolutional layer input by the user, and input the initial input data and initial weight parameter data of the current convolutional layer to the ASIC chip or FPGA. The initial input data and initial weight parameter data are subsequently processed.
  • the ASIC chip or FPGA can directly perform subsequent processing based on the initial input data and initial weight parameter data. If the user does not perform the initial input data and initial weight parameter data in advance
  • the ASIC chip or FPGA can quantize the initial input data to obtain the input data of the current convolutional layer, and quantize the initial weight parameter data to obtain the weight parameter data of the current convolutional layer. The processed input data and weight parameter data are subjected to subsequent calculation processing.
  • the storage space occupied by the quantized input data can be made smaller than the storage space occupied by the input data before quantization, so as to reduce the storage space, reduce the bandwidth occupied by the transmission data, and reduce The complexity of the arithmetic unit in the neural network processor and the purpose of improving the energy consumption ratio of the chip.
  • the initial input data is 32-bit floating point data, which can be recorded as data in FP32 format.
  • a data in FP32 format can be quantized into an 8-bit integer data, which can be recorded as data in INT8 format.
  • quantize a i in FP32 format to INT8 Quantizing factor can be quantified by s a, Equation 1 can be seen by quantitative formula:
  • z is a convolution of the output data of the current layer
  • a i is the initial input floating-point data
  • w i is the initial weight of the float parameter data
  • s a float for the initial input data is quantized
  • the quantization factor used in the process Is the input data after the quantization process
  • s w is the quantization factor used in the quantization process of the floating-point initial weight parameter data
  • It is the weight parameter data after quantization processing.
  • the initial weight parameter data can be quantized to obtain the quantized weight data.
  • the storage space occupied by the quantized weight parameter data can be made smaller than the storage space occupied by the weight parameter data before quantization, thereby reducing storage space, reducing bandwidth occupied by transmission data, and reducing nerves.
  • the weight parameter data may also be floating-point data, which becomes integer data after being quantized.
  • Step S302 Perform winograd processing on the input data to obtain input data to be calculated.
  • winograd processing can also be performed on the input data.
  • Some convolution operations can be implemented in different ways, some of which are more cumbersome, and some of which are relatively simple.
  • the more cumbersome convolution operation can be replaced by the relatively simple convolution operation by equivalent replacement to reduce the number of multiplication operations during the convolution operation.
  • the operation results obtained by the more cumbersome convolution operation or the simpler convolution operation are consistent.
  • Step S303 Perform winograd processing on the weight parameter data.
  • the weight parameter data can also be subjected to winograd processing, and the weight parameter data to be calculated can be obtained by performing winograd processing on the weight parameter data.
  • step S304 the number of data bits of the weight parameter data processed by winograd is reduced, and the weight parameter data after the reduction is quantized to obtain the weight parameter data to be calculated.
  • the number of data bits of the weight parameter data to be calculated is reduced to that of the input data to be calculated.
  • the number of data bits is the same.
  • the hardware requirements for supporting the data to be calculated for calculation will also be reduced, which is conducive to reducing hardware power consumption and hardware volume.
  • Step S305 Perform a convolution operation based on the input data to be calculated and the weight parameter data to be calculated to obtain intermediate output data.
  • the convolutional layer in the neural network model can be provided with multiple input nodes and multiple output nodes. For each output node, it is necessary to multiply and accumulate multiple input nodes and weight parameter data to obtain the output node Data, the data of the input node is the input data.
  • the convolution operation can be performed based on the input data to be calculated and the weight parameter data to be calculated to obtain the intermediate output data. Because the input data and weight parameter data were subjected to over-processing and winograd processing, the intermediate output data also needs to be processed Further processing is performed to make the final output data consistent with the operation result obtained by convolution operation based on the input data and weight parameter data that are not processed by quantization and winograd.
  • Step S306 performing inverse quantization processing on the intermediate output data, performing winograd result transformation processing on the intermediate output data after the inverse quantization processing, to obtain output data of the current convolutional layer.
  • the intermediate output data can be inversely quantized, and then the inverse quantized
  • the processed intermediate output data is subjected to winograd result transformation processing, and the final operation result is the output data of the current convolutional layer.
  • the step of performing inverse quantization processing on the intermediate output data may include performing inverse quantization processing on the intermediate output data based on the quantization factor used in the quantization process.
  • the method for running a neural network model may include the following steps:
  • the size of the weight parameter data is 3 ⁇ 3, and the stride parameter (stride) used in the process of performing the convolution operation is 1.
  • the step of performing winograd result transformation processing on the intermediate output data after dequantization processing may include: performing winograd result transformation processing on the intermediate output data after dequantization processing based on the third transformation matrix; wherein, the first transformation matrix is The second conversion matrix is The third conversion matrix is
  • the input data can be obtained by quantizing the initial input data through the above formula 1, and then the winograd processing can be performed on the input data through the formula 3.
  • the processing process can be seen in FIG. 4.
  • Input data to be calculated B T ⁇ quantized input data ⁇ B (Equation 3)
  • the input data to be calculated is data in INT10 format.
  • the initial weight parameter data can be quantified by formula 4 to obtain the weight parameter data:
  • the weight parameter data can be processed by winograd by formula 5.
  • the processing procedure can be seen in FIG. 5.
  • Weight parameter data to be calculated G ⁇ weight parameter data after quantization ⁇ G T (Equation 5)
  • the weight parameter data obtained is 12-bit data with a decimal point and a sign.
  • the 10-bit data is an integer part
  • the 2-bit data is a decimal part
  • the 10-bit data is an integer part including 1 bit as a sign bit
  • the remaining 9 bits are data bits.
  • the weight parameter data processed by winograd is the highest first preset except the sign bit. Whether the value of the number of data bits is 0, if the value of the highest first preset number of data bits except the sign bit in the weight parameter data processed by winograd is 0, only the weight parameter processed by winograd will be retained.
  • the sign bit in the data and the value on the data bits other than the highest first preset number of data bits are used to obtain the weight parameter data after the reduction.
  • the weight parameter data after the reduction is obtained, and the weight parameter data after the reduction is 8 bits.
  • the sign bit in the weight parameter data processed by winograd and all data bits other than the highest first preset number of data bits are reserved.
  • the data bits all the values of the data bits except the highest first preset number of data bits are set to 1, and the weight parameter data after the reduction is obtained, and the weight parameter data after the reduction is 8 bits.
  • the integer part of the data before derating is "111111110" except for the sign bit.
  • the memory unit used to store the weight parameter data processed by winograd can be pre-configured.
  • a memory unit with 8-bit data as an integer part and 2-bit data as a decimal part can be configured to store the weight parameter data processed by winograd.
  • the 12-bit data with a decimal point and a sign bit will overflow in the above-mentioned memory unit, and finally only the sign in the integer part will be retained. Digits, the value in the lowest 8 digits, and the value in the fractional part.
  • the hardware volume and power consumption of the multiply-accumulator that needs to perform operations can be reduced, but the accuracy of the output data will not be reduced.
  • 10-bit data with a decimal point and a sign bit can be obtained.
  • the 8-bit data is the integer part
  • the 2-bit data is the decimal part.
  • the number of decimal places in the weight parameter data after the reduction can be determined; based on the number of decimal places, the product factor is determined, and the weight parameter data after the reduction is multiplied by the product factor to obtain an integer weight parameter data.
  • the number of decimal places in the weight parameter data is x, and 2 to the power of x can be determined as the product factor.
  • the 10-digit data with decimal point and sign bit can be enlarged four times as a whole, namely Multiply by 4.
  • the quantization factor can be obtained (the quantization factor can be the quantization factor s w used in the quantization process of the initial weight parameter data), and the quantization factor is divided by the product factor to obtain the transformation After the quantization factor, the transformed quantization factor s w can be
  • the quantization factor s w can be divided by 4, namely After enlarging the entire 10-bit data with decimal point and sign bit by four times, it is equivalent to shifting the 10-bit data with decimal point and sign bit to the left by 2 digits, and finally the 10-bit data with decimal point and sign bit is transformed into A 10-bit integer without a decimal point is the data in INT10 format. In the data in INT10 format, 1 bit is the sign bit, and the remaining 9 bits are data bits.
  • the method of obtaining the quantization factor is the prior art, and the quantization factor (usually called scale in English) can be obtained based on different quantization methods.
  • a quantization method is to count the maximum value max and the minimum value. min.
  • the quantization factor (scale) (max-min)/255, because INT8 contains 255 segment steps.
  • the scale that minimizes the total error is the final determined scale.
  • the methods for determining the various quantization factors mentioned above are all in the prior art, and will not be repeated in this application.
  • the input data in the INT10 format and the weight parameter data in the INT10 format can be obtained, and then the convolution operation can be performed based on the input data in the INT10 format and the weight parameter data in the INT10 format to obtain a signed 32-bit integer as an intermediate output data.
  • the intermediate output data may be subjected to inverse quantization processing based on the transformed quantization factor, and then, based on the third transformation matrix, the inverse quantization processing intermediate output data may be subjected to winograd result transformation processing.
  • the intermediate output data after the inverse quantization process can be subjected to winograd result transformation processing by formula 6.
  • the AT , B T , and G transformation matrices used in the processing are determined by the size and step size of the weight parameter data.
  • the AT , B T , and G transformation matrices are sequentially
  • the weight parameter data size is 3 ⁇ 3
  • the input data size is 4 ⁇ 4
  • the step length parameter is 1 for description.
  • the process of winograd processing on input data, weight data, and intermediate output data can be seen in Figure 6.
  • the step of performing a convolution operation based on the input data to be calculated and the weight parameter data to be calculated may include: controlling the multiply accumulator to perform the convolution operation based on the input data to be calculated and the weight parameter data to be calculated, wherein,
  • the multiply-accumulator is a multiply-accumulator that supports convolution of 10-bit integer data.
  • a multiply accumulator array may be provided in the neural network processor, and the multiply accumulator array includes a large number of multiply accumulators (MAC).
  • MAC multiply accumulators
  • the method provided by the embodiment of the present application may further include: acquiring input quantization processing configuration information; the step of performing quantization processing on the initial input data may include: if the quantization processing configuration information is used to indicate convolution in the integer domain Quantize the initial input data; the step of quantizing the initial weight parameter data may include: if the quantization configuration information is the configuration information used to indicate the convolution operation in the integer domain, the initial input data is quantized.
  • the weight parameter data is quantized; the step of quantizing the weight parameter data processed by winograd may include: if the quantization processing configuration information is configuration information for indicating convolution operation in the integer domain, then the weight after winograd processing is performed
  • the user can configure the quantization process, and the user can choose whether to perform quantization on the initial input data and initial weight parameter data, or the user can choose to perform convolution operations in the floating-point domain or in the integer domain.
  • the computer device can obtain the quantitative processing configuration information input by the user. As shown in Figure 7, if the quantization processing configuration information is the configuration information used to instruct the convolution operation in the integer domain, the computer device performs quantization processing on the initial input data, quantization processing on the initial weight parameter data, and after winograd processing The weight parameter data is quantized, and the intermediate output data needs to be dequantized later.
  • the quantization processing configuration information is the configuration information used to indicate the convolution operation in the floating-point domain, skip the quantization processing of the initial input data, the quantization processing of the initial weight parameter data, and the weight parameter data after winograd processing. The steps of quantization and inverse quantization of the intermediate output data.
  • the user can configure the winograd processing process, and the user can choose whether to perform winograd processing on input data and weight parameter data.
  • the computer device can obtain winograd processing configuration information input by the user. As shown in Figure 7, if the winograd processing configuration information is the configuration information used to instruct winograd processing, the computer device performs winograd processing on the input data, performs winograd processing on the weight parameter data, and performs the inverse quantization processing on the intermediate output data. Winograd result conversion processing.
  • the winograd processing configuration information is the configuration information for instructing not to perform winograd processing, skip the winograd processing on the input data, the winograd processing on the weight parameter data, and the winograd result conversion processing on the intermediate output data after the inverse quantization process. A few steps.
  • the user inputs weight parameter data in a floating-point format, and quantizes the input data and weight parameter data to accelerate the calculation process.
  • the user inputs the weight parameter data that has been over-processed, and the neural network processor provides computing capabilities, such as providing integer data with a number of data bits of 10 for convolution operations, and supporting integer data with a number of data bits of 8.
  • the data undergoes convolution operations.
  • the user inputs weight parameter data in a floating-point format, and performs winograd processing on the input data and weight parameter data to accelerate the calculation process.
  • the user inputs the weight parameter data that has been over-processed, and performs winograd processing on the weight parameter data and the input data that have been over-processed, so as to further accelerate the calculation process.
  • the user inputs the weight parameter data in a floating-point format, and further accelerates the calculation process by performing quantization processing and winograd processing on the input data and the weight parameter data.
  • the quantized input data and weight parameter data are processed by winograd, so that the processed input data and weight parameter data are convenient for convolution operation in the device, and the operation of the current convolution layer is improved.
  • Speed can ultimately achieve the goal of improving the running speed of the entire neural network model.
  • the device includes:
  • the acquisition circuit 801 is used to acquire the input data and weight parameter data of the current convolutional layer, and can specifically implement the acquisition function in the above step S301 and other implicit steps.
  • the first processing circuit 802 is configured to perform winograd processing on the input data to obtain input data to be calculated; perform winograd processing on the weight parameter data; reduce the number of data bits of the weight parameter data after winograd processing, and lower the bit
  • the latter weight parameter data is subjected to quantization processing to obtain the weight parameter data to be calculated, which can specifically implement the data processing functions in steps S302, S303, and S304, as well as other implicit steps.
  • the convolution circuit 803 is configured to perform a convolution operation based on the input data to be calculated and the weight parameter data to be calculated to obtain intermediate output data, which can specifically implement the convolution function in step S305 above, and other implications step.
  • the second processing circuit 804 is configured to perform inverse quantization processing on the intermediate output data; perform winograd result transformation processing on the intermediate output data after the inverse quantization processing to obtain the output data of the current convolutional layer, which can specifically implement the above steps The data processing function in S306, and other implicit steps.
  • the acquisition circuit 801, the first processing circuit 802, the convolution circuit 803, and the second processing circuit 804 may be implemented by hardware circuits.
  • the quantized input data and weight parameter data are processed by winograd, so that the processed input data and weight parameter data are convenient for convolution operation in the device, and the operation of the current convolution layer is improved.
  • Speed can ultimately achieve the goal of improving the running speed of the entire neural network model.
  • the device for running a neural network model provided by the foregoing embodiment belongs to the same concept as the embodiment of the method for running a neural network model.
  • the specific implementation process please refer to the method embodiment, which will not be repeated here.
  • the computer device may include a processor 910 and an apparatus 920 for running a neural network model.
  • the processor 910 may obtain the input data and weight parameter data of the current convolution layer input by the user, and transmit the input data and weight parameter data of the current convolution layer to the device 920 running the neural network model.
  • the specific manner in which each circuit performs the operation has been described in detail in the embodiment of the method, and detailed description will not be given here.
  • the computer may be implemented in whole or in part by software, hardware, firmware, or any combination thereof.
  • a software program it can be implemented in the form of a computer product in whole or in part.
  • the computer program product includes one or more computer instructions.
  • the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium.
  • the computer instructions may be transmitted from a website, computer, server, or data center.
  • the computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center integrated with one or more available media.
  • the usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • General Health & Medical Sciences (AREA)
  • General Physics & Mathematics (AREA)
  • Evolutionary Computation (AREA)
  • Computational Linguistics (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Artificial Intelligence (AREA)
  • Neurology (AREA)
  • Image Analysis (AREA)
  • Complex Calculations (AREA)
  • Image Processing (AREA)

Abstract

一种运行神经网络模型的方法、装置和计算机设备,属于人工智能技术领域。所述方法包括:获取当前卷积层的输入数据和权重参数数据(S301);对输入数据进行winograd处理(S302);对权重参数数据进行winograd处理(S303);降低winograd处理后的权重参数数据的数据位数目,对降位后的权重参数数据进行量化处理(S304);基于待运算的输入数据和待运算的权重参数数据进行卷积运算(S305);对中间输出数据进行反量化处理;对反量化处理后的中间输出数据进行winograd结果变换处理,得到当前卷积层的输出数据(S306)。提高卷积层的运算速度,最终可以实现提高整个神经网络模型的运行速度的目的。

Description

运行神经网络模型的方法、装置和计算机设备
本申请要求于2019年10月18日提交的申请号为201910996290.2、发明名称为“运行神经网络模型的方法、装置和计算机设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请是关于人工智能技术领域,尤其是关于一种运行神经网络模型的方法、装置和计算机设备。
背景技术
当今人工智能技术的发展离不开神经网络(Neural Networks,NN)技术的发展,神经网络是由大量的、简单的神经元广泛地互相连接而形成的复杂网络系统。一个神经网络模型可以由多个网络层构成,典型的网络层可以包括卷积层(Convolution,Conv)、池化层(Pooling)、全连接层(Full Connection,FC)等。不同类型的网络层涉及的运算类型不同,对于卷积层来说,需要基于输入数据和权重参数进行卷积运算。卷积运算的具体运算过程较为繁琐,在进行卷积运算时需要做较多次的乘累加操作。在实际应用中,单个卷积层就需要做百万甚至千万次的累加乘操作,单个卷积层的运行速度就已经比较慢了,而神经网络模型一般包括多个卷积层,整个神经网络模型的运行速度极慢。
发明内容
为了克服相关技术中存在的问题,本申请提供了以下技术方案:
根据本申请实施例的第一方面,提供一种运行神经网络模型的方法,所述方法包括:
获取当前卷积层的输入数据和权重参数数据;
对所述输入数据进行winograd处理,得到待运算的输入数据;
对所述权重参数数据进行winograd处理;
降低winograd处理后的权重参数数据的数据位数目,对降位后的权重参数数据进行量化处理,得到待运算的权重参数数据;
基于所述待运算的输入数据和所述待运算的权重参数数据进行卷积运算,得到中间输出数据;
对所述中间输出数据进行反量化处理;
对反量化处理后的中间输出数据进行winograd结果变换处理,得到所述当前卷积层的输出数据。
通过本申请实施例提供的方法,通过对量化后的输入数据、权重参数数据进行winograd处理,使得处理后的输入数据、权重参数数据便于在设备中进行卷积运算,提高当前卷积层的运算速度,最终可以实现提高整个神经网络模型的运行速度的目的。同时,本申请中通过 对权重参数数据的数据位数目进行降位,可以使得用于支持待运算的数据进行运算的硬件(如乘法器)的要求也会降低,有利于降低硬件的功耗和硬件体积。
在一种可能的实现方式中,所述winograd处理后的权重参数数据为带符号位的定点型的数据,所述降低winograd处理后的权重参数数据的数据位数目,包括:
如果所述winograd处理后的权重参数数据中除了符号位之外的最高预设数目个数据位的数值都是0,则保留所述winograd处理后的权重参数数据中的所述符号位以及除了所述最高预设数目个数据位之外的数据位上的数值,得到降位后的权重参数数据;或者,
如果所述最高预设数目个数据位中的任一数据位的数值是1,则保留所述winograd处理后的权重参数数据中的所述符号位以及除了所述最高预设数目个数据位之外的数据位,将所述除了所述最高预设数目个数据位之外的数据位的数值都设置为1,得到降位后的权重参数数据。
可以预先配置用于存储winograd处理后的权重参数数据的内存单元,例如配置使用8位数据为整数部分且2位数据为小数部分共10位的内存单元来存储winograd处理后的权重参数数据,这样在进行winograd处理之后,即使结果实际为12位带小数点的数据,该12位带小数点的数据在上述内存单元中也会溢出,最终只保留下整数部分中最低8位上的数值以及小数部分的数值。
在实际应用中,即使整数部分中除符号位之外的高2位上的数据不是00,但是由于神经网络模型整体极其复杂,进行运算的权重参数数据的数目繁多,因此直接舍去整数部分中除符号位之外最高2位上的数值,通过降位后的权重参数数据进行卷积运算,对神经网络模型最终输出数据的精度的影响也甚微。
通过降低winograd处理后的权重参数数据的数据位数目以及对降位后的权重参数数据进行量化处理,使得待运算的权重参数数据的数据位数目降低至和待运算的输入数据的数据位数目一致,同时当待运算的数据的数据位数目比较低时,用于支持待运算的数据进行运算的硬件的要求也会降低,有利于降低硬件的功耗和硬件体积。
在一种可能的实现方式中,所述降位后的权重参数数据为带符号位的定点型的数据;
所述对降位后的权重参数数据进行量化处理,包括:
确定所述降位后的权重参数数据中小数位数目;
基于所述小数位数目,确定乘积因子;
将所述降位后的权重参数数据乘以所述乘积因子,得到整数型的权重参数数据;
所述对所述中间输出数据进行反量化处理,包括:
获取量化因子;
将所述量化因子除以所述乘积因子,得到变换后的量化因子;
基于所述变换后的量化因子,对所述中间输出数据进行反量化处理。
实际应用中,量化过程中可以通过乘积因子将定点型的权重参数数据整体扩大,为了保证量化处理前后权重参数数据的值不变,可以获取量化因子,将量化因子除以乘积因子,得到变换后的量化因子,基于变换后的量化因子对中间输出数据进行反量化处理,以最终保持输出结果的一致性。
在一种可能的实现方式中,所述基于所述小数位数目,确定乘积因子,包括:
将2的所述小数位数目次幂,确定为乘积因子。
权重参数数据中小数位数目为x,可以将2的x次幂,确定为乘积因子。
在一种可能的实现方式中,所述量化因子为对初始权重参数数据进行量化处理的过程中使用的量化因子。
对初始权重参数数据进行量化处理的过程中使用的量化因子可以是s w,变换后的量化因子s w可以是
Figure PCTCN2020121896-appb-000001
在一种可能的实现方式中,所述当前卷积层的输入数据和权重参数数据分别为8位整数型的数据,所述待运算的输入数据为10位整数型的数据,所述winograd处理后的权重参数数据的整数部分为10位且小数部分为2位,所述待运算的权重参数数据为10位整数型的数据。8位整数型的当前卷积层的输入数据和权重参数数据,可以是用户已量化好的数据,也可以是经过本申请提供的系统进行量化处理后得到的数据,这些数据是比较常见的格式,易于基于现有的技术实现,降低了开发成本。
在一种可能的实现方式中,所述基于所述待运算的输入数据和所述待运算的权重参数数据进行卷积运算,包括:
控制乘累加器基于所述待运算的输入数据和所述待运算的权重参数数据进行卷积运算,其中,所述乘累加器为支持10位整数型的数据进行卷积运算的乘累加器。
由于数据位数目降低,因此需要执行运算的乘累加器的硬件体积、功耗都可以随之降低,但是输出数据的精度不会降低。
在一种可能的实现方式中,在获取当前卷积层的输入数据和权重参数数据之前,所述方法还包括:
获取当前卷积层的初始输入数据和初始权重参数数据;
所述获取当前卷积层的输入数据和权重参数数据,包括:
对所述初始输入数据进行量化处理,得到所述当前卷积层的输入数据;
对所述初始权重参数数据进行量化处理,得到所述当前卷积层的权重参数数据。
如果用户已对当前卷积层的输入数据和权重参数数据进行过量化处理,则当前卷积层的输入数据和权重参数数据为量化后的数据,可以直接对当前卷积层的输入数据和权重参数数据进行winograd处理,如果用户未对当前卷积层的输入数据和权重参数数据进行过量化处理,则当前卷积层的输入数据和权重参数数据为浮点型的数据,可以先对初始输入数据和初始权重参数数据进行量化处理,再进行winograd处理。
在一种可能的实现方式中,所述方法还包括:
获取输入的量化处理配置信息;
所述对所述初始输入数据进行量化处理,包括:
如果所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对所述初始输入数据进行量化处理;
所述对所述初始权重参数数据进行量化处理,包括:
如果所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对所述初始权重参数数据进行量化处理;
所述对降位后的权重参数数据进行量化处理,包括:
如果所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对降位后 的权重参数数据进行量化处理;
所述对所述中间输出数据进行反量化处理,包括:
如果所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对所述中间输出数据进行反量化处理。
用户可以对量化处理过程进行配置,用户可以选择是否需要对输入数据、权重参数数据进行量化处理,或者用户可以选择在浮点域还是在整数域进行卷积运算。通过用户的配置,可以灵活选择是否对卷积运算过程中使用的数据进行量化处理。
在一种可能的实现方式中,所述方法还包括:
获取输入的winograd处理配置信息;
所述对所述输入数据进行winograd处理,包括:
如果所述winograd处理配置信息是用于指示进行winograd处理的配置信息,则对所述输入数据进行winograd处理;
所述对所述权重参数数据进行winograd处理,包括:
如果所述winograd处理配置信息是用于指示进行winograd处理的配置信息,则对所述权重参数数据进行winograd处理;
所述对反量化处理后的中间输出数据进行winograd结果变换处理,包括:
如果所述winograd处理配置信息是用于指示进行winograd处理的配置信息,则对反量化处理后的中间输出数据进行winograd结果变换处理。
用户可以对winograd处理过程进行配置,用户可以选择是否需要对输入数据、权重参数数据进行winograd处理。通过用户的配置,可以灵活选择是否对卷积运算过程中使用的数据进行winograd处理。
在一种可能的实现方式中,所述权重参数数据的尺寸为3×3,进行卷积运算的过程中使用的步长参数为1;
所述对所述输入数据进行winograd处理,包括:
基于第一转换矩阵,对所述输入数据进行winograd处理;
所述对所述权重参数数据进行winograd处理,包括:
基于第二转换矩阵,对所述权重参数数据进行winograd处理;
所述对反量化处理后的中间输出数据进行winograd结果变换处理,包括:
基于第三转换矩阵,对反量化处理后的中间输出数据进行winograd结果变换处理;
其中,所述第一转换矩阵为
Figure PCTCN2020121896-appb-000002
所述第二转换矩阵为
Figure PCTCN2020121896-appb-000003
所述第三转换矩阵为
Figure PCTCN2020121896-appb-000004
在对输入数据进行winograd处理的过程中,可以通过等价替换的方式,将方式比较繁琐的卷积运算替换为方式比较简单的卷积运算,以减少卷积运算过程中进行乘法运算的次数,但是对于相同运算数据,通过方式比较繁琐的卷积运算或者方式比较简单的卷积运算得到的运算结果都是一致的。
根据本申请实施例的第二方面,提供了一种运行神经网络模型的装置,该装置包括至少一个电路,该至少一个电路用于实现上述第一方面所提供的运行神经网络模型的方法。
根据本申请实施例的第三方面,提供了一种计算机设备,该计算机设备包括处理器和第二方面所提供的运行神经网络模型的装置。
根据本申请实施例的第四方面,提供了一种计算机可读存储介质,包括指令,当所述计算机可读存储介质在计算机设备上运行时,使得所述计算机设备执行上述第一方面所述的方法。
根据本申请实施例的第五方面,提供了一种包含指令的计算机程序产品,当所述计算机程序产品在计算机设备上运行时,使得所述计算机设备执行上述第一方面所述的方法。
本申请的实施例提供的技术方案可以包括以下有益效果:
通过本申请实施例提供的方法,通过对量化后的输入数据、权重参数数据进行winograd处理,使得处理后的输入数据、权重参数数据便于在设备中进行卷积运算,提高当前卷积层的运算速度,最终可以实现提高整个神经网络模型的运行速度的目的。
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本申请。
附图说明
此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本申请的实施例,并与说明书一起用于解释本申请的原理。在附图中:
图1是根据一示例性实施例示出的一种计算机设备的结构示意图;
图2是根据一示例性实施例示出的一种神经网络处理器的结构示意图;
图3是根据一示例性实施例示出的一种运行神经网络模型的方法的流程示意图;
图4是根据一示例性实施例示出的一种对输入数据进行winograd处理的示意图;
图5是根据一示例性实施例示出的一种对权重参数数据进行winograd处理的示意图;
图6是根据一示例性实施例示出的一种winograd处理的流程示意图;
图7是根据一示例性实施例示出的一种运行神经网络模型的方法的流程示意图;
图8是根据一示例性实施例示出的一种运行神经网络模型的装置的结构示意图;
图9是根据一示例性实施例示出的一种计算机设备的结构示意图。
通过上述附图,已示出本申请明确的实施例,后文中将有更详细的描述。这些附图和文字描述并不是为了通过任何方式限制本申请构思的范围,而是通过参考特定实施例为本领域技术人员说明本申请的概念。
具体实施方式
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述 的实施方式并不代表与本申请相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本申请的一些方面相一致的装置和方法的例子。
本申请实施例提供了一种运行神经网络模型的方法,该方法可以由计算机设备实现。计算机设备的一种结构示意图如图1所示,计算机设备中可以设置有处理器(Central Processing Unit,CPU)、神经网络处理器和内存(Memory)。处理器和神经网络处理器可以位于同一个片上系统(System on Chip,SoC),处理器、神经网络处理器和Memory之间可以通过AXI(Advanced eXtensible Interface,一种总线协议)总线进行电性连接。处理器可以通过AXI总线控制神经网络处理器启动运算处理,当神经网络处理器接收到处理器发送的用于指示启动运算处理的控制指令时,可以从内存中读取图像数据和权重参数数据,在神经网络处理器中基于图像数据和权重参数数据进行运算处理。在神经网络处理器完成运算处理之后,得到输出数据,并将输出数据再通过AXI总线写回到Memory中,神经网络处理器还可以向处理器发送用于指示运算处理执行完毕的指示信息。
本申请实施例提供的一种运行神经网络模型的方法可以在上述计算机设备中设置的神经网络处理器中实现,神经网络处理器可以作为单独的一个电性元件,也可以集成到SoC芯片中,或者可以集成到特殊应用集成电路(Application Specific Integrated Circuit,ASIC)芯片中。计算机设备可以智能手机、视频监控器、车载智能终端等。
本申请实施例提供的神经网络处理器的结构可见图2所示,神经网络处理器可以包括核心计算引擎、数据缓冲器(Buffer)、参数缓冲器、专用线性处理器引擎、输出控制模块和控制模块。其中,核心计算引擎用于进行神经网络模型中的卷积层和全连接层的相关运算,将运算结果发送到输出控制模块中。数据缓冲器用于存储运算过程中需要使用的数据(如用户输入的图像数据),数据缓冲器可以将存储的数据发送至核心计算引擎或者专用线性处理器引擎。参数缓冲器用于存储运算过程中需要使用的权重参数数据,将存储的权重参数数据发送至核心计算引擎或者专用线性处理器引擎。专用线性处理引擎用于进行神经网络模型中的除了卷积层和全连接层之外的网络层的相关运算,将运算结果发送到输出控制模块中。输出控制模块用于接收运算结果,通过AXI总线将运算结果发送至Memory。控制模块用于控制上述核心计算引擎、数据缓冲器、参数缓冲器、专用线性处理器引擎、输出控制模块等进行有序运行。
可以通过设置有神经网络处理器的计算机设备对图像数据进行识别,在不同领域识别不同图像数据有不同的意义,但是都可以依靠计算机设备完成对图像数据进行识别的过程。计算机设备中预先存储有训练好的神经网络模型,可以通过训练好的神经网络模型对图像数据进行识别,在训练好的神经网络模型对图像数据进行识别的过程中,需要在计算机设备中运行神经网络模型。本申请实施例以视频监控领域为例进行说明,其他领域的情况类似,不再一一进行举例。
为了便于对本申请的理解,下面对本申请中涉及的winograd算法进行说明:
winograd算法原理,即对于卷积运算通过等价替换,减少乘法的次数,以节省运算时间,同时保持输出结果不变。
具体的,对于卷积运算中的输入数据d,通过变换矩阵B,转换为n*n的矩阵,对于权重参数数据g,通过变换矩阵G,同样转换为n*n的矩阵。然后,对于转换后的两个n*n的矩阵进行点积,得到中间输出数据,再通过转换矩阵A对中间输出数据进行转换,得到与上 述卷积运算相同的输出数据。对于上述处理过程可以表示为如下公式:Y=A T[[GgG T]⊙[B TdB]]A,其中,A T、B T、G T分别为转换矩阵A、B、G的转置矩阵,⊙为点乘运算符号,Y为输出数据。
此外,还需说明的是,权重参数数据的尺寸、步长参数均相同的卷积运算,在做winograd处理时对应同一组转换矩阵A、B、G。
本申请一示例性实施例提供了一种运行神经网络模型的方法,如图3所示,该方法的处理流程可以包括如下的步骤:
步骤S301,获取当前卷积层的输入数据和权重参数数据。
在实施中,用户可以在家里安装视频监控器,当开启视频监控器的人物识别功能之后,视频监控器可以实时录制家里的环境视频,视频监控器可以对环境视频中的每个视频帧进行识别。当在任一视频帧中识别出人物图像之后,可以向用户绑定的终端推送识别结果。
完成单个视频帧的识别过程需要消耗一定时长,在实际应用中希望消耗的时长不高于录制单个视频帧所需时长,同时希望识别的准确率能够满足用户期望。向神经网络模型输入一个视频帧,神经网络模型识别该视频帧中是否存在人物图像,且如果存在人物图像,神经网络模型还需要标注出人物图像在视频帧中的位置,这个过程可以在神经网络处理器中完成。
视频监控器录制一个视频帧,将该视频帧存储到Memory中。处理器向神经网络处理器发送用于指示启动运算处理的控制指令,神经网络处理器从Memory中读取该视频帧。
在神经网络处理器中,该视频帧可以作为神经网络模型的第一个网络层即输入层的输入数据,通过第一个网络层对输入数据进行处理,得到第一个网络层的输出数据。前一个网络层的输出数据可以作为下一个网络层的输入数据。神经网络模型可以包括多个网络层,多个网络层可以包括输入层、卷积层、池化层、全连接层、输出层等。可以判断当前运行到的网络层是否是卷积层,如果当前运行到的网络层是卷积层,则将当前卷积层的前一个网络层的输出数据作为当前卷积层的输入数据,同时可以获取当前卷积层的权重参数数据。
可选地,在执行步骤S301之前,本申请实施例提供的方法还可以包括:获取当前卷积层的初始输入数据和初始权重参数数据。步骤S301包括:对初始输入数据进行量化处理,得到当前卷积层的输入数据;对初始权重参数数据进行量化处理,得到当前卷积层的权重参数数据。
在实施中,用户可以输入当前卷积层的初始输入数据和初始权重参数数据,计算机设备可以接收输入的当前卷积层的初始输入数据和初始权重参数数据。如果用户预先对初始输入数据和初始权重参数数据进行过量化处理(此时初始输入数据和初始权重参数数据可以是8位整数型的数据),则可以将初始输入数据和初始权重参数数据直接作为当前卷积层的输入数据和权重参数数据,进行后续运算处理。如果用户预先未对初始输入数据和初始权重参数数据进行过量化处理,则初始输入数据和初始权重参数数据为浮点型的数据,可以对初始输入数据进行量化处理,得到当前卷积层的输入数据,对初始权重参数数据进行量化处理,得到当前卷积层的权重参数数据,基于经过量化处理的输入数据和权重参数数据进行后续运算处理。
上述过程可以由计算机设备的CPU、图像处理器(Graphics Processing Unit,GPU)、ASIC芯片、现场可编程逻辑门阵列(Field Programmable Gate Array,FPGA)中任几个电路实现。例如,CPU或者GPU可以获取用户输入的当前卷积层的初始输入数据和初始权重参数数据, 向ASIC芯片或者FPGA输入当前卷积层的初始输入数据和初始权重参数数据,由ASIC芯片或者FPGA基于初始输入数据和初始权重参数数据进行后续处理。
如果用户预先对初始输入数据和初始权重参数数据进行过量化处理,则ASIC芯片或者FPGA可以直接基于初始输入数据和初始权重参数数据进行后续处理,如果用户预先未对初始输入数据和初始权重参数数据进行过量化处理,则ASIC芯片或者FPGA可以对初始输入数据进行量化处理,得到当前卷积层的输入数据,对初始权重参数数据进行量化处理,得到当前卷积层的权重参数数据,基于经过量化处理的输入数据和权重参数数据进行后续运算处理。
通过对初始输入数据进行量化(Quantization)处理的过程,可以使量化处理后的输入数据占用的存储空间小于量化前的输入数据占用的存储空间,从而达到降低存储空间、降低传输数据占用带宽以及降低神经网络处理器中运算单元的复杂度、提高芯片能耗比的目的。
在一种可能的实现方式中,初始输入数据为32位浮点型数据,可以记为FP32格式的数据。可以将一个FP32格式的数据量化为一个8位整数型数据,可以记为INT8格式的数据。例如,将FP32格式的a i量化为INT8格式的
Figure PCTCN2020121896-appb-000005
可以通过量化因子s a进行量化,量化公式可见公式1:
Figure PCTCN2020121896-appb-000006
如果将1024个FP32格式的数据量化为INT8格式的数据,则原始1024个FP32格式的数据需要占用4096Byte的存储空间,可以降为占用1028Byte的存储空间。1028Byte的存储空间中有1024Byte的存储空间是用于存储INT8格式的数据的,有4Byte的存储空间是用于存储FP32格式的量化因子的。此时一个卷积层的输出数据z的计算公式可见公式2:
Figure PCTCN2020121896-appb-000007
其中,z为当前卷积层的输出数据,a i为浮点型的初始输入数据,w i为浮点型的初始权重参数数据,s a为对浮点型的初始输入数据进行量化处理的过程中使用的量化因子,
Figure PCTCN2020121896-appb-000008
为量化处理后的输入数据,s w为对浮点型的初始权重参数数据进行量化处理的过程中使用的量化因子,
Figure PCTCN2020121896-appb-000009
为量化处理后的权重参数数据。
基于相似的方式,可以对初始权重参数数据进行量化处理,得到量化处理后的权重数据。通过对权重参数数据进行量化处理的过程,可以使量化处理后的权重参数数据占用的存储空间小于量化前的权重参数数据占用的存储空间,从而达到降低存储空间、降低传输数据占用带宽以及降低神经网络处理器中运算单元的复杂度、提高芯片能耗比的目的。权重参数数据也可以是浮点型的数据,在经过量化处理之后变为整数型的数据。
步骤S302,对输入数据进行winograd处理,得到待运算的输入数据。
在实施中,在得到量化处理后的输入数据之后,还可以对输入数据进行winograd处理,某些卷积运算是可以通过不同方式实现的,有的方式比较繁琐,有的方式则比较简单。在对输入数据进行winograd处理的过程中,可以通过等价替换的方式,将方式比较繁琐的卷积运算替换为方式比较简单的卷积运算,以减少卷积运算过程中进行乘法运算的次数,但是对于相同运算数据,通过方式比较繁琐的卷积运算或者方式比较简单的卷积运算得到的运算结果都是一致的。通过对输入数据进行winograd处理,可以得到待运算的权重参数数据。
步骤S303,对权重参数数据进行winograd处理。
在实施中,在得到量化处理后的权重数据之后,还可以对权重参数数据进行winograd处 理,通过对权重参数数据进行winograd处理,可以得到待运算的权重参数数据。
步骤S304,降低winograd处理后的权重参数数据的数据位数目,对降位后的权重参数数据进行量化处理,得到待运算的权重参数数据。
在实施中,通过降低winograd处理后的权重参数数据的数据位数目以及对降位后的权重参数数据进行量化处理,使得待运算的权重参数数据的数据位数目降低至和待运算的输入数据的数据位数目一致,同时当待运算的数据的数据位数目比较低时,用于支持待运算的数据进行运算的硬件的要求也会降低,有利于降低硬件的功耗和硬件体积。步骤S304的具体实现方式会在本文后面进行详细介绍,在此暂不赘述。
步骤S305,基于待运算的输入数据和待运算的权重参数数据进行卷积运算,得到中间输出数据。
在实施中,神经网络模型中的卷积层中可以设置有多个输入节点和多个输出节点,对于每个输出节点,需要通过多个输入节点和权重参数数据进行乘累加运算得到输出节点的数据,输入节点的数据为输入数据。可以基于待运算的输入数据和待运算的权重参数数据进行卷积运算,得到中间输出数据,由于前面对输入数据、权重参数数据进行过量化处理和winograd处理,因此还需要对中间输出数据进行进一步处理,以让最终输出数据和基于不经过量化处理和winograd处理的输入数据、权重参数数据进行卷积运算得出的运算结果一致。
步骤S306,对中间输出数据进行反量化处理,对反量化处理后的中间输出数据进行winograd结果变换处理,得到当前卷积层的输出数据。
在实施中,如果先对输入数据或者权重参数数据进行量化处理,然后再对量化处理后的数据进行winograd处理,则在此步骤中可以先对中间输出数据进行反量化处理,然后再对反量化处理后的中间输出数据进行winograd结果变换处理,最终得到的运算结果即为当前卷积层的输出数据。对中间输出数据进行反量化处理的步骤可以包括基于量化处理过程中使用的量化因子,对中间输出数据进行反量化处理。
可选地,本申请实施例提供的一种运行神经网络模型的方法可以包括以下步骤:
(1)对初始输入数据进行量化处理,得到输入数据。
(2)对输入数据进行winograd处理,得到待运算的输入数据。
(3)对初始权重参数数据进行量化处理,得到权重参数数据。
(4)对权重参数数据进行winograd处理。
(5)降低winograd处理后的权重参数数据的数据位数目,对降位后的权重参数数据进行量化处理,得到待运算的权重参数数据。
(6)基于待运算的输入数据和待运算的权重参数数据进行卷积运算,得到中间输出数据。
(7)对中间输出数据进行反量化处理。
(8)对反量化处理后的中间输出数据进行winograd结果变换处理,得到当前卷积层的输出数据。
可以在核心计算引擎中完成上述操作步骤。可选地,权重参数数据的尺寸为3×3,进行卷积运算的过程中使用的步长参数(stride)为1。对输入数据进行winograd处理的步骤可以包括:基于第一转换矩阵,对输入数据进行winograd处理;对权重参数数据进行winograd处理的步骤可以包括:基于第二转换矩阵,对权重参数数据进行winograd处理;对反量化处理后的中间输出数据进行winograd结果变换处理的步骤可以包括:基于第三转换矩阵,对反 量化处理后的中间输出数据进行winograd结果变换处理;其中,第一转换矩阵为
Figure PCTCN2020121896-appb-000010
第二转换矩阵为
Figure PCTCN2020121896-appb-000011
第三转换矩阵为
Figure PCTCN2020121896-appb-000012
可以通过上述公式1对初始输入数据进行量化处理得到输入数据,接着,可以通过公式3对输入数据进行winograd处理,处理过程可见图4所示。
待运算的输入数据=B T×量化处理后的输入数据×B   (公式3)
此时,如果输入数据为INT8格式的数据,则待运算的输入数据为INT10格式的数据。
在对权重参数数据进行处理时,首先可以通过公式4对初始权重参数数据进行量化处理,得到权重参数数据:
Figure PCTCN2020121896-appb-000013
接着,在得到权重参数数据之后,可以通过公式5对权重参数数据进行winograd处理,处理过程可见图5所示。
待运算的权重参数数据=G×量化处理后的权重参数数据×G T   (公式5)
此时,如果输入数据为INT8格式的数据,且权重参数数据也是INT8格式的数据(其中INT8格式的数据中1位为符号位,其余7位为数据位),则在对权重参数数据进行winograd处理后,得到的权重参数数据为12位带小数点且带符号的数据。12位带小数点且带符号位的数据中的10位数据为整数部分,2位数据为小数部分,10位数据为整数部分中包括1位为符号位,其余9位为数据位。
对于整数部分的10位数据中除了符号位之外的高2位上的数据,存在很大概率为00,因此可以判断winograd处理后的权重参数数据中除了符号位之外的最高第一预设数目个数据位的数值是否都是0,如果winograd处理后的权重参数数据中除了符号位之外的最高第一预设数目个数据位的数值都是0,则只保留winograd处理后的权重参数数据中的符号位以及除了最高第一预设数目个数据位之外的数据位上的数值,得到降位后的权重参数数据。例如,只保留winograd处理后的权重参数数据的整数部分中最低7位上的数值以及符号位,得到降位后的权重参数数据,降位后的权重参数数据为8位。或者,如果最高第一预设数目个数据位中的任一数据位的数值是1,则保留winograd处理后的权重参数数据中的符号位以及除了最高第一预设数目个数据位之外的数据位,将除了最高第一预设数目个数据位之外的数据位的数值都设置为1,得到降位后的权重参数数据,降位后的权重参数数据为8位。例如,降位前的数据整数部分中除了符号位之外为“111111110”,可以只保留winograd处理后的权重参数数据的整数部分中最低7位,将winograd处理后的权重参数数据的整数部分中最低7位的数值都设置为1。在实际应用中,即使整数部分中除符号位之外的高2位上的数据不是00,但是由于神经网络模型整体极其复杂,进行运算的权重参数数据的数目繁多,因此直接舍去整数部分中除符号位之外最高2位上的数值,通过降位后的权重参数数据进行卷积运算,对 神经网络模型最终输出数据的精度的影响也甚微。
可以预先配置用于存储winograd处理后的权重参数数据的内存单元,例如配置使用8位数据为整数部分且2位数据为小数部分共10位的内存单元来存储winograd处理后的权重参数数据,这样在进行winograd处理之后,即使结果实际为12位带小数点且带符号位的数据,该12位带小数点且带符号位的数据在上述内存单元中也会溢出,最终只保留下整数部分中的符号位、最低8位上的数值以及小数部分的数值。由于数据位数目降低,因此需要执行运算的乘累加器的硬件体积、功耗都可以随之降低,但是输出数据的精度不会降低。
通过上述操作可以得到10位带小数点且带符号位的数据,10位带小数点且带符号位的数据中的8位数据为整数部分,2位数据为小数部分。可选地,为了去除小数部分,可以确定降位后的权重参数数据中小数位数目;基于小数位数目,确定乘积因子,将降位后的权重参数数据乘以乘积因子,得到整数型的权重参数数据。实际应用中,权重参数数据中小数位数目为x,可以将2的x次幂,确定为乘积因子。可以将10位带小数点且带符号位的数据整体扩大四倍,即将
Figure PCTCN2020121896-appb-000014
乘以4。为了保证量化处理前后w i的值不变,可以获取量化因子(量化因子可以是对初始权重参数数据进行量化处理的过程中使用的量化因子s w),将量化因子除以乘积因子,得到变换后的量化因子,变换后的量化因子s w可以是
Figure PCTCN2020121896-appb-000015
实际应用中,可以将量化因子s w除以4,即
Figure PCTCN2020121896-appb-000016
在将10位带小数点且带符号位的数据整体扩大四倍之后,相当于将10位带小数点且带符号位的数据左移2位,最终10位带小数点且带符号位的数据就变换为10位不带小数点的整数,即INT10格式的数据,INT10格式的数据中1位为符号位,其余9位为数据位。
本申请中,量化因子的获取方式为现有技术,可以基于不同的量化方式来获取量化因子(在英文中通常也被称为scale),例如,一种量化方法是统计最大值max,最小值min,比如需要进行8bit量化的话,量化因子(scale)=(max-min)/255,因为INT8包含255个分段台阶。或者也可以通过其他的方法再确定多个候选scale,然后计算x_float-x_q*scale的误差(x_float为一个浮点数,x_q为一个定点数),统计整个张量(tensor)所有个点的误差总和,使得误差总和最小的scale,就是最后的确定的scale。上述各种量化因子的确定方法都为现有技术本申请不再赘述。
通过上述步骤可以得到INT10格式的输入数据和INT10格式的权重参数数据,接着可以基于INT10格式的输入数据和INT10格式的权重参数数据进行卷积运算,得到带符号位的32位整数,作为中间输出数据。
在得到中间输出数据之后,可以基于变换后的量化因子,对中间输出数据进行反量化处理,接着,可以基于第三转换矩阵,对反量化处理后的中间输出数据进行winograd结果变换处理。可以通过公式6对反量化处理后的中间输出数据进行winograd结果变换处理。
输出数据=A T×反量化后的中间输出数据×A    (公式6)
对输入数据和权重数据进行winograd处理时,处理过程中使用的A T、B T、G变换矩阵是和权重参数数据的尺寸、步长参数决定的。在尺寸为3×3的权重参数数据、步长参数为1 的情况下,A T、B T、G变换矩阵依次为
Figure PCTCN2020121896-appb-000017
Figure PCTCN2020121896-appb-000018
以权重参数数据的尺寸为3×3、输入数据的尺寸为4×4、步长参数为1进行说明,对输入数据、权重数据、中间输出数据进行winograd处理的过程可见图6所示。
可选地,基于待运算的输入数据和待运算的权重参数数据进行卷积运算的步骤可以包括:控制乘累加器基于待运算的输入数据和待运算的权重参数数据进行卷积运算,其中,乘累加器为支持10位整数型的数据进行卷积运算的乘累加器。
在实施中,在神经网络处理器中可以设置有乘累加器阵列,乘累加器阵列中包括大量的乘累加器(Multiply Accumulate,MAC)。在本申请实施例中,如果需要基于INT10格式的输入数据和INT10格式的权重参数数据进行卷积运算,则可以选用包括支持数据位数目为10的整数型的数据进行卷积运算的乘累加器的神经网络处理器完成卷积运算。
可选地,本申请实施例提供的方法还可以包括:获取输入的量化处理配置信息;对初始输入数据进行量化处理的步骤可以包括:如果量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对初始输入数据进行量化处理;对初始权重参数数据进行量化处理的步骤可以包括:如果量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对初始权重参数数据进行量化处理;对winograd处理后的权重参数数据进行量化处理的步骤可以包括:如果量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对winograd处理后的权重参数数据进行量化处理;对中间输出数据进行反量化处理的步骤可以包括:如果量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对中间输出数据进行反量化处理。
在实施中,用户可以对量化处理过程进行配置,用户可以选择是否需要对初始输入数据、初始权重参数数据进行量化处理,或者用户可以选择在浮点域还是在整数域进行卷积运算。计算机设备可以获取用户输入的量化处理配置信息。如图7所示,如果量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,计算机设备则对初始输入数据进行量化处理,对初始权重参数数据进行量化处理,对winograd处理后的权重参数数据进行量化处理,后续还需要对中间输出数据进行反量化处理。
如果量化处理配置信息是用于指示在浮点域进行卷积运算的配置信息,则跳过对初始输入数据进行量化处理、对初始权重参数数据进行量化处理、对winograd处理后的权重参数数据进行量化处理、对中间输出数据进行反量化处理这几个步骤。
可选地,本申请实施例提供的方法还可以包括:获取输入的winograd处理配置信息;对量化处理后的输入数据进行winograd处理的步骤可以包括:如果winograd处理配置信息是用 于指示进行winograd处理,则对输入数据进行winograd处理;对权重参数数据进行winograd处理的步骤可以包括:如果winograd处理配置信息是用于指示进行winograd处理,则对权重参数数据进行winograd处理;对反量化处理后的中间输出数据进行winograd结果变换处理的步骤可以包括:如果winograd处理配置信息是用于指示进行winograd处理,则对反量化处理后的中间输出数据进行winograd结果变换处理。
在实施中,用户可以对winograd处理过程进行配置,用户可以选择是否需要对输入数据、权重参数数据进行winograd处理。计算机设备可以获取用户输入的winograd处理配置信息。如图7所示,如果winograd处理配置信息是用于指示进行winograd处理的配置信息,计算机设备则对输入数据进行winograd处理,对权重参数数据进行winograd处理,对反量化处理后的中间输出数据进行winograd结果变换处理。
如果winograd处理配置信息是用于指示不进行winograd处理的配置信息,则跳过对输入数据进行winograd处理、对权重参数数据进行winograd处理、对反量化处理后的中间输出数据进行winograd结果变换处理这几个步骤。
通过本申请实施例提供的方法,可以适用于以下几个场景:
(1)用户输入浮点型格式的权重参数数据,通过对输入数据、权重参数数据进行量化处理,以实现对运算过程加速。
(2)用户输入已经过量化处理的权重参数数据,神经网络处理器提供运算能力,如提供支持数据位数目为10的整数型的数据进行卷积运算、支持数据位数目为8的整数型的数据进行卷积运算。
(3)用户输入浮点型格式的权重参数数据,通过对输入数据、权重参数数据进行winograd处理,以实现对运算过程加速。
(4)用户输入已经过量化处理的权重参数数据,对已经过量化处理的权重参数数据、输入数据进行winograd处理,以实现进一步对运算过程加速。
(5)用户输入浮点型格式的权重参数数据,通过对输入数据、权重参数数据进行量化处理以及winograd处理,以实现进一步对运算过程加速。
在实际应用中,除了上面举的几个场景的例子之外,还可以扩展出其他场景,对此本申请实施例不作限定。
通过本申请实施例提供的方法,通过对量化后的输入数据、权重参数数据进行winograd处理,使得处理后的输入数据、权重参数数据便于在设备中进行卷积运算,提高当前卷积层的运算速度,最终可以实现提高整个神经网络模型的运行速度的目的。
本申请又一示例性实施例提供了一种运行神经网络模型的装置,如图8所示,该装置包括:
获取电路801,用于获取当前卷积层的输入数据和权重参数数据,具体可以实现上述步骤S301中的获取功能,以及其他隐含步骤。
第一处理电路802,用于对所述输入数据进行winograd处理,得到待运算的输入数据;对所述权重参数数据进行winograd处理;降低winograd处理后的权重参数数据的数据位数目,对降位后的权重参数数据进行量化处理,得到待运算的权重参数数据,具体可以实现上述步骤S302、步骤S303和步骤S304中的对数据的处理功能,以及其他隐含步骤。
卷积电路803,用于基于所述待运算的输入数据和所述待运算的权重参数数据进行卷积运算,得到中间输出数据,具体可以实现上述步骤S305中的卷积功能,以及其他隐含步骤。
第二处理电路804,用于对所述中间输出数据进行反量化处理;对反量化处理后的中间输出数据进行winograd结果变换处理,得到所述当前卷积层的输出数据,具体可以实现上述步骤S306中的对数据的处理功能,以及其他隐含步骤。
需要说明的是,上述获取电路801、第一处理电路802、卷积电路803和第二处理电路804可以由硬件电路实现。
关于上述实施例中的装置,其中各个电路执行操作的具体方式已经在有关该方法的实施例中进行了详细描述,此处将不做详细阐述说明。
通过本申请实施例提供的装置,通过量化后的对输入数据、权重参数数据进行winograd处理,使得处理后的输入数据、权重参数数据便于在设备中进行卷积运算,提高当前卷积层的运算速度,最终可以实现提高整个神经网络模型的运行速度的目的。
上述实施例提供的运行神经网络模型的装置与运行神经网络模型的方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。
本申请又一示例性实施例提供了一种计算机设备,如图9所示,计算机设备可以包括处理器910和运行神经网络模型的装置920。处理器910可以获取用户输入的当前卷积层的输入数据和权重参数数据,向运行神经网络模型的装置920传输当前卷积层的输入数据和权重参数数据。关于上述实施例中的装置,其中各个电路执行操作的具体方式已经在有关该方法的实施例中进行了详细描述,此处将不做详细阐述说明。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件程序实现时,可以全部或者部分地以计算机产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机指令时,全部或者部分地产生按照本申请实施例所述的流程或者功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另外一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如,固态硬盘Solid State Disk(SSD))等。
本领域技术人员在考虑说明书及实践这里公开的公开后,将容易想到本申请的其它实施方案。本申请旨在涵盖本申请的任何变型、用途或者适应性变化,这些变型、用途或者适应性变化遵循本申请的一般性原理并包括本申请未公开的本技术领域中的公知常识或惯用技术手段。说明书和实施例仅被视为示例性的,本申请的真正范围和精神由权利要求指出。
应当理解的是,本申请并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围进行各种修改和改变。本申请的范围仅由所附的权利要求来限制。

Claims (23)

  1. 一种运行神经网络模型的方法,其特征在于,所述方法包括:
    获取当前卷积层的输入数据和权重参数数据;
    对所述输入数据进行winograd处理,得到待运算的输入数据;
    对所述权重参数数据进行winograd处理;
    降低winograd处理后的权重参数数据的数据位数目,对降位后的权重参数数据进行量化处理,得到待运算的权重参数数据;
    基于所述待运算的输入数据和所述待运算的权重参数数据进行卷积运算,得到中间输出数据;
    对所述中间输出数据进行反量化处理;
    对反量化处理后的中间输出数据进行winograd结果变换处理,得到所述当前卷积层的输出数据。
  2. 根据权利要求1所述的方法,其特征在于,所述winograd处理后的权重参数数据为带符号位的定点型的数据,所述降低winograd处理后的权重参数数据的数据位数目,包括:
    如果所述winograd处理后的权重参数数据中除了符号位之外的最高预设数目个数据位的数值都是0,则保留所述winograd处理后的权重参数数据中的所述符号位以及除了所述最高预设数目个数据位之外的数据位上的数值,得到降位后的权重参数数据;或者
    如果所述最高预设数目个数据位中的任一数据位的数值是1,则保留所述winograd处理后的权重参数数据中的所述符号位以及除了所述最高预设数目个数据位之外的数据位,将所述除了所述最高预设数目个数据位之外的数据位的数值都设置为1,得到降位后的权重参数数据。
  3. 根据权利要求2所述的方法,其特征在于,所述降位后的权重参数数据为带符号位的定点型的数据;
    所述对降位后的权重参数数据进行量化处理,包括:
    确定所述降位后的权重参数数据中小数位数目;
    基于所述小数位数目,确定乘积因子;
    将所述降位后的权重参数数据乘以所述乘积因子,得到整数型的权重参数数据;
    所述对所述中间输出数据进行反量化处理,包括:
    获取量化因子;
    将所述量化因子除以所述乘积因子,得到变换后的量化因子;
    基于所述变换后的量化因子,对所述中间输出数据进行反量化处理。
  4. 根据权利要求3所述的方法,其特征在于,所述基于所述小数位数目,确定乘积因子,包括:
    将2的所述小数位数目次幂,确定为乘积因子。
  5. 根据权利要求3所述的方法,其特征在于,所述量化因子为对初始权重参数数据进行量化处理的过程中使用的量化因子。
  6. 根据权利要求3所述的方法,其特征在于,所述当前卷积层的输入数据和权重参数数据分别为8位整数型的数据,所述待运算的输入数据为10位整数型的数据,所述winograd处理后的权重参数数据的整数部分为10位且小数部分为2位,所述待运算的权重参数数据为10位整数型的数据。
  7. 根据权利要求6所述的方法,其特征在于,所述基于所述待运算的输入数据和所述待运算的权重参数数据进行卷积运算,包括:
    控制乘累加器基于所述待运算的输入数据和所述待运算的权重参数数据进行卷积运算,其中,所述乘累加器为支持10位整数型的数据进行卷积运算的乘累加器。
  8. 根据权利要求1所述的方法,其特征在于,在获取当前卷积层的输入数据和权重参数数据之前,所述方法还包括:
    获取当前卷积层的初始输入数据和初始权重参数数据;
    所述获取当前卷积层的输入数据和权重参数数据,包括:
    对所述初始输入数据进行量化处理,得到所述当前卷积层的输入数据;
    对所述初始权重参数数据进行量化处理,得到所述当前卷积层的权重参数数据。
  9. 根据权利要求8所述的方法,其特征在于,所述方法还包括:
    获取输入的量化处理配置信息;
    所述对所述初始输入数据进行量化处理,包括:
    如果所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对所述初始输入数据进行量化处理;
    所述对所述初始权重参数数据进行量化处理,包括:
    如果所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对所述初始权重参数数据进行量化处理;
    所述对降位后的权重参数数据进行量化处理,包括:
    如果所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对降位后的权重参数数据进行量化处理;
    所述对所述中间输出数据进行反量化处理,包括:
    如果所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息,则对所述中间输出数据进行反量化处理。
  10. 根据权利要求1所述的方法,其特征在于,所述方法还包括:
    获取输入的winograd处理配置信息;
    所述对所述输入数据进行winograd处理,包括:
    如果所述winograd处理配置信息是用于指示进行winograd处理的配置信息,则对所述输入数据进行winograd处理;
    所述对所述权重参数数据进行winograd处理,包括:
    如果所述winograd处理配置信息是用于指示进行winograd处理的配置信息,则对所述权重参数数据进行winograd处理;
    所述对反量化处理后的中间输出数据进行winograd结果变换处理,包括:
    如果所述winograd处理配置信息是用于指示进行winograd处理的配置信息,则对反量化处理后的中间输出数据进行winograd结果变换处理。
  11. 根据权利要求1所述的方法,其特征在于,所述权重参数数据的尺寸为3×3,进行卷积运算的过程中使用的步长参数为1;
    所述对所述输入数据进行winograd处理,包括:
    基于第一转换矩阵,对所述输入数据进行winograd处理;
    所述对所述权重参数数据进行winograd处理,包括:
    基于第二转换矩阵,对所述权重参数数据进行winograd处理;
    所述对反量化处理后的中间输出数据进行winograd结果变换处理,包括:
    基于第三转换矩阵,对反量化处理后的中间输出数据进行winograd结果变换处理;
    其中,所述第一转换矩阵为
    Figure PCTCN2020121896-appb-100001
    所述第二转换矩阵为
    Figure PCTCN2020121896-appb-100002
    所述第三转换矩阵为
    Figure PCTCN2020121896-appb-100003
  12. 一种运行神经网络模型的装置,其特征在于,所述装置包括:
    获取电路,用于获取当前卷积层的输入数据和权重参数数据;
    第一处理电路,用于对所述输入数据进行winograd处理,得到待运算的输入数据;对所述权重参数数据进行winograd处理;降低winograd处理后的权重参数数据的数据位数目,对降位后的权重参数数据进行量化处理,得到待运算的权重参数数据;
    卷积电路,用于基于所述待运算的输入数据和所述待运算的权重参数数据进行卷积运算,得到中间输出数据;
    第二处理电路,用于对所述中间输出数据进行反量化处理;对反量化处理后的中间输出数据进行winograd结果变换处理,得到所述当前卷积层的输出数据。
  13. 根据权利要求12所述的装置,其特征在于,所述winograd处理后的权重参数数据为带符号位的定点型的数据,所述第一处理电路用于降低winograd处理后的权重参数数据的数据位数目时,具体用于:
    当所述winograd处理后的权重参数数据中除了符号位之外的最高预设数目个数据位的数值都是0时,保留所述winograd处理后的权重参数数据中的所述符号位以及除了所述最高预设数目个数据位之外的数据位上的数值,得到降位后的权重参数数据;或者
    当所述最高预设数目个数据位中的任一数据位的数值是1时,保留所述winograd处理后的权重参数数据中的所述符号位以及除了所述最高预设数目个数据位之外的数据位,将所述除了所述最高预设数目个数据位之外的数据位的数值都设置为1,得到降位后的权重参数数据。
  14. 根据权利要求13所述的装置,其特征在于,所述降位后的权重参数数据为带符号位的定点型的数据;
    所述第一处理电路用于对降位后的权重参数数据进行量化处理时,具体用于:
    确定所述降位后的权重参数数据中小数位数目;
    基于所述小数位数目,确定乘积因子;
    将所述降位后的权重参数数据乘以所述乘积因子,得到整数型的权重参数数据;
    所述第二处理电路用于对所述中间输出数据进行反量化处理时,具体用于:
    获取量化因子;
    将所述量化因子除以所述乘积因子,得到变换后的量化因子;
    基于所述变换后的量化因子,对所述中间输出数据进行反量化处理。
  15. 根据权利要求14所述的装置,其特征在于,所述第一处理电路用于基于所述小数位数目,确定乘积因子时,具体用于:
    将2的所述小数位数目次幂,确定为乘积因子。
  16. 根据权利要求14所述的装置,其特征在于,所述量化因子为对初始权重参数数据进行量化处理的过程中使用的量化因子。
  17. 根据权利要求14所述的装置,其特征在于,所述当前卷积层的输入数据和权重参数数据分别为8位整数型的数据,所述待运算的输入数据为10位整数型的数据,所述winograd处理后的权重参数数据的整数部分为10位且小数部分为2位,所述待运算的权重参数数据为10位整数型的数据。
  18. 根据权利要求17所述的装置,其特征在于,所述卷积电路用于基于所述待运算的输入数据和所述待运算的权重参数数据进行卷积运算,得到中间输出数据时,具体用于:
    控制乘累加器基于所述待运算的输入数据和所述待运算的权重参数数据进行卷积运算,其中,所述乘累加器为支持10位整数型的数据进行卷积运算的乘累加器。
  19. 根据权利要求12所述的装置,其特征在于,所述获取电路,还用于获取当前卷积层的初始输入数据和初始权重参数数据;
    所述获取电路用于获取当前卷积层的输入数据和权重参数数据时,具体用于:
    对所述初始输入数据进行量化处理,得到所述当前卷积层的输入数据;
    对所述初始权重参数数据进行量化处理,得到所述当前卷积层的权重参数数据。
  20. 根据权利要求19所述的装置,其特征在于,所述获取电路,还用于获取输入的量化处理配置信息;
    所述获取电路用于对所述初始输入数据进行量化处理时,具体用于:
    当所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息时,对所述初始输入数据进行量化处理;
    所述获取电路用于对所述初始权重参数数据进行量化处理时,具体用于:
    当所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息时,对所述初始权重参数数据进行量化处理;
    所述第一处理电路用于对降位后的权重参数数据进行量化处理时,具体用于:
    当所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息时,对降位后的权重参数数据进行量化处理;
    所述第二处理电路用于对所述中间输出数据进行反量化处理时,具体用于:
    当所述量化处理配置信息是用于指示在整数域进行卷积运算的配置信息时,对所述中间输出数据进行反量化处理。
  21. 根据权利要求12所述的装置,其特征在于,所述获取电路,还用于获取输入的winograd处理配置信息;
    所述第一处理电路用于对所述输入数据进行winograd处理时,具体用于:
    当所述winograd处理配置信息是用于指示进行winograd处理的配置信息时,对所述输入数据进行winograd处理;
    所述第一处理电路用于对所述权重参数数据进行winograd处理时,具体用于:
    当所述winograd处理配置信息是用于指示进行winograd处理的配置信息时,对所述权重参数数据进行winograd处理;
    所述第二处理电路用于对反量化处理后的中间输出数据进行winograd结果变换处理时,具体用于:
    当所述winograd处理配置信息是用于指示进行winograd处理的配置信息时,对反量化处理后的中间输出数据进行winograd结果变换处理。
  22. 根据权利要求12所述的装置,其特征在于,所述权重参数数据的尺寸为3×3,进行卷积运算的过程中使用的步长参数为1;
    所述第一处理电路用于对所述输入数据进行winograd处理时,具体用于:
    基于第一转换矩阵,对所述输入数据进行winograd处理;
    所述第一处理电路用于对所述权重参数数据进行winograd处理时,具体用于:
    基于第二转换矩阵,对所述权重参数数据进行winograd处理;
    所述第二处理电路用于对反量化处理后的中间输出数据进行winograd结果变换处理时,具体用于:
    基于第三转换矩阵,对反量化处理后的中间输出数据进行winograd结果变换处理;
    其中,所述第一转换矩阵为
    Figure PCTCN2020121896-appb-100004
    所述第二转换矩阵为
    Figure PCTCN2020121896-appb-100005
    所述第三转换矩阵为
    Figure PCTCN2020121896-appb-100006
  23. 一种计算机设备,其特征在于,所述计算机设备包括处理器和权利要求12-22中任一项所述的运行神经网络模型的装置,其中:
    所述处理器,用于向所述装置传输当前卷积层的输入数据和权重参数数据。
PCT/CN2020/121896 2019-10-18 2020-10-19 运行神经网络模型的方法、装置和计算机设备 WO2021073638A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910996290.2 2019-10-18
CN201910996290.2A CN112686365B (zh) 2019-10-18 2019-10-18 运行神经网络模型的方法、装置和计算机设备

Publications (1)

Publication Number Publication Date
WO2021073638A1 true WO2021073638A1 (zh) 2021-04-22

Family

ID=75445207

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/121896 WO2021073638A1 (zh) 2019-10-18 2020-10-19 运行神经网络模型的方法、装置和计算机设备

Country Status (2)

Country Link
CN (1) CN112686365B (zh)
WO (1) WO2021073638A1 (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113570033B (zh) * 2021-06-18 2023-04-07 北京百度网讯科技有限公司 神经网络处理单元、神经网络的处理方法及其装置
CN113392973B (zh) * 2021-06-25 2023-01-13 广东工业大学 一种基于fpga的ai芯片神经网络加速方法

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107993186A (zh) * 2017-12-14 2018-05-04 中国人民解放军国防科技大学 一种基于Winograd算法的3D CNN加速方法及系统
CN108805267A (zh) * 2018-05-28 2018-11-13 重庆大学 用于卷积神经网络硬件加速的数据处理方法
CN109359730A (zh) * 2018-09-26 2019-02-19 中国科学院计算技术研究所 面向固定输出范式Winograd卷积的神经网络处理器
CN109615068A (zh) * 2018-11-08 2019-04-12 阿里巴巴集团控股有限公司 一种对模型中的特征向量进行量化的方法和装置
CN109740740A (zh) * 2019-01-03 2019-05-10 厦门美图之家科技有限公司 卷积计算的定点加速方法及装置
CN110135580A (zh) * 2019-04-26 2019-08-16 华中科技大学 一种卷积网络全整型量化方法及其应用方法

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2018107383A1 (zh) * 2016-12-14 2018-06-21 上海寒武纪信息科技有限公司 神经网络的卷积运算方法、装置及计算机可读存储介质
CN108009634B (zh) * 2017-12-21 2021-05-25 美的集团股份有限公司 一种卷积神经网络的优化方法、装置及计算机存储介质
CN108765247B (zh) * 2018-05-15 2023-01-10 腾讯科技(深圳)有限公司 图像处理方法、装置、存储介质及设备
CN109767000B (zh) * 2019-01-16 2022-01-25 厦门美图之家科技有限公司 基于Winograd算法的神经网络卷积方法及装置

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107993186A (zh) * 2017-12-14 2018-05-04 中国人民解放军国防科技大学 一种基于Winograd算法的3D CNN加速方法及系统
CN108805267A (zh) * 2018-05-28 2018-11-13 重庆大学 用于卷积神经网络硬件加速的数据处理方法
CN109359730A (zh) * 2018-09-26 2019-02-19 中国科学院计算技术研究所 面向固定输出范式Winograd卷积的神经网络处理器
CN109615068A (zh) * 2018-11-08 2019-04-12 阿里巴巴集团控股有限公司 一种对模型中的特征向量进行量化的方法和装置
CN109740740A (zh) * 2019-01-03 2019-05-10 厦门美图之家科技有限公司 卷积计算的定点加速方法及装置
CN110135580A (zh) * 2019-04-26 2019-08-16 华中科技大学 一种卷积网络全整型量化方法及其应用方法

Also Published As

Publication number Publication date
CN112686365A (zh) 2021-04-20
CN112686365B (zh) 2024-03-29

Similar Documents

Publication Publication Date Title
US11249721B2 (en) Multiplication circuit, system on chip, and electronic device
WO2020156259A1 (zh) 内存管理方法、装置、移动终端及存储介质
WO2021179587A1 (zh) 神经网络模型量化方法、装置、电子设备及计算机可读存储介质
WO2021073638A1 (zh) 运行神经网络模型的方法、装置和计算机设备
WO2021022685A1 (zh) 一种神经网络训练方法、装置及终端设备
CN109542512B (zh) 一种数据处理方法、装置和存储介质
JP2022502733A (ja) ニューラル・ネットワーク・コアにおける動的精度のためのデータ表現
CN110929865A (zh) 网络量化方法、业务处理方法及相关产品
CN106775638A (zh) 一种对象序列化方法、装置和计算设备
WO2019084788A1 (zh) 用于神经网络的运算装置、电路及相关方法
WO2022021834A1 (zh) 神经网络模型确定方法、装置、电子设备、介质及产品
CN112967207B (zh) 一种图像处理方法、装置、电子设备及存储介质
US11615607B2 (en) Convolution calculation method, convolution calculation apparatus, and terminal device
CN112085175B (zh) 基于神经网络计算的数据处理方法和装置
CN109697083B (zh) 数据的定点化加速方法、装置、电子设备及存储介质
US20210044303A1 (en) Neural network acceleration device and method
WO2023198150A1 (zh) 脑电数据的数据压缩方法、芯片、设备及存储介质
CN110378479B (zh) 基于深度学习的图片输入方法、装置及终端设备
CN109740730B (zh) 运算方法、装置及相关产品
US20200242467A1 (en) Calculation method and calculation device for sparse neural network, electronic device, computer readable storage medium, and computer program product
CN116129501A (zh) 人脸位姿估计方法及装置
WO2019114044A1 (zh) 图像处理方法、装置、电子设备及计算机可读存储介质
CN112597113B (zh) 一种数据快速读取方法、装置、电子设备及存储介质
CN112926646B (zh) 数据批量标准化方法、计算设备和计算机可读存储介质
WO2021238289A1 (zh) 序列处理的方法与装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20876965

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20876965

Country of ref document: EP

Kind code of ref document: A1