A Low Effort Approach to Structured CNN Design Using PCA

Deep learning models hold state of the art performance in many fields, yet their design is still based on heuristics or grid search methods that often result in overparametrized networks. This work proposes a method to analyze a trained network and deduce an optimized, compressed architecture that preserves accuracy while keeping computational costs tractable. Model compression is an active field of research that targets the problem of realizing deep learning models in hardware. However, most pruning methodologies tend to be experimental, requiring large compute and time intensive iterations of retraining the entire network. We introduce structure into model design by proposing a single shot analysis of a trained network that serves as a first order, low effort approach to dimensionality reduction, by using PCA (Principal Component Analysis). The proposed method simultaneously analyzes the activations of each layer and considers the dimensionality of the space described by the filters generating these activations. It optimizes the architecture in terms of number of layers, and number of filters per layer without any iterative retraining procedures, making it a viable, low effort technique to design efficient networks. We demonstrate the proposed methodology on AlexNet and VGG style networks on the CIFAR-10, CIFAR-100 and ImageNet datasets, and successfully achieve an optimized architecture with a reduction of up to 3.8X and 9X in the number of operations and parameters respectively, while trading off less than 1% accuracy. We also apply the method to MobileNet, and achieve 1.7X and 3.9X reduction in the number of operations and parameters respectively, while improving accuracy by almost one percentage point.


I. INTRODUCTION
D EEP Learning is widely used in a variety of applica- tions, but often suffers from issues arising from exploding computational complexity due to the large number of parameters and operations involved.With the increasing availability of compute power, state of the art Convolutional Neural Networks (CNNs) are growing rapidly in size, making them prohibitive to deploy in energy-constrained environments.This is exacerbated by the lack of a principled, explainable way to reason out the architecture of a neural network, in terms of the number of layers and the number of filters per layer.In this paper, we refer to these parameters as the depth and layer-wise width of the network, respectively.The design of a CNN is currently based on heuristics or grid searches for optimal parameters [1].Often, when a designer wants to develop a CNN for new data, transfer learning is used to adapt well-known networks that hold state of the art performance on established datasets.This adaptation comes in the form of minor changes to the final layer and fine-tuning on the new data.It is rare to evaluate the fitness of the original network on the given dataset on fronts other than accuracy.Even for networks designed from scratch, it is common to either perform a grid search for the network architecture, or to start with a variant of 8-64 filters per layer, and double the number of filters per layer as a rule of thumb [2], [3].This often results in an over-designed network, full of redundancy [4].Many works have shown that networks can be reduced to a fraction of their original size without any loss in accuracy [5], [6], [7].This redundancy not only increases training time and computational complexity, but also creates the need for specialized training in the form of dropout and regularization [8].
Practical Problems with Current Model Compression Methods: The field of model compression explores ways to prune a network post training in order to remove redundancy.However, most of these techniques involve multiple time and compute intensive iterations to find an optimal threshold for compression, making it impractical to compress large networks [6], [9], [10].An iteration here is referred to as the entire procedure of training or retraining a network, instead of a forward and backward pass on a mini-batch.Most standard pruning techniques broadly follow the methodology outlined in the flowchart in Fig. 1a.They start with a pre-trained network and prune the network layer by layer, empirically finding a threshold for pruning in each layer.The pruning threshold modulates the fraction of pruning performed at each iteration and that, in turn, affects the accuracy, which is estimated by retraining.This results in the two loops shown in the figure.Loop 1 iterates to find a suitable pruning threshold for a layer, and Loop 2 repeats the entire process for each layer.Since these loops are multiplicative, and each iteration involves retraining the whole network, pruning a network becomes many times more time and compute intensive than training it.Some methods require only one of the two loops [11], [12], but that still results in a large number of retraining iterations for state of the art networks.Furthermore, the resulting thresholds are not explainable, and therefore can not usually be justified or predicted with any degree of accuracy.
Proposed Method to Optimize Architecture: To address these issues, we propose a low effort technique that uses Principal Component Analysis (PCA) to analyze the network in a single pass, and gives us an optimized design in terms of the number of filters per layer (width), and the number of layers (depth) without the need for retraining.Here, we refer to optimality in terms of removal of redundancy.We do not claim that our method results in the most optimal architecture.However, it is, to the best of our knowledge, a method which optimizes a pre-trained network with the lowest effort in terms of retraining iterations.The proposed method is elucidated in Fig. 1b.We start with a pre-trained network, and analyze the activations of all layers simultaneously using PCA.We then determine the optimized network's layer-wise width from the number of principal components required to explain 99.9% of the cumulative explained variance.We call these the 'significant dimensions' of each layer and optimize the depth based on when these significant dimensions start contracting.Once the requisite width and depth are identified, the user can create a new, randomly initialized network of the identified width and depth and train once to get the final, efficient model.It removes both the loops since we analyze the entire network in one shot, and have a pre-defined threshold for each layer instead of an empirical one.The proposed method optimizes the architecture in one pass, and only requires a total of one retraining iteration for the whole network, drastically reducing the time required for compression.In addition, the choice of the threshold is predetermined and explainable, and therefore can be adapted to suit different energy budgets.This provides an accuracy-efficiency tradeoff knob that can be utilized for more error-tolerant applications where energy consumption is a driving factor in model architecture search.
Contributions: The main contribution of this work is a practical compression technique with explainable design heuristics for optimizing network architecture, at negligible extra compute cost or time.To the best of our knowledge, this is the first work that analyzes all layers of networks simultaneously and optimizes structure in terms of both width and depth, without any iterative searches for thresholds for compression per layer.The additional benefits of using this methodology are two-fold.First, for more error tolerant applications, where accuracy can sometimes be traded for faster inference or lower energy consumption, this analysis offers a way to gracefully tune that trade-off.Second, the resultant PCA graphs (Fig. 10) are indicative of the sensitivity of layers and help identify layers that can be aggressively targeted while compressing the network.This is discussed in detail in section III.The effectiveness of the proposed methodology to optimize the structures of some widely used network architectures is demonstrated in Section IV.

