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.
Introduction
Deep neural networks (DNNs) are notoriously vulnerable to adversarial examples—inputs with tiny, imperceptible perturbations that trick a model into making high-confidence errors. While adversarial training is the gold standard for defense, it is computationally expensive and often insufficient on its own. This has led to the rise of test-time defenses, which attempt to "fix" the model or the input during the prediction phase. However, most existing test-time defenses face a major hurdle: latency. Dynamic defenses often require complex optimizations or auxiliary models for every single input, slowing down inference by $2\times$ to $500\times$.
Researchers have developed Robust Feature Inference (RFI), a "static" test-time defense that provides the security benefits of adaptation without the crippling computational cost. By projecting a model's features onto a "robust subspace" derived from the spectral properties of the training data, RFI consistently improves robustness across various architectures and datasets with $1\times$ the inference speed of the base model.
Methodology
The core idea of RFI is that not all features learned by a network are equally robust; some are "non-robust" directions that attackers easily exploit. The framework operates in three main stages:
- Feature Extraction: Any deep network is treated as a feature extractor $\phi(x)$ followed by a linear output layer with weights $\beta$.
- Spectral Analysis: Using the training data, the covariance matrix of the features in the penultimate layer is computed. An eigendecomposition then finds the "principal directions" (eigenvectors) of the feature space.
- Robustness Scoring and Projection: Based on a theoretical analysis of Generalized Additive Models (GAMs), the authors show that directions with larger eigenvalues—those capturing the most variance and aligning with class signals—are naturally more robust. At test time, the model's weights $\beta$ are projected onto the subspace spanned by these most robust features.
Because this projection can be pre-computed and folded into the final linear layer's weights, the model's architecture remains unchanged, resulting in zero additional latency during deployment.
Key Results and Insights
The researchers evaluated RFI across several standard computer vision benchmarks, including CIFAR-10, CIFAR-100, and ImageNet, as well as the standardized RobustBench.
- Consistent Robustness Gains: RFI improved the robust accuracy of models on RobustBench by an average of 2%, and up to 9% on calibrated models. It remains effective even against transfer attacks and adaptive attackers who know the defense is in place.
- Efficiency: While competing defenses like Anti-adv or SODEF increase inference time by $8\times$ and $2\times$ respectively, RFI maintains a $1\times$ (no overhead) cost.
- Spectral Robustness: A key theoretical finding is that the most informative features (those with high variance) are also the most robust. This suggests attackers exploit low-variance directions that the model hasn't learned to stabilize.
Conclusion
RFI offers a simple, effective, and fast defense strategy that can be integrated with any existing training procedure. While the gains are relatively modest compared to the massive effort required for adversarial training, the zero-latency nature of RFI makes it a highly practical addition to the robust machine learning toolkit. Future work includes testing RFI on Vision Transformers (ViTs) and integrating the projection directly into the training process.
Summary updated