Navigating Noise: A Study of How Noise Influences Generalisation and
  Calibration of Neural Networks
Enhancing the generalisation abilities of neural networks (NNs) through
integrating noise such as MixUp or Dropout during training has emerged as a
powerful and adaptable technique. Despite the proven efficacy of noise in NN
training, there is no consensus regarding which noise sources, types and
placements yield maximal benefits in generalisation and confidence calibration.
This study thoroughly explores diverse noise modalities to evaluate their
impacts on NN's generalisation and calibration under in-distribution or
out-of-distribution settings, paired with experiments investigating the metric
landscapes of the learnt representations across a spectrum of NN architectures,
tasks, and datasets. Our study shows that AugMix and weak augmentation exhibit
cross-task effectiveness in computer vision, emphasising the need to tailor
noise to specific domains. Our findings emphasise the efficacy of combining
noises and successful hyperparameter transfer within a single domain but the
difficulties in transferring the benefits to other domains. Furthermore, the
study underscores the complexity of simultaneously optimising for both
generalisation and calibration, emphasising the need for practitioners to
carefully consider noise combinations and hyperparameter tuning for optimal
performance in specific tasks and datasets.
Martin Ferianc, Ondrej Bohdal, Timothy Hospedales, Miguel Rodrigues
# Impact of Noise on Calibration and Generalisation of Neural Networks

###### Abstract

Noise injection and data augmentation strategies have been effective for enhancing the generalisation and robustness of neural networks (NNs). Certain types of noise such as label smoothing and MixUp have also been shown to improve calibration. Since noise can be added in various stages of the NN's training, it motivates the question of when and where the noise is the most effective. We study a variety of noise types to determine how much they improve calibration and generalisation, and under what conditions. More specifically we evaluate various noise-injection strategies in both in-distribution (ID) and out-of-distribution (OOD) scenarios. The findings highlight that activation noise was the most transferable and effective in improving generalisation, while input augmentation noise was prominent in improving calibration on OOD but not necessarily ID data.

Machine Learning, ICML 2023 Workshop on Spurious Correlations, Invariance, and Stability. Honolulu, Hawaii, USA. Copyright 2023 by the author(s).

Machine Learning, ICML 2023 Workshop on Spurious Correlations, Invariance, and Stability. Honolulu, Hawaii, USA. Copyright 2023 by the author(s).

## 1 Introduction

Noise injection methods have emerged as a promising approach to enhance the generalisation of neural networks (NNs) (Srivastava et al., 2014; Neelakantan et al., 2017). Given the importance of noise for Bayesian NNs (BNNs) (Gal and Ghahramani, 2016; Blundell et al., 2015; Welling and Teh, 2011), we hypothesise that noise injections during training of standard NNs can also positively impact their calibration. Calibration refers to the alignment of prediction's accuracy to their confidence (Guo et al., 2017).

Examples of noise injection approaches include dropout (Srivastava et al., 2014; Gal and Ghahramani, 2016), label smoothing (Szegedy et al., 2016), MixUp (Zhang et al., 2018), Gaussian noise (Blundell et al., 2015), shrinking and perturbing NN weights (Ash and Adams, 2020), and gradient noise (Neelakantan et al., 2017). By introducing noise during the training, these methods encourage active exploration of the parameter space and can be applied to various components of the network, including the input, targets, activations, gradients and the model itself. In this paper, we aim to provide a fair comparison of noise injection methods during training and investigate their impact on both calibration and generalisation of NNs in a computer vision classification setting. We ensure fairness of the comparison through dedicated hyperparameter optimization per noise type and we examine the transferability of found hyperparameters from one dataset or architecture to another. To robustly evaluate both generalisation and calibration we consider testing the methods on both test in-distribution (ID) and out-of-distribution (OOD) data.

The key takeaways from our work are: 1) Activation noise, especially dropout (Srivastava et al., 2014), improves generalisation and marginally also calibration across architectures and datasets. 2) Input augmentation, MixUp (Zhang et al., 2018), improves calibration and generalisation on OOD data but not necessarily ID data. 3) Model noise and gradient noise improve generalisation and calibration, but only to a smaller extent than input or activation noise.

## 2 Related Work

