Distribution Shift Detection for Deep Neural Networks

Guy Bar-Shalom, Yonatan Geifman, Ran El-Yaniv

TL;DR

Monitoring production deep neural networks for distribution shift is often bottlenecked by computationally expensive two-sample statistical tests over massive reference datasets. This paper introduces an ultra-efficient, window-based shift detection framework that condenses reference training sets into just $O(\log m)$ theoretical coverage bounds using selective prediction principles. The resulting detector operates in $O(k + \log m)$ time per window of size $k$ and consistently outperforms state-of-the-art baselines on CIFAR-10 and ImageNet across noise, domain, and adversarial shifts.

What Problem Does This Paper Address?

When deep learning models are deployed in production, incoming data streams can diverge from training distributions due to natural drift, corrupted inputs, or adversarial attacks. Left undetected, this silent degradation damages predictive reliability.

Existing black-box shift detection (BBSD) methods typically compress inputs into embeddings or softmax vectors and run two-sample statistical tests (e.g., Kolmogorov–Smirnov or Maximum Mean Discrepancy) between a reference "in-distribution" (ID) dataset of size $m$ and a recent test window of size $k$. However, these methods are computationally "lazy": evaluating each new test window requires re-processing the reference dataset, yielding time complexities scaling as $O(d(m \log m + k \log k))$ or $O(d(m^2 + k^2 + mk))$. On modern datasets where $m$ is hundreds of thousands or billions of samples, continuous production monitoring with these methods is prohibitively expensive.

Methods

The authors repurpose principles from selective classification (where a model abstains from predicting when confidence is low) into a distribution shift monitor:

  1. Selection with Guaranteed Coverage (SGC): Given a model $f$, a confidence-rate function $\kappa_f$ (such as Softmax Response or negative entropy, Soft-Entropy), and a target coverage $c^*$, SGC uses a binary search over training data $S_m$ to identify a confidence threshold $\theta$. Applying an inversion of the binomial CDF (based on Langford’s generalization bound), it computes a tight numerical lower bound $b^*$ guaranteed to bound the population coverage with probability $\ge 1 - \delta$.
  2. Offline Summary to $O(\log m)$ Scalars: The authors run SGC across $\lfloor \log_2 m \rfloor$ target coverages spread across $(0, 1)$, obtaining pairs of thresholds and bounds $\{(\theta_j, b^*_j)\}$. This step runs once offline, distilling an arbitrarily large training set into roughly 30 numerical values (e.g., 32 scalars for a 3-billion-sample dataset).
  3. Online Window Monitoring via $t$-Test: For an incoming test window $W_k = \{x_1, \dots, x_k\}$, the detector calculates empirical coverages $\hat{c}_j(\theta_j, W_k)$. The mean empirical coverage across all thresholds ($\hat{\mu}$) is tested against the expected bound average ($\mu$) using a one-sample $t$-test ($H_0: \hat{\mu} \ge \mu$ vs. $H_1: \hat{\mu} < \mu$). If the $p$-value falls below significance level $\alpha$, a shift alarm is triggered.
Offline Training:
  S_m (ID Data) ──► SGC Algorithm ──► Store O(log m) (threshold, bound) pairs

Online Monitoring:
  Window W_k (size k) ──► Compute Empirical Coverages ──► 1-sample t-test vs. Bounds ──► Alarm if p < α

Datasets

The authors evaluated their detector across vision classification tasks:

  • In-Distribution (ID) Source Data: CIFAR-10 and ImageNet (evaluated using ResNet-18, ResNet-50, and EfficientNet-B0).
  • Synthetic Benchmark: A 2D Gaussian mixture problem used to analyze upper and lower bound behavior under controlled mean shifts.
  • Shift Scenarios (AD Data):
  • Image transformations: Rotations ($10^\circ$ to $180^\circ$) and Gaussian noise.
  • Natural domain shifts & corruptions: CIFAR-100, SVHN, ImageNet-A, ImageNet-O, and ImageNet-C (75 visual distortions across severities 1, 3, and 5).
  • Adversarial attacks: FGSM, PGD, and Carlini–Wagner (CW).
  • Contamination proportions: Windows mixed with $p \in \{1, 2/3, 1/3\}$ shifted samples.

Key Insights and Ideas

  • Coverage as a Sensitive Canary: If the data-generating process remains stationary, an empirical window should respect theoretical coverage bounds. Shifts uniformly degrade model confidence, triggering clear bound violations.
  • Mid-Range Coverages Hold the Strongest Signal: Synthetic experiments revealed that detection sensitivity peaks not at extreme thresholds ($c^* \approx 1$), but at mid-range coverages ($\approx 0.7$), where the margin between clean and shifted distributions is widest.
  • Massive Complexity Reduction: Online inference drops from scaling with $m$ to just $O(k + \log m)$ in both time and space, enabling real-time detection on resource-constrained production systems.
  • Fewer False Alarms: The theoretical bounds dramatically reduce false positive rates on pure in-distribution data, visible in major gains under precision-recall metrics (AUPR-Tr).

Key Results

  • CIFAR-10: Across ResNet-18 and ResNet-50, the proposed method with Soft-Entropy (Ours-Ent) achieved 98.57%–98.72% Agg-AUROC, outperforming the strongest baseline, KS-BBSD-S (97.27%–97.61%), and MMD baselines (~83%–87%). On the in-distribution identification metric (Agg-AUPR-Tr), Ours-Ent reached ~92.1%, dwarfing KS-BBSD-S (~82.6%–83.7%) and MMD (~27%–35%).
  • ImageNet (EfficientNet-B0):
  • At full window contamination ($p=1$), Ours-Ent achieved 99.15% Agg-AUROC vs. 98.30% for KS-BBSD-S.
  • At partial contamination ($p=1/3$), where shifts are subtle, Ours-Ent retained 93.50% Agg-AUROC and 61.76% Agg-AUPR-Tr, whereas KS-BBSD-S degraded to 89.16% and 44.28%, respectively.

Limitations and Future Work

  • Task Scope: The formulation currently targets multi-class classification; extending it to regression (e.g., via MC-dropout uncertainty) or structured prediction (object detection, segmentation) remains future work.
  • Uniform Aggregation: Currently, bounds are aggregated using an unweighted average before the $t$-test; learned or non-uniform weighting could improve detection power.
  • Shift Diagnosis: The algorithm alerts practitioners that a shift has occurred, but does not diagnose the type of shift (covariate vs. concept drift) nor propose automatic model adaptation.

Summary updated

Abstract

To deploy and operate deep neural models in production, the quality of their predictions, which might be contaminated benignly or manipulated maliciously by input distributional deviations, must be monitored and assessed. Specifically, we study the case of monitoring the healthy operation of a deep neural network (DNN) receiving a stream of data, with the aim of detecting input distributional deviations over which the quality of the network's predictions is potentially damaged. Using selective prediction principles, we propose a distribution deviation detection method for DNNs. The proposed method is derived from a tight coverage generalization bound computed over a sample of instances drawn from the true underlying distribution. Based on this bound, our detector continuously monitors the operation of the network over a test window and fires off an alarm whenever a deviation is detected. This novel detection method consistently and significantly outperforms the state of the art with respect to the CIFAR-10 and ImageNet datasets, thus establishing a new performance bar for this task, while being substantially more efficient in time and space complexities.
BibTeX
@inproceedings{barshalom2023distribution,
  author = {Guy Bar-Shalom and Yonatan Geifman and Ran El-Yaniv},
  title = {{Distribution Shift Detection for Deep Neural Networks}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=P3n4wFJGs5},
}
Figure