Test-Time Backdoor Defense via Detecting and Repairing

Jiyang Guan, Jian Liang, Ran He

TL;DR

This paper introduces Test-Time Backdoor Defense (TTBD), a novel framework that secures deep neural networks against backdoor attacks during deployment. By combining a new prediction-change-based detection method with game-theoretic Shapley value estimation, TTBD successfully identifies poisoned test samples and prunes backdoor neurons on-the-fly using just a single batch of unlabelled, partially poisoned data.

What Problem Does This Paper Address?

Deep neural networks (DNNs) are vulnerable to backdoor attacks, where an attacker injects malicious, triggered samples into the training dataset. The resulting model behaves perfectly normally on clean data but reliably outputs an attacker-defined incorrect classification whenever a specific "trigger" (like a small pixel pattern or image warp) is present.

Traditional defenses typically happen before model deployment, requiring defenders to have access to the training pipeline or a substantial verification dataset of clean, labeled data to retrain or prune the model. However, in modern Machine Learning as a Service (MLaaS) pipelines, users often download pre-trained models directly, making pre-deployment defense impossible.

This paper tackles the challenge of test-time backdoor defense. At test time, a defender only has access to the deployed model and a small stream of incoming test data, which may be a mixture of clean and poisoned samples. The challenge is twofold: accurately separating poisoned samples from clean ones without ground-truth labels, and repairing the model's weights using only this limited, noisy data batch.

Methods

The authors propose a two-stage framework called Test-Time Backdoor Defense (TTBD):

Figure 1. Framework of Test-Time Backdoor Defense (TTBD). Samples and models in the red broader represent poisoned samples and models, and samples and models in the green broader represent clean samples and models.

Stage 1: Poisoned Sample Detection

To separate malicious samples from clean ones, the authors introduce Detection During Pruning (DDP). DDP builds on the insight that poisoned samples strongly activate specific backdoor neurons. If you temporarily prune the neurons with the highest activations for a given sample, a poisoned sample will experience a massive shift in its final prediction, whereas a clean sample's prediction will remain relatively stable. This is quantified using a metric called the Prediction Change Score (PCS). DDP overcomes the limitations of prior state-of-the-art detection methods like TeCo, which fail on certain architectures like VGG.

Stage 2: Backdoor Removal via Shapley Values

Once the poisoned samples are flagged, the model must be repaired. Instead of relying on raw activation values to guide pruning—which is highly inaccurate when dealing with very small sample sizes—TTBD uses Shapley value estimation from cooperative game theory.

The framework treats neurons as "players" and evaluates their marginal contribution to two metrics: clean Accuracy (ACC) and Attack Success Rate (ASR). To make this computationally feasible for deep networks, they use a Monte-Carlo estimation strategy with early stopping. TTBD then prunes neurons that exhibit a high absolute Shapley value for ASR but a low absolute Shapley value for ACC, surgically removing the backdoor functionality while preserving the model's core utility.

Datasets

The authors evaluated their approach against 7 popular state-of-the-art backdoor attacks (including BadNets, Blended, SIG, LF, WaNet, IAB, and SSBA) across three standard computer vision datasets:

  • CIFAR10
  • CIFAR100
  • Tiny-ImageNet

Experiments were conducted across diverse model architectures, specifically PreAct-ResNet18, VGG19, and DenseNet161.

Key Insights and Ideas

  • The Attacker's Payload as a Diagnostic Tool: Instead of viewing poisoned test samples purely as a threat, TTBD turns them into a diagnostic asset. The unique activation patterns triggered by malicious inputs provide the exact signal needed to locate and destroy the backdoor neurons.
  • Game Theory Over Raw Activation: Simple activation-based pruning often degrades clean model accuracy because benign features can also highly activate backdoor-adjacent neurons. Shapley values provide a mathematically rigorous way to decouple a neuron's contribution to the backdoor from its contribution to legitimate tasks.
  • The Need for Absolute Shapley Values: Standard Shapley calculations can mask a neuron's true impact if it has large positive marginal values in some contexts and large negative ones in others, causing them to cancel out. Switching to absolute Shapley values ensures these highly influential neurons are correctly targeted for pruning.

Key Results

TTBD demonstrates remarkable performance, effectively neutralizing backdoors using a batch of just 100 test images (with a 10% poisoning rate) without needing any clean training data for fine-tuning.

  • ResNet18 on CIFAR10: As shown in Table 1, TTBD-DDP reduced the average Attack Success Rate (ASR) across 7 different attacks from 88.18% down to just 2.32%, while incurring only a minor drop in clean accuracy (from 92.31% to 89.67%). It significantly outperformed traditional post-training methods like Fine-Pruning (FP).
Table 1. Defense methods against common attacks on PreAct-ResNet18 using CIFAR10.
  • Architecture Agnosticism: While the previous state-of-the-art detection method (TeCo) completely failed on VGG19 architectures (leaving an average ASR of 65.59%), TTBD-DDP successfully defended VGG19 models, crushing the average ASR down to 2.64%.
  • Defending Sparse Attacks: Under extreme scenarios where attackers poison data at a very low rate (e.g., 1%) to evade detection, an aggregated variant called TTBD-SPARSE successfully cleared the backdoor by accumulating samples across 20 test batches.

Limitations and Future Work

The primary limitation of TTBD is its dependency on the first-stage detection accuracy. If the detection method fails to isolate a sufficient number of poisoned samples, the subsequent Shapley value estimation will be guided primarily by clean data, which can lead to suboptimal pruning and a sharper decline in clean accuracy.

The authors note that future research will focus on developing even more robust, precise, and architecture-independent sample detection methods to further solidify test-time defenses.

Summary updated

Abstract

Deep neural networks have played a crucial part in many critical domains, such as autonomous driving, face recognition, and medical diagnosis. However, deep neural networks are facing security threats from backdoor attacks and can be manipulated into attacker-decided behaviors by the backdoor attacker. To defend the backdoor, prior research has focused on using clean data to remove backdoor attacks before model deployment. In this paper, we investigate the possibility of defending against backdoor attacks at test time by utilizing partially poisoned data to remove the backdoor from the model. To address the problem, a two-stage method Test-Time Backdoor Defense (TTBD) is proposed. In the first stage, we propose a backdoor sample detection method DDP to identify poisoned samples from a batch of mixed, partially poisoned samples. Once the poisoned samples are detected, we employ Shapley estimation to calculate the contribution of each neuron's significance in the network, locate the poisoned neurons, and prune them to remove backdoor in the models. Our experiments demonstrate that TTBD removes the backdoor successfully with only a batch of partially poisoned data across different model architectures and datasets against different types of backdoor attacks.
BibTeX
@inproceedings{guan2024test,
  author = {Jiyang Guan and Jian Liang and Ran He},
  title = {{Test-Time Backdoor Defense via Detecting and Repairing}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2024},
  doi = {10.1109/cvpr52733.2024.02319},
}
Figure