A General Framework For Detecting Anomalous Inputs to DNN Classifiers

Jayaram Raghuram, Varun Chandrasekaran, Somesh Jha, Suman Banerjee

Introduction

Deep Neural Networks (DNNs) are notoriously overconfident. They can misclassify an image with 99% certainty if it’s slightly tweaked by an adversary or if it’s something they’ve never seen before (out-of-distribution, or OOD). Current defenses often fall into two traps: supervised overfitting (failing against unseen attacks) and heuristic fragmentation (relying on single layers or final outputs, missing the holistic "fingerprint" of an anomaly).

To address this, researchers have introduced JTLA (Joint statistical Testing across DNN Layers for Anomalies). JTLA is an unsupervised framework that detects adversarial and OOD inputs by analyzing internal neural network representations across all layers. By treating anomaly detection as a statistical testing problem, it achieves state-of-the-art performance without needing to be trained on specific attack examples, making it robust even against clever, "defense-aware" adversaries.

The JTLA Framework

The core of the paper is JTLA, a meta-algorithm composed of four distinct stages:

  1. Test Statistics (TS): For a given input, the algorithm looks at its $k$-nearest neighbors ($k$NN) in the training data at every layer. It uses a multinomial Likelihood Ratio Test (LRT) to see if the neighbor classes match the network's predicted class. If an input predicted as a "cat" is surrounded by "truck" neighbors in the middle layers, the TS flags it.
  2. Normalizing Transformations: Since different layers have different scales and distributions, JTLA converts these raw statistics into p-values. This puts everything on a uniform [0, 1] scale, representing how "surprising" the observation is relative to normal data.
  3. Layerwise Aggregation: It combines these p-values across all layers. The authors explore Fisher’s method (for independent tests) and Harmonic Mean p-values (for dependent tests) to create a single "suspicion score."
  4. Scoring & Decision: Finally, it applies a scoring function tailored for either adversarial or OOD detection and compares it against a threshold set to maintain a low False Positive Rate (e.g., 1%).
Distributions of test statistics for normal vs. adversarial samples across layers. Note how the overlap (BC) decreases in later layers, making anomalies easier to spot.

Core Insights

  • Joint Testing is Key: Anomalies often look "normal" in some layers but "weird" in others. By testing across all layers simultaneously, JTLA catches subtle deviations that single-layer methods miss.
  • Unsupervised Robustness: Because JTLA doesn't "learn" what an attack looks like, it isn't easily fooled by new attack variants. It simply learns what "normal" looks like and flags anything else.
  • Conditioning on Predictions: A major insight is evaluating an input's statistics based on the class the network thinks it is. If the network predicts "dog" but the internal representations look like "airplane" training data, that's a strong signal of an adversarial attack.
  • Defense-Aware Adversaries: The authors developed a new adaptive attack specifically designed to bypass $k$NN-based defenses. JTLA still performed remarkably well against this sophisticated adversary.

Performance Highlights

The framework was evaluated on standard image classification benchmarks (MNIST, SVHN, CIFAR-10) for both adversarial and OOD detection.

JTLA consistently outperformed state-of-the-art unsupervised baselines like Deep kNN and Trust Score.

  • Adversarial Detection: On CIFAR-10 and SVHN, JTLA achieved significantly higher Average Precision (AP) across various attacks (PGD, CW, FGSM).
  • OOD Detection: JTLA beat other unsupervised methods and remained competitive with supervised methods (like the Mahalanobis detector), even though supervised methods have the unfair advantage of seeing outlier data during training.
Adversarial detection performance on CIFAR-10. JTLA (purple/green lines) consistently stays at the top across different attack strengths.

Limitations and Future Work

While highly effective, JTLA has some limitations. Running $k$NN queries across many high-dimensional layers can be computationally expensive. Although the authors mitigated this using dimensionality reduction (NPE) and fast approximate nearest neighbor searches (NNDescent), real-time deployment on edge devices might still be challenging. Additionally, like most anomaly detectors, JTLA requires a clean validation set to calibrate the detection threshold.

Future directions include exploring more complex test statistics beyond $k$NN class counts and extending the framework to non-image domains like Natural Language Processing (NLP).

Summary updated

BibTeX
@inproceedings{raghuram2021general,
  author = {Jayaram Raghuram and Varun Chandrasekaran and Somesh Jha and Suman Banerjee},
  title = {{A General Framework For Detecting Anomalous Inputs to DNN Classifiers}},
  booktitle = {International Conference on Machine Learning},
  year = {2021},
  url = {https://openreview.net/forum?id=sT31lI5OZhQ},
}
Figure