II. PREVIOUS WORK ON MODEL COMPRESSION
We divide model compression methods into four broad categories.The first are techniques that prune individual weights, such as in [5], [6], [14] and [13].These techniques result in unstructured sparsity that is difficult to leverage in hardware.It requires custom hardware design and limits the savings that can be achieved.The second category tackles this problem by removing entire filters.Authors of [15], [11] and [16] focus on finding good metrics to determine the significance of a filter and other pruning criterion.Authors of [17] pose pruning as a subset selection problem based on the next layer's statistic.Methods in this category that do not compromise accuracy significantly require iterative retraining, incurring a heavy computational and time penalty on model design.While authors of [11] analyze all layers together, their layer-wise analysis requires many iterations.Authors of [33] also remove filters by introducing multiple losses for each layer that select the most discriminative filters, but their method iterates until a stopping condition is reached within a layer and iterates over each layer, thus keeping both loops active.The third category, and the one that relates to our method the most, involves techniques that find different ways to approximate weight matrices, either with lower ranked ones or by quantizing such as in [7], [10], [18], [19] and [20].However, these methods are done iteratively for each layer, preserving at least one of the loops in Fig. 1a, making it a bottleneck for large network design.Authors of [20] use a similar idea, but choose a layerwise rank empirically, by minimizing the reconstruction error.Authors of [34] group the network into binarized segments and train these segments sequentially, resulting in the second loop, though over segments rather than layers.The binary bases of the segments are found empirically, and the method requires custom hardware and training methods.Authors of [9] also use a similar scheme, but most of their savings appears to come from the regularizer rather than the postprocessing.The regularization procedure adds more hyperparameters to the training procedure, thus increasing iterations to optimize model design.Another difference is that we optimize both width and depth, and then train a new network from scratch, letting the network recreate the requisite filters.Aggressive quantization, all the way down to binary weights such as in [21] and [22] results in accuracy degradation for large networks.The fourth category is one that learns the sparsity pattern during training.This includes modifying the loss function to aid sparsity such as in [30] and [29], or interspersing sparsifying iterations with the training iterations such as in [29].These result in extensive sparsity, but require longer training or non-standard training algorithms such as in [27], [28], [32] and [32], and do not always guarantee structured sparsity that can be quickly leveraged in existing hardware.A non-standard architecture is created in [31] which consists of a well connected nucleus at initialization and the connectivity is optimized during training.Almost all of these works target static architectures, and optimize connectivity patterns rather than coming up with a new efficient architecture that does not require specialized training procedures or hardware implementations.Many of them are iterative over layers or iterative within a layer [25], [26].None of these works optimize the number of layers.
There are other techniques that prune a little differently.Authors of [12] define an importance score at the last but one layer and backpropagate it to all the neurons.Given a fixed pruning ratio, they remove the weights with scores below that.While this does get a holistic view of all layers, thus removing the second loop in Fig. 1a, the first loop however still remains active as the pruning ratio is found empirically.Authors of [23] learn a set of basis filters by introducing a new initialization technique.However, they decide the structure before training, and the method finds a compressed representation for that structure.The savings come from linear separability of filters into 1x3 and 3x1 filter, but the authors do not analyze if all the original filters need to be decomposed into separable filters.In comparison, our work takes in a trained network, and outputs an optimized architecture with reduced redundancy, given an accuracy target from the parent network.The work in [24] shows interesting results for pruning that do not require pretraining, but they too assume a fixed level of sparsity per layer.The algorithm in [35] works a little differently than the other model compression techniques.It creates a new smaller student model and trains it on the outputs of the larger teacher model.However, there is no guarantee that the smaller model itself is free of redundancy, and the work does not suggest a method for designing the smaller network.Along with these differences, to the best of our knowledge, none of the prior works demonstrate a heuristic to optimize depth of a network.Another element of difference is that OBD [6] OBS [13] Denton [7] Comp-Aware [9] Jaderberg [10] Molchanov [11] NISP [12] AxNN [14] Li_efficient [15] Auto Balanced [16] ThiNet [17] SqueezeNet [18] MobileNet [19] Zhang [20] BinarizedNN [21] XNORNet [22] Iannou [23] SNIP [24] Lottery Ticket [25] Imp-Estimation [26] NetTrim [27] Runtime_pruning [28] Learning-comp [29] Learned_L0 [30] Nucleus Nets [31] Structure-learning [32] Discrimin-aware [33] Structure-binary [34] Our Method many of these methodologies are applied to weights, but we analyze activations, treating them as samples of the responses of weights acting on inputs.This is explained in detail in section III.
The method we propose differs from these techniques in three major ways: a) the entire network with all layers is analyzed in a single shot, without iterations.Almost all prior works preserve at least one of the two loops shown in Fig. 1a, while our methodology does not need either, making it a computationally viable way to optimize architectures of trained networks, b) the underlying choice of threshold is explainable and therefore exposes a knob to trade off accuracy and efficiency gracefully that can be utilized in energy constrained design tasks, and c) it targets both depth of the network and the width for all the layers simultaneously.To elaborate on the number of retraining iterations needed, let L represent the number of layers and N represent the number of iterations to find a suitable pruning threshold within a layer.Networks like VGG-16 have 13 convolutional layers, and for the sake of comparison, we assume a low estimate of N as 4, which means that 4 sparsity percentages are tested.Methods such as [5], [7] and [11] that have both loop1 and loop2 active will require T*N=52 retraining iterations.Methods like [6], [26] and [29] that have only loop1 require N=4 number of retraining iterations and those that have only loop2 will require L=13 number of iterations, such as in [9], [28] and [32].Since a whole retraining iteration can take many simulation days to converge, a large number of simulations is impractical.In contrast, our method only has 1 retraining iteration.
We would also like to point out that most of the works discussed in this section are orthogonal to ours and could potentially be used in conjunction, after using our method as a first order, lowest effort compression technique.These differences are highlighted in tabular format in Table 1.

