This application claims priority to Chinese Patent Application Number 201610663201.9 filed on Aug. 12, 2016 and Chinese Patent Application Number 201610663563.8 filed on Aug. 12, 2016, U.S. application Ser. No. 15/242,622 filed on Aug. 22, 2016, U.S. application Ser. No. 15/242,624 filed on Aug. 22, 2016, the entire content of which are incorporated herein by reference.
The present invention relates to artificial neural network, for example, convolutional neural network. In particular, the present invention relates to how to accelerate a complex neural network by fixed-point data quantization.
Artificial neural network (ANN), in particular, convolutional neural network (CNN) has achieved great success in various fields. For example, in the field of computer vision (CV), CNN is widely used and most promising.
Image classification is a basic problem in computer vision (CV). In recent years, Convolutional Neural Network (CNN) has led to great advances in image classification accuracy. In Image-Net Large- Scale Vision Recognition Challenge (ILSVRC) 2012, Krizhevsky et al. showed that CNN had great power by achieving the top-5 accuracy of 84.7% in classification task, which was significantly higher than other traditional image classification methods. In the following years, the accuracy has been improved to 88.8%, 93.3%, and 96.4% in ILSVRC 2013, 2014, and 2015.
While achieving state-of-the-art performance, CNN-based methods demand much more computations and memory resources compared with traditional methods. In this manner, most CNN-based methods have to depend on large servers. However, there has been a non-negligible market for embedded systems which demands capabilities of high-accuracy and real-time object recognition, such as auto-piloted car and robots. But for embedded systems, the limited battery and resources are serious problems.
CNN is widely used in imaging processing. The advantages of CNN-based approach is that it is easy to train a CNN and CNN has a relatively simple computational structure. However, it is also known that CNN-based approach is both operational-intensive and memory-intensive. The existing CNNs commonly use 32-bit or 64-bit floating-number system. Given the fact that there are lots of redundant data in a CNN, it has been proposed to convert CNN into relatively short fixed-point numbers without substantial loss of accuracy.
In the previously filed patent applications, the inventor proposes a method and system to quantizing CNN into a fixed-point representation. For example, it proposes how to quantize a simple CNN (which has no complex sub-network/branches) layer by layer. Specifically, the proposed solution quantizes a serialized neural network. As shown in
The above proposed solution cannot be applied to a complex network, such as GoogLeNet, SqueezeNet, etc., which have merged branches and parallel sub-networks.
The present invention proposes a solution to quantize a complex neural network. In addition to achieving each layer's optimal quantization, it also considers how to maintain consistency when different layers are merged or concatenated.
According to one aspect of the application, it proposes a method for optimizing an Artificial Neural Network (ANN), said method comprising: (a) fixed-point data quantizing step, for converting output of each layer of said ANN into fixed-point numbers, (b) sub-network identifying step, for identifying at least one sub-network from said ANN, wherein each sub-network has a concatenation layer as its output, wherein said concatenation layer receives at least two outputs of previous-level layers as its inputs and concatenates said inputs into one output; (c) fixed-point modifying step, for each sub-network, modifying the fixed-point range of each output of the previous-level layers of said concatenation layer on the basis of the fixed-point range of said concatenation layer.
According to one aspect of the application, it proposes a method for optimizing an Artificial Neural Network (ANN), said ANN has branches and at least comprises convolutional layers CONV 1, CONV 2, . . . CONV n, and fully connected layers FC 1, FC 2, . . . , FC m, concatenation layers CONCAT1, CONCAT2, . . . , CONCAT 1, wherein n, m and 1 are positive integers, said method comprising: (a) fixed-point data quantizing step, for converting output of each of said CONV, FC and CONCAT layers into fixed-point numbers, (b) CONCAT layer identifying step, for identifying at least one sub-network from said ANN, wherein each sub-network has a CONCAT layer as its output, wherein said CONCAT layer receives at least two outputs of previous-level layers as its inputs and concatenates said inputs into one output; (c) fixed-point modifying step, for each sub-network, modifying the fixed-point range of each output of the previous-level layers of said CONCAT layer on the basis of the fixed-point range of said CONCAT layer.
According to another aspect of the invention, it proposes a device for optimizing an Artificial Neural Network (ANN), said ANN has branches and at least comprises convolutional layers CONV 1, CONV 2, . . . CONV n, and fully connected layers FC 1, FC 2, . . . , FC m, concatenation layers CONCAT1, CONCAT2, . . . , CONCAT 1, wherein n, m and l are positive integers, said device comprising: fixed-point data quantizing unit, configured for converting output of each of said CONV, FC and CONCAT layers into fixed-point numbers; CONCAT layer identifying unit, configured for identifying at least one sub-network from said ANN, wherein each sub-network has a CONCAT layer as its output, wherein said CONCAT layer receives at least two outputs of previous-level layers as its inputs and concatenates said inputs into one output; fixed-point modifying unit, configured for, for each sub-network, modifying the fixed-point range of each output of the previous-level layers of said CONCAT layer on the basis of the fixed-point range of said CONCAT layer.
Some content of the present application has been proposed by the inventor in a previous paper “Going Deeper With Embedded FPGA Platform for Convolutional Neural Network” (FPGA 2016.2). In the present application, the inventor proposes further improvements on the basis of the previous paper.
In order to illustrative the concepts of the present invention, the application explains how CNN is applied in image processing, e.g., image classification/prediction. Other Artificial Neural Network, such as DNN and RNN, can be improved and implemented in a similar manner.
Concepts of CNN
As shown in
The parameters of a CNN model are called “weights”. The first layer of a CNN reads an input image and outputs a series of feature maps. The following layers read the feature maps generated by previous layers and output new feature maps. Finally a classifier outputs the probability of each category that the input image might belong to.
CONV layer and FC layer are two essential types of layer in CNN. After CONV layers, there are usually pooling layers.
For a CNN layer, fjin denotes its j-th input feature map, fiout denotes the i-th output feature map, and bi denotes the bias term to the i-th output map.
For CONV layers, nin and nout represent the number of input and output feature maps respectively.
For FC layers, nin and nout are the length of the input and output feature vector.
A CONV layer takes a series of feature maps as input and convolves with convolutional kernels to obtain the output feature map.
A nonlinear layer, which applies nonlinear activation function to each element in the output feature maps is often attached to CONV layers.
The CONV layer can be expressed with Equation 1:
fiout=Σj=1ngi,j+bi(1≤i ≤nout) (1)
where gi,j is the convolutional kernel applied to j-th input feature map and i-th output feature map.
FC layer applies a linear transformation on the input feature vector:
fout=Wfin+b (2)
where W is an nout×nin transformation matrix and b is the bias term. It should be noted, for the FC layer, the input is not a combination of several 2-D feature maps but just a feature vector. Consequently, in Equation 2, the parameter nin and nout actually corresponds to the lengths of the input and output feature vector.
Pooling layer, which outputs the maximum or average value of each subarea in each feature maps, is often attached to the CONV layer. Max-pooling can be expressed as Equation 3:
where p is the pooling kernel size. This non-linear “down sampling” not only reduces the feature map size and the computation for later layers, but also provides a form of translation invariance.
CNN can be used to classify images in a forward inference process. But before using the CNN for any task, one should first train the CNN on a dataset. Recent research showed that, a CNN model pre-trained on a large dataset for a given task can be used for other tasks and achieved high accuracy with minor adjustment in network weights. This minor adjustment is called “fine-tune”. The training of the CNN is mostly implemented on large servers. For embedded FPGA platform, we only focus on accelerating the inference process of a CNN.
At the left end of
Data Quantization for Serialized ANN
For a fixed-point number, its value can be expressed as
n=Σi=0bw−1Bi·2−fl·2i (4)
where bw is the bit width of the number and fl is the fractional length which can be negative.
In order to convert floating-point numbers into fixed-point ones while achieving the highest accuracy, it proposes a dynamic-precision data quantization strategy and an automatic workflow.
Unlike previous static precision quantization strategies, in the proposed data quantization flow, fl is dynamic for different layers and feature map sets while static in one layer to minimize the truncation error of each layer.
As shown in
The weight quantization phase aims to find the optimal fl for weights in one layer, as shown in Equation 5:
where W is a weight and W(bw, fl) represents the fixed-point format of W under the given bw and fl
In one embodiment, the dynamic ranges of weights in each layer is analyzed first, for example, by sampling. After that, the fl is initialized to avoid data overflow. Furthermore, we search for the optimal fl in the adjacent domains of the initial fl.
In an alternative embodiment, the optimal fl is decided based on the following Equation 6.
wherein W is the weight matrix of one layer, W (bw, fl) represents the fixed-point format of W under the given bw and fl, i represents one bit of bw bits, ki represents the weight of said bit i.
The data quantization phase aims to find the optimal fl for the output of a layer. Said output is used as the input of the next layer. In ANN image processing, a benchmark data set is used to train said ANN. said input/output is a set of feature maps between two layers.
In one embodiment, firstly, weight quantization is conducted for ally CONV and FC layers of ANN. Then, in order to conduct data quantization, the benchmark data is input to ANN, and output of each layer is available after said training.
For output of each layer, the intermediate data of the fixed-point CNN model and the floating-point CNN model are compared layer by layer using a greedy algorithm to reduce the accuracy loss. For each layer, the optimization target is shown in Equation 7:
In Equation 7, x+ represents the result of a layer when we denote the computation of a layer as x+=A·x. It should be noted, for either CONV layer or FC layer, the direct result x+ has longer bit width than the given standard. Consequently, truncation is needed when optimizing fl selection. Finally, the entire data quantization configuration is generated.
In an alternative embodiment, we use the following Equation 8 to find fl.
wherein x+=A·x, A represents the operation applied by one of the CONV layers and FC layers of the ANN, x represents the input of one layer, x+ represents the output of said layer, i represents one bit out of bw bits, ki represents the weight of said bit i.
In the above example of data quantization, it finishes weight quantization of all CONV layers and FC layers of the ANN, and then conducts data quantization for each feature map set on the basis of the quantized CONV layers and FC layers.
According to another embodiment of the present invention, it performs weight quantization and data quantization in an alternative (i.e., interleaved) manner. Specifically, for example, it conducts weight quantization for one of said CONV layers and FC layers in sequence; after conducting weight quantization for the present layer, but before conducting weight quantization for next layer of said CONV layers and FC layers, it conducts data quantization of output (i.e., feature map sets) from said present layer.
The above solution is applicable to a simple neural network, such as a completely serialized neural network.
As shown on the left branch of
As shown on the right branch of
Data Quantization for a Complex Neural Network
The process of
However, the process of
In a complex neural network, e.g., GoogLeNet, concatenation operation is common. It is represented by a CONCAT layer, which concates two or more inputs from preceding layers into one single output. For example, a CONCAT layer has two inputs: input A and input B, input A is a set of feature maps having C1 channels and W*H dimension, input B has a set of feature maps having C2 channels and W*H dimension. After the concatenation, the CONCAT layer outputs a set of feature maps of W*H*(C1+C2).
BLOB is binary large object, which is used as a container for binary files. A typical BLOB is used for storing images or voice.
In the present invention, BLOB may be a 4-dimensional data structure, which accommodates the W*H*C feature maps. The preceding level of a CONCAT layer has a plurality of layers, which output BLOB1, BLOB2, . . . , BLOBn respectively to the CONCAT layer. The CONCAT layer concates (or merges) these inputs into one single output BLOB.
In hardware implementation, in order to conduct concatenation/merging operation on BLOB1, BLOB2, . . . BLOBn, it is necessary to change the address of BLOB1, BLOB2, . . . BLOBn in the memory.
When BLOB1, BLOB2, . . . BLOBn are represented by fixed-point numbers, it is likely that different BLOBi have different fixed-point range. However, for the concatenation operation, different fixed-point ranges of the preceding inputs BLOBi may result in a conflict. The CONCAT layer can only choose one of the different fixed-point ranges. Thus, BLOBi of other fixed-point ranges cannot be accurately represented by the CONCAT layer.
In the process shown in
The left branch of weight quantization shown in
Firstly, it estimates the numerical range of output of all layers of said neural network, including CONV layers, FC layers, and CONCAT layers. The estimation is conducted by on-line running actual or sample data in the neural network and get the output in floating numbers.
According to one embodiment, said first step comprises: providing input data to said ANN, said input data is processed by said convolutional layers CONV 1, CONV 2, . . . CONV n, and fully connected layers FC 1, FC 2, . . . , FC m, concatenation layers CONCAT1, CONCAT2, . . . , CONCAT 1.
Secondly, it converts the output of each layer from floating-number into fixed-numbers.
Specifically, in one embodiment, during converting output of each of said CONV, FC and CONCAT layers from float-point numbers into fixed-point numbers, the numerical range of fixed-point numbers is dynamically chosen for different layers while remains static in one layer.
According to one embodiment of the present invention, it finds the optimal fixed-point range (e.g., fl) for each layer based on the criteria of equation 7 or 8.
Thirdly, it modifies fixed-point range for output of each preceding layer of CONCAT layer on the basis of the fixed-point range of CONCAT layer.
Specifically, in third step, it identifies a CONCAT layer. In other words, it identifies at least one sub-network from said neural network, wherein each sub-network has a CONCAT layer as its output, wherein said CONCAT layer receives at least two outputs of previous-level layers as its inputs and concatenates said inputs into one output.
Next, for each of previous-level layers of said CONCAT layer, it compares each previous-level layer's fixed-point range with said CONCAT layer's fixed-point range. If they are different, adjusting the fixed-point range of said previous-level layer to be same as the fixed-point range of said CONCAT layer.
In addition, according to one embodiment, if one previous-level layer of said CONCAT layer (e.g., CONCAT1) is also a CONCAT layer (e.g., CONCAT2), identifying another sub-network with said CONCAT2 as its output, and conducting third step for said another sub-network.
As shown in the left branch of
The left and right branches of
In one embodiment, before starting data quantization, it conducts weight quantization for all CONV layers, FC layers and CONCAT layers of the neural network.
Or, it conducts the weight quantizing step and data quantizing in an alternative manner. Specifically, after conducting weight quantization for the present layer of said CONV layers, FC layers and CONCAT layers, before conducting weight quantization for next layer of said CONV layers, FC layers and CONCAT layers, it conducts data quantization of the output of said present layer.
In addition, in one embodiment, it outputs the fixed-point number range of each of said CONV layers, FC layers and CONCAT layers said after third step.
In
Following the process shown in
In a second step, it converts the output from floating-point number into fixed-point number. In the example of
In a third step, it modifies the fixed-point ranges of CONV3 and CONV4 on the basis of the fixed-point range of CONCAT layer.
Specifically, it compares the fixed-point range of CONV3 (fl=5) with that of CONCAT (fl=4). As they are different, it modifies the fixed-point range of output of CONV3 as fl=4.
Next, it compares the fixed-point range of CONV4 (fl=3) with that of CONCAT (fl=4). As they are different, it modifies the fixed-point range of output of CONV4 as fl=4.
If the CONCAT layer has other inputs, it modifies them in a similar manner.
In addition, if one preceding input of the CONCAT layer (CONCAT1) is also a CONCAT layer (CONCAT2), it will repeat the process to said preceding CONCAT layer (CONCAT2). Firstly, the CONCAT 2 is taken as an input and modified on the basis of the fixed-point range of CONCAT 1. Next, the modified CONCAT2 is considered as a CONCAT layer, and all preceding inputs' fixed-point ranges of CONCAT2 are modified on the basis of CONCAT2.
It should be understood that the present application is not limited to a neural network with CONCAT layers. It can be applied to a complex neural network with merging/branching/serializing/parallel structures. The concatenation operation should also be widely interpreted as combining more inputs/branches into one.
Also the term “a plurality of” in the specification and claims refers to “two or more”.
Those skilled in the art may understand and implement other variations to the disclosed embodiments from a study of the drawings, the present application, and the appended claims.
In the claims, the word “comprising” does not exclude other elements or steps, and the indefinite article “a” or “an” does not exclude a plurality.
In applications according to present application, one element may perform functions of several technical feature recited in claims.
Any reference signs in the claims should not be construed as limiting the scope. The scope and spirit of the present application is defined by the appended claims.
| Number | Date | Country | Kind |
|---|---|---|---|
| 2016 1 0663201 | Aug 2016 | CN | national |
| 2016 1 0663563 | Aug 2016 | CN | national |
| Number | Name | Date | Kind |
|---|---|---|---|
| 9317482 | Davis et al. | Apr 2016 | B2 |
| 20170076195 | Yang | Mar 2017 | A1 |
| 20170243085 | Vanhoucke | Aug 2017 | A1 |
| 20170316286 | Szegedy | Nov 2017 | A1 |
| 20180046894 | Yao | Feb 2018 | A1 |
| 20180046896 | Yu | Feb 2018 | A1 |
| 20180046903 | Yao | Feb 2018 | A1 |
| 20180046905 | Li | Feb 2018 | A1 |
| 20180046913 | Yu | Feb 2018 | A1 |
| 20180068207 | Szegedy | Mar 2018 | A1 |
| 20180089834 | Spizhevoy | Mar 2018 | A1 |
| 20190034784 | Li | Jan 2019 | A1 |
| 20190034796 | Li | Jan 2019 | A1 |
| Number | Date | Country |
|---|---|---|
| 102129397 | Jul 2011 | CN |
| 104915322 | Sep 2015 | CN |
| 105488565 | Apr 2016 | CN |
| 205139973 | Apr 2016 | CN |
| 105681628 | Jun 2016 | CN |
| 105760933 | Jul 2016 | CN |
| Entry |
|---|
| Szegedy et al., “Going deeper with convolutions”, In CVPR, 2015, pp. 1-9 (Year: 2015). |
| Qui et al., “Going Deeper with Embedded FPGA Platform for Convolutional Neural Network”, Feb. 21-23, 2016, FPGA 2016, pp. 26-35 (Year: 2016). |
| A Massively Parallel Coprocessor for Convolutional Neural Networks, DOI: 10.1109/ASAP.2009.25. |
| NeuFlow: Dataflow vision processing system-on-a-chip, DOI: 10.1109/MWSCAS.2012.6292202. |
| Going Deeper with Embedded FPGA Platform for Convolutional Neural Network, DOI: 10.1145/2847263.2847265. |
| 1. Image-Net Large-Scale Vision Recognition Challenge (ILSVRC) 2012. |
| 15. Long short-term memory recurrent neural network architectures for large scale acoustic modeling[C]// Interspeech. 2014: 338-342. |
| 16. Long short-term memory based recurrent neural network architectures for large vocabulary speech recognition[J]. arXiv preprint arXiv:1402.1128, 2014. |
| 23. DSD: Regularizing Deep Neural Networks with Dense-Sparse-Dense Training Flow in NIPS 2016. |
| Learning both Weights and Connections for Efficient Neural Networks, arXiv:1506.02626v3 [cs.NE] Oct. 30, 2015. |
| 8. DSD: Regularizing Deep Neural Networks with Dense-Sparse-Dense Training Flow in NIPS 2016. |
| 9. Long Short-term Memory, Neural Computation 9(8):1735-80 ⋅ Dec. 1997, DOI: 10.1162/neco.1997.9.8.1735. |
| Number | Date | Country | |
|---|---|---|---|
| 20180046896 A1 | Feb 2018 | US |
| Number | Date | Country | |
|---|---|---|---|
| Parent | 15242622 | Aug 2016 | US |
| Child | 15252220 | US | |
| Parent | 15242624 | Aug 2016 | US |
| Child | 15242622 | US |