# ClipQ: Clipping Optimization for the Post-Training Quantization of Convolutional Neural Network
## 1 Introduction  
In recent years, convolutional neural networks (CNNs) have produced excellent results in computer vision tasks such as image classification [1, 2, 3, 4], object detection [5, 6, 7, 8], and image segmentation [9, 10, 11, 12, 13]. However, the large-scale parameters and high-complexity computation of CNNs challenge the storage, power consumption, and computing power of the device. In the deployment of chips for stereo matching networks in deep estimation tasks and the application of mobile devices such as drone driving, CNNs will quickly deplete their storage, memory, batteries, and computing units [14]. Therefore, reducing the scale of the parameter and computational complexity of CNNs is of great importance for the deployment of neural networks in mobile applications [15]. Researchers have proposed a series of CNN compression and acceleration methods, such as lightweight network design, low rank decomposition, pruning, quantization, etc. Quantization is a technique that converts floating-point weights and activations into low-precision fixed-point numbers. Quantization can reduce the data bit width, such as in deep learning scenarios for weather forecasting, which can directly reduce the storage pressureof multi-source data related to lightning and lower hardware power consumption [16]. Segmenting intraoral photography images can improve computational speed and save time for clinical diagnosis [17]. However, since low-bit data cannot fully represent the information of floating-point data, quantization usually hurts network performance. Current quantization methods involve training-based quantization [18; 19; 20] and post-training quantization [21; 22; 23; 24; 25]. Training-based quantization methods improve performance by inserting quantization nodes or low-level computing units and optimizing parameters through backpropagation, but the time cost is enormous. Quantification after training has been widely applied in mobile model deployment due to its convenience and efficiency. But it will cause a greater loss of network performance, especially for lightweight networks. Crop optimization can effectively improve the performance of quantization after training, such as TensorRt [22], EasyQuant [26], MSE [21], ACIQ [27], etc., which aims to select the optimal clipping thresholds to minimize the quantization deviation. But these methods have two problems. One is the issue of attention balance [28]. For example, if ownership values are treated equally in weight pruning, the quantization accuracy of important weights will decrease, resulting in greater network performance loss. The second issue is the threshold problem, as existing pruning optimization methods find it difficult to find the optimal search step size and search interval. In this paper, a novel clipping optimization method named ClipQ is proposed to overcome the above problems. More specifically, we obtain weight attention according to the absolute value criterion from the pruning technique and then the particle swarm algorithm instead of a grid search is used to find the best weight clipping thresholds, which adaptively adjusts the search step and direction based on search experience. For activation clipping, ClipQ represents the channel attention of activation based on the channel information entropy and utilizes principal component analysis to characterize the spatial attention of activation [29]. Channel attention and spatial attention will be combined to preferentially reduce the quantization deviation of important activations. The main contributions of this paper are summarized as follows:  
1. We design spatial attention, channel attention and weight attention to overcome the attention equalization problem in clipping optimization. 2. The particle swarm algorithm is applied to weight clipping for the first time, which helps to solve the optimal clip threshold more stably, compared to grid search. 3. The excellent performance of ClipQ is demonstrated in image classification, semantic segmentation, and object detection tasks.