Robust Feature Inference: A Test-time Defense Strategy using Spectral Projections

Anurag Singh, Mahalakshmi Sabanayagam, Krikamol Muandet, Debarghya Ghoshdastidar

Abstract

Test-time defenses are used to improve the robustness of deep neural networks to adversarial examples during inference. However, existing methods either require an additional trained classifier to detect and correct the adversarial samples, or perform additional complex optimization on the model parameters or the input to adapt to the adversarial samples at test-time, resulting in a significant increase in the inference time compared to the base model. In this work, we propose a novel test-time defense strategy called Robust Feature Inference (RFI) that is easy to integrate with any existing (robust) training procedure without additional test-time computation. Based on the notion of robustness of features that we present, the key idea is to project the trained models to the most robust feature space, thereby reducing the vulnerability to adversarial attacks in non-robust directions. We theoretically characterize the subspace of the eigenspectrum of the feature covariance that is the most robust for a generalized additive model. Our extensive experiments on CIFAR-10, CIFAR-100, tiny ImageNet and ImageNet datasets for several robustness benchmarks, including the state-of-the-art methods in RobustBench show that RFI improves robustness across adaptive and transfer attacks consistently. We also compare RFI with adaptive test-time defenses to demonstrate the effectiveness of our proposed approach.

The Challenge of Adversarial Robustness

Deep neural networks are notoriously vulnerable to adversarial examples—inputs carefully crafted with imperceptible perturbations that cause models to fail. While adversarial training remains a primary defense, it is computationally expensive. Alternative test-time defenses often introduce significant latency, requiring secondary models or per-input optimization that can slow down inference by orders of magnitude.

Robust Feature Inference (RFI) addresses this by providing a defense with zero additional computational overhead during inference. The core premise is that neural networks learn both "robust" features (signal) and "non-robust" features (noise). Attackers primarily exploit the latter. RFI identifies and projects the model's decision-making process onto a subspace defined by these robust features.

Methodology: Spectral Projection

The RFI framework operates in two distinct stages after a model has been trained. First, it performs a post-training analysis of the feature covariance matrix at the penultimate layer using the training data. Through eigendecomposition, the most significant directions of variation are identified. Second, a class-specific robustness score is used to select the top $K$ eigenvectors, forming a "robust subspace."

Overview of the RFI framework, showing the post-training computation of robust features and their application during inference.

The final classification layer's weights are then projected onto this subspace. Because this projection is applied to the weights themselves before deployment, the mathematical operations required for a prediction remain identical to the original model, ensuring a 1x inference time multiplier.

Experimental Results

The authors evaluated RFI across standard benchmarks including CIFAR-10, CIFAR-100, and ImageNet, as well as state-of-the-art models from the RobustBench leaderboard. The results demonstrate that RFI consistently improves adversarial robustness across various training regimes, including standard training and established adversarial training methods like PGD and TRADES.

Performance comparison of various training methods with and without RFI on CIFAR-10, highlighting gains in adversarial robustness across different attack norms.

Key findings from the experiments include:

  • Efficiency: RFI maintains the original model's inference speed, unlike competing defenses that can be 2x to 8x slower.
  • Robustness Gains: For standard models, RFI can increase $\ell_2$ robustness from near-zero to nearly 10%. For already robust models, it typically adds a consistent ~2% margin.
  • Transfer Attack Resilience: RFI is particularly effective against transfer attacks, where adversarial examples are generated using a different source model.

Theoretical and Empirical Insights

Theoretical analysis using Generalized Additive Models (GAM) and Neural Tangent Kernels (NTK) suggests that features associated with the largest eigenvalues of the covariance matrix are the most robust. Empirically, the optimal number of features to retain ($K$) often matches the number of classes, a finding that links RFI to the "Neural Collapse" phenomenon observed in deep learning.

Importantly, RFI does not rely on "gradient obfuscation." Its robustness holds even when attackers have full knowledge of the defense mechanism, indicating that it addresses a fundamental structural vulnerability in the feature space.

Conclusion

Robust Feature Inference offers a practical, high-efficiency method for enhancing the security of deep learning models. While it introduces a minor trade-off in clean accuracy, its ability to boost robustness without increasing inference latency makes it a compelling choice for real-world deployment. Future work may explore integrating these spectral projections directly into the training process to further optimize the balance between accuracy and robustness.

Summary updated

BibTeX
@article{singh2024robust,
  author = {Anurag Singh and Mahalakshmi Sabanayagam and Krikamol Muandet and Debarghya Ghoshdastidar},
  title = {{Robust Feature Inference: A Test-time Defense Strategy using Spectral Projections}},
  journal = {Accepted by TMLR},
  year = {2024},
  url = {https://openreview.net/forum?id=9OHAtWdFWB},
}
Figure