III. FRAMING OPTIMAL MODEL DESIGN AS A DIMENSIONALITY REDUCTION PROBLEM
In this section, we present our motivation to draw away from the idea of ascribing significance to individual elements towards analyzing the space described by those elements together.We then describe how to use PCA in the context of CNNs and how to flatten the activation matrix to detect redundancy by looking at the principal components of this space.We then outline the method to analyze the results of PCA and use it to optimize the network layer-wise width and depth.The complete algorithm is summarized as a pseudocode in Algorithm 1.
While this is not the first work that uses PCA to analyze models [7], [9], the focus in this work is on a practical method of compressing pre-trained networks that does not involve multiple iterations of retraining.In other contexts, PCA has also been used to initialize neural networks [36], and to analyze their adversarial robustness [37].3a: Filter to be pruned is shown in black and the one that got changed the most is in blue.The filter in blue also had the highest Pearson correlation coefficient [38] with the filter in black.Fig. 3b: Mismatches are shown here.The filter that is pruned out is in black, the one closest to it according to Pearson coefficient is in blue.The two filters that changed the most after retraining are in pink.

A. LOOKING AT THE FILTER SPACE RATHER THAN INDIVIDUAL FILTERS
In an attempt to understand what happens during pruning and retraining, an exhaustive search was carried out during every iteration for a layer in order to identify the filter that caused the least degradation in accuracy upon removal.This means that at any iteration, all remaining filters were removed one at a time, and the net was retrained.Removal of whichever filter caused the least drop in accuracy was identified as the least significant filter for that iteration.This exhaustive analysis can only be carried out for small networks that do not require a long time to train.A small 3 layer network was trained on CIFAR-10 and visualized the effect of pruning and retraining.An animation was created from the iterative results of removing the identified least significant filter and retraining the model for the first layer, comprising of 32 filters.This analysis was carried out for the first layer so the filters can be effectively visualized.The resulting animation can be seen at this link [39] and gives a good insight into what occurs during pruning and retraining.Stills from the animation are shown in Fig. 2 and Fig. 3.
An interesting pattern is observed to be repeated throughout the animation: one or more of the remaining filters appear to 'absorb' the characteristics of the filter that is pruned out.A particular snapshot is shown and explained in Fig. 2. The filters before pruning are shown on the left in Fig. 2a.The filter that is being removed in this iteration is highlighted.The filters after pruning and retraining are shown on the right in Fig. 2b.It can be seen that the checkerboard pattern of the filter that was pruned out gets pronounced in the filter highlighted in Fig. 2b upon retraining.Before retraining, this filter looked similar to the filter being pruned, but the similarity gets more pronounced upon retraining.This pattern is repeated often in the animation, and leads to the hypothesis that as a filter is removed, it seems to be recreated in some other filter(s) that visually appear to be correlated to it.Since the accuracy did not degrade, we infer that if the network layer consists of correlated filters, the network can recreate the significant filters with any of them upon retraining.
Given that it visually appears that each pruned out filter is absorbed by the one 'closest' to it, we tried to determine if we could successfully predict the retained filter that would absorb the pruned out filter.Pearson correlation coefficient was used to quantify similarity between filters.A filter was chosen to be pruned and it was checked if the filter that changed the most upon retraining the system was the one which had the maximum Pearson correlation coefficient with the filter being pruned out.The L2 distance between the filter before and after retraining was used as a measure of change.Fig. 3a shows an example iteration in which the filter identified as closest to the pruned out filter, and the filter that changed the most upon retraining were the same.But more significantly, it was observed that there were a lot of cases where the identified and predicted filters did not match, as sometimes one filter was absorbed by multiple filters combining to give the same feature as the pruned out filter, although each of them had low correlation coefficients individually.An illustrating example of such a mismatch is explained in Fig. 3b.
Viewing compression from the angle that each network has learned some significant and non significant filters or weights implicitly assumes that there is a static significance metric that can be ascribed to an element.This is counter-intuitive as the element can be recreated upon retraining.Even thinking of pruning as a subset selection problem does not account for the fact that on retraining, the network can adjust its filters and therefore the subset from which selection occurs is not static.This motivates a shift of perspective on model compression from removal of insignificant elements (neurons, connections, filters) to analyzing the space described by those elements.
From our experiments, it would appear to be more beneficial instead to look at the behavior of the space described by the filters as a whole and find its dimensionality, which is discussed in the subsequent subsections.features in a dataset.It identifies new, orthogonal features which are linear combinations of all the input features.These new features are ranked based on the amount of variance of the input data they can explain.As an analogy, consider a regression problem to predict house rates with N samples of houses and M features in each sample.The input to PCA would be an NxM sized matrix, with N samples of M features among which we are trying to identify redundancy.
PCA for Dimensionality Reduction: A sample output of PCA is shown in Fig. 4, with cumulative explained variance sketched as a function of the number of top ranked principal components.The way this graph is utilized in the proposed method to uncover redundancy is by drawing out the red line, which shows how many features are required for explaining 99.9% of the total variance in the input data.In this example, almost all the variance is explained by only 11 out of 64 features.Eleven new features can be constructed as linear combinations of the original 64 filters that suffice to explain virtually all the variance in the input, thus exposing redundancy in the feature space.
PCA in the Context of CNNs: The success of currently adopted pruning techniques can be attributed to the redundancy present in the network.Fig. 5 shows the filters of the first layer of AlexNet [40].Many filters within the layer FIGURE 6: The output of convolving one filter with an input patch can be viewed as the feature value of that filter.The green pixels in the output activation map make up one sample for PCA.
are highly correlated and potentially detect the same feature, therefore making insignificant contributions to accuracy.In the previous section, we deduced that pruned out filters, if redundant, could be recreated by a linear combination of retained filters without the retrained network suffering a drop in accuracy.This led us to view the optimal architecture as an intrinsic property of the space defined by the entire set of features, rather than of the features themselves.In order to remove redundancy, optimal model design is framed as a dimensionality reduction problem with the aim of identification of the number of uncorrelated 'eigenfilters' of the desired, smaller subspace of the entire hypothesis space of filters in a particular layer.By using PCA, the notion of the significance of a filter is implicitly removed, since the filters that are the output of PCA are linear combinations of all the original filters.It is the dimensionality which is of primary importance rather than the 'eigenfilters'.We believe that the dimensionality determines an optimal space of relevant transformations, and the network can learn the requisite filters within that space upon training.
Activations as Input Data to PCA for Detecting Filter Redundancy: The activations, which are instances of filter activity, are used as feature values of a filter to detect redundancy between the filters generating these activations.The standard input to PCA is a 2-dimensional matrix where each row represents a new sample, and each column corresponds to a feature value of a particular filter for all those samples.In this formulation, the feature value of a filter is its output value upon convolution with an input patch, as shown in Fig. 6.Hence a data point in the PCA matrix at the location [i,j] corresponds to the activation generated when the i th input patch is acted upon by the j th filter.The same input patch is convolved upon by all the filters, making up a full row of feature values for that input patch.As many of these input patches are available as there are pixels in one output activation map of that layer.Flattening the activation map after convolution gives many samples for all M filters in that layer.If there are activations that are correlated in this flattened matrix across all samples, it implies that they are generated by redundant filters that are looking at similar features in the input.
Let A L be the activation matrix obtained as the output of a forward pass.L refers to the layer that generated this activation map and is being analyzed for redundancy among its filters.
The first filter-sized input patch convolves with the first filter to give the top left pixel of the output activation map.The same patch convolves with all M filters to give rise to a vector ∈ R 1×1×M .This is viewed as one sample of M parameters, with each parameter corresponding to the activity of a filter.Sliding to the next input patch provides another such sample of activity.Suppose A L ∈ R N ×H×W ×M , where N is the mini-batch size, H and W are the height and width of the activation map, and M is the number of filters that generated this map.Thus, it is possible to collect N × H × W samples in one forward pass, each consisting of M parameters simply by flattening the matrix A L ∈ R N ×H×W ×M → B L ∈ R D×M , where D = N × H × W . Since PCA is a data-intensive technique, we found that collecting data over enough mini batches such that D M is is roughly larger than 100 provides enough samples to detect redundancy.We then perform PCA analysis on B L .We perform Singular Value Decomposition (SVD) on the mean normalized, symmetric matrix B T L B L and analyze its M eigenvectors v i and eigenvalues λ i .
The trace, tr(B T L B L ) is the sum of the diagonal elements of the sample variance-covariance matrix, and hence equal to the sum of variance of individual parameters, which we call the total variance T.
The trace is also equal to the sum of eigenvalues.
Hence, each λ i can be thought of as explaining a λ i /T ratio of total variance.Since the λ i 's are ordered by largest to smallest in magnitude, we can calculate how many eigenvalues are cumulatively required to explain 99.9% of the total variance, which we refer to as the significant dimensions for that layer, S L .
These significant dimensions are used to infer the optimized width and depth, as explained in the subsequent sections.From PCA we also know the transformation that was applied to B L and we can apply the same transformation to the filters to visualize the 'principal' filters generated by PCA.This is shown in Fig. 7. Fig. 7a shows the trained filters, and Fig. 7b shows the ranked 'eigenfilters' determined by PCA.The filters are displayed according to diminishing variance contribution, with the maximum contributing component on top left and the least contributing component on the bottom right.

