Ghost Noise for Regularizing Deep Neural Networks
Batch Normalization (BN) is widely used to stabilize the optimization process
and improve the test performance of deep neural networks. The regularization
effect of BN depends on the batch size and explicitly using smaller batch sizes
with Batch Normalization, a method known as Ghost Batch Normalization (GBN),
has been found to improve generalization in many settings. We investigate the
effectiveness of GBN by disentangling the induced ``Ghost Noise'' from
normalization and quantitatively analyzing the distribution of noise as well as
its impact on model performance. Inspired by our analysis, we propose a new
regularization technique called Ghost Noise Injection (GNI) that imitates the
noise in GBN without incurring the detrimental train-test discrepancy effects
of small batch training. We experimentally show that GNI can provide a greater
generalization benefit than GBN. Ghost Noise Injection can also be beneficial
in otherwise non-noisy settings such as layer-normalized networks, providing
additional evidence of the usefulness of Ghost Noise in Batch Normalization as
a regularizer.
Atli Kosson, Dongyang Fan, Martin Jaggi
# Ghost Noise for Regularizing Deep Neural Networks

###### Abstract

Batch Normalization (BN) is widely used to stabilize the optimization process and improve the test performance of deep neural networks. The regularization effect of BN depends on the batch size and explicitly using smaller batch sizes with Batch Normalization, a method known as Ghost Batch Normalization (GBN), has been found to improve generalization in many settings. We investigate the effectiveness of GBN by disentangling the induced "Ghost Noise" from normalization and quantitatively analyzing the distribution of noise as well as its impact on model performance. Inspired by our analysis, we propose a new regularization technique called Ghost Noise Injection (GNI) that imitates the noise in GBN without incurring the detrimental train-test discrepancy effects of small batch training. We experimentally show that GNI can provide a greater generalization benefit than GBN. Ghost Noise Injection can also be beneficial in otherwise non-noisy settings such as layer-normalized networks, providing additional evidence of the usefulness of Ghost Noise in Batch Normalization as a regularizer.

