Fast test-time defenses for vision-language models such as CLIP work in two steps. They look at a few augmented copies of an image, and if the embeddings behave suspiciously they apply a correction. These defenses need no retraining and add little latency. Everything, however, depends on the first step: a scalar "is this attacked?" gate with a hand-set threshold. When the gate fires on clean images, clean accuracy drops. When it can be fooled, robustness collapses.
We propose to turn the curse of dimensionality, usually treated as a nuisance, into the gate's calibration tool. In a 512-dimensional embedding space, independent random directions are almost exactly orthogonal. So once augmentation-induced embedding shifts are whitened on clean data, their average pairwise cosine has a known null distribution. That null gives a z-score with a user-chosen false-alarm rate, and that rate should transfer across datasets without per-dataset tuning. Adversarial images produce coherent drift, meaning shifts that all point the same way. The gate then becomes a hypothesis test instead of a tuned threshold, and the clean-accuracy cost of defending becomes a number the deployer sets in advance.
Core Claim
Existing fast defenses gate on raw divergences or drift statistics. CSR compares features of an image and its low-pass-filtered version. ATAC uses a cosine-consistency gate on augmentation drift vectors. DBD uses a Directional Bias score measuring how concentrated drift is. These papers motivate the proposal, because they show drift coherence carries the signal. They also expose its weakness. ATAC reports clean-accuracy loss from gate misclassifications. None of the three says how its threshold behaves across datasets, or ties its statistic to high-dimensional geometry.
Our claim has two parts. First, a whitened, augmentation-mean-centred drift-coherence statistic has an approximately standard-normal distribution on clean inputs across datasets. Thresholding it at a chosen level $\alpha$ therefore bounds the fraction of clean images that get "corrected," and so bounds the clean-accuracy drop, with no per-dataset calibration. Second, such a gate lets us measure an explicit "evasion price" for adaptive attacks of the kind CLIP-MAD mounts. That paper adds a loss term forcing the gate statistic to read "clean" and drives several defenses to near zero. To make the drift look incoherent, the attacker must make the perturbation invariant to the augmentations. We will quantify how much extra perturbation budget that costs. We do not claim immunity.
The statistic is simple. Let $e(\cdot)$ be the frozen CLIP image encoder and $a_1,\dots,a_k$ the augmentations. Let $\mu_j$ be the mean clean drift of augmentation $j$, and $W$ a shrinkage whitening matrix. Both are estimated once from a few thousand unlabeled clean images. Define $z_j = W\,(e(a_j x) - e(x) - \mu_j)$ and
$$T(x) = \sqrt{\tfrac{k(k-1)\,d_{\text{eff}}}{2}}\;\cdot\;\frac{2}{k(k-1)}\sum_{i<j}\cos(z_i, z_j),$$
where $d_{\text{eff}}$ is the effective rank retained by whitening. The scaling follows from a standard fact: for independent isotropic vectors in $d$ dimensions, pairwise cosines have mean zero and variance about $1/d$, and are pairwise uncorrelated. So under the clean null, $T$ is approximately $\mathcal{N}(0,1)$. Inputs with $T$ above the $(1-\alpha)$ normal quantile are routed to a correction step. That step is borrowed from ATAC and DBD: shift the embedding against the mean drift. Clean inputs pass through untouched.
Research Program
The work has three parts.
The first part is geometric and empirical. We measure how raw gate statistics shift across datasets, including CSR-style divergence, ATAC's cosine consistency and DBD's DB-score. We then test whether mean-centring and whitening make the clean distribution of $T$ dataset-invariant. The key design choice is subtracting the per-augmentation mean $\mu_j$. Clean drift is not isotropic: blur, for instance, moves every embedding in a shared direction. Without centring, the null would be wrong.
The second part assembles the defense, with correction reused from prior work, and measures the full robustness, clean accuracy and latency picture.
The third part is the adversarial analysis. We attack $T$ directly with CLIP-MAD's dual objective, using Expectation Over Transformation (averaging gradients over the randomly sampled augmentations) and BPDA (a straight-through gradient approximation for any non-differentiable step). We report attack success as a function of budget $\epsilon$ and of the weight on the gate term. The deliverable is the curve showing how much larger $\epsilon$ must be to evade $T$ than to evade raw-cosine gates.
Adversarial training overhead enters as a constraint. The method has no training loop: its only offline cost is forward passes to estimate $\mu_j$ and $W$. We report that cost against ROB tokens' 200 optimization steps.
Baselines
The naive reference is undefended CLIP ViT-B/16. On DBD's fine-grained suite it reports 67.9% clean accuracy and 0.0% robust accuracy under PGD-100.
The strongest existing method is DBD. It reports 93.8% average robust accuracy under PGD-100 across fine-grained datasets at 0.025 s/image, against R-TPT's 43.2% at 0.181 s/image (DBD). Under BPDA+EOT its reconstruction fails, although its score still flags about 81% of attacks. DBD is the strongest competitor because its score is the closest relative of $T$. We rerun it with its own 31-to-16 transformation filtering on the same backbone, datasets and attack code. To beat it we must meet two conditions. We must match its PGD-100 robust accuracy within noise. Under adaptive attacks aimed at the gate itself, where DBD's reported detection is the 81% figure, we must show higher detection or a larger evasion price.
ATAC is the second strong baseline, run on its 13-dataset suite. It reports nearly 50% average improvement over prior test-time defenses, but no per-dataset numbers were found on Lacuna, so we reproduce it ourselves. CSR is included for clean-accuracy comparison: it reports a 0.7% clean penalty and runs 12x faster than R-TPT (CSR). R-TPT anchors the slow-but-adaptive regime; CLIP-MAD reports its robust accuracy falling from 37.5% to 0.7%.
Two ablations isolate the key ingredient. The first uses the raw, unwhitened, uncentred mean pairwise drift cosine, with a threshold set at a quantile on ImageNet clean data. The second applies whitening without mean-centring. Every method gets the same augmentations where applicable, the same correction step, the same number of forward passes and the same attack budget.
Why not just…?
Why not just tune each gate's threshold on held-out clean data per dataset? This is the real threat. An oracle per-dataset quantile threshold controls false alarms by construction. We therefore report it as an upper reference, not a competitor we must beat. Our claim is about transfer: calibrate once on ImageNet, deploy on EuroSAT, PCAM and the fine-grained sets. The first ablation settles the question. If raw coherence with an ImageNet-set threshold hits the target false-alarm rate on every dataset as well as $T$ does, the concentration-based calibration adds nothing, and we will say so.
Why not just use a Mahalanobis or k-nearest-neighbour distance on the single clean embedding? It costs one forward pass, which makes it the cheapest real-time option. The outlier-detection literature, however, reports that distances lose contrast in high dimensions. LUNAR documents nearest-neighbour degradation. Work on PCA compression ratios shows kNN distance, LOF and Isolation Forest losing to subspace statistics at 10,000+ dimensions. Neither covers adversarial inputs, so we run a Mahalanobis gate on identical data. We expect it to catch large perturbations but miss small ones whose embedding stays on the clean shell.
Why not just pay for robustness once with Robustness Tokens? ROB tokens train 10 prepended tokens on a frozen ViT in 200 steps. They raise DINOv2-G's white-box accuracy from 0.3% to 63.1% at a clean cost of 85.6% to 85.2%. That is a serious alternative. Its weaknesses are that the tokens act as a secret key that fails if exposed, and that it adds sequence length to every forward pass. We will train ROB tokens on CLIP ViT-B/16 and compare them on the same attacks, including a white-box attack that knows the token values. The two approaches are also complementary, since $T$ could gate a ROB-token model.
Why not just low-pass filter or JPEG-compress the input? Frequency filtering fails on global low-frequency attacks such as color-curve shifts, which is CSR's own admitted blind spot. Our augmentation set spans spatial, pixel and frequency domains, and we include color-curve attacks explicitly to test whether $T$ covers that gap.
Proposed Experiments
We use CLIP ViT-B/16 and ViT-L/14 on DBD's 15-dataset zero-shot suite and ATAC's 13-dataset suite. Attacks are PGD-100, AutoAttack and C&W, with global color-curve attacks added. We report clean accuracy, robust accuracy, gate AUROC, realized false-alarm rate against the nominal $\alpha$, and wall-clock latency per image on one GPU.
Three checks decide the outcome. The first is null validity. With $\mu_j$ and $W$ fit on ImageNet only, the realized clean false-alarm rate at $\alpha = 1\%$ should fall between 0.5% and 2% on every dataset, and the clean-accuracy drop should never exceed $\alpha$. Failure here falsifies the core claim. The second is non-adaptive parity: robust accuracy within noise of DBD at no worse latency. The third is the adaptive evasion price. Using a CLIP-MAD objective aimed at $T$ with EOT, we plot attack success against $\epsilon$ and against the gate-loss weight $\lambda$. The claim survives only if evading $T$ requires a clearly larger $\epsilon$ than evading the raw-cosine ablation at the same misclassification rate. If the curves coincide, whitening buys calibration but not security, and the note's contribution narrows to the calibration result.
References
- Contrastive Spectral Rectification: Test-Time Defense towards Zero-shot Adversarial Robustness of CLIP
- ATAC: Augmentation-Based Test-Time Adversarial Correction for CLIP
- Adversarial Attacks Already Tell the Answer: Directional Bias-Guided Test-time Defense for Vision-Language Models
- You Don't Protect if You Don't Expect: Breaking the Key Assumption behind CLIP's Test-Time Defenses
- LUNAR: Unifying Local Outlier Detection Methods via Graph Neural Networks
- Capturing the denoising effect of PCA via compression ratio
- Robustness Tokens: Towards Adversarial Robustness of Transformers