C. OPTIMIZING WIDTH USING PCA
The previous subsection outlines a way of generating PCA matrices for each layer.PCA analysis is then performed on these flattened matrices, and the cumulative variance explained is sketched as a function of the number of filters, as shown in Fig. 4. The 'significant dimensionality' of our desired space of filters is defined as the number of uncorrelated filters that can explain 99.9% of the variance of features.This significant dimensionality, S L for each layer is the identified layer-wise width of the optimized network.Since this analysis can be performed simultaneously for all layers, one forward pass gives us the significant dimensions of all layers, which is used to optimize depth as explained in the next subsection.

D. OPTIMIZING DEPTH OF THE NETWORK
An empirical observation that emerged out of our experiments was a heuristic to optimize the number of layers of the neural network.A possible explanation for this heuristic could be arrived at by considering each layer as a transformation to progressively expand the input data into higher dimensions until the data is somewhat linearly separable and can be classified with desired accuracy.This means that the width of the network per layer should be a non-decreasing function of number of layers.However, as can be seen from the results in Section IV, summarized in Table 2, the number of significant dimensions expand up to a certain layer and then start contracting.We hypothesize that the layers that have lesser significant dimensions than the preceding layer are not contributing any relevant transformations of the input data, and can be considered redundant for the purpose of classification.If the significant dimensions are sketched for each layer, then the depth can be optimized by retaining the layers that maintain monotonicity of this graph.In Section IV, we show empirical evidence that supports our hypothesis by removing a layer and retraining the system iteratively.We notice that the accuracy starts degrading only at the optimized depth identified by our method, confirming that it is indeed a good heuristic for optimizing depth that circumvents the need for iterative retraining.8a shows how to generate the PCA matrix for a particular layer, and then find its significant dimensions.Fig. 8b shows how to use the results of Fig. 8a run in parallel on multiple layers to deduce the structure of the optimized network in terms of number of layers and number of filters in each layer.The structure of other layers (maxpool, normalization etc.) is retained from the parent network.
The methodology is summarized in the form of pseudocode shown in Algorithm 1.The first procedure collects activations from many mini-batches and flattens it as described in the first part of Fig. 8a.It outputs a 2 dimensional matrix that is input to the PCA procedure in the second function.The number of components for the PCA procedure is equal to the number of filters generating that activation map.The second function, shown in the second part of Fig. 8a runs PCA on the flattened matrix and sketches the cumulative explained variance ratio as a function of number of components.It outputs the significant dimensions for that layer as the number of filters required to cumulatively explain 99.9% of the total variance.In the third function, this process is repeated in parallel for all layers and a vector of significant dimensions is obtained.This is shown in Fig. 8b.This corresponds to the width of each layer of the new initialized network.Next, we sketch the number of significant dimensions, and remove the layers that break the monotonicity of this graph.This decides the number of layers in the optimized network.The structure of the optimized network is hence obtained without any training iterations.The entire process just requires one training iteration (line 38 in Algorithm 1), on a new network initialized from scratch.This simplifies the pruning method considerably, resulting in a practical method to design efficient networks.

