Abstract
Despite their successful application to a variety of tasks, neural networks remain limited, like other machine learning methods, by their sensitivity to shifts in the data: their performance can be severely impacted by differences in distribution between the data on which they were trained and that on which they are deployed. In this article, we propose a new family of representations, called MAGDiff, that we extract from any given neural network classifier and that allows for efficient covariate data shift detection without the need to train a new model dedicated to this task. These representations are computed by comparing the activation graphs of the neural network for samples belonging to the training distribution and to the target distribution, and yield powerful data- and task-adapted statistics for the two-sample tests commonly used for data set shift detection. We demonstrate this empirically by measuring the statistical powers of two-sample Kolmogorov-Smirnov (KS) tests on several different data sets and shift types, and showing that our novel representations induce significant improvements over a state-of-the-art baseline relying on the network output.
Introduction
Machine learning models often suffer from "silent failure." A model trained on pristine laboratory data might perform poorly when deployed in the real world due to distribution shift—changes in the input data caused by sensor degradation, lighting changes, or environmental factors. Detecting these shifts is notoriously difficult in high-dimensional spaces like images.
A popular baseline, Black Box Shift Detection (BBSD), monitors the model's final output (the "Confidence Vector"). However, the final output is highly compressed; by the time a shift is visible in the classification probabilities, the network may have already discarded the subtle internal signals that could have warned of an impending failure. This research introduces MAGDiff (Mean Activation Graph Difference), a sensitive "canary in the coal mine" that monitors the internal layers of a neural network to detect shifts earlier and more reliably.
Methodology
MAGDiff is a "plug-and-play" method that leverages the Activation Graph, a weighted representation of how a specific neural network layer processes an input. The process involves three main steps:
- Representation Extraction: For a given layer, the method computes the Frobenius norm distance between the activation graph of a new sample and the mean activation graph of each class from the training set.
- MAGDiff Vector Construction: This results in a $D$-dimensional vector (where $D$ is the number of classes). Each coordinate measures how much a new image "excites" the network's internal neurons compared to the training images for a specific class.
- Statistical Testing: To determine if a shift has occurred, a batch of these MAGDiff vectors is collected from the new data and compared to a "clean" reference set using a two-sample Kolmogorov-Smirnov (KS) test.
Crucially, this method requires no retraining and no additional models (like autoencoders). It simply sits on top of any existing pre-trained classifier, utilizing the features the network has already learned to be relevant for its task.
Experimental Setup
The researchers evaluated MAGDiff across five standard computer vision benchmarks: MNIST, FashionMNIST, CIFAR-10, SVHN, and Imagenette. They tested three types of covariate shifts—Gaussian noise, Gaussian blur, and Image shift (rotations, translations, and zooms)—each at six levels of intensity.
Results and Discussion
The experiments revealed that internal layers are significantly less compressed than the final output. While the final output is designed to be invariant to certain changes to achieve better generalization, internal layers preserve more "texture" of the input distribution, making them superior for shift detection.
Key findings include:
- Superior Detection Power: In almost every scenario, MAGDiff reached a statistical power of 1.0 (perfect detection) much faster than the Confidence Vector (CV) baseline.
- Sensitivity to Subtle Shifts: MAGDiff is particularly effective at detecting "low-intensity" shifts that are almost invisible to the human eye and do not yet significantly impact model accuracy.
- Sample Efficiency: MAGDiff requires significantly fewer samples to reach high confidence. For example, on MNIST with low-intensity noise, MAGDiff could detect the shift with a sample size of $m=100$, while the CV-based method remained essentially blind even at $m=1000$.
Conclusion
MAGDiff provides a powerful, task-adapted framework for detecting covariate shifts without the overhead of training secondary models. While it is specifically designed for covariate shifts rather than label shifts, its ability to provide early warnings for subtle data degradation makes it a valuable tool for ensuring the reliability of deployed neural networks. Future work may explore more complex graph features derived from Topological Data Analysis (TDA) or extending the framework to regression tasks.
Summary updated