+
Footnote †: Code available at [https://github.com/epfl/ghost-noise](https://github.com/epfl/ghost-noise)

## 1 Introduction

The use of normalization methods has become widespread in deep learning since the introduction of Batch Normalization [12] (BN) in 2015. For convolutional network training, the batch normalization of a tensor \(\mathbf{X}\in\mathbb{R}^{N\times C\times H\times W}\) with batch size \(N\), \(C\) channels, height \(H\), and width \(W\), is given by:

\[\hat{\mathbf{X}}=\frac{\mathbf{X}-\mathbf{\mu}}{\sqrt{\mathbf{\sigma}^{2}+\varepsilon}}, \qquad\mathbf{\mu}=\frac{1}{NHW}\sum_{n,h,w}\mathbf{X}_{n,:,h,w},\quad\mathbf{\sigma}^{2}= \frac{1}{NHW}\sum_{n,h,w}(\mathbf{X}-\mathbf{\mu})^{2}_{n,:,h,w} \tag{1}\]

where \(\mathbf{\mu}\in\mathbb{R}^{1\times C\times 1\times 1}\) is the mean, \(\mathbf{\sigma}\in\mathbb{R}^{1\times C\times 1\times 1}\) the variance, and operations are broadcasted and performed elementwise. Following a normalization operation, we typically have an affine transformation \(\mathbf{Y}=\mathbf{\gamma}\odot\hat{\mathbf{X}}+\mathbf{\beta}\) with a trainable gain \(\mathbf{\gamma}\in\mathbb{R}^{1\times C\times 1\times 1}\) and bias \(\mathbf{\beta}\in\mathbb{R}^{1\times C\times 1\times 1}\). The mean and variance are computed over the batch dimension causing the final prediction of a given sample to depend on others in the batch. This cross-sample dependency is undesirable for inference, e.g. if test data arrives in small correlated batches or even one sample at a time. In practice, \(\mathbf{\mu},\mathbf{\sigma}\) from Equation 1 are replaced with \(\hat{\mathbf{\mu}}\) and \(\hat{\mathbf{\sigma}}\) that are exponential moving averages of the \(\mathbf{\mu},\mathbf{\sigma}\) used during training. Each sample contributes to its own normalization statistics during training but not inference, causing a discrepancy that can degrade performance. This can be addressed by modifying the deployment network to take the statistics of the current sample into account as done in EvalNorm [19] and Inference Example Weighing [21], at a slightly increased computation cost.

The batch dependency of BN can be detrimental during training under certain circumstances. This is especially true when the available batch size is small or the elements of the batch are correlated [25], where the statistics may deviate significantly from the population statistics. This can lead to a mismatch between the statistics used for normalization during training and those used during inference. A number of alternative methods such as Layer Normalization [1], Instance Normalization [10], Group Normalization [24], Online Normalization [4], Batch Renormalization [11] and Weight
Normalization [18] have been proposed to overcome some of these issues. These either normalize across other dimensions of the tensor \(\mathbf{X}\), are applied to the weights instead, or make use of the history over prior batches to augment the effective size of the batch.

The stochasticity induced by the cross-sample dependency of BN can sometimes have a beneficial regularization effect, which is frequently observed but poorly understood. From a geometrical point of view, Keskar et al. [13] empirically found that training with small batches arrives at flatter minima, which they argue contributes to better generalization. Hoffer et al. [8] observed that performing batch normalization over smaller subgroups of the batch could improve generalization. They call these smaller batches _ghost batches_ and this method of explicitly using smaller batches in batch normalization is known as **Ghost Batch Normalization (GBN)** or sometimes just Ghost Normalization. Summers and Dinneen [21] also observed this effect and recommended the use of GBN. The regularization effect arises from the noise in \(\mathbf{\mu},\mathbf{\sigma}\) computed over a batch compared to the corresponding statistics for the full dataset. This noise, which we will refer to as **Ghost Noise**, increases for smaller batches and may explain the improved generalization with Ghost Batch Normalization. Figure 1 shows an example of how the ghost batch size can affect performance.

In this work we analyze the ghost noise and the train-test discrepancy in Ghost Batch Normalization. The strength of both effects increases with smaller batch sizes, creating a trade-off between the regularization from the ghost noise and the detrimental effect of train-test discrepancy. We propose a new method, **Ghost Noise Injection (GNI)**, which decouples the ghost noise from the normalization process, allowing us to increase the regularization strength without the need to perform normalization using small batch sizes thereby avoiding their negative effects. It also enables us to apply it in new settings, such as with Layer Normalization, that do not induce noise on its own.

Experimentally, we find that Ghost Nose Injection can provide a greater regularization effect than Ghost Batch Normalization. We ablate the method and find that both the scaling and shifting noise of GNI contributes to its effectiveness. In convolutional neural networks, the noise magnitude can vary between channels and layers depending on their distribution, in particular how much of their variance comes from the spatial extent of a single sample compared to the variance between samples. This "adaptivity" may be important, as we find that simpler IID noise methods are unable to match the regularization effect of GNI. This includes several dropout variants as well as IID noise based on our analysis of the ghost noise distribution.

To summarize, our contributions are as follows:

* We study the batch size dependency of the regularization effect of batch normalization. We show that both the shift and scale components of the induced noise can positively contribute to the generalization performance, and that the distribution of noise is channel and layer dependent in convolutional networks.
* We propose a novel regularization method, Ghost Noise Injection (GNI) that decouples the normalization and noise effects of Batch Normalization.
* We perform extensive experiments to validate the effectiveness of our proposed regularizer, showing that it can outperform Ghost Batch Normalization as well as simpler IID noise methods, such as dropout variants.

## 2 Methods and Analysis

### Ghost batch normalization

We can divide a batch \(\mathbf{X}\in\mathbb{R}^{B\times C}\) it into \(g=\frac{B}{N}\) ghost batches (i.e. non-overlapping subgroups): \(\{\mathbf{X}_{1},\mathbf{X}_{2},...\mathbf{X}_{g}\}\), of size \(N\) each. Ghost Batch Normalization is equivalent to performing standard Batch Normalization on each ghost batch independently. For simplicity, we will drop the full convolutional tensor notation from this point onward focusing on the simpler fully connected case. We emphasize that the normalization statistics are still computed on a per-feature basis. Writing a

Figure 1: Impact of ghost batch size on ResNet18 validation accuracy (mean\(\pm\)std) on CIFAR-100.
ghost batch as \(\mathbf{X}_{i}=[\mathbf{x}_{1},\mathbf{x}_{2},..,\mathbf{x}_{N}]\in\mathbb{R}^{B\times C}\), and \(\mathbf{x}_{i}\in\mathbb{R}^{1\times C}\) the normalization becomes:

\[\widetilde{\mathbf{X}}_{i}=\frac{\mathbf{X}_{i}-\mathbf{\mu}_{i}}{\mathbf{\sigma}_{i}},\qquad \qquad\mathbf{\mu}_{i}=\frac{1}{N}\sum_{j}\mathbf{x}_{j}\in\mathbb{R}^{1\times C}, \qquad\mathbf{\sigma}_{i}^{2}=\frac{1}{N}\sum_{j}(\mathbf{x}_{j}-\mathbf{\mu}_{i})^{2}\in \mathbb{R}^{1\times C} \tag{2}\]

The computation over smaller batch sizes leads to higher variance in \(\mathbf{\mu},\mathbf{\sigma}\). Here we note that the term "batch" is highly overloaded and there are at least three different batch sizes of interest:

* Accelerator batch size is the number of samples each worker (e.g. GPU) uses during a single forward / backward pass through the network.
* Ghost batch size, or normalization batch size, is the number of samples over which normalization statistics are calculated.
* Optimization batch size is the number of samples contributing to each optimizer update.

With local accumulation or distributed training, we can have optimization batch size bigger than the accelerator batch size. Likewise, we can also have normalization batch size bigger than accelerator batch size when using e.g. synchronized batch normalization in distributed training.

### Reducing train-test discrepancy

Smaller normalization batch sizes result in increased stochasticity with a potential regularization impact. At the same time, these smaller batches increase the contribution of each sample to the \(\mathbf{\mu},\mathbf{\sigma}\) used in the normalization. This does not match the test time behavior, where pre-calculated running statistics are used to normalize new coming samples. To reduce this over-dependency, we explore an alternative where we prevent each sample from contributing to the normalization statistics used for itself. Instead we compute a different set of statistics for each sample, where we consider all other elements in the ghost batch. We refer to this technique as Exclusive Batch Normalization (XBN). This way, the normalization statistics during training no longer depend on the sample itself, better matching the situation at test-time. We can write the XBN mean and variance computation as:

\[\mathbf{\mu}_{i}=\frac{1}{N-1}\sum_{j\neq i}\mathbf{x}_{j},\qquad\mathbf{\sigma}_{i}^{2}= \frac{1}{N-1}\sum_{j\neq i}(\mathbf{x}_{j}-\mathbf{\mu}_{i})^{2} \tag{3}\]

Importantly, XBN maintains a similar level of noise as GBN while reducing the discrepancy between the train and test time. However, removing the self-dependency of the normalization has a major downside, which is that the self-dependency of normalization bounds the output range which can improve stability. Without it the output range can grow arbitrarily, destabilizing training. We empirically observe this behavior for smaller batch sizes, but when the batch size is big enough to support stable training, we do observe a test accuracy boost, likely due to the reduced train-test discrepancy. Below we analyze the output range for GBN vs XBN.

**Bounded output range of GBN:** The GBN output corresponding to an input \(\mathbf{x}_{i}\) is given by:

\[\frac{\mathbf{x}_{i}-\frac{1}{N}\sum_{j}\mathbf{x}_{j}}{\sqrt{\frac{1}{N}\sum_{j}(\bm {x}_{j}-\frac{1}{N}\sum_{t}\mathbf{x}_{t})^{2}+\varepsilon}}=\frac{\mathbf{x}_{i}- \frac{1}{N}\sum_{j}\mathbf{x}_{j}}{\sqrt{\frac{1}{N}\left((\mathbf{x}_{i}-\frac{1}{N} \sum_{t}\mathbf{x}_{t})^{2}+\sum_{j\neq i}(\mathbf{x}_{j}-\frac{1}{N}\sum_{t}\mathbf{x}_{t })^{2}\right)+\varepsilon}} \tag{4}\]

For analysis purposes, we treat \(\varepsilon\) as 0 for now. The reciprocal of Equation 4 is:

\[\frac{\sqrt{\frac{1}{N}\sum_{j}(\mathbf{x}_{j}-\frac{1}{N}\sum_{t}\mathbf{x}_{t})^{2} }}{\mathbf{x}_{i}-\frac{1}{N}\sum_{j}\mathbf{x}_{j}}=\sqrt{\left(\frac{1}{N}+\sum_{j \neq i}\frac{(\mathbf{x}_{j}-\frac{1}{N}\sum_{t}\mathbf{x}_{t})^{2}}{(\mathbf{x}_{i}-\frac {1}{N}\sum_{t}\mathbf{x}_{t})^{2}}\right)}\geq\frac{1}{\sqrt{N}} \tag{5}\]

which implies that the magnitude of the output is bounded by the square root of the ghost batch size.

**Unbounded output range of XBN:** With XBN the output for a single element \(\mathbf{x}_{i}\) will be:

\[\frac{\mathbf{x}_{i}-\frac{1}{N-1}\sum_{j\neq i}\mathbf{x}_{j}}{\sqrt{\frac{1}{N-1} \sum_{j\neq i}(\mathbf{x}_{j}-\frac{1}{N-1}\sum_{t\neq i}\mathbf{x}_{t})^{2}+\varepsilon}} \tag{6}\]
The numerator here has no dependency on \(\mathbf{x}_{i}\) and if we ignore \(\varepsilon\), it can therefore be arbitrarily small in comparison, making the output unbounded. For example when all \(\mathbf{x}_{j},j\neq i\) are identical, the numerator of Equation 6 will be \(\sqrt{\varepsilon}\), which is close to 0 in practice (the default value in PyTorch is \(\varepsilon=10^{-5}\)). Large values like these can destabilize training. We observe this in practice when using smaller batch sizes, likely due to \(\mathbf{\sigma}_{i}^{2}\) randomly being close to zero for some ghost batches. It may be possible to mitigate this issue, for example by clamping the computed sigma or the resulting output, but we do not pursue this further here. The preceding analysis indicates that self-dependency can be beneficial for stability but larger batch sizes are preferable to minimize the resulting train-test discrepancy. We therefore seek alternative ways of obtaining the Ghost Noise of small batches that do not rely on decreasing the normalization batch size. This would confer stability while also avoiding a significant train-test discrepancy by keeping the self-dependency small.

### Modelling Ghost Batch Normalization as Double Normalization

One of our key insights is that performing a standard batch normalization before ghost batch normalization does not change the output of the GBN. For a batch \(\mathbf{X}\), batch normalization BN and ghost batch normalization GBN we can write this as:

\[\text{GBN}(\mathbf{X})\ =\ \overline{\text{GBN}(\ \overline{\text{BN}(\mathbf{X})}\ )} \tag{7}\]

This follows from the fact that normalization is invariant to affine transformations of the inputs, i.e. \(f(\mathbf{X})=\mathbf{a}\mathbf{X}+\mathbf{b}\) where \(\mathbf{a},\mathbf{b}\) are constant vectors. When \(\varepsilon\) is small enough to be ignored, we have:

\[\text{BN}(\mathbf{a}\mathbf{X}+\mathbf{b})=\frac{(\mathbf{a}\mathbf{X}+\mathbf{b})-\mathbf{\mu}(\mathbf{a}\bm {X}+\mathbf{b})}{\sqrt{\mathbf{\sigma}_{i}^{2}(\mathbf{a}\mathbf{X}+\mathbf{b})+\varepsilon}}= \frac{\mathbf{a}\mathbf{X}+\mathbf{b}-\mathbf{a}\mathbf{\mu}(\mathbf{X})-\mathbf{b}}{\sqrt{\mathbf{a}^{2}\mathbf{ \sigma}_{i}^{2}(\mathbf{X})+\varepsilon}}=\frac{\mathbf{X}-\mathbf{\mu}(\mathbf{X})}{\sqrt{ \mathbf{\sigma}_{i}^{2}(\mathbf{X})+\varepsilon/\mathbf{a}^{2}}}\approx\text{BN}(\mathbf{X}) \tag{8}\]

where we treat \(\mathbf{\mu}\) and \(\mathbf{\sigma}\) as functions. For a given batch, BN is an affine transformation with:

\[\mathbf{a}=(\mathbf{\sigma}_{i}^{2}(\mathbf{X})+\varepsilon)^{-\frac{1}{2}},\qquad\mathbf{b}= -(\mathbf{\sigma}_{i}^{2}(\mathbf{X})+\varepsilon)^{-\frac{1}{2}}\mathbf{\mu}(\mathbf{X}) \tag{9}\]

The coefficients of course depend on \(\mathbf{X}\), but that does not matter for the following normalization.

This decomposition of GBN into two successive normalization operations lets us isolate the differences between standard batch normalization and ghost batch normalization. Ignoring \(\varepsilon\), the double normalization \(\text{GBN}(\text{BN}(\mathbf{X}))\) can be formulated as:

\[\hat{\mathbf{X}}:=\ \overline{\text{BN}}\left(\mathbf{X}\right)=\frac{\mathbf{X}-\mathbf{\mu}} {\mathbf{\sigma}}=[\hat{\mathbf{X}}_{1},..,\hat{\mathbf{X}}_{g}],\qquad\widetilde{\mathbf{X}} _{j}:=\ \overline{\text{GBN}}\left(\hat{\mathbf{X}}\right)_{j}=\frac{\hat{\mathbf{X}}_{j}- \hat{\mathbf{\mu}}_{j}}{\hat{\mathbf{\sigma}}_{j}} \tag{10}\]

where we split the normalized batch into \(g\) ghost batches and show the following GBN for the \(j\)-th subgroup. We can now write the \(\mathbf{\mu}_{j}\) and \(\mathbf{\sigma}_{j}\) of the original \(\text{GBN}(\mathbf{X})\) setup in Equation 2 as:

\[\mathbf{\mu}_{j}=\mathbf{\mu}+\mathbf{\sigma}\hat{\mathbf{\mu}}_{j},\qquad\mathbf{\sigma}_{j}=\bm {\sigma}\hat{\mathbf{\sigma}}_{j} \tag{11}\]

GBN  would be equivalent to \(\overline{\text{BN}}\) if \(\hat{\mathbf{\mu}}_{j}=0\) and \(\hat{\mathbf{\sigma}}_{j}=1\). This happens when the ghost batches are identical, but generally they contain different samples resulting in random variations in \(\hat{\mathbf{\mu}}_{j}\) and \(\hat{\mathbf{\sigma}}_{j}\). These fluctuations cause noise with two components, additive (or shifting) noise from \(\hat{\mathbf{\mu}}_{j}\) and multiplicative (or scaling) noise from \(\hat{\mathbf{\sigma}}_{j}\). The increased train-test discrepancy of GBN comes from the dependency of \(\hat{\mathbf{\mu}}_{j}\) and \(\hat{\mathbf{\sigma}}_{j}\) on a given sample.

### Ghost Noise Injection

The preceding analysis isolates \(\hat{\mathbf{\mu}}_{j}\) and \(\hat{\mathbf{\sigma}}_{j}\) in Equation 11 as the source of Ghost Noise and the train-test discrepancy from self-dependency. We propose replacing the Ghost Batch Normalization in the double normalization setup with a new method, Ghost Noise Injection (GNI) given by:

\[\mathbf{Y}=\frac{\hat{\mathbf{X}}-\mathbf{m}}{\mathbf{s}} \tag{12}\]

where \(\mathbf{m}\) and \(\mathbf{s}\) are independent and identically distributed random vectors corresponding to each sample in the input \(\hat{\mathbf{X}}\). The elements of \(\mathbf{m}\) and \(\mathbf{s}\) are computed as the mean and standard deviation of a randomly sampled (with replacement) subsets of size \(N\) from \(\hat{\mathbf{X}}\). We will refer to the subset size as ghost batch size like for GBN. We treat the resulting \(\mathbf{m}\) and \(\mathbf{s}\) as pure noise, i.e. _we don't backpropagate through their computation_. GNI has two main advantages over GBN:
* Each sample is unlikely to contribute strongly to its own normalization statistics, reducing the train-test discrepancy for a given level of noise (similar to XBN).
* We can freely select normalization batch size \(N\), and it does not need to divide the accelerator batch size used.

**Wider Applicability of GNI:** Ghost Noise Injection does not necessarily need to follow batch normalization. In this case we can instead perform GNI as \(\mathbf{Y}=\frac{\hat{\mathbf{X}}-(\mathbf{m}-\mathbf{\mu})}{\mathbf{s}/\mathbf{\sigma}}\) where \(\mathbf{\mu}\) and \(\mathbf{\sigma}\) are computed like in batch normalization (but without backpropagating through them). This lets us decouple the noise from the normalization, allowing us to inject ghost noise anywhere in the network.

### The Distribution of Ghost Noise

The estimated mean \(\hat{\mathbf{\mu}}_{i}\) and standard deviation \(\hat{\mathbf{\sigma}}_{i}\) from the \(i\)-th ghost batch, can be interpreted as bootstrapped statistics derived from the empirical distribution \(P_{\hat{\mathbf{X}}}\). Following the normalization in Equation 10, the variable \(\hat{\mathbf{X}}\) exhibits a zero mean and unit variance. Assuming that the individual elements of \(\hat{\mathbf{X}}\) are normally distributed allows us to derive an analytical distribution for the mean and variance, giving us additional insights into the workings of GBN. For this section we focus on the distribution for a single channel \(c\) in the \(g\)-th ghost batch, which we denote \(\hat{\mu}_{gc}\) and \(\hat{\sigma}_{gc}\).

#### 2.5.1 Fully Connected Layers

If we assume that the output of batch normalization is independent and normally distributed, the normalization statistics \(\hat{\mathbf{\mu}}_{i}\) and \(\hat{\mathbf{\sigma}}_{i}^{2}\) are computed over a sample \(\hat{\mathbf{X}}=[\hat{\mathbf{x}}_{1},..,\hat{\mathbf{x}}_{N}]\) of \(N\) variables from \(\mathcal{N}(0,1)\). We can the derive the distribution of the sample mean, and therefore the shift noise, as:

\[\hat{\mu}_{gc}=\frac{1}{N}\sum_{i=1}^{N}\hat{x}_{ic}\sim\mathcal{N}\left(0, \frac{1}{N}\right) \tag{13}\]

Since the sum of standard normally distributed variables follows a chi-squared distribution we get:

\[\hat{\sigma}_{gc}^{2}=\frac{1}{N}\sum_{i=1}^{N}(\hat{x}_{ic}-0)^{2}\sim\frac{1 }{N}\chi^{2}(N) \tag{14}\]

This clearly shows the dependency of the noise on the ghost batch size. Larger ghost batch sizes correspond to less noise, explaining their reduced generalization benefit as observed in e.g. Figure 1.

**Analytical Ghost Noise Injection:** From the above analysis, instead of computing ghost statistics from a sampled batch, we could directly sample \(\hat{\mathbf{\mu}}_{g}\) and \(\hat{\mathbf{\sigma}}_{g}^{2}\) from the analytical distribution for each channel. Let \(\hat{\mathbf{X}}\) be \(\mathbf{X}\) after batch normalization like before. For each channel \(c\), we can then inject noise using:

\[\frac{\hat{\mathbf{X}}_{c}-\mu_{c}}{\sigma_{c}}\qquad\text{with }\mu_{c}\sim P_{\hat{ \mu}_{gc}},\sigma_{c}\sim P_{\hat{\sigma}_{gc}^{2}} \tag{15}\]

\(P_{\hat{\mu}_{gc}}\) is given in Equation 13 and \(P_{\hat{\sigma}_{gc}^{2}}\) is given in Equation 14. The hyperparameter \(N\) is used to vary the amount of noise, corresponding to different ghost batch sizes.

**Comparison to Gaussian Dropout:** Here we would like to point out the similarity between the scaling noise and Gaussian Dropout which is written as:

\[\hat{\mathbf{X}}\cdot\mathbf{t}\qquad\text{with }\mathbf{t}\sim\mathcal{N}(1, \tfrac{p}{1-p}) \tag{16}\]

where \(\mathbf{t}\) is sampled element-wise from the Gaussian distribution and \(p\) is interpreted like the drop probability in standard dropout (\(p=0\) for no dropout). Both the scaling noise and Gaussian dropout are multiplicative with similar but slightly different distributions.

#### 2.5.2 Convolutional Layers

In convolutional neural networks the batch statistics are computed across both the batch and spatial dimensions (e.g. the height and width of an image). The data can therefor vary in two separate ways, between samples across the batch dimension, i.e. _inter-sample variance_ and within a single sample
across the spatial dimension, i.e. _intra-sample variance_. This differs from the fully connected case where all variance arises across the batch dimension and there is no concept of intra-sample variance.

To investigate the effects of this, we analyze a simple model. We will assume that \(\mathbf{X}\in\mathbb{R}^{B\times C\times I}\), where \(I\) is the spatial dimension e.g. \(I=H\times W\) where \(H\) is the height and \(W\) the width for image data. We further assume the true linear \(b\)-th batch in a specific channel \(c\) is sampled i.i.d. from a normal distribution, i.e. \(\mu_{bc}\overset{i.i.d.}{\sim}\mathcal{N}(0,\sigma_{Bc}^{2})\), where \(\sigma_{Bc}^{2}\) denotes the inter-sample variance and only varies across \(c\), i.e. it is constant across \(B\). We model the \(i\)-th spatial location in the \(b\)-th batch as being sampled from \(x_{bic}\overset{i.i.d.}{\sim}\mathcal{N}(\mu_{bc},\sigma_{Ic}^{2})\), with an intra-sample variance \(\sigma_{Ic}^{2}\) that does not vary across \(I\).After batch normalization, we always have unit variance, which means \(\sigma_{Bc}^{2}+\sigma_{Ic}^{2}=1\), for any \(c\). Now assume we sample a random ghost batch of size \(N\). As the sample mean is an average of all samples, we still have it following a normal distribution, and the mean and variance can be calculated as follows:

\[\mathbb{E}[\hat{\mu}_{gc}]=\mathbb{E}\left[\frac{1}{NI}\sum_{n}\sum_{i}x_{nic }\right]=\frac{1}{NI}\sum_{n}\sum_{i}\mathbb{E}[x_{nic}]=0 \tag{17}\]

\[\begin{split}\mathrm{Var}[\hat{\mu}_{gc}]&=\mathbb{ E}\left[\frac{1}{NI}\sum_{n}\sum_{i}x_{nic}\right]^{2}\\ &=\mathbb{E}\left[\frac{1}{NI}\sum_{n}\sum_{i}x_{nic}-\mu_{nc}+\mu _{nc}\right]^{2}\\ &=\frac{1}{N^{2}I^{2}}\sum_{n}\sum_{i}\sigma_{Ic}^{2}+\frac{1}{N^ {2}I^{2}}NI^{2}\sigma_{Bc}^{2}\\ &=\frac{1}{NI}\sigma_{Ic}^{2}+\frac{1}{N}\sigma_{Bc}^{2}\end{split} \tag{18}\]

The distribution of shift noise in channel \(c\) can thus be written as:

\[\hat{\mu}_{gc}\sim\mathcal{N}\left(0,\frac{1}{NI}\sigma_{Ic}^{2}+\frac{1}{N} \sigma_{Bc}^{2}\right) \tag{19}\]

For the scale noise in a specific channel \(c\), we have

\[\begin{split}\hat{\sigma}_{gc}^{2}=&\frac{1}{NI} \sum_{i}\sum_{n}(x_{nic}-\mu_{nc}+\mu_{nc})^{2}\\ =&\frac{1}{NI}\sum_{i}\sum_{n}\left((x_{nic}-\mu_{nc })^{2}+(\mu_{nc}-\mu)^{2}+2(x_{nic}-\mu_{nc})(\mu_{nc}-\mu)\right)\\ \overset{\pi_{nc}\otimes\mathbb{E}\,x_{nc}}{\approx}& \frac{1}{NI}\sum_{i}\sum_{n}\sigma_{Ic}^{2}\left(\frac{x_{nic}-\mu_{nc}}{\sigma _{Ic}}\right)^{2}+\frac{1}{N}\sigma_{Bc}^{2}\sum_{n}\left(\frac{\mu_{nc}-\mu}{ \sigma_{Bc}}\right)^{2}+\frac{1}{N}(\mu_{nc}-\mu_{nc})(\mu_{nc}-\mu)\\ =&\frac{1}{NI}\sum_{i}\sum_{n}\sigma_{Ic}^{2}\left( \frac{x_{nic}-\mu_{nc}}{\sigma_{Ic}}\right)^{2}+\frac{1}{N}\sigma_{Bc}^{2}\sum_ {n}\left(\frac{\mu_{nc}-\mu}{\sigma_{Bc}}\right)^{2}\end{split} \tag{20}\]

It follows that \(\hat{\sigma}_{gc}^{2}\) approximately follows a mixture of two chi-square distributions.

\[\hat{\sigma}_{gc}^{2}\sim\frac{\sigma_{Ic}^{2}}{NI}\chi^{2}(NI)+\frac{\sigma_{ Bc}^{2}}{N}\chi^{2}(N) \tag{21}\]

When \(\sigma_{Ic}^{2}=0\), the results coincide with the 1d case. However, the analysis in 2D case gives us more freedom to separate inter- (\(\sigma_{Bc}^{2}\)) and intra-(\(\sigma_{Ic}^{2}\)) sample variances. Another insightful aspect is that it provides more understanding of the differences across channels. As both \(\sigma_{Bc}^{2}\) and \(\sigma_{Ic}^{2}\) are channel-specific, there is indeed a channel-wise noise effect, which we will provide an empirical proof in Figure 3.
## 3 Experiments

**Base Setup:** We use ResNet-18 [6] training on CIFAR-100 [14] as our main experimental setup. The dataset consists of 32x32 images split into 50000 training and 10000 test samples, evenly split between 100 classes. For hyperparameter tuning, we use a random subset of 10% of the training dataset as validation set. We report the test set results for the best-performing hyperparameters, after retraining on the entire training set. All the models were trained for 200 epochs, using a cosine decay learning rate schedule with a 5 epoch warmup at a batch size of 256. The dataset is relatively small and contains few images in each class, making regularization important. ResNet-18 is a moderately sized network which helps keep the computational cost of training reasonable, allowing us to perform multiple runs of each setting. We use a learning rate of \(\eta=0.3\) for all experiments, which was tuned on the validation set for training with standard batch normalization. Further details are listed in Appendix A.

**Ghost Batch Normalization:** The top left panel of Figure 2 shows how the ghost batch size affects the final validation accuracy when using Ghost Batch Normalization. Using a ghost batch size of 256 is equivalent to standard batch normalization. We see that the accuracy increases for smaller batch sizes up to a certain extent, after which it goes down again. This increase is likely due to increased regularization while the eventual decline may come from either too much regularization or by the amplified bias in normalization statistics leading to a train-test discrepancy. The optimal ghost batch size of 16 gives an accuracy boost of just over 1% on both the validation set and the test set (Table 1).

**Reducing the Train-Test Discrepancy:** In the upper middle panel of Figure 2 we investigate the effectiveness of Exclusive Batch Normalization (XBN, Equation 3) and EvalNorm [19] (EN). Both methods aim at improving test performance by reducing the train-test discrepancy, XBN by changing sample dependency during training time to be more similar to inference time while EvalNorm does the opposite. XBN can be unstable for small batch sizes (see analysis in Section 2.2), in this case batch sizes smaller than 32. XBN and EN both seem to resolve some of the train-test discrepancy,

\begin{table}
\begin{tabular}{l c c c c c} \hline \hline  & BN & GBN-16 & GNI-16 & XBN & EN \\ \hline Mean & 77.10 & 78.20 & **78.84** & 78.33 & 78.33 \\ Std & 0.26 & 0.10 & 0.09 & 0.40 & 0.27 \\ \hline \hline \end{tabular}
\end{table}
Table 1: Test accuracy comparison (mean\(\pm\)std for 3 runs)

Figure 2: CIFAR-100 ResNet-18 validation accuracy versus ghost batch size and dropout probability for different methods. Each line is the average of five runs and the shaded area shows the standard deviation. The dotted lines show the standard batch normalization performance and the maximum for ghost batch normalization. For dropout (DO, lower right panel), B=Bernoulli, G=Gaussian, E=elementwise and C=channelwise. See Section 3 for further experimental details and discussion.
giving a small accuracy boost over Ghost Batch Normalization. XBN performs slightly better on the validation set, but similarly on the test set (Table 1).

**Decoupling the Noise:** In Figure 2, the lower-left panel shows the performance of Ghost Noise Injection for different ghost batch sizes. We observe a significant boost, around twice that of Ghost Batch Normalization. At higher ghost batch sizes, GNI performs similarly to XBN. This may indicate that GNI also successfully reduces the train-test discrepancy while stabilizing smaller batch sizes, allowing us to benefit from their increased regularization effect. Out of the methods we have tried, GNI also performs the best on the test set. In the lower middle panel of Figure 2 we investigate the effect of the different noise components of GNI. GNI \(\mathbf{\mu}\) only includes the shift and GNI \(\mathbf{\sigma}\) only the scaling term. Either one gives a significant boost on their own but is unable to match GNI, suggesting that both components of Ghost Noise are beneficial in this setting.

**Ghost Noise Distribution:** Figure 3 shows measured distributions of both the scale and shift components of the noise generated by GNI. The observed average distributions are similar to our derived distribution for the fully connected case, but the batch size parameter must be adjusted to account for the intra-sample variance component (Section 21). The distributions vary significantly between layers and channels (not shown here), especially later in training potentially due to changes in the intra-sample variance component. In the top right panel of Figure 2 we apply our analytical ghost noise injection to training. We observe some gain but are unable to match the performance of the sample-based GNI, which may indicate that the per-channel variations are important.

**Dropout:** Ghost Noise Injection is a regularizer and a potential alternative to Dropout. In Figure 2 (bottom right) we compare four variants of dropout (Bernoulli/Gaussian and Element-wise/Channel-wise) to the other methods. We apply the dropout after the second normalization layer on each branch, as was done in Wide Residual Networks [26]. We find that dropout performs similarly to the Analytical Ghost Noise Injection but is unable to match either GBN or sample-based GNI.

**Applicability to other Normalizers:** So far we have applied GNI on top of Batch Normalization. However, GNI is not limited to this use case. Figure 4 shows the CIFAR-100 validation accuracy of a ResNet-18 where batch normalization has been replaced by weight-standardization [17] and layer normalization [1]. We find that GNI can also provide a significant accuracy boost in this setting, bringing the performance with this noise-free normalization method in line with that of GBN.

**Generalization to other Datasets:** Table 2 shows that GNI can also regularize the training of ResNet-50 on ImageNet-1k and ResNet-20 on CIFAR-10. In both cases Ghost Noise Injections provides a decent boost in accuracy and outperforms Ghost Batch Normalization.

**Additional Experimental Results:** We report additional experiments in Appendix B.

Figure 3: Measured GNI noise distributions for ResNet18 on CIFAR100 with a Ghost Batch Size of 32 along with analytical fully connected distributions for a batch size 256. Each GNI line is an average over a layer, the distributions also vary between channels inside each layer. The lines are plotted with a standard color spectrum (i.e. the rainbow) from violet (first layer) to red (last layer).
## 4 Related Work

**Mitigating Train-test Discrepancy:** Singh and Shrivastava [19] proposed EvalNorm to estimate corrected normalization statistics to use for BN during evaluation, such that training and testing time normalized activation distributions become closer. Summers and Dinneen [21] incorporated example statistics during inference, which reduces the output range of a network with Batch Normalization during testing. While both works try to mitigate train-test discrepancy by alternating test time normalization statistics, our XBN shows that it is also possible to address the same issue by reducing sample dependency during training time. XBN brings increased generalization performances but unfortunately is not stable with respect to small batch sizes. Nonetheless, it might still provide some new perspectives for future works.

**Noise Injection:** Liu et al. [15] proposed a composition of two trainable scalars and a zero-centered noise injector for regularizing normalization-free DNNs. Camuto et al. [3] analyzed Gaussian Noise Injection from a more theoretical point of view and found injected noise particularly regularises neural network layers that are closer to the output. Compared to these two, Ghost Noise Injection more closely imitates the noise of batch normalization, accounting for the channel and layer wise differences in the distribution.

**Dropout:** Dropout was first proposed by Srivastava et al. [20] as a simple regularization approach to prevent units from co-adapting too much. Wei et al. [22] demonstrates the explicit and implicit regularization effects from dropout, and found out that the implicit regularization effect is analogous to the effect of stochasticity in small mini-batch stochastic gradient descent. Hou and Wang [9], He et al. [7] applied channel-wise dropout and experimentally showed consistent benefits in DNNs with convolutional structures. Further, it is observed that channel-wise dropout encourages its succeeding layers to minimize the intra-class feature variance [7].

## 5 Conclusion

In this study we have investigated the source of an important part of the regularization effect of batch normalization, the generalization benefit from smaller batch sizes. To the best of our knowledge, this has not been thoroughly studied before, despite Batch Normalization being one of the most widely used methods in deep learning. By formulating Ghost Batch Normalization as a series of two normalization operations, we are able to analyze the impact of smaller batch sizes on the noise and train-test discrepancy. In our analysis of the noise shows that it is channel dependent and has two components, shifting and scaling that both contribute to its effectiveness. We also show that we can reduce the discrepancy by preventing a sample from contributing to its own normalization statistics during training. Our proposed Ghost Noise Injection (GNI) is able to increase the levels of Ghost Noise without performing normalization on smaller batches, avoiding the train-test discrepancy. We show GNI has a beneficial impact on generalization in a number of settings, including where batch normalization is not present. This further highlights the importance of Ghost Noise as a source of regularization in batch normalization.

\begin{table}
\begin{tabular}{l c c c c c c c} \hline \hline Setup & BN-256 & GBN-16 & GBN-32 & GBN-64 & GNI-16 & GNI-32 & GNI-64 \\ \hline \multirow{2}{*}{C10-RN20} & 92.22 & 92.65 & 92.53 & 92.50 & **93.01** & 92.76 & 92.56 \\  & \(\pm\)0.05 & \(\pm\)0.07 & \(\pm\)0.33 & \(\pm\)0.13 & \(\pm\)0.28 & \(\pm\)0.11 & \(\pm\)0.12 \\ i1k-RN50 & 77.43 & 76.90 & 77.14 & 77.48 & 77.62 & 77.70 & **77.98** \\ \hline \hline \end{tabular}
\end{table}
Table 2: ResNet-20 CIFAR-10 (mean\(\pm\)std for 3 runs) and ResNet-50 ImageNet-1k accuracy

Figure 4: Accuracy impact of Ghost Noise Injection on Weight Standardized Layer Normalized ResNet18 trained on CIFAR100. The black dotted lines correspond to Figure 2 and the red dotted line to no GNI.