E. ADDITIONAL INSIGHTS
Our method comes with two additional insights.First, the PCA graphs give designers a way to estimate the accuracyefficiency tradeoff, and the ability to find a smaller architecture that retains less than 99.9% of the variance depending on the constrained energy or memory budget of the application.for sample in act_layer do for all layer in layers do Accuracy-Efficiency Tradeoff: Fig. 9 shows the effect of decreasing the percentage of retained variance on accuracy for 3 different dataset-network pairs.Each point in the graph is a network that is trained from scratch, whose layer-wise architecture is defined by the choice of cumulative variance to retain, shown on the x-axis.The linearity of this graph shows that PCA gives a good, reliable way to arrive at an architecture for reduced accuracy without having to do empirical experiments each time.Section IV explains this figure in greater detail.The linearity of the graphs shows that reduction in variance retained is a good estimator of accuracy degradation.

Sensitivity of Different Layers to Pruning:
The second insight that the PCA graphs hint at is the sensitivity of layers to pruning, as a steeper graph points to the fact that lesser filters can explain most of the variance of the data.If the graph is very sharp, then it can be pruned more aggressively compared to a smoother graph where the principal components are well spread out with each component contributing to accuracy.This is shown in Fig. 10, plotted for training VGG-16 [2] adapted to CIFAR-10 data.From this figure, the expansion of the number of significant dimensions until layer 7 and subsequent contraction from layer 8 can also be observed, leading to the identification of the optimized number of layers before the classifier as 7.
Putting these two insights together helps designers with constrained energy budgets make informed choices of the architecture that gracefully trade off accuracy for energy.The final architecture depends only on the PCA graphs and the decided variance to retain.Therefore, given an energy budget, it is possible to identify a reduced amount of variance to retain across all layers that meets this budget.From the PCA graphs, the percentage of variance retained immediately identifies layer-wise width, and the depth can be identified from the contraction of the layer-wise widths.For even more aggressive pruning, the graphs expose the layers most resilient to pruning that can be targeted further.Note that all of these insights are available without a single retraining iteration.Thus a given energy budget can directly translate to an architecture, making efficient use of time and compute power.

IV. RESULTS FOR OPTIMIZING NETWORK STRUCTURES
Experiments carried out on some well known architectures are summarized in Table 2. Discussions on the experiments, along with some practical guidelines for application are   10a shows that layers 1-7 have increasing sensitivity to pruning, whereas the sensitivity decreases from layers 8 onwards as seen in Fig. 10b.mentioned in the following subsections.PyTorch [41] was used to train the models, and the model definitions and training hyperparameters were picked up from models and training methodologies available at [42].A toolkit [43] available with PyTorch was used for profiling networks to estimate the number of operations and parameters for different networks.

A. EXPERIMENTS ON OPTIMIZING WIDTH
Fig. 10 shows the PCA graphs of different layers for all layers of the batch normalized VGG-16 network trained on CIFAR-10.These graphs are evaluated on the activations of a layer before the action of the non linearities, flattened as explained in Fig. 8.It can be observed that not all components are necessary to obtain 99.9% cumulative variance of the input.The significant dimensions are identified, that is the dimensions needed to explain 99.9% of the total variance, a new network is randomly initialized and trained from scratch with layer-wise width as identified by the significant dimensions.The resulting accuracy drops and savings in number of parameters and operations can be seen from the 'Significant Dimensions' row of each network in Table 2.

B. EXPERIMENTS ON OPTIMIZING DEPTH
Fig. 11 shows the degradation of retrained accuracy as the last remaining layer is iteratively removed, for CIFAR-10/VGG-16 and CIFAR-100/VGG-19.For both networks, a drop in accuracy is noticed upon removing the layers where the identified layer-wise width is still expanding.For example, significant dimensions for CIFAR-10/VGG-16 from Table 2 can be seen to expand until layer 7, which is the number of layers below which the accuracy starts degrading in Fig. 11a.A similar trend is observed for CIFAR-100/VGG-19, confirming that the expansion of dimensions is a good criterion for deciding how deep a network should be.

C. ARCHITECTURES WITH REDUCED ACCURACY
The correlation between the explained variance and accuracy is illustrated in Fig. 9.It shows results for CIFAR-10/VGG-16 and AlexNet and VGG-19 adapted to CIFAR-100.The graph shows how the accuracy degrades with retaining a number of filters that explain a decreasing percentage of variance.Each point refers to the accuracy of a new network trained from scratch.The configuration of the network was identified by the corresponding percentage of variance to explain, shown on the x-axis.The relationship is approximately linear until the unsaturated region of the PCA graphs is reached, where each filter contributes significantly to the accuracy.The termination point for these experiments was either when accuracy went down to random guessing or the variance retention identified a requirement of zero filters for some layer.For instance, the graph for CIFAR-100/VGG-19 stops at 80% variance retention because going below this identified zero filters in some layers.The linearity of this graph shows that the explained variance is a good knob to tune for exploring the accuracy-energy tradeoff.

