Abstract
Deep learning models are vulnerable to adversarial attacks—subtle perturbations that cause misclassification. Existing defenses often require expensive retraining or are specific to certain attack types. This paper presents a novel, attack-agnostic detection method that leverages the statistical properties of internal neural network activations. By comparing the distribution of activations (logits) of test samples against a reference distribution of clean data using metrics like Energy Distance (ED) and Maximum Mean Discrepancy (MMD), the proposed method achieves high detection accuracy (up to 100% AUC) even with a single test image.
Introduction
Deep neural networks (DNNs) have achieved remarkable success in various domains, yet they remain notoriously brittle. Adversarial attacks—carefully crafted, nearly invisible perturbations to input data—can trick state-of-the-art models into making egregious errors, such as misidentifying a stop sign as a speed limit sign.
Current defensive strategies generally fall into two categories: adversarial training and dedicated detection modules. Adversarial training involves retraining models on "poisoned" data, which is computationally intensive and may degrade performance on clean data. Detection modules often rely on secondary sub-networks that are frequently overfit to specific attack methodologies. There is a critical need for a detection framework that is both attack-agnostic (effective against unseen tricks) and sample-efficient (capable of real-time detection without large batches of data).
Methodology
The core hypothesis of this research is that while an adversarial image may appear visually similar to a specific class, its internal representation within the network—specifically the activations in the penultimate layers—will deviate significantly from the statistical distribution of genuine images of that class.
The proposed workflow consists of four main stages:
- Feature Extraction: Instead of analyzing high-dimensional and noisy raw pixels, the method extracts "logits"—the raw scores generated before the final softmax layer.
- Reference Distribution: A baseline of "normal" activation patterns is established for each class using clean training data.
- Statistical Distance Calculation: Upon receiving a new input, the system calculates the distance between its activations and the reference distribution using two metrics:
- Maximum Mean Discrepancy (MMD): A kernel-based test comparing distribution means in high-dimensional space.
- Energy Distance (ED): A metric based on distances between points in two distributions, highly effective at identifying if samples originate from the same source.
- Thresholding: Inputs exceeding a predefined statistical distance threshold are flagged as adversarial.
Experimental Setup
The method was evaluated on two standard benchmarks: MNIST (handwritten digits) and CIFAR-10 (color images across 10 categories). The robustness of the detector was tested against three major attack types: the Fast Gradient Sign Method (FGSM), Projected Gradient Descent (Madry/PGD), and the high-strength Carlini-Wagner (CW-l2) attack.
A key insight of this work is the advantage of operating in "activation space." By utilizing logits rather than raw pixels, the dimensionality is significantly reduced, making statistical tests far more sensitive and enabling detection with as few as $n=1$ sample.
Results
Performance was evaluated using the Area Under the Curve (AUC) metric. On the MNIST dataset, the system achieved near-perfect results, reaching 100% AUC against Carlini-Wagner attacks even with a single sample.
On the more complex CIFAR-10 dataset, the detector remained highly effective. With just one test image, Energy Distance (ED) achieved an AUC of 94.2% against Carlini-Wagner attacks and 88.4% against Madry attacks. As the number of test samples increased to 20, detection accuracy consistently improved, often exceeding 95% across all attack types.
Discussion and Future Work
The proposed method demonstrates that internal network states provide a rich signal for identifying adversarial perturbations without prior knowledge of the attack mechanism. However, several avenues for future research remain. The current study utilized a CIFAR-10 model with 71.8% accuracy; future work should investigate if the statistical gap between clean and adversarial data persists in more accurate, naturally robust models. Additionally, exploring intermediate hidden layers beyond logits may yield even more discriminative features. Finally, the resilience of such statistical detectors against "adaptive attacks" warrants further investigation.
Summary updated