Standard NNs were shown to lack calibration (Guo et al., 2017), motivating the need for approaches focusing on training NNs such that their confidence matches their accuracy. Bayesian NNs (BNNs) (Blundell et al., 2015; Gal and Ghahramani, 2016; Welling and Teh, 2011) and NN ensembles (Lakshminarayanan et al., 2017) are popular approaches for obtaining well-calibrated models, but they are computationally expensive as they require random sampling and multiple forward passes during test time. Alternative methods have been proposed without increasing computational complexity, particularly during training. They include different loss functions (Kumar et al., 2018; Mukhoti et al., 2020; Bohdal et al., 2021) and temperature scaling (Guo et al., 2017). However, these approaches have
their own limitations and may not be suitable for all scenarios. On the other hand, most noise injections are applicable to any NN architecture and any task.

For **input noise** injection, commonly used are MixUp and Output Diversified Sampling (ODS) methods. MixUp (Zhang et al., 2018) linearly interpolates between two samples and their labels, while ODS (Tashiro et al., 2020) augments the input to diversify predictions and was used in the context of adversarial examples but not calibration. MixUp has been shown to improve calibration and generalisation (Zhang et al., 2022), but its transferability between datasets and architectures has not been explored. Additionally, we investigate naive Gaussian and uniform noise injection, which adds Gaussian or uniform noise to the input during training. In terms of **target noise** injection, label smoothing (Pereyra et al., 2017) and MixUp (Zhang et al., 2018) label interpolation are frequently used. Label smoothing replaces hard targets with soft targets and has already been shown to improve calibration, but not on OOD data (Muller et al., 2019). **Activation noise** injections include Dropout, Gaussian and uniform noise injections. Dropout (Srivastava et al., 2014) randomly sets activations to zero. Gaussian noise injection (Blundell et al., 2015; Camuto et al., 2020; Alemi et al., 2017; Yu et al., 2021) adds Gaussian noise to the activations, while uniform noise injection adds uniform noise. In BNNs, these injections are applied both during training and evaluation, whereas in this work we only apply noise during training. Furthermore, **gradient noise** has been shown to improve generalisation through adding annealed Gaussian noise to the gradients during training (Neelakantan et al., 2017; Welling & Teh, 2011). However, it was not benchmarked on calibration, especially without ensembling weights at different training time-steps. Finally for **model noise** injection, recently Gaussian noise injection via shrinking and perturbing weights (Ash & Adams, 2020) at a given epoch frequency was shown to improve retraining generalisation, but calibration on ID or OOD data was not considered.

To the best of our knowledge, the noise injections have been studied 1) separately (Zhang et al., 2022; Muller et al., 2019), 2) orthogonally for generalisation and calibration on ID or OOD data, and 3) without a unified hyperparameter (HP) optimization protocol. This research aims to start the conversation into a comprehensive analysis of the noise injection methods and their relationship to generalisation and calibration, across datasets and NN architectures, providing valuable insights into their effectiveness and practicality.

## 3 Methodology

This study focuses on training a NN with noise perturbations to investigate their impact on NN's accuracy and calibration, identifying which perturbations are helpful and when. The noises are divided between **input**, **target**, **activation**, **gradient** and **model**, and their deployment during training is outlined in Algorithm 1 via blue lines. The probability of applying each noise to a batch out of \(B\) batches is determined by the HP \(p\in[0,1]\), except model noise, which was applied with a selected frequency during the \(T\) training epochs. The noises have associated HPs and tuning ranges.

```
0: Training dataset \(D=\{(x^{b},y^{b})\}_{b=1}^{B}\), \(B\) batches, learning rate \(\eta\), number of epochs \(T\), weights \(\theta\), operation \(g(\cdot,\theta)\), hidden states \(h^{b}\), hidden depth \(D\), activation \(f(\cdot)\), probability of applying noise to a batch \(p\)
1: Initialize \(\theta\) randomly
2:for\(t=1\) to \(T\)do
3:for\(b=1\) to \(B\)do
4: Randomly select \((x^{b},y^{b})\) from \(D\)
5: Sample \(e\sim U(0,1)\) {If \(e<p\)}
6:Input noise: Modify \(x^{b}\)
7:Target noise: Modify \(y^{b}\)
8:for\(i=1\) to \(D\)do
9:\(h^{b}_{i}=g(h^{b}_{i-1},\theta)\) {Where \(h^{b}_{0}=x^{b}\)}
10:Activation noise: Modify \(h^{b}_{i}\) before activation
11:\(h^{b}_{i}=f(h^{b}_{i})\)
12:endfor
13: Compute predicted output \(\hat{y}^{i}=g(h^{b}_{D},\theta)\)
14: Compute loss \(\mathcal{L}(\hat{y}^{i},y^{i})\) and gradients \(\nabla_{\theta}\mathcal{L}\)
15:Gradient noise: Modify \(\nabla_{\theta}\mathcal{L}\)
16: Update weights: \(\theta\leftarrow\theta-\eta\nabla_{\theta}\mathcal{L}\)
17:endfor
18:if\(t\mod\text{frequency}=0\)and\(t<0.75T\)then
19:Model noise: Modify \(\theta\)
20:endif
21:endfor
22:return\(\theta\)
```