D. RESULTS AND DISCUSSION
Putting together the ideas discussed, the results of employing this method on some standard networks are summarized in Table 2.Each configuration is shown as a vector.Each component in the vector corresponds to a layer, with the value equal to the number of filters in a convolutional layer, and 'M' refers to a maxpool layer.There are 5 network-dataset combinations considered, CIFAR-10/VGG-16, CIFAR-10/MobileNet, CIFAR-100/VGG-19, Im-ageNet/AlexNet and ImageNet/VGG-19.The row for significant dimensions just lists out the number of filters in that layer that explain 99.9% of the variance.This will make up the layerwise width of the optimized architecture.If these dimensions contract at a certain layer, then the final configuration has the contracting layers removed, thus optimizing the depth of the network.The table also shows the corresponding computational efficiency achieved, characterized by the reduction in number of parameters and operations.
CIFAR-10, VGG-16_BN: The batch normalized version of VGG-16 was applied to CIFAR-10.The layer-wise significant dimensions are shown in Table 2. From the table, it can be seen that in the third block of 3 layers of 256 filters, the conv layer right before maxpool does not add significant dimensions, while the layer after maxpool has an expanded number of significant dimensions.Hence, the conv layer before maxpool was removed while retaining the maxpool layer.In the third block, only one layer expands the significant dimensions, so it was retained and all subsequent layers were removed.The final network halved the depth to 7 layers with only a 0.7% drop in accuracy.The resulting significant dimensions and layer removal is visualized in Fig. 12a.The number of operations and parameters are reduced by 1.9X and 3.7X respectively.
CIFAR-10, MobileNet: The MobileNet [19] architecture was trained on CIFAR-10.The configuration is shown in Table 2.The original block configuration is shown as a 3tuple, with the first and second element corresponding to the number of filters in the first and second convolutional layers respectively, and the third element corresponds to the stride of the second convolutional layer.However, since the first convolutional layer of each block in MobileNet has a separate filter acting on each channel, we can not directly apply PCA to the intermediate activation map.As a workaround, a new network with the same configuration was trained, but with the first convolutional layer instantiated without grouping.This means that all the filters have the same depth as the input map and all channels of the input map are connected to all channels of the filters, as in standard convolution without any grouping.This results in increasing the number of operations and parameters by 8.5X and 8.7X respectively.The compression algorithm is instead applied to this network, as a proxy to the original network, and a reduction of 14.5X and 34.4X is seen in the number of operations and parameters respectively, which translates to a reduction of 1.7X and 3.8X compared to the original MobileNet architecture (with grouping).The blocks are all reduced to just one convolutional layer, with no grouping.Even though the original network is considered to be one of the most efficient networks, we are able to further reduce its size and computational complexity while gaining almost a percentage point in accuracy.The number of layers reduce from 28 in the original network to 8 in the optimized network.
CIFAR-100, VGG-19_BN: The analysis was expanded to CIFAR-100, using the batch normalized version of VGG-19.A similar trend was seen as in the previous case, and the optimized network consisted of 7 layers again.The resulting  significant dimensions and layer removal is visualized in Fig. 12b.An increase in accuracy of nearly one percent was observed, presumably owing to the fact that the network was too big for the dataset, thus having a higher chance of overfitting.The final reduction in number of operations and parameters is 3.8X and 9.1X, respectively.CIFAR-100, AlexNet: To change the style of architecture to one with a smaller number of layers, the analysis was carried out for CIFAR-100 dataset on the AlexNet architecture and it was observed that the layer-wise depth decreased for all layers, but not by a large factor, as AlexNet does not seem to be as overparametrized a network as the VGG variants.However, the last two layers could be removed as they did not expand the significant dimensions, resulting in a reduction of 2.1X in both the number of operations and parameters.
ImageNet, VGG-19_BN: The final test was on the Ima-geNet dataset, and the batch normalized VGG-19 network was used.In the previous experiments, the VGG network adapted to CIFAR datasets had only one fully connected layer, but here the VGG network has 3 fully connected layers, which take up the bulk of the total number of parameters (86% of the total parameters are concentrated in the three fully connected layers.)Since the proposed compression technique only targets the convolutional layers, the total reduction in number of parameters is small.However the total number of operations still reduced by 1.7X the original number with just a 0.24% drop in accuracy.Here, the depth did not reduce further as the number of significant dimensions remained non decreasing, and therefore reducing layers resulted in an accuracy hit.The final configuration is the same as the widthreduced configuration shown in Table 2.
Limitations: One of the major limitations of this method is that it does not apply to ResNet style networks with shortcut connections.Removing dimensions at a certain layer that connects directly to a different layer can result in recreating the significant dimensions in the latter layer, thus making this analysis incompatible.Similarly the method does not directly apply to layers with grouping, since the filters do not act on common inputs channels.The workaround, as discussed in the case of MobileNet in section IV, is to train a new network with the same configuration but without grouping, and apply the method to that network.Another limitation is that this method only applies to a pre-trained network.We do not claim that it results in the most optimal compressed architecture; instead, this is the lowest effort compression that is available at negligible extra cost and can be used as a first order, coarse grained compression method.More fine grained methods can then be applied on the resulting structure.Another point to note is that since we view the compression method as identification of relevant subspace of filters, we do not apply it to the fully connected layers.However, if there were many fully connected layers, the resulting activations are already flattened and our method for reducing width can still be applied in a straightforward manner.

E. SOME PRACTICAL CONSIDERATIONS FOR THE EXPERIMENTS
Three guidelines were followed throughout all experiments.First, while the percentage variance one would like to retain depends on the application and acceptable error tolerance,it was empirically found that preserving 99.9% is a sweet spot with about half to one percentage point in accuracy degradation and a considerable gain in computational cost.Second, this analysis has only been done on activation outputs for convolutional layers before the application of non-linearities such as ReLU.Non-linearities introduce more dimensions, but those are not a function of the number of filters in a layer.And lastly, the number of samples to be taken into account for PCA are recommended to be around 2 orders of magnitudes more than the width of the layer (number of filters to detect redundancy in).Note that one image gives height times width number of samples, so a few mini-batches are usually enough to gather these many samples.It is easier in the first few layers as the activation map is large, but in the later layers, activations need to be collected over many mini-batches to make sure there are enough samples to run PCA analysis on.However, this is a fraction of the time and compute cost of running even a single test iteration (forward pass over the whole dataset), and negligible compared to the cost of retraining.There is no hyper-parameter optimization followed in these experiments; the same values as for the original network are used.

V. CONCLUSION
A novel method to perform a single shot analysis of any given trained network to optimize network structure in terms of both the number of layers and the number of filters per layer is presented.The analysis is free of iterative retraining, which reduces the computational and time complexity of pruning a trained network by a large number of retraining iterations.It has explainable results and takes the guesswork out of choosing layer-wise thresholds for pruning.It exposes an accuracy-complexity knob that model designers can tweak to arrive at an optimized design for their application, and highlights the sensitivity of different layers to pruning.It is applied to popular networks and datasets.At negligible extra time and computational cost of analysis, an optimized structure is identified that achieves up to 3.8X reduction in number of operations and up to 9.1X reduction in number of parameters, with less than 1% drop in accuracy upon training on the same task.We apply the algorithm to a highly efficient network, MobileNet and are able to achieve a reduction of 1.7X and 3.9X in the number of operations and parameters respectively, while improving accuracy by almost one percentage point.

FIGURE 1 :
FIGURE 1: Fig. 1a shows the flowchart for standard pruning techniques.It involves two multiplicative loops, each involving retraining of the entire network.In contrast, the proposed technique, shown in Fig. 1b only requires a single retraining iteration for the whole network.

FIGURE 2 :
FIGURE 2: Visualization of pruning.The filter to be pruned is highlighted on the left and the filter it merges with is highlighted on the right.It can be seen that the merged filter incorporates the diagonal checkerboard pattern from the removed filter.

FIGURE 3 :
FIGURE 3: Fig.3a: Filter to be pruned is shown in black and the one that got changed the most is in blue.The filter in blue also had the highest Pearson correlation coefficient[38] with the filter in black.Fig.3b: Mismatches are shown here.The filter that is pruned out is in black, the one closest to it according to Pearson coefficient is in blue.The two filters that changed the most after retraining are in pink.

FIGURE 4 :
FIGURE 4: Cumulative percentage of the variance of input explained by ranked principal components.The red line identifies the significant dimensions that explain 99.9% variance.

FIGURE 5 :
FIGURE 5: First layer filters of AlexNet, trained on ImageNet.A considerable amount of redundancy is clearly visible in the filters.

FIGURE 7 :
FIGURE 7: The learned filters of a convolutional layer with 32 filters on CIFAR-10 are shown on the left and the corresponding ranked filters transformed according to principal components are shown on the right.

FIGURE 8 :
FIGURE 8: Visualization of the algorithm.Fig.8ashows how to generate the PCA matrix for a particular layer, and then find its significant dimensions.Fig.8bshows how to use the results of Fig.8arun in parallel on multiple layers to deduce the structure of the optimized network in terms of number of layers and number of filters in each layer.The structure of other layers (maxpool, normalization etc.) is retained from the parent network.

FIGURE 9 :
FIGURE 9: The degradation of accuracy w.r.t.target variance to explain for different networks.Each point here is a freshly trained network whose layer-wise width was decided by the corresponding amount of variance to explain on the x axis.The linearity of the graphs shows that reduction in variance retained is a good estimator of accuracy degradation.

FIGURE 12 :
FIGURE 12:  The graphs show how the significant dimensions vary with layers.The layers that do not result in a monotonic increase can be dropped, and are crossed out on the X axis.Fig.11ashows results for CIFAR-10/VGG-16 and Fig.11bfor CIFAR-100/VGG-19.

TABLE 2 :
Summary of Results