Abstract
Deep neural networks are hard to run on devices with limited memory and computing power. Pruning, which removes parts of a network that are not needed, can make them smaller, but in most cases it does not remove everything that is redundant. This work presents a mixed filter pruning approach that uses principal component analysis (PCA) together with the geometric median.
First, a pre-trained network is analyzed with PCA to find the important filters in every layer. These are used to build a new network that has fewer layers and fewer filters per layer, and the new network is trained. Second, the geometric median is used to find redundant filters in the trained network, and these are removed to compress it further. Finally, the pruned network is fine-tuned to regain its accuracy. Experiments on the CIFAR-10, CIFAR-100 and ILSVRC 2017 datasets show that the network can be compressed to a large extent without a significant loss of accuracy. For example, VGG-16 on CIFAR-10 needs 18.56 times fewer operations and 3.33 times fewer parameters, for a loss of almost 1% in accuracy.
Introduction
Convolutional neural networks (CNNs) are the state of the art in many tasks, such as face recognition, object detection and image classification. The best networks are deep and wide, with millions of parameters, and they need powerful graphics processors to train and run. At the same time, there is a growing wish to run neural networks on mobile devices, which have very limited memory and computing power. The VGG-19 network, for instance, has about 143 million parameters.
One of the main ways to make a network smaller is pruning, which removes filters or weights that are redundant without hurting accuracy. Figure 1 shows the filters of the first layer of the AlexNet network, and many of them look alike, which shows the redundancy. Most pruning methods, however, need many iterations to find a suitable threshold for each layer, which takes a lot of time and computing, and even then the network is not fully pruned. This work combines two earlier ideas in a mixed approach that focuses on redundancy rather than on how important each filter is to the accuracy: PCA is used to shrink the network’s layers and filters, and the geometric median is then used to remove the remaining redundant filters.
Related Work
Earlier work to make neural networks smaller falls into several groups. Weight pruning removes individual weights that matter little. One well-known method of this kind made the VGG-16 network 49 times smaller, but it leaves the network with an irregular structure that needs special hardware to benefit from. Filter pruning removes whole filters instead, which keeps the structure regular. Many of these methods have to repeat the pruning and retraining several times, which costs a lot of time and computing.
Other approaches approximate the weights with simpler numbers or matrices (quantization and low-rank approximation), or change the training so that many weights become zero. Some combine weight pruning and filter pruning, but they need a large amount of computation to find the filters and to regain the accuracy afterwards.
Proposed Method
The method has two steps, shown in Figure 2. Neither of them needs repeated rounds of pruning.
Step 1: PCA. A pre-trained network is run on data, and the outputs of all its layers (the activations) are analyzed with PCA. For each layer, the number of principal components needed to explain 99.9% of the variance gives the number of filters that layer really needs. The depth of the network is then set by looking at where these numbers stop growing: a layer with the same or fewer filters than the layer before it does not add a useful transformation, so it is removed. A new network with these fewer layers and fewer filters is created, started from random values and trained on the data.
Step 2: Geometric median. In the trained network, the geometric median of all the filters in a layer is found, which represents the information they share. The filters closest to it carry the most common information and can be replaced by the other filters, so they are set to zero and removed. The network is then fine-tuned to regain its accuracy.
To use PCA, the activations of each layer are flattened into a table where every row is one input sample and every column is one filter (Figure 3). PCA is then run on this table.
The method was tested on three public datasets and three networks: AlexNet and VGG-16 on CIFAR-10 (10 classes), VGG-19 on CIFAR-100 (100 classes) and VGG-19 on ILSVRC 2017 (1,000 classes). The method was implemented in PyTorch and run on an NVIDIA Tesla K80 GPU.
Results and Discussion
VGG-16 on CIFAR-10. PCA showed that the network’s 13 convolutional layers could be reduced to 6 (Figure 4). After the geometric median step and 50 epochs of fine-tuning, the network needed 18.56 times fewer operations and 3.33 times fewer parameters. Its accuracy went from 93.57% to 92.38%. The earlier PCA-based method reached only 7.78 times fewer operations and 2.82 times fewer parameters, and the geometric-median-only method 1.42 and 1.62 times, so the new method compressed the most.
AlexNet on CIFAR-10. AlexNet is smaller and has less redundancy, but the network still went from 5 convolutional layers to 4 (Figure 5). Operations were reduced by 2.61 times and parameters by 4.85 times, and the accuracy even rose from 86.31% to 87.51%. Both numbers were better than those of the two earlier methods.
VGG-19 on CIFAR-100. VGG-19 has 16 convolutional layers and a lot of redundancy. PCA reduced it to 7 layers (Figure 6), and the final network needed 16.02 times fewer operations and 36.42 times fewer parameters, with the accuracy falling from 70.42% to 67.77%, a loss of about 2.65%.
VGG-19 on ILSVRC 2017. On this very large dataset, the compression was smaller: 1.87 times fewer operations and 2.4 times fewer parameters, with the accuracy going from 74.24% to 73.69%, a loss of about 0.5%. The authors explain that with so many images, most of the filters are needed to learn features, so fewer of them are redundant.
Conclusions
This work presents a mixed pruning method that removes redundancy from convolutional networks without repeated rounds of pruning. The network is first analyzed with PCA, and a new network with fewer layers and fewer filters is trained. Redundant filters are then found with the geometric median and set to zero, and the network is fine-tuned to regain its accuracy. The method greatly reduces the computing cost with only a small loss of accuracy. The authors suggest that future work could aim at pruning with better accuracy.
Author Contributions
- Conceptualization: Waqas Ahmed, Shahab Ansari and Muhammad Hanif.
- Methodology: Waqas Ahmed, Shahab Ansari and Muhammad Hanif.
- Investigation: Waqas Ahmed and Shahab Ansari.
- Formal analysis: Shahab Ansari and Muhammad Hanif.
- Software: Waqas Ahmed and Akhtar Khalil.
- Data curation, project administration and resources: Akhtar Khalil.
- Supervision: Shahab Ansari, Muhammad Hanif and Akhtar Khalil.
- Validation: Waqas Ahmed, Shahab Ansari, Muhammad Hanif and Akhtar Khalil.
- Visualization: Shahab Ansari and Akhtar Khalil.
- Writing, original draft: Waqas Ahmed, Shahab Ansari and Muhammad Hanif.
- Writing, review and editing: Waqas Ahmed, Shahab Ansari, Muhammad Hanif and Akhtar Khalil.
Funding
The authors received no specific funding for this work.
Data Availability
The data underlying the results presented in the study will be made available on demand. The datasets used are public: CIFAR-10 and CIFAR-100 and ILSVRC 2017.
Competing Interests
The authors have declared that no competing interests exist.