**Algorithm 1** Training of Neural Network with Noise

**Input noise:** The input noise consisted of 2 naive variants and 2 variants which tapped into predictions or the targets to compute the noise. The two naive variants consisted of adding Gaussian or uniformly sampled noise \(n\sim U(-\sigma,\sigma);n\sim\mathcal{N}(0,\sigma)\) added to inputs \(x\) with standard deviation \(\sigma\in[1e^{-4},1e^{-1}]\). We considered ODS (Tashiro et al., 2020) with respect to \(\epsilon\in[1e^{-4},1e^{-1}]\) and temperature \(T\in[0.5,5.0]\), and MixUp (Zhang et al., 2018) with \(\alpha\in[0,1]\) which also modified the targets accordingly. **Target noise:** In addition to MixUp we considered a static noise introduced to the labels \(y\) in the form of label smoothing (Muller et al., 2019) with the smoothing factor \(l\in[0,0.25]\). **Activation noise:** The hidden states prior to applying the activation function, \(\{h^{b}_{i}\}_{i=0}^{D}\), where \(D\) is the depth of the net, could be disturbed by 3 types of activation noise: additive Gaussian or Uniform
\(n\sim U(-\sigma,\sigma);n\sim\mathcal{N}(0,\sigma)\) with \(\sigma\in[1-4,1e^{-1}]\) as a tunable HP or multiplicative Dropout (Srivastava et al., 2014) that incorporates a dropout rate \(d\in[0,1]\). The activation noise was used prior to an activation \(f(\cdot)\) for all linear or convolutional operations \(g(\cdot,\theta)\) but not in the output layer. **Gradient noise:** The noise applied to the gradients \(\nabla_{\theta}\mathcal{L}\) followed (Neelakantan et al., 2017) with the step size \(\eta\in[0,1]\) and the annealing factor \(\gamma\in[0,1]\). **Model noise**: Lastly the model noise follows the idea of shrinking and perturbing the weights \(\theta\)(Ash and Adams, 2020) with a shrink factor \(\mu\in[0.0,1.0]\) and standard deviation \(\sigma\in[0.0,1e^{-3}]\) with frequency of perturbing every frequency \(\in[0,80]\) epochs, except the last 25% of training epochs.

## 4 Experiments

SettingsWe first tune the learning rate and L2 regularisation of a no-noise network which are reused when tuning the HPs of each noise injection method on three different combinations: ResNet-18 paired with CIFAR-10 or CIFAR-100 and a fully connected (FC) network paired with SVHN. The tuning is performed using \(1/4\) of the training budget over the course of one day, using model-based Tree-structured Parzen Estimator method (Bergstra et al., 2011). With these settings we are able to evaluate about 40 configurations selected using Bayesian Optimization. Our protocol allows us to optimize the performance of each noise injection method and provide fair comparison. Full experimental details are in Appendix A, including a summary of the identified HPs.

To assess the effectiveness of the noise injection methods, we measure their performance using three metrics: Error \([\downarrow,\%]\), Expected Calibration Error (ECE) (Guo et al., 2017) \([\downarrow,\%]\), and Negative Log-Likelihood (NLL) \([\downarrow]\) that we report in Appendix B. These metrics provide insights into the accuracy and its match with the confidence of the NNs' predictions. We evaluate the performance on both the ID test set and an augmented OOD set that includes an average over visual corruptions across 19 categories and 5 severities (Hendrycks and Dietterich, 2019). These corruptions include, for example, adding snow or fog to the image, changing the brightness or saturation of the image or blurring the image. We conduct experiments on a series of deployment scenarios where 1) the tuned HPs are directly used on the tuned dataset and architecture, 2) the architecture is changed but the HPs are kept, 3) the HPs come from a different source dataset. The results presented are averaged across 3 seeds and the best results are in **bold**.

