# ClipQ: Clipping Optimization for the Post-Training Quantization of Convolutional Neural Network
## 3 Method
### Activation Clipping Optimization  
Unlike weight, activation is not the inherent parameter of the network. We obtain activation by inferring on a few calibration samples. The activation will be quantized layer by layer. There are some features in the activation, such as 0-value activation maps, background features, etc., which have little effect on the output of the network. In activation clipping, we want to pay less attention to them, so activation attention is proposed. From the channel perspective, we can regard activation \(A\in R^{c\times h^{\prime}\times w^{\prime}}\) as the feature map extracted by \(c\) convolution kernels, as shown in Figure 4, where \(c\) represents the number of channels of activation, \(h^{\prime}\) is the height of the activation, and \(w^{\prime}\) means the activation's width. Although the input images are different, the feature maps extracted by the same convolution kernel are similar. For example, zero feature maps appear in the  
Figure 3: Linear Search and Particle Swarm Optimization. (**a**) Linear search for \(x_{min}\) and \(x_{max}\). (**b**) The initial state of particle swarm optimization. (**c**) The convergence status of particle swarm optimization. same channel. According to [PERSON]'s theorem, the amount of information contained in data is proportional to its information entropy. \[I_{j}=-\sum_{i}p_{i}\log\left(p_{i}\right) \tag{10}\]  
Specifically, as shown in Figure 5, we first compute the distribution histogram of activation for each channel in the same interval \([min(A),max(A)]\). The information entropy of the jth channel is calculated by (10), where \(p_{i}\) represents the frequency of the i-th group data in the distribution histogram. From the spatial perspective, we can regard the activation as a matrix \(X\) composed of \(h^{\prime}\times w^{\prime}\) groups of feature vectors and the vector dimension is \(c\). It means that the convolutional layer encodes the relevant region (receptive field) of the picture into a feature vector. In general, deep convolutional layers have a larger receptive field and more convolution kernels, indicating that a larger region is encoded with longer dimensions. In visual tasks such as image recognition and object detection, the importance of feature vectors varies among different positions. The internet focuses more on the prospects, so the activation of foreground regions should be given priority consideration. In addition, the input regions are encoded as equal-length feature vectors, so their redundancy is also different. In order to reflect the coding redundancy and the network's attention on activation in different regions, ClipQ compresses the original activation based on principal component analysis to remove redundant information and obtain its principal component. In the principal component, different regions of the network input will be encoded as a single numerical value. Its numerical magnitude can be thought of as the network's attention to activations [39]. We regard it as the spatial attention of activations. Specifically, feature vectors in \(X\) subtract their own mean to obtain the decentralization matrix \(X^{\prime}\) at first. Then, we perform singular value decomposition of \(X^{\prime}\):  
\[X^{\prime}=U\Sigma V^{\intercal} \tag{11}\]  
\(U\in R^{h^{\prime}w^{\prime}\times h^{\prime}w^{\prime}}\) is an orthogonal matrix whose column vectors are called left singular vectors. \(\Sigma\in R^{h^{\prime}w^{\prime}\times n}\) is a diagonal matrix, with n singular values arranged on its diagonal. Figure 4: Channel feature map of the first convolution layer of MobileNetV2. Figure 5: The calculation of Channel Importance. \(U\in R^{n\times n}\) is also an orthogonal matrix, and its column vector is called the right singular vector. We compress \(X\) in the column direction by obtaining the projection of \(X\) on the first column vector of \(V\). Finally, ReLu and normalization will act on the projection to obtain the spatial attention of activation \(\sigma\in R^{l/n^{\prime}}\).