Abstract
Deep learning methods have shown state of the art performance in a range of tasks from computer vision to natural language processing. However, it is well known that such systems are vulnerable to attackers who craft inputs in order to cause misclassification. The level of perturbation an attacker needs to introduce in order to cause such a misclassification can be extremely small, and often imperceptible. This is of significant security concern, particularly where misclassification can cause harm to humans. We thus propose Deep Latent Defence, an architecture which seeks to combine adversarial training with a detection system. At its core Deep Latent Defence has a adversarially trained neural network. A series of encoders take the intermediate layer representation of data as it passes though the network and project it to a latent space which we use for detecting adversarial samples via a $k$-nn classifier. We present results using both grey and white box attackers, as well as an adaptive $L_{\infty}$ bounded attack which was constructed specifically to try and evade our defence. We find that even under the strongest attacker model that we have investigated our defence is able to offer significant defensive benefits.
Introduction
Deep learning models are notoriously "brittle." Small, often imperceptible perturbations to an input—known as adversarial examples—can cause a state-of-the-art model to misclassify an image with high confidence. Current defenses generally fall into two camps: adversarial training, which makes models inherently more robust but often fails against unseen attacks, and detection mechanisms, which can be bypassed by "adaptive" attackers. Deep Latent Defence (DLD) addresses these gaps by providing a scalable, robust hybrid framework that combines both approaches.
Methodology
The DLD architecture operates in two main phases: training and detection.
Training Phase
The system begins with a base network trained using Projected Gradient Descent (PGD) adversarial training. Defensive encoders are attached to the intermediate layers of this network to project high-dimensional layer outputs into a lower-dimensional latent space. Crucially, these encoders are trained using a contrastive loss function, forcing the latent space to cluster training data of the same class together while pushing different classes apart based on $L_2$ distance. This optimization makes the latent space significantly better suited for distance-based detection than raw activations.
Detection Phase
During deployment, when a new sample is processed, its latent representation is compared to the training data using a $k$-nearest neighbor ($k$-NN) algorithm. The system calculates a "non-conformity score": if the $k$ nearest neighbors in the latent space belong to a different class than what the model predicted, the input is flagged as adversarial.
Experimental Results
The researchers evaluated DLD on two standard computer vision benchmarks: MNIST (handwritten digits) and SVHN (Street View House Numbers).
Performance Against Attacks
DLD provides a massive boost in "robustness"—defined as the probability that an attack is either correctly classified or successfully detected. On MNIST, while the base model's accuracy dropped to a mere 11.73% under a Carlini-Wagner (CW) attack, DLD maintained a robustness of 96.10%. The system achieved ROC AUC scores of over 0.98 for most MNIST attacks, indicating high detector precision.
Adaptive Attack Testing
To rigorously test the defense, the authors developed a custom Adaptive Attack. This white-box attack attempts to simultaneously fool the classifier and minimize the distance to the target class's latent centroid. Even under this "gold standard" test, DLD offered significant defensive benefits, proving it is not easily circumvented by attackers aware of the detection mechanism.
Discussion and Future Work
A key finding is that intermediate layers are highly informative; adversarial perturbations cause internal activations to deviate from the "normal" distribution before reaching the final output. DLD effectively taps into this internal "dissonance."
However, challenges remain. There is an inherent trade-off between detection sensitivity and false positives; on SVHN, the false positive rate reached approximately 10% to achieve high robustness. Additionally, performing $k$-NN searches against large training sets can be computationally expensive. Future work will explore more efficient approximate nearest neighbor search methods and evaluate the system on higher-resolution datasets like ImageNet.
Summary updated