RESEARCH PROJECT Published 24 January 2022 · PLOS ONE, 17(1), e0262386 · Open Access (CC BY)

PCA Driven Mixed Filter Pruning for Efficient ConvNets

Waqas Ahmed1,*, Shahab Ansari1,*, Muhammad Hanif1,* and Akhtar Khalil2,*

1 Faculty of Computer Science and Engineering, GIK Institute of Engineering Sciences and Technology, Topi, Swabi, KPK, Pakistan
2 iFhaja Research Consultation, Peshawar, KPK, Pakistan
* These authors contributed equally to this work.

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.

Neural network pruning Convolutional neural networks Principal component analysis Geometric median Model compression

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.

The 64 first-layer convolutional filters of AlexNet, many of which look similar
Figure 1. The first-layer convolutional filters of AlexNet. Source: Ahmed et al., PLOS ONE (2022), CC BY.

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.

Flowchart of the PCA driven mixed pruning technique from a pre-trained network to an optimized model
Figure 2. Flowchart of the proposed PCA driven mixed pruning technique. Source: Ahmed et al., PLOS ONE (2022), CC BY.

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.

Feature maps flattened into the matrix that is the input to PCA
Figure 3. The activations of a layer are flattened into a matrix that is the input to PCA. Source: Ahmed et al., PLOS ONE (2022), CC BY.

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.

Number of filters per layer in VGG-16 on CIFAR-10, original and after PCA
Figure 4. Compressed architecture of VGG-16 on CIFAR-10: the original number of filters and the significant dimensions found by PCA. Source: Ahmed et al., PLOS ONE (2022), CC BY.

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.

Number of filters per layer in AlexNet on CIFAR-10, original and after PCA
Figure 5. Compressed architecture of AlexNet on CIFAR-10. Source: Ahmed et al., PLOS ONE (2022), CC BY.

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%.

Number of filters per layer in VGG-19 on CIFAR-100, original and after PCA
Figure 6. Compressed architecture of VGG-19 on CIFAR-100. Source: Ahmed et al., PLOS ONE (2022), CC BY.

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

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.