{'fraction_non_alphanumeric': 0.04171109577871166, 'fraction_numerical': 0.009847582010913881, 'mean_word_length': 4.553465691396726, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
An Overview of Datatype Quantization Techniques for Convolutional Neural Networks

Convolutional Neural Networks (CNNs) are becoming increasingly popular due to their superior performance in the domain of computer vision, in applications such as objection detection and recognition. However, they demand complex, power-consuming hardware which makes them unsuitable for implementation on low-power mobile and embedded devices. In this paper, a description and comparison of various techniques is presented which aim to mitigate this problem. This is primarily achieved by quantizing the floating-point weights and activations to reduce the hardware requirements, and adapting the training and inference algorithms to maintain the network's performance.


I. INTRODUCTION
In recent years, CNNs have proven to be much more effective in computer vision tasks as compared to existing conventional approaches. One drawback of CNNs, however, is their complexity in terms of the number of parameters and computations. For this reason, neural networks are typically applied on high-powered Graphical Processing Units (GPUs) with huge memory space. As an example, AlexNet [1] contains approximately 61M parameters, and performs 1.5B highprecision operations in order to classify a single image. This makes it prohibitively expensive to train CNNs on resourceconstrained mobile or embedded devices.
Significant research has therefore been undertaken to discover ways to reduce the memory and computational resources required by CNNs. The principal approach has been to quantize the high precision network parameters by reducing their word lengths, so as to reduce (a) the memory bandwidth and storage, (b) memory access and floating-point computations, and (c) power consumption. However, arbitrary quantization of all network parameters significantly degrades the network's performance. To avoid this, the back-propagation algorithm has to be modified, and the degree of quantization has to be carefully optimized to achieve a balance between network compression and performance.
In this paper, an analysis of some works that aim to compress CNNs is presented. The organization is as follows: section II provides a brief round-up of many network compression techniques. In section III, the most recent and promising of these approaches are discussed in detail. Section IV compares the results produced by these approaches and how they compare to existing state-of-the-art networks in terms of inference performance and memory requirements.

II. RELATED WORK
The various techniques that have been proposed to reduce the memory and computational footprint of CNNs can be roughly categorized in one of two groups:

A. Compressing Pretrained Networks
One of the earliest works in this area was Optimal Brain Surgeon [2], which pruned the network (i.e. remove unnecessary weights) by using a metric based on the Hessian of the loss function. More recently, Han et al. [3] introduced Deep Compression, which involved a three-stage pipeline that (1) pruned, (2) quantized and partially retrained, and (3) compressed the resulting weights using Huffman Coding. Denton et al. [4] noted that there are redundancies within the parameters of each layer, and proposed using matrix factorization methods to reduce the number of parameters.
Chen et al. [5] proposed HashedNets, wherein a low-cost hashing function is used to randomly group weights into hash buckets, and all weights in a single bucket share a single parameter value. Vanhoucke et al. [6] quantized the weights and activations of a pretrained network to a fixed-point length of 8-bits. As a refinement of this approach, Anwar et al. [7] apply layer-specific quantization based on the sensitivity of each layer and an L 2 -error minimization technique. Lin et al. [8] adopt a similar approach, but use an optimization strategy based on minimizing the signal-to-quantization-noiseratio (SQNR) to determine the bit-width for each layer. Shin et al. [9] retrain deep networks using a variable quantization step-size based on the L 2 -distance between the fixed-point and floating-point weights. Hwang et al. [10] on the other hand, enforce ternary weights while quantizing (-1, 0 and +1), and then retrain the network after quantization to regain inference accuracy.

B. Training Quantized Networks
A comparatively smaller set of works focuses on training quantized networks from scratch. Lin et al. [11] introduce Ternary Weights Networks (TWNs), wherein all weights have values -1, 0 or +1. By assuming that all weights are uniformly or normally distributed, they were able to determine the thresholds for quantization. Meng et al. [12] build upon this, but utilize the two-bit weights fully by allowing four possible weight values (-2, -1, +1, +2), and learning the optimal scaling factor for each kernel.
Courbariaux et al. [13] introducted BinaryConnect, wherein they restrict all weight values to either -1 or +1, and further argue that binarization, in addition to compressing the network, also provides a form of regularization. Rastegari et al. [14] came up with XNOR-nets, in which they not only quantize the kernel weights, but also the network inputs. Furthermore, they formulate the convolution as a series of XNOR operations to speed up the computations.

III. DATATYPE QUANTIZATION
In this section, some of the contemporary works mentioned in the previous section are described in more detail. The works are chosen so as to provide a holistic overview of all the approaches that yield appreciable results and offer interesting theoretical perspectives.

A. Compressing Pretrained Networks
Generally, compressing pretrained networks involves one or both of the following steps: (1) Determining the quantization parameters, namely the step-size and bitwidth. These may be preset based on an assumption, or they may be computed analytically; (2) Retraining the network after quantization in order to partially recover the loss in inference accuracy.

1) Variable bit-width (Lin et al.):
In [8], the quantized network is not retrained, but both quantization parameters are determined analytically. Assuming that the weights in a CNN are normally distributed, the quantization parameters are determined by minimizing the SQNR. To this end, an approximate linear expression for SQNR is derived. The relationship between the floating-point and quantized products of the weight and activation can be given as: r w¨r a " pw`n w q¨pa`n a q » w¨a`w¨n a`nw¨a where w and a are the floating-point weights and activations (input from previous layer) respectively, r w and r a are the quantized weights and activations, and n w and n a are the quantization errors associated with the weight and activation respectively. The above approximation holds if |n a | ! |a| and |n w | ! |w|. Here, it is apparent that pw¨n a`nw¨a q is the overall quantization noise when taking the product of w and a. From this, it is deduced that the SQNR of w¨a, γ w¨a is related to the individual SQNRs of w and a (γ w and γ a ) as follows: This is an important linear relation that can be extended to multiple layers. The final output SQNR γ output for a CNN with n layers is therefore: The overall SQNR is thus simply the harmonic mean of the individual SQNRs at each step. Separately, is shown that in general, 10 log γ " κ¨β, where κ is the quantization efficiency which is dependent on the type of distribution assumed, and β is the bitwidth. Combining this relation with (1), it is trivial to formulate an optimization problem that minimizes the bitwidth β i for each layer i, with the constraint that the SQNR γ i does not fall below a certain threshold.
2) Ternary Weights (Hwang et al.): In [10], ternary weights 1, 0,´1 are enforced, so the bitwidth is 2. Given a pretrained network with floating-point weights, the quantization is carried out in three steps as follows: 1) Compute an initial step-size ∆ init for the entire network using an L 2 -error minimization approach similar to Lloyd-Max quantization. 2) Quantize the weights in all layers of the network using step-size ∆ init i.e. ∆ i " ∆ init , @i P r1, ns, where n is the number of layers. 3) Fine-tune the step-size layer-wise. Starting from the quantizer in the first layer i.e. i " 1: a) Try several step-sizes ∆ 1 i close to the initial stepsize, and for each ∆ 1 i , calculate the L 2 -error at the output. Set ∆ i " ∆i , where ∆i is the ∆ 1 i that achieved the lowest L 2 -error. b) Increment i by 1 and repeat steps (a) and (b) until i " n.
The quantized network is then retrained to fine-tune the weights. To this end, the standard back-propagation algorithm with Stochastic Gradient Descent (SGD) and mini-batches is used, but with two modifications: 1) The forward and back-propagation is carried out using the quantized weights, but the parameter update is still applied to the floating-point weights. This is because the amount of update is usually very small at a single step. The updated floating-point weights are then quantized for further use.
2) The floating-point weights are used for calculating the derivative of the activation function during backpropagation. This is because the derivative of the sigmoid activation function often vanishes to 0 when the function value only has three quantization levels.