### Analysis

Tuned HyperparametersIn this scenario, we evaluate the performance of the noise injection methods when the HPs are tuned specifically for the dataset and architecture. The results for these experiments are in Tables 1 and 2, and they show that activation and input augmentation noises are prominent in improving the accuracy and calibration of the networks across the datasets. Dropout was the most effective for improving ID generalisation in CIFAR-10 and CIFAR-100, while MixUp was the most effective for SVHN. Uniform activation worked the best for improving ID calibration in CIFAR-10 and CIFAR-100, whereas ODS was the best in SVHN. The strong result obtained by ODS on SVHN shows that adversarial attack techniques may be useful also for other uses-cases, including calibration. Interestingly, some of the improvements carried to OOD data, for example, where the error on SVHN or CIFAR-100 was the lowest with MixUp or dropout. However, when considering calibration on OOD data, MixUp was dominant for CIFAR-10 and CIFAR-100. On average, dropout improved generalisation and MixUp improved calibration when considering both ID and OOD data. The naive Gaussian and uniform input noise perturbations did not bring significant improvements.

Architecture TransferIn this scenario, we assess the performance of the noise injection methods when the HPs are transferred to a different architecture while keeping the dataset constant. We conduct experiments using SVHN with ResNet-18 with HPs tuned on an FC network. Furthermore, we use HPs tuned for ResNet-18 for both CIFAR-10 and CIFAR-100 and we change the architecture to WideResNet-18. The results are presented in Tables 3 and 4. Considering the performance on ID data, we see that dropout reduced error across architectures and also improved calibration. Contrary to the improvements seen on SVHN when using FC, MixUp did not reduce the error when using ResNet-18 and it even recorded worse performance on OOD data than no noise at all. Switching focus to OOD data, model perturbation moderately improved calibration for CIFAR-100, while activations had a negative impact and led to worse calibration. Even though WideResNet-18 and ResNet-18 are relatively similar, transferring hyperparameters for example for MixUp in CIFAR-100, did not prove efficient as seen in calibration on OOD data which became worse than not using any noise at all. In summary, activation noises, most notably dropout, performed well on improving generalisation on both ID and OOD data and moderately on calibration on ID data. However, no method was able to consistently improve calibration on OOD data after the architecture was changed.

Dataset TransferUnder these settings, we investigate the transferability of hyperparameters by evaluating the noise injection methods on the same architectures but using different datasets. Specifically, we evaluate SVHN with ResNet-18 and HPs from CIFAR-100/ResNet-18, CIFAR
10 with ResNet-18 and CIFAR-100/ResNet-18 HPs, and CIFAR-100 with ResNet-18 but with CIFAR-10/ResNet-18 HPs. The results are shown in Tables 5 and 6. For all SVHN, CIFAR-10, CIFAR-100, the most significant error improvements across ID or OOD data were achieved using dropout and Gaussian noise. Interestingly, the activation Gaussian noise was able to improve calibration on both ID and OOD data on CIFAR-100, but not on the other datasets. MixUp has demonstrated varying results, for example on SVHN or CIFAR-10 the calibration on ID data was worse than not using any noise at all, while in CIFAR-100 there was a marginal improvement. Nevertheless on OOD data MixUp was able to improve calibration across all datasets.

SummaryThe effectiveness of noise injections varies with the dataset and architecture. Nevertheless, especially in the tuned regime, certain settings of different noises improved both generalisation and calibration. Activation noise injections demonstrated promising results for error reduction across ID data, while input augmentations seemed to be the most effective for OOD data. Dropout was the most effective in improving error on ID or OOD data, and it proved to be transferable across architectures and datasets. MixUp was the best in improving the performance on OOD data in terms of calibration and accuracy, but not necessarily on the ID data. Interestingly, hidden in its mediocrity, model noise was able to marginally improve accuracy and calibration across majority of considered scenarios. Additional evaluation in terms of NLL, in Appendix B, has shown MixUp, dropout and model perturbations to be the most effective.
## Acknowledgements

Martin Ferianc was sponsored through a scholarship from the Institute of Communications and Connected Systems at UCL. Ondrej Bohdal was supported by the EPSRC Centre for Doctoral Training in Data Science, funded by the UK Engineering and Physical Sciences Research Council (grant EP/L016427/1) and the University of Edinburgh.
