{'fraction_non_alphanumeric': 0.02947398788345033, 'fraction_numerical': 0.013607077603615732, 'mean_word_length': 4.821158690176323, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Energy Consumption Analysis of pruned Semantic Segmentation Networks on an Embedded GPU

Deep neural networks are the state of the art in many computer vision tasks. Their deployment in the context of autonomous vehicles is of particular interest, since their limitations in terms of energy consumption prohibit the use of very large networks, that typically reach the best performance. A common method to reduce the complexity of these architectures, without sacrificing accuracy, is to rely on pruning, in which the least important portions are eliminated. There is a large literature on the subject, but interestingly few works have measured the actual impact of pruning on energy. In this work, we are interested in measuring it in the specific context of semantic segmentation for autonomous driving, using the Cityscapes dataset. To this end, we analyze the impact of recently proposed structured pruning methods when trained architectures are deployed on a Jetson Xavier embedded GPU.


Introduction
In the course of the last decade, deep neural networks have become a staple in many computer vision tasks such as classification, detection or semantic segmentation. This makes them especially interesting for the field of autonomous vehicles. Cityscapes [3] is a semantic segmentation dataset designed for this field. It presents a significant challenge due to its high resolution, its size and the variety of images and classes.
For this dataset, state of the art is held by networks such as HRNets [20], which are composed of a large number of parameters and operations during inference and produce large intermediate products that cause a large memory footprint. Such costs are prohibitive for embedded devices and thus compromise their usage in autonomous vehicles.
To reduce the cost of a network, the domain of neural networks compression presents multiple different methods, such as quantization [4], distillation [9] or pruning [5]. In this article we focus on pruning and more especially on "structured" filter pruning [13] that removes entire neurons in convolution layers of deep neural networks. Structured pruning can be a challenge to implement when applying different pruning rates for each layer of a network that includes longrange dependencies between layers because of, for example, residual connections [7]. Therefore, slimming down networks is a distinct issue, while most works in the field stick to putting weights to zero to measure, instead, the impact of pruning on a network's performance.
Our article aims at providing a solution to leverage irregular structured sparsity in HRNet-48 and measure the gains in energy consumption on a NVIDIA Jetson AGX Xavier embedded GPU. We report results using two different pruning methods of the literature and show how each of them allows for a different trade-off between performance and cost for the same network architecture. We also compare these results to that of non-pruned HRNet-32 and HRNet-18, and discuss the implications of these results in the general discussion on the ability of pruning to produce efficient architectures.

Semantic Segmentation Networks
At first, deep semantic segmentation neural networks were built by concatenating a classification network and a decoder. The convolution layers of the (usually pretrained) encoder classification network produce intermediate representations that are successively fed to the decoder that upsamples and sums them together. This principle was introduced by Long et al. [15] (FCN) and then perfected by Ronneberger et al. [18] (U-net) that cemented the symmetry between encoder and decoder that can be found in other networks, such as SegNet [1]. Dilated (or "atrous") convolutions [23] led to another family of semantic segmentation networks that, instead of upsampling and summing together intermediate representations of decreasing resolution, managed to alter a classification network so that said resolutions remains high. Such principle can be found among DeepLab networks [2], that also introduce the principle of pyramid pooling (i.e., operating on multiple resolutions at once to extract information at various scales).
Both ideas of pyramid pooling and maintaining high resolution gave birth to HRNet [20], which, instead of being a modified classification network, is fully designed for such a task. Variants of it, with an additional decoder, are state of the art [24]. However, HRNet tends to be a very complex network, whose cost is unsuitable for embedded hardware. Some works draw inspiration from HRNet to design networks more adapted to such hardware [10]. Our approach is to study how pruning could reduce the cost of HRNet.

Neural Network Pruning
First introduced during the late 80's [11], pruning is now a widespread method to reduce the cost of deep neural networks [6]. Since removing weights in an unstructured manner leads to sparse tensors that are difficult to optimize effi-ciently [12,16], it is possible instead to remove whole neurons, i.e. filters in the case of convolution layers [13]. Indeed, such kind of removal alters input and output dimensions of layers and it is necessary to remove inter-dependant weights between layers in a consistent way. This is rather straightforward to do in simple networks such as VGG [19], but networks such as HRNets present much more intricate dependencies between layers, partly because of residual connections [7]. Indeed, such connections imply a certain regularity in the dimensions of intermediate products of the network. In the case of global pruning, where each layer can be pruned at different rates to get a global count of parameters (in opposition to local pruning that prunes equally every layer), pruning can break this regularity, which means that summing these tensors is not possible without scattering them into tensors of the same dimension. Multiple works solve this problem using different kind of operators [8].

Method
Our work focuses on pruning HRNet. Indeed, both its significance in the state of the art and its prohibitive cost in memory and computation power make it an especially relevant subject for experimentation to measure how pruning can make semantic segmentation suitable for embedded hardware.
We used the Cityscapes dataset [3] to train our networks. Indeed, Cityscapes is a popular dataset in the scope of autonomous vehicles and features high resolution images and annotations for 19 different classes (among others that are not used during training). All the results featured in this article concern networks we trained ourselves.
We chose two different structured pruning methods: Slimming [13], an influential method in the literature, and SWD [22], that is more recent and has shown a certain ability to give competitive results on multiple networks or tasks with different kinds of pruning structures.
All our measurements were run on a NVIDIA Jetson AGX Xavier embedded GPU under the "30W All" mode, with JetPack SDK 5.0, CUDA 11.4.14, cuDNN 8.3.2, TensorRT 8.4.0 EA and running inference with ONNX Runtime 1.12.0 while using the TensorRT execution provider and using the tegrastats utility to measure power consumption. The number of MAC operations is counted using the ONNX Operations Counter tool.

Training Conditions
Our HRNet networks are trained during 200 epochs with a batch size of 10 on 3 NVIDIA Quadro K6000 GPUs, using the Pytorch 1.9.0 framework with CUDA 11.3. We use the SGD optimizer with weight decay set to 5·10 −4 , momentum set to 0.9 and base learning rate set to 0.01. We decrease learning rate using the poly policy with the power of 2 (i.e. learning rate is reduced by (1 − current epoch epochs ) 2 at each epoch). We use the RMI loss [25] and report accuracy in term of mean intersection over union (mIoU). Most of these hyperparameters come from the original papers of HRNet.
During testing, input images are of size 3 × 1024 × 2048. During training, they are randomly cropped and resized, with a scale of [0. 5,2], to 3 × 512 × 1024. Data augmentation also involves random flips, random Gaussian blur, and color jittering. All samples from the dataset are normalized. More implementary precisions can be found consulting the source code available at https://github.com/HugoTessier-lab/Neural-Network-Shrinking.git.
Our baseline performance for HRNet-48 shows significant differences with the results announced in the original paper [20]. Indeed, using recent versions of Python and Pytorch (that we need for our tools to work properly), we were unable to reproduce the original results, even when applying the same training conditions or even when using available pretrained networks and the original source code. When using a pretrained HRNet-48 on Cityscapes, the best results we got were obtained with our implementation and lead to a mIoU accuracy of 73%. Therefore, we conclude that the performance we get with our own training, which is of 77% in mIoU, is good enough not to harm the conclusions of our article in any way.

Pruning Strategies
Pruning Structure and Target: We prune convolution filters and all the weights that depend on them. This includes corresponding batch normalization coefficients and kernels in filters of following layers. We also take into account long-range dependencies introduced by residual connections. The tensors of the network's weights are then reshaped so that the remaining parameters allocated in memory, the pruning target and the count of weights that still contribute to the network's function perfectly match.
Pruning criterion: We prune filters on the basis of the magnitude of the learnt multiplicative coefficient in its corresponding batch-normalization layer [13].
Pruning methods -Slimming: During training, batch-normalization layers are penalized by a smooth-L 1 norm of their multiplicative coefficient, in order to enforce sparsity. Networks are pruned in three steps, with a linearly increasing pruning rate until the final one is reached. After each pruning step, the network is fine-tuned during 20 epochs. Such an iterative process helps preventing layer collapse [21]. Once the final pruning rate is reached, the network is re-trained following a warm-restart schedule, which can be called LR-Rewinding [17]. -SWD: Since SWD prunes progressively throughout pruning, it does not need iterations. Instead we prune directly at the intended final pruning rate once the networks have been trained under the constraint of SWD's penalty. The hyperparameters a min and a max of SWD are set to 1 · 10 −1 and 1 · 10 10 respectively, because with weight decay set to 5 · 10 −4 , learning rate to 0.01 and the aforementioned scheduler, we get a min × W D × LR = 0.1 × W D × LR < W D × LR and a max × W D × LR × 200 n=1 1 − n 200 2 ≈ 1 · 10 10 × 1.25 · 10 −10 ≈ 1, which means that SWD starts off as negligible and ends up applying a penalty to targeted weights that almost equals their magnitude, thus pruning them. After that, LR-Rewinding is applied.

ONNX Implementation details
The ONNX format has the clear advantage of being supported by a wide array of frameworks, that themselves can be ported on many different hardware. Therefore, gains observed in our experiments can be reproduced on other devices. Structured pruning can introduce some dimensional discrepancies, which can be solved by introducing operators to reshape tensors coming from layers that were pruned differently [8]. In our implementation, we chose to insert a Scat-terND ONNX operator, that inserts the data from a tensor into another whose dimension matches that of the layers that will take this tensor as an input. This operator is placed before any tensor addition operation to prevent any incompatibility in dimensions. This solves the problem but counts a drawback, that can be however put into perspective. Indeed, this operator needs additional temporary empty feature maps before summation, which introduces an additional cost in memory space and latency at inference. This problem is inevitable with our paradigm and can be found in previous works [8]. Preventing this problem would require rearranging the network in a much more complicated way, which we wished not to dwell into yet.
This implementation is the one that gave us the best performance in inference time, energy consumption and size of the network. However, it still has a nonnegligible impact on performance, as can be seen in our experiments. This cost is likely due to the unconventional nature of this operator in neural networks, that makes it poorly supported by most frameworks. Indeed, TensorRT treats it as a "foreign node" that is accelerated using a library, Myelin, distinct from those used for all other nodes. The fact that the Scatter operator and its variants are only supported since TensorRT 8.0 hints that the acceleration of these operations still has room for improvement. Yet, this overall configuration is the one that performed the best during our preliminary experiments.

Experiments
We measured power consumption using the tegrastats utility every second while ONNX Runtime executes 1000 inference of a given network on GPU, after 100 inferences as a warm-up. We compute the integral of instantaneous power consumption (in mW) for all the duration of the experiment and get the overall energy consumption (in J). We report the results for inputs of different resolutions and batch sizes in Figure 1. We chose 2 different dimensions: (1 × 3 × 64 × 128) and (1 × 3 × 512 × 1024). We also report results for non-pruned baselines such as HRNet-32 or HRNet-18. Figure 2 shows various trade-offs, for inputs of size (1 × 3 × 512 × 1024), between mIoU accuracy of the networks on CityScapes and their energy consumption, amount of remaining operations or parameters. All our reported numbers of operations do not take into account those of the ScatterND operators, but only that of convolutions. Indeed, as energy consumption already includes the impact of these operators, our operation count rather gives an indication on the distribution of sparsity in the network.

Impact on Hardware
Our experiments show that we can leverage global filter pruning and reduce energy consumption. The efficiency of pruning slightly depends on the size of the inputs, even though results get more stable once inputs are of sufficient resolution, as can be seen in Figure 1. This was achieved using ScatterND ONNX operations, whose cost in latency and energy is not negligible. Figure 1 shows that non-pruned smaller networks, such as HRNet-32 and HRNet-18, are energetically more efficient than pruned networks, even when comparing at equal number of operations. One would expect operations, latency and energetic consumption to be correlated, and that the difference between, for example, the consumption and latency of HRNet-32 and that of pruned networks of similar count of operations should match. However, this is only partly true, as indicated in Table 1. Indeed, once the cost of the "foreign nodes", that are what TensorRT turn the ScatterND operations into, is removed from the overall latency of the net- work, results in latency are closer to each other but there is still a difference. When isolating the latency of convolution layers, that are supposed to count the same number of operations across the three compared networks, one can see that those of non-pruned HRNet-32 run significantly faster. As the difference in operations, that is minimal, or parameters, that should be in favor to the pruned networks, cannot explain this gap, we suppose that it is due to differences in the acceleration tactics empirically chosen by TensorRT. This would mean that not only ScatterND operations are costly but also that their presence harms the optimization of the rest of the network. This is likely due to their unconventional nature in convolution networks.  Table 1: Count of remaining parameters (Param.) and operations (Op.), overall latency (Lat.), latency with the exclusion of foreign nodes (Lat.*) and latency of convolution layers only (C. Lat.), for two different sizes of inputs, of HRNet-48 pruned using SWD (SWD) or Slimming (Slim.) and a non-pruned HRNet-32 (HRN32). For HRNet-32, the percentage of parameters and operations gives a relative comparison to those of non-pruned HRNet-48. Measurements and profiling were performed using the trtexec utility.
The most likely solutions to this problem would be either: 1) a better choice of operators, that we do not know as our solution is the one that gave us the best performance, 2) a new custom operator that cuts the drawbacks of our current solution, that uses preexisting ONNX operators or 3) a better support of Scatter operations and of this type of use in networks from TensorRT and other frameworks. Figure 2 provides three different trade-off curves, for both pruned HRNet-48 and HRNet-18, which each lead to a different observation. Green dots provide performance of non-pruned networks. The accuracy-to-energy trade-off as well as the accuracy-to-operations trade-off is in favor of HRNet-18 compared to HRNet-48. On the contrary, HRNet-48 is better on the accuracy-to-parameters trade-off. In the literature on network pruning, the parameters count is often used to measure the complexity of the pruned network. Our results show that it is a bad proxy for its actual energy consumption and computational complexity. The reason is that, since different layers in the network are applied to intermediate representations of different resolutions, all parameters in the network do not have the same cost in term of operations and energy.

Pruning as Architecture Search
It seems that pruning HRNet-48 leads to save parameters that are responsible for many operations. Indeed, HRNet-18, that is uniformly thinner than HRNet-48, counts much fewer operations than pruned networks that contain as many parameters. This is surprising, since the criterion described in Section 3.2 does not explicitly imply any bias towards targeting parameters responsible for fewer or more operations. Since this behavior leads to architectures that seem suboptimal, one can wonder if this the best that pruning can do or if it is due to some unexpected bias in the criterion.
One hypothesis would be that parameters that are responsible for many operations are indeed more important and of greater magnitude, in which case the count of operations and accuracy would be strongly correlated. This hypothesis is rather unlikely. Indeed, one example of strong correlation is the parametersto-accuracy trade-off in Figure 2: all points are roughly located on the same average curve, whatever the pruning method or the pruned network. In the case of the operations-to-accuracy (or even the energy-to-accuracy) trade-off, there is a noticeable gap between pruned HRNet-48 and HRNet-18 as well as between networks pruned using SWD or Slimming. Moreover, networks pruned using SWD both contain fewer operations and have a better accuracy compared to those pruned using Slimming, even though they contain the same number of parameters, which is the opposite behavior to the one to be expected if the hypothesis was true.
If such parameters are not more important, then there is apparently no reason why pruning would prioritize saving them. Therefore it is likely that such a behavior is an accident and due to an unwanted bias in the criterion. Various types of analogous imbalances are to be seen in many criteria in the literature [21]. Since this bias visibly harms pruning in a way that makes it less efficient than training thin baselines from scratch, it seems that further investigations are necessary to figure out the reason of such biases and how to avoid them to improve considerably the performance of pruning.
Finally, the fact that pruning HRNet-18 leads to better results than pruning HRNet-48 leads to both the intuitive observation, that it is better to prune a network that is closer to the desired target, and the counter-intuitive observation that pruning the bigger network failed to come up with the same efficient architecture, while the ability of pruning to produce them is supposedly its main interest [14].

Conclusion
We have measured the energetic consumption of the HRNet-48 and HRNet-18 semantic segmentation networks, pruned using global structured pruning methods. Thanks to the use of ScatterND ONNX operations, we are able to leverage the sparsity on embedded GPU, demonstrating the ability of global pruning to reduce the cost of networks. However, our experiments also show the necessity both to elaborate a more efficient implementation of operators required to leverage pruning and to explore further how biased are pruning criteria, as they lead to distributions of sparsity that are energetically sub-optimal.