B. Training Quantized Networks
These works implement a quantized network by training it from scratch.

1) XNOR-Net (Rastegari et al.):
In [14], XNOR-Nets are introduced which binarize both the weights and the inputs to the network. For a given 3D convolution filter W with n floating-point weights, let the binarized filter be Ă W " αB (where α is a scaling factor and B P t`1,´1u n ). Attempting to minimize the L 2 -error between the floating-point and quantized weights yields the familiar optimization problem: Since W is a known variable and W T W and B T B are constants, the problem simplifies to B˚" argmax B pW T Bq.
The solution to this is simply B˚" signpW q i.e. B i is +1 when W i is positive, and vice versa. Solving for α˚in the above equation and substituting the expression for B˚, the following solution is obtained: This shows that the optimal step-size α˚is simply the mean of the absolute values of all the individual weights in W . Insofar as binarization of inputs is concerned, it should be recalled that a convolution is simply a series of dotproduct and shift operations. It follows that if both weight and input matrices to a layer are purely binary, the operation can be implemented using highly efficient XNOR-bitcounting operations [15]. In order to binarize the input I that is to be convolved with a weight kernel W , the objective is to minimize the L 2 -error for every single dot-product operation between W and the sub-matrix X (belonging to I) being operated on. We denote binarized X as r X and express it in a similar way to Ă W : r X " βH, where β is a scaling factor and H P t`1,´1u n . The optimal value of H, H˚, and the optimal value of B, B˚is found to be: Interestingly, this result has the same form as that obtained for α˚and B˚. The fully binarized network is then trained using the standard SGD in conjunction with momentumbased or ADAM learning rate adaptation, but there are two noteworthy changes: (1) the floating-point weights are still used for parameter updating (for the same reason as Hwang et al. [10]), and (2) for back-propagation, the following derivative of the signpq function is used [15]:

Bsignprq
Br " 2) Ternary Weights (Li et al.): In [11], a ternary network is implemented i.e. the bitwidth is fixed to two. The stepsize, ∆ is determined by attempting to minimize the Euclidean distance between the floating-point weights w i and quantized weights r w i . The following quantization function is used: where i is the weight index within a particular filter, and α is simply a scaling factor that is applied to the ternary weights 1, 0,´1. The optimization problem can be formulated as: α˚" argmin α w´r w 2 2 (6) Substituting (5) into (6) and expanding the squared term, the problem can be rewritten as: where I |∆| " ti ||w i | ď ∆u, |I ∆ | denotes the number of elements in I ∆ , and c ∆ " ř iPI c ∆ w 2 i . The solution for α˚is: i.e. the mean of all floating-point weights in I ∆ . Substituting (8) into (7) gives: In order to solve this problem easily, a simplifying assumption is made similar to [8] that all w i are either: (1) uniformly distributed, in which case ∆˚" 2 3 E|w|, or (2) normally distributed with zero mean, in which case ∆˚" 0.75E|w|.
To train the network, SGD is used in conjunction with Batch Normalization and momentum-based learning rate scaling. The quantized ternary weights are used during both forward and back-propagation, but for parameter update, the high-precision floating-point weights are used.

IV. EXPERIMENTAL RESULTS
The results for the networks from subsection III-B are given in Table I. The top-1 and top-5 accuracy percentages on the ImageNet database [16] for three quantization schemes are given. The model compression (i.e. the factor by which the memory footprint of the network is reduced in comparison to the non-quantized network) can be explained by the fact that floating-point values are normally represented as 32-bit variables. In ternary and binary-weighted networks however, the weights are represented using 2-bit and 1-bit variables respectively, thereby resulting in 16x and 32x model compression. With regard to speedup in CPU processing time, Rastegari et al. [14] offer the most promising results. Consider that in a standard convolution, the total number of operations is cN W N I , where c is the number of channels, and N W and N I are the number of elements in a single channel of the weight kernel and input matrix respectively. Using their proposed binary approximation however, convolution can be performed with cN W N I binary operations and N I non-binary operations. Since modern CPUs can perform 64 binary operations per clock cycle, the speedup S " cNW NI 1 64 cNW NI`NI " 64cNW cNW`64 . The actual speedup achieved for various filter sizes and number of channels is given in Figure 1. Fig. 1. Speedup on XNOR-net [14] for various filter sizes and number of channels Figure 1 summarizes the results from the work of Lin et al. [8] which quantizes pretrained networks. It shows the top-5 error rate on ImageNet using AlexNet architecture; the improvement gain by using their layer-wise optimization approach as opposed to uniformly quantizing all the layers can also be seen. As comparison, the top-5 error rate of the full-precision, floating-point AlexNet [1] is 17% Fig. 2. Top-5 error rates on ImageNet using quantization scheme proposed by Lin et al. [8] Lastly, the ternary quantization scheme for converting pretrained networks proposed by Hwang et al. resulted in a classification error rate of 1.08% on the MNIST database of handwritten digits 1 . This error rate is comparable to that observed by full-precision networks implemented with the LeNet-4 architecture [18].

CONCLUSION
Quantization of CNNs enables them to be deployed on lowpower, resource-constrained devices. In this paper, an overview of several network quantization approaches was given, with a more detailed description of some. Even though floatingpoint weights are still used during the weight update phase of back-propagation, the need for floating-point multiplications is eliminated. This is beneficial if CNNs are to be implemented on microcontrollers, since the latter often have 1 MNIST: http://yann.lecun.com/exdb/mnist/ limited floating-point computation capability, and similarly beneficial for FPGA-based implementations since floatingpoint multipliers are costly in terms of the number of slices required. In the best case, if all weights and inputs are binary, multiply-accumulate operations are replaced by 1-bit XNORcount operations which are extremely cheap to implement on hardware.