{"title": "CNNpack: Packing Convolutional Neural Networks in the Frequency Domain", "book": "Advances in Neural Information Processing Systems", "page_first": 253, "page_last": 261, "abstract": "Deep convolutional neural networks (CNNs) are successfully used in a number of applications. However, their storage and computational requirements have largely prevented their widespread use on mobile devices. Here we present an effective CNN compression approach in the frequency domain, which focuses not only on smaller weights but on all the weights and their underlying connections. By treating convolutional filters as images, we decompose their representations in the frequency domain as common parts (i.e., cluster centers) shared by other similar filters and their individual private parts (i.e., individual residuals). A large number of low-energy frequency coefficients in both parts can be discarded to produce high compression without significantly compromising accuracy. We relax the computational burden of convolution operations in CNNs by linearly combining the convolution responses of discrete cosine transform (DCT) bases. The compression and speed-up ratios of the proposed algorithm are thoroughly analyzed and evaluated on benchmark image datasets to demonstrate its superiority over state-of-the-art methods.", "full_text": "CNNpack: Packing Convolutional Neural Networks\n\nin the Frequency Domain\n\nYunhe Wang1,3, Chang Xu2, Shan You1,3, Dacheng Tao2, Chao Xu1,3\n\n1Key Laboratory of Machine Perception (MOE), School of EECS, Peking University\n\n2Centre for Quantum Computation and Intelligent Systems,\n\nSchool of Software, University of Technology Sydney\n\n3Cooperative Medianet Innovation Center, Peking University\n\nwangyunhe@pku.edu.cn, Chang.Xu@uts.edu.au, youshan@pku.edu.cn,\n\nDacheng.Tao@uts.edu.au, xuchao@cis.pku.edu.cn\n\nAbstract\n\nDeep convolutional neural networks (CNNs) are successfully used in a number\nof applications. However, their storage and computational requirements have\nlargely prevented their widespread use on mobile devices. Here we present an\neffective CNN compression approach in the frequency domain, which focuses not\nonly on smaller weights but on all the weights and their underlying connections.\nBy treating convolutional \ufb01lters as images, we decompose their representations\nin the frequency domain as common parts (i.e., cluster centers) shared by other\nsimilar \ufb01lters and their individual private parts (i.e., individual residuals). A\nlarge number of low-energy frequency coef\ufb01cients in both parts can be discarded\nto produce high compression without signi\ufb01cantly compromising accuracy. We\nrelax the computational burden of convolution operations in CNNs by linearly\ncombining the convolution responses of discrete cosine transform (DCT) bases.\nThe compression and speed-up ratios of the proposed algorithm are thoroughly\nanalyzed and evaluated on benchmark image datasets to demonstrate its superiority\nover state-of-the-art methods.\n\n1\n\nIntroduction\n\nThanks to the large amount of accessible training data and computational power of GPUs, deep\nlearning models, especially convolutional neural networks (CNNs), have been successfully applied to\nvarious computer vision (CV) applications such as image classi\ufb01cation [19], human face veri\ufb01cation\n[20], object recognition, and object detection [7, 17]. However, most of the widely used CNNs can\nonly be used on desktop PCs or even workstations due to their demanding storage and computational\nresource requirements. For example, over 232MB of memory and over 7.24 \u00d7 108 multiplications\nare required to launch AlexNet and VGG-Net per image, preventing them from being used in mobile\nterminal apps on smartphones or tablet PCs. Nevertheless, CV applications are growing in importance\nfor mobile device use and there is, therefore, an imperative to develop and use CNNs for this purpose.\nConsidering the lack of GPU support and the limited storage and CPU performance of mainstream\nmobile devices, compressing and accelerating CNNs is essential. Although CNNs can have millions\nof neurons and weights, recent research [9] has highlighted that over 85% of weights are useless\nand can be set to 0 without an obvious deterioration in performance. This suggests that the gap in\ndemands made by large CNNs and the limited resources offered by mobile devices may be bridged.\nSome effective algorithms have been developed to tackle this challenging problem. [8] utilized vector\nquantization to allow similar connections to share the same cluster center. [6] showed that the weight\nmatrices can be reduced by low-rank decomposition approaches.[4] proposed a network architecture\n\n30th Conference on Neural Information Processing Systems (NIPS 2016), Barcelona, Spain.\n\n\fFigure 1: The \ufb02owchart of the proposed CNNpack.\n\nusing the \u201chashing trick\u201d and [4] then transferred the HashedNet into the discrete cosine transform\n(DCT) frequency domain [3]. [16, 5] proposed binaryNet, whose weights were -1/1 or -1/0/1 [2]. [15]\nutilizes a sparse decomposition to reduce the redundancy of weights and computational complexity of\nCNNs. [9] employed pruning [10], quantization, and Huffman coding to obtain a greater than 35\u00d7\ncompression ratio and 3\u00d7 speed improvement, thereby producing state-of-the-art CNNs compression\nto the best of our knowledge. The effectiveness of the pruning strategy relies on the principle that\nif the absolute value of a weight in a CNN is suf\ufb01ciently small, its in\ufb02uence on the output is often\nnegligible. However, these methods tend to disregard the properties of larger weights, which might\nalso provide opportunities for compression. Moreover, independently considering each weight ignores\nthe contextual information of other weights.\nTo address the aforementioned problems, we propose handling convolutional \ufb01lters in the frequency\ndomain using DCT (see Fig. 1). In practice, convolutional \ufb01lters can be regarded as small and\nsmooth image patches. Hence, any operation on the convolutional \ufb01lter frequency coef\ufb01cients in the\nfrequency domain is equivalent to an operation performed simultaneously over all weights of the\nconvolutional \ufb01lters in the spatial domain. We factorize the representation of the convolutional \ufb01lter\nin the frequency domain as the composition of common parts shared with other similar \ufb01lters and\nits private part describing some unique information. Both parts can be signi\ufb01cantly compressed by\ndiscarding a large number of subtle frequency coef\ufb01cients. Furthermore, we develop an extremely fast\nconvolution calculation scheme that exploits the relationship between the feature maps of DCT bases\nand frequency coef\ufb01cients. We have theoretically discussed the compression and the speed-up of\nthe proposed algorithm. Experimental results on benchmark datasets demonstrate that our proposed\nalgorithm can consistently outperform state-of-the-art competitors, with higher compression ratios\nand speed gains.\n\n2 Compressing CNNs in the Frequency Domain\n\nRecently developed CNNs contain a large number of convolutional \ufb01lters. We regard convolutional\n\ufb01lters as small images with intrinsic patterns, and present an approach to compress CNNs in the\nfrequency domain with the help of the DCT.\n\n2.1 The Discrete Cosine Transform (DCT)\n\nThe DCT plays an important role in JPEG compression [22], which is regarded as an approximate\nKL-transformation for 2D images [1]. In JPEGs, the original image is usually divided into several\nsquare patches. For an image patch P \u2208 Rn\u00d7n, its DCT coef\ufb01cient C \u2208 Rn\u00d7n in the frequency\ndomain is de\ufb01ned as:\n\nCj1j2 = D(Pi1i2 ) = sj1 sj2\n\nwhere sj = (cid:112)1/n if j = 0 and sj = (cid:112)2/n, otherwise, and C = C T P C is the matrix form of\n\nthe DCT, where C = [c1, ..., cd] \u2208 Rd\u00d7d is the transformation matrix. The basis of this DCT is\n\n\u03b1(i1, i2, j1, j2)Pi1i2 = cT\nj1\n\ni1=0\n\ni2=0\n\nP cj2,\n\n(1)\n\nn\u22121(cid:88)\n\nn\u22121(cid:88)\n\n2\n\n\fSj1j2 = cj1cT\n\nj2, and \u03b1(i1, i2, j1, j2) denotes the cosine basis function:\n\n(cid:18) \u03c0(2i1 + 1)j1\n\n(cid:19)\n\n(cid:18) \u03c0(2i2 + 1)j2\n\n(cid:19)\n\n,\n\n(2)\n\ncos\n\n2n\n\n2n\n\n\u03b1(i1, i2, j1, j2) = cos\n\n(cid:16) \u03c0(2i+1)j\n\n(cid:17)\n\nand cj(i) =\nimage by simply utilizing the inverse DCT, i.e.,\n\n2n\n\n. The DCT is a lossless transformation thus we can recover the original\n\nPi1i2 = D\u22121(Cj1j2) =\n\nsj1sj2\u03b1(i1, i2, j1, j2)Cj1j2 ,\n\n(3)\n\nwhose matrix form is P = CCC T . Furthermore, to facilitate the notations we denote the DCT and the\ninverse DCT for vectors as vec(C) = D(vec(P )) = (C \u2297 C)vec(P ) and vec(P ) = D\u22121(vec(C)) =\n(C \u2297 C)T vec(C), where vec(\u00b7) is the vectorization operation and \u2297 is the Kronecker product.\n\nj1=0\n\nj2=0\n\nn\u22121(cid:88)\n\nn\u22121(cid:88)\n\n1 , ..., F (i)\nNi\n] \u2208 Rd2\n\n2.2 Convolutional Layer Compression\nComputing Residuals in the Frequency Domain. For a given convolutional layer Li, we \ufb01rst\nextract its convolutional \ufb01lters F (i) = {F (i)\n}, where the size of each convolutional \ufb01lter is\ndi \u00d7 di and Ni is the number of \ufb01lters in Li. Each \ufb01lter can then be transformed into a vector, and\nj ),\u2200 j = 1, ..., Ni.\ni \u00d7Ni, where x(i)\ntogether they form a matrix Xi = [x(i)\nDCT has been widely used for image compression, since DCT coef\ufb01cients present an experienced\ndistribution in the frequency domain. Energies of high-frequency coef\ufb01cients are usually much\nsmaller than those of low-frequency coef\ufb01cients for 2D natural images, i.e., the high frequencies\ntend to have values equal or close to zero [22]. Hence, we propose to transfer Xi into the DCT\nfrequency domain and obtain its frequency representation C = D(Xi) = [C1, ...,CNi ]. Since a\nnumber of convolutional \ufb01lters will share some similar components, we divide them into several\ngroups G = {G1, ..., GK} by exploiting K centers U = [\u00b51, ..., \u00b5k] \u2208 Rdi\u00d7K with the following\nminimization problem:\n\nj = vec(F (i)\n\n1 , ..., x(i)\nNi\n\n||C \u2212 \u00b5k||2\n2,\n\n(4)\n\nK(cid:88)\n\n(cid:88)\n\nk=1\n\nC\u2208Gk\n\narg min\nG\n\n(5)\n\nwhere \u00b5k is the cluster center of Gk. Fcn. 4 can easily be solved with the conventional k-means\nalgorithm [9, 8]. For each Cj, we denote its residual with its corresponding cluster as Rj = Cj \u2212 \u00b5kj ,\nwhere kj = arg mink ||Cj\u2212\u00b5k||2. Hence, each convolutional \ufb01lter is represented by its corresponding\ncluster center shared by other similar \ufb01lters and its private part Rj in the frequency domain. We\nfurther employ the following (cid:96)1-penalized optimization problem to control redundancy in the private\nparts for each convolutional \ufb01lter:\n\n||(cid:98)Rj \u2212 Rj||2\n\n2 + \u03bb||(cid:98)Rj||1,\narg min(cid:98)Rj\n(cid:98)Rj = sign(Rj) (cid:12) max{|Rj| \u2212 \u03bb\n\n, 0},\n\nwhere \u03bb is a parameter for balancing the reconstruction error and sparsity penalty. The solution to\nFcn. 5 is:\n\n(6)\nwhere sign(\u00b7) is the sign function. We can also control the redundancy in the cluster centers using the\nabove approach as well.\nQuantization, Encoding, and Fine-tuning. The sparse data obtained through Fcn. 6 is continuous,\nwhich is not bene\ufb01t for storing and compressing. Hence we need to represent similar values with\na common value, e.g., [0.101, 0.100, 0.102, 0.099] \u2192 0.100. Inspired by the conventional JPEG\n\nalgorithm, we use the following function to quantize (cid:98)Rj:\n(cid:40)\n\n(cid:41)\n\n2\n\nRj = Q(cid:16)(cid:98)Rj, \u2126, b\n(cid:17)\n\n= \u2126 \u00b7 I\n\nClip((cid:98)Rj,\u2212b, b)\n\n\u2126\n\n,\n\n(7)\n\nwhere Clip(x,\u2212b, b) = max(\u2212b, min(b, x)) with boundary b > 0, and \u2126 is a large integer with\nsimilar functionality to the quantization table in the JPEG algorithm. It is useful to note that the\n\n3\n\n\fquantized values produced by applying Fcn. 7 can be regarded as the one-dimensional k-means\ncenters in [9], thus a dictionary can consist of unique values in all {R1, ...,RNi}. Since occurrence\nprobabilities of elements in the codebook are unbalanced, we employ the Huffman encoding for a\nmore compact storage. Finally, the Huffman encoded data is stored in the compressed sparse row\nformat (CSR), denoted as Ei.\nIt has also been shown that \ufb01ne-tuning after compression further enhances network accuracy [10, 9].\nIn our algorithm, we also employ the \ufb01ne-tuning approach by holding weights that have been\ndiscarded so that the \ufb01ne-tuning operation does not change the compression ratio. After generating a\nnew model, we apply Fcn. 7 again to quantize the new model\u2019s parameters until convergence.\nThe above scheme for compressing convolutional CNNs stores four types of data: the compressed\ndata Ei, the Huffman dictionary with Hi quantized values, the k-means centers U \u2208 Rd2\ni \u00d7K, and\nthe indexes for mapping residual data to centers. It is obvious that if all \ufb01lters from every layer can\nshare the same Huffman dictionary and cluster centers, the compression ratio will be signi\ufb01cantly\nincreased.\n\n2.3 CNNpack for CNN Compression\n\nGlobal Compression Scheme. To enable all convolutional \ufb01lters to share the same cluster centers\nU \u2208 Rd2\ni \u00d7k in the frequency domain, we must convert them into a \ufb01xed-dimensional space. It is\nintuitive to directly resize all convolutional \ufb01lters into matrices of the same dimensions and then\napply k-means. However, this simple resizing method increases the amount of the data that needs to\nbe stored. Considering d as the target dimension and di \u00d7 di as the convolutional \ufb01lter size of the\ni-th layer, the weight matrix would be inaccurately reshaped in the case of di < d or di > d.\nA more reasonable approach would be to resize the DCT coef\ufb01cient matrices of convolutional \ufb01lters\nin the frequency domain, because high-frequency coef\ufb01cients are generally small and discarding\nthem only has a small impact on the result (di > d). On the other hand, the introduced zeros will be\nimmediately compressed by CSR since we do not need to encode or store them (di < d). Formally,\nthe resizing operation for convolutional \ufb01lters in the DCT frequency domain can be de\ufb01ned as:\n\n(cid:98)Cj1,j2 = \u0393(C, d) =\n\n(cid:26) Cj1,j2,\n\nif j1, j2 \u2264 d,\n\n0,\n\notherwise.\n\n(8)\nwhere d \u00d7 d is the \ufb01xed \ufb01lter size, C \u2208 Rdi\u00d7di is the DCT coef\ufb01cient matrix of a \ufb01lter in the i-th\n\nlayer and (cid:98)C \u2208 Rd\u00d7d is the coef\ufb01cient matrix after resizing. After applying Fcn. 8, we can pack all\n\nthe coef\ufb01cient matrices together and use only one set of cluster centers to compute the residual data\nand then compress the network. We extend the individual compression scheme into an integrated\nmethod that is convenient and effective for compressing deep CNNs, which we call CNNpack. The\nprocedures of the proposed algorithm are detailed in the supplementary materials.\nCNNpack has \ufb01ve hyper-parameters: \u03bb, d, K, b, and \u2126. Its compression ratio can be calculated by:\n\n(cid:80)p\n(cid:0)Ni log K + Bi\n\n(cid:80)p\n\ni=1\n\ni=1 32Nid2\ni\n\n(cid:1) + 32H + 32d\n\nrc =\n\n2\n\n,\n\nK\n\n(9)\n\nwhere p is the number of convolutional layers and H is the bits for storing the Huffman dictionary. It\nis instructive to note that a larger \u03bb (Fcn. 5) puts more emphasis on the common parts of convolutional\n\ufb01lters, which leads to a higher compression ratio rc. A decrease in any of b, d and \u2126 will increase\nrc accordingly. Parameter K is related to the sparseness of Ei, and a larger K would contribute\nmore to Ei\u2019s sparseness but would lead to higher storage requirement. A detailed investigation of\nall these parameters is presented in Section. 4, and we also demonstrate and validate the trade-off\nbetween the compression ratio and CNN accuracy of the convolutional neural work (i.e., classi\ufb01cation\naccuracy [19]).\n\n3 Speeding Up Convolutions\n\nAccording to Fcn. 9, we can obtain a good compression ratio by converting the convolutional \ufb01lters\ninto the DCT frequency domain and representing them using their corresponding cluster centers and\n\n4\n\n\fresidual data Ri = [R1, ...,RNi ]. This is an effective strategy to reduce CNN storage requirements\nand transmission consumption. However, two other important issues need to be emphasized: memory\nusage and complexity.\nThis section focuses on a single layer throughout, we will drop the layer index i in order to simplify\nnotation. In practice, the residual data R in the frequency domain cannot be simply used to calculate\nconvolutions, so we must \ufb01rst transform them to the original \ufb01lters in the spatial domain, thus not\nsaving memory. Furthermore, the transformation will further increase algorithm complexity. It is\nthus necessary to explore a scheme that enables the proposed compression method to easily calculate\nfeature maps of original \ufb01lters in the DCT frequency domain.\nGiven a convolutional layer L with its \ufb01lters F = {Fq}N\nq=1 of size d \u00d7 d, we denote the input data\nas X \u2208 RH\u00d7W and its output feature maps as Y = {Y1, Y2, ..., YN} with size H(cid:48) \u00d7 W (cid:48), where\nYq = Fq \u2217 X for the convolution operation \u2217. Here we propose a scheme which decomposes the\ncalculation of the conventional convolutions in the DCT frequency domain.\nFor the DCT matrix C = [c1, ..., cd], the d \u00d7 d convolutional \ufb01lter Fq can be represented by its\nDCT coef\ufb01cient matrix C(q) with DCT bases {Sj1,j2}d\nj2, namely,\nSj1,j2. In this way, feature maps of X through F can be calculated\n(Sj1,j2 \u2217 X), where M = d2 is the number of DCT bases. Fortunately,\nsince the DCT is an orthogonal transformation, all of its bases are rank-1 matrices. Note that\n\n(cid:80)d\nFq = (cid:80)d\nas Yq = (cid:80)d\nj2=1 C(q)\nSj1,j2 \u2217 X =(cid:0)cj1cT\nj1,j2=1 C(q)\n\n(cid:1) \u2217 X, and thus feature map Yq can be written as\n\nj1,j2=1 de\ufb01ned as Sj1,j2 = cj1cT\n\nj1=1\n\nj1,j2\n\nj1,j2\n\nj2\n\nd(cid:88)\n\nd(cid:88)\n\nYq = Fq \u2217 X =\n\nC(q)\n\nj1,j2\n\n(Sj1,j2 \u2217 X) =\n\nC(q)\n\nj1,j2\n\n[cj1 \u2217 (cT\n\nj2\n\n\u2217 X)].\n\n(10)\n\nj1,j2=1\n\nj1,j2=1\n\nOne drawback of this scheme is that when the number of \ufb01lters in this layer is relatively small, i.e.,\nM \u2248 N, Fcn. 10 will increase computational cost. Moreover, the complexity can be further reduced\ngiven the fascinating fact that the feature maps calculated by these DCT bases are exactly the same as\nthe DCT frequency coef\ufb01cients of the input data. For a d \u00d7 d matrix X, we consider the matrix form\nof its DCT, i.e., C = C T XC, and DCT bases {Sj1,j2}, then the coef\ufb01cient Cj1,j2 can be calculated\nas\nCj1,j2 = cT\nj2 ) \u2217 X = Sj1,j2 \u2217 X, (11)\nthus we can obtain the feature maps of M DCT bases by only applying the DCT once. Thus the\ncomputational complexity of our proposed scheme can be analyzed in Proposition 1.\nProposition 1. Given a convolutional layers with N \ufb01lters, denote M = d\u00d7 d as the number of DCT\nbase, and C \u2208 Rd2\u00d7N as the compressed coef\ufb01cients of \ufb01lters in this layer. Suppose \u03b4 is the ratio of\nnon-zero elements in C, while \u03b7 is the ratio of non-zero elements in K(cid:48) active cluster centers of this\nlayer. The computational complexity of our proposed scheme is O((d2 log d+\u03b7M K(cid:48)+\u03b4M N )H(cid:48)W (cid:48)).\n\nj2 \u2217 X) = cj1 \u2217 (cT\n\nj2 \u2217 X) = (cj1 \u2217 cT\n\nj2 ) \u2217 X = (cj1 cT\n\nj1 Xcj2 = cT\n\nj1 (cT\n\nThe proof of Proposition 1 can be found in the supplementary materials. According to Proposition 1,\nthe proposed compression scheme in the frequency domain can also improve the speed. Compared to\nthe original CNN, for a convolutional layer, the speed-up of the proposed method is\n\nrs =\n\nd2N H(cid:48)W (cid:48)\n\n(d2 log d + \u03b7K(cid:48)M + \u03b4N M )H(cid:48)W (cid:48) \u2248\n\nN\n\n\u03b7K(cid:48) + \u03b4N\n\n.\n\n(12)\n\nObviously, the speed-up ratio of the proposed method is directly relevant to \u03b7 and \u03b4, which correspond\nto \u03bb in Fcn. 6.\n\n4 Experimental Results\n\nBaselines and Models. We compared the proposed approach with 4 baseline approaches: Prun-\ning [10], P+QH (Pruning + Quantization and Huffman encoding) [9], SVD [6], and XNOR-Net [16].\nThe evaluation was conducted using the MNIST and ILSVRC2012 datasets. We compared the\nproposed compression approach with four baseline CNNs: LeNet [14, 21], AlexNet [13], VGG-16\nNet [19], and ResNet-50 [11]. All methods were implemented using MatConvNet [21] and run on\n\n5\n\n\fNVIDIA Titan X graphics cards. Model parameters were stored and updated as 32 bit \ufb02oating-point\nvalues.\nImpact of parameters. As discussed above, the proposed compression method has several important\nparameters: \u03bb, d, K, b, and \u2126. We \ufb01rst tested their impact on the network accuracy by conducting\nan experiment using MNIST [21], where the network has two convolutional layers and two fully-\nconnected layers of size 5 \u00d7 5 \u00d7 1 \u00d7 20, 5 \u00d7 5 \u00d7 20 \u00d7 50, 4 \u00d7 4 \u00d7 50 \u00d7 500, and 1 \u00d7 1 \u00d7 500 \u00d7 10,\nrespectively. The model accuracy was 99.06%. The compression results of different \u03bb and d after\n\ufb01ne-tuning 20 epochs are shown in Fig. 2 in which k was set as 16, b was equal to +\u221e since it did\nnot make an obvious contribution to the compression ratio even when set at a relatively smaller value\n(e.g., b = 0.05) but caused the accuracy reduction. \u2126 was set to 500, making the average length\nof weights in the frequency domain about 5, a bit larger than that in [9] but more \ufb02exible and with\nrelatively better performance. Note that all the training parameters used their the default settings,\nsuch as for epochs, learning rates, etc..\nIt can be seen from Fig. 2 that although a lower d slightly improves the compression ratio and\nspeed-up ratio simultaneously, this comes at a cost of decreased overall network accuracy; thus, we\nkept d = max{di}, \u2200 i = 1, ..., p, in CNNpack. Overall, \u03bb is clearly the most important parameter in\nthe proposed scheme, which is sensitive but monotonous. Thus, it only needs to be adjusted according\nto demand and restrictions. Furthermore, we tested the impact of number of cluster centers K. As\nmentioned above, K is special in that its impact on performance is not intuitive, and when it becomes\nlarger, E becomes sparser but needs more space for storing cluster centers U and indexes. Fig. 3\nshows that K = 16 provides the best trade-off between compression performance and accuracy.\n\nFigure 2: The performance of the proposed approach with different \u03bb and d.\n\nFigure 3: The performance of the proposed approach with different numbers of cluster centers K.\nWe also report the compression results by directly compressing the DCT frequency coef\ufb01cients of\noriginal \ufb01lters C as before (i.e., K = 0, the black line in Fig. 3). It can be seen that the clustering\nnumber does not affect accuracy, but a suitable K does enhance the compression ratio. Another\ninteresting phenomenon is that the speed-up ratio without decomposition is larger than that of the\nproposed scheme because the network is extremely small and the clustering introduces additional\ncomputational cost as shown in Fcn. 12. However, recent networks contain a lot more \ufb01lters in a\nconvolutional layer, larger than K = 16.\nBased on the above analysis, we kept \u03bb = 0.04 and K = 16 for this network (an accuracy of 99.14%).\nAccordingly, the compression ratio rc = 32.05\u00d7 and speed-up ratio rs = 8.34\u00d7, which is the best\ntrade-off between accuracy and compression performance.\nFilter visualization. The proposed algorithm operates in the frequency domain, and although we\ndo not need to invert the compressed net when calculating convolutions, we can reconstruct the\nconvolutional \ufb01lters in the spatial domain to provide insights into our approach. Reconstructed\nconvolution \ufb01lters are obtained from the LeNet on MNIST, as shown in Fig. 4.\n\n6\n\n0.9800.9840.9880.9920.0250.0350.0450.055Accuracyld- = 5d- = 4d- = 3204060800.0250.0350.0450.055Compression ratiold- = 5d- = 4d- = 35101520250.0250.0350.0450.055Speedup ratiold- = 5d- = 4d- = 30.9860.9880.9900.9920.0250.0350.0450.055AccuracylK = 16K = 64K = 128K = 0204060800.0250.0350.0450.055Compression ratiolK = 16K = 64K = 128K = 051015200.0250.0350.0450.055Speedup ratiolK = 16K = 64K = 128K = 0\fFigure 4: Visualization of example \ufb01lters learned on MNIST: (a) the original convolutional \ufb01lters, (b)\n\ufb01lters after pruning, (c) convolutional \ufb01lters compressed by the proposed algorithm.\n\nThe proposed approach is fundamentally different to the previously used pruning algorithm. Ac-\ncording to Fig. 4(b), weights with smaller magnitudes are pruned while in\ufb02uences of larger weights\nhave been discarded. In contrast, our proposed algorithm not only handles the smaller weights but\nalso considers impacts of those larger weights. Most importantly, we accomplish the compressing\ntask by exploring the underlying connections between all the weights in the convolutional \ufb01lter (see\nFig. 4(c)).\nCompression AlexNet and VGGNet on ImageNet. We next employed CNNpack for CNN com-\npression on the ImageNet ILSVRC-2012 dataset [18], which contains over 1.2M training images and\n50k validation images. First, we examined two conventional models: AlexNet [13], with over 61M\nparameters and a top-5 accuracy of 80.8%; and VGG-16 Net, which is much larger than the AlexNet\nwith over 138M parameters and has a top-5 accuracy of 90.1%. Table 1 shows detailed compression\nand speed-up ratios of the AlexNet with \u03bb = 0.04 and K = 16. The result of the VGG-16 Net can\nbe found in the supplementary materials. The reported multiplications are for computing one image.\n\nTable 1: Compression statistics for AlexNet.\n\nLayer\nconv1\nconv2\nconv3\nconv4\nconv5\nfc6\nfc7\nfc8\nTotal\n\nNum of Weights\n11 \u00d7 11 \u00d7 3 \u00d7 96\n5 \u00d7 5 \u00d7 48 \u00d7 256\n3 \u00d7 3 \u00d7 256 \u00d7 384\n3 \u00d7 3 \u00d7 192 \u00d7 384\n3 \u00d7 3 \u00d7 192 \u00d7 256\n6 \u00d7 6 \u00d7 256 \u00d7 4096\n1 \u00d7 1 \u00d7 4096 \u00d7 4096\n1 \u00d7 1 \u00d7 4096 \u00d7 1000\n\n60954656\n\nMemory\n0.13MB\n1.17MB\n3.37MB\n2.53MB\n1.68MB\n144MB\n64MB\n\n15.62MB\n232.52MB\n\nrc\n878\u00d7\n94\u00d7\n568\u00d7\n42\u00d7\n43\u00d7\n148\u00d7\n15\u00d7\n121\u00d7\n39\u00d7\n\nMultiplication\n1.05\u00d7108\n2.23\u00d7108\n1.49\u00d7108\n1.12\u00d7108\n0.74\u00d7108\n0.37\u00d7108\n0.16\u00d7108\n0.04\u00d7108\n7.24\u00d7108\n\nrs\n127\u00d7\n28\u00d7\n33\u00d7\n15\u00d7\n12\u00d7\n100\u00d7\n8\u00d7\n60\u00d7\n25\u00d7\n\nWe achieved a 39\u00d7 compression ratio and a 46\u00d7 compression ratio for AlexNet and VGG-16 Net,\nrespectively. The layer with a relatively larger \ufb01lter size had a larger compression ratio because it\ncontains more subtle high-frequency coef\ufb01cients. In contrast, the highest speed-up ratio was often\nobtained on the layer whose \ufb01lter number N was much larger than its \ufb01lter size, e.g., the fc6 layer of\nAlexNet. We obtained an about 9\u00d7 speed-up ratio on VGG-16 Net, which is lower than that on the\nAlexNet since complexity is relevant to the feature map size and the \ufb01rst several layers de\ufb01nitely have\nmore multiplications. Unfortunately, their \ufb01lter numbers are relatively small and their compression\nratios are all small, thus the overall speed-up ratio is lower than that on AlexNet. Accordingly, when\nwe set K = 0, the compression ratio and the speed-up ratio of AlexNet were close to 35\u00d7 and 22\u00d7\nand those of VGG-16 Net were near 28\u00d7 and 7\u00d7. This reduction is due to these two networks being\nrelatively large and containing many similar \ufb01lters. Moreover, the \ufb01lter number in each layer is larger\nthan the number of cluster centers, i.e., N > K. Thus, cluster centers can effectively reduce memory\nconsumption and computational complexity simultaneously.\nResNet-50 on ImageNet. Here we discuss a more recent work, ResNet-50 [11], which has more\nthan 150 layers and 54 convolutional layers. This model achieves a top-5 accuracy of 7.71% and\na top-1 accuracy of 24.62% with only about 95MB parameters [21]. Moreover, since most of its\nconvolutional \ufb01lters are 1 \u00d7 1, i.e., its architecture is very thin with less redundant weights, it is very\nhard to perform compression methods on it.\nFor the experiment on ResNet-50, we set K = 0 since the functionality of Fcn. 7 for 1-dimensional\n\ufb01lters are similar to that of k-means clustering, thus cluster centers are dispensable for this model.\nFurther, we set \u03bb = 0.04 and therefore discarded about 84% of original weights in the frequency\n\n7\n\n\f(a) Compression ratios of all convolutional layers. (b) Speed-up ratios of all convolutional layers.\n\nFigure 5: Compression statistics for ResNet-50 (better viewed in color version).\n\ndomain. After \ufb01ne-tuning, we obtained a 7.82% top-5 accuracy on ILSVRC2012 dataset. Fig. 5\nshows the detailed compression statistics of ResNet-50 utilizing the proposed CNNpack. In summary,\nmemory usage for storing its \ufb01lters was squeezed by a factor of 12.28\u00d7.\nIt is worth mentioning that, larger \ufb01lters seem have more redundant weights and connections because\ncompression ratios on layers with 1\u00d71 \ufb01lters are smaller than those on layers with 3\u00d73 \ufb01lters. On\nthe other side, these 1\u00d71 \ufb01lters hold a larger proportion of multiplications of the ResNet, thus we got\nan about 4\u00d7 speed-up on this network.\nComparison with state-of-the-art methods. We detail a comparison with state-of-the-art-methods\nfor compressing DNNs in Table 2. CNNpack clearly achieves the best performance in terms of both\nthe compression ratio (rc) and the speed-up ratio (rs). Note that although Pruning+QH achieves a\nsimilar compression ratio to the proposed method, \ufb01lters in their algorithm are stored after applying a\nmodi\ufb01ed CSC format which stores index differences, means that it needs to be decoded before any\ncalculation. Hence, the compression ratio of P+QH will be lower than that have been reported in [9]\nif we only consider memory usage. In contrast, the compressed data produced by our method can be\ndirectly used for network calculation. In reality, online memory usage is the real restriction for mobile\ndevices, and the proposed method is superior to previous works in terms of both the compression\nratio and the speed-up ratio.\n\nTable 2: An overall comparison of state-of-the-art methods for deep neural network compression and\nspeed-up, where rc is the compression ratio and rs is the speed-up.\n\nModel\n\nEvaluation Original\n\nPruning [10]\n\nP+QH [9]\n\nSVD [6] XNOR [16]\n\n64\u00d7\n58\u00d7\n56.8%\n31.8%\n\n-\n-\n-\n-\n\nCNNpack\n\n39\u00d7\n25\u00d7\n41.6%\n19.2%\n46\u00d7\n9.4\u00d7\n29.7%\n10.4%\n\n1\n1\n\n1\n1\n\n41.8%\n19.2%\n\n28.5%\n9.9%\n\nAlexNet\n\nVGG16\n\nrc\nrs\n\ntop-1 err\ntop-5 err\n\nrc\nrs\n\ntop-1 err\ntop-5 err\n\n5 Conclusion\n\n9\u00d7\n-\n\n42.7%\n19.6%\n13\u00d7\n-\n\n31.3\n10.8\n\n35\u00d7\n-\n\n42.7%\n19.7%\n49\u00d7\n3.5\u00d7\n31.1%\n10.9%\n\n5\u00d7\n2\u00d7\n44.0%\n20.5%\n\n-\n-\n-\n-\n\nNeural network compression techniques are desirable so that CNNs can be used on mobile devices.\nTherefore, here we present an effective compression scheme in the DCT frequency domain, namely,\nCNNpack. Compared to state-of-the-art methods, we tackle this issue in the frequency domain,\nwhich can offer the probability for more compression ratio and speed-up. Moreover, we no longer\nindependently consider each weight since each frequency coef\ufb01cient\u2019s calculation involves all\nweights in the spatial domain. Following the proposed compression approach, we explore a much\ncheaper convolution calculation based on the sparsity of the compressed net in the frequency domain.\nMoreover, although the compressed network produced by our approach is sparse in the frequency\ndomain, the compressed model has the same functionality as the original network since \ufb01lters in the\nspatial domain have preserved intrinsic structure.Our experiments show that the compression ratio\nand the speed-up ratio are both higher than those of state-of-the-art methods. The proposed CNNpack\napproach creates a bridge to link traditional signal and image compression with CNN compression\ntheory, allowing us to further explore CNN approaches in the frequency domain.\nAcknowledgements This work was supported by the National Natural Science Foundation of China\nunder Grant NSFC 61375026 and 2015BAF15B00, and Australian Research Council Projects: FT-\n130101457, DP-140102164 and LE-140100061.\n\n8\n\n\fReferences\n[1] Nasir Ahmed, T Natarajan, and Kamisetty R Rao. Discrete cosine transform. Computers, IEEE Transac-\n\ntions on, 100(1):90\u201393, 1974.\n\n[2] Sanjeev Arora, Aditya Bhaskara, Rong Ge, and Tengyu Ma. Provable bounds for learning some deep\n\nrepresentations. ICML, 2014.\n\n[3] Wenlin Chen, James T Wilson, Stephen Tyree, Kilian Q Weinberger, and Yixin Chen. Compressing\n\nconvolutional neural networks. arXiv preprint arXiv:1506.04449, 2015.\n\n[4] Wenlin Chen, James T Wilson, Stephen Tyree, Kilian Q Weinberger, and Yixin Chen. Compressing neural\n\nnetworks with the hashing trick. 2015.\n\n[5] Matthieu Courbariaux and Yoshua Bengio. Binarynet: Training deep neural networks with weights and\n\nactivations constrained to+ 1 or-1. arXiv preprint arXiv:1602.02830, 2016.\n\n[6] Emily L Denton, Wojciech Zaremba, Joan Bruna, Yann LeCun, and Rob Fergus. Exploiting linear structure\n\nwithin convolutional networks for ef\ufb01cient evaluation. In NIPs, 2014.\n\n[7] Ross Girshick, Jeff Donahue, Trevor Darrell, and Jitendra Malik. Rich feature hierarchies for accurate\n\nobject detection and semantic segmentation. In CVPR, 2014.\n\n[8] Yunchao Gong, Liu Liu, Ming Yang, and Lubomir Bourdev. Compressing deep convolutional networks\n\nusing vector quantization. arXiv preprint arXiv:1412.6115, 2014.\n\n[9] Song Han, Huizi Mao, and William J Dally. Deep compression: Compressing deep neural networks with\n\npruning, trained quantization and huffman coding. 2016.\n\n[10] Song Han, Jeff Pool, John Tran, and William Dally. Learning both weights and connections for ef\ufb01cient\n\nneural network. In NIPs, 2015.\n\n[11] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition.\n\narXiv preprint arXiv:1512.03385, 2015.\n\n[12] Yangqing Jia, Evan Shelhamer, Jeff Donahue, Sergey Karayev, Jonathan Long, Ross Girshick, Sergio\nIn\n\nGuadarrama, and Trevor Darrell. Caffe: Convolutional architecture for fast feature embedding.\nProceedings of the ACM International Conference on Multimedia, 2014.\n\n[13] Alex Krizhevsky, Ilya Sutskever, and Geoffrey E Hinton. Imagenet classi\ufb01cation with deep convolutional\n\nneural networks. In NIPs, 2012.\n\n[14] Yann LeCun, L\u00e9on Bottou, Yoshua Bengio, and Patrick Haffner. Gradient-based learning applied to\n\ndocument recognition. Proceedings of the IEEE, 86(11):2278\u20132324, 1998.\n\n[15] Baoyuan Liu, Min Wang, Hassan Foroosh, Marshall Tappen, and Marianna Pensky. Sparse convolutional\n\nneural networks. In CVPR, 2015.\n\n[16] Mohammad Rastegari, Vicente Ordonez, Joseph Redmon, and Ali Farhadi. Xnor-net: Imagenet classi\ufb01ca-\n\ntion using binary convolutional neural networks. arXiv preprint arXiv:1603.05279, 2016.\n\n[17] Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun. Faster r-cnn: Towards real-time object detection\n\nwith region proposal networks. In NIPs, 2015.\n\n[18] Olga Russakovsky, Jia Deng, Hao Su, Jonathan Krause, Sanjeev Satheesh, Sean Ma, Zhiheng Huang,\nAndrej Karpathy, Aditya Khosla, Michael Bernstein, et al. Imagenet large scale visual recognition challenge.\nIJCV, 115(3):211\u2013252, 2015.\n\n[19] Karen Simonyan and Andrew Zisserman. Very deep convolutional networks for large-scale image recogni-\n\ntion. ICLR, 2015.\n\n[20] Yi Sun, Yuheng Chen, Xiaogang Wang, and Xiaoou Tang. Deep learning face representation by joint\n\nidenti\ufb01cation-veri\ufb01cation. In NIPs, 2014.\n\n[21] Andrea Vedaldi and Karel Lenc. Matconvnet: Convolutional neural networks for matlab. In Proceedings\n\nof the 23rd Annual ACM Conference on Multimedia Conference, 2015.\n\n[22] Gregory K Wallace. The jpeg still picture compression standard. Consumer Electronics, IEEE Transactions\n\non, 38(1):xviii\u2013xxxiv, 1992.\n\n9\n\n\f", "award": [], "sourceid": 169, "authors": [{"given_name": "Yunhe", "family_name": "Wang", "institution": "Peking University"}, {"given_name": "Chang", "family_name": "Xu", "institution": "Peking University"}, {"given_name": "Shan", "family_name": "You", "institution": null}, {"given_name": "Dacheng", "family_name": "Tao", "institution": "Nanyang Technological University"}, {"given_name": "Chao", "family_name": "Xu", "institution": "Peking University"}]}