SSL-Cleanse: Trojan Detection and Mitigation in Self-Supervised Learning

Mengxin Zheng, Jiaqi Xue, Zihao Wang, Xun Chen, Qian Lou, Lei Jiang, Xiaofeng Wang

TL;DR

SSL-Cleanse is a new defense framework designed to detect and neutralize "Trojan" backdoors hidden within self-supervised learning (SSL) encoders. By using novel clustering and trigger-reversal techniques, it can identify malicious triggers and "unlearn" them without needing any data labels or knowledge of the downstream tasks, reducing attack success rates from over 98% to just 0.3%.

What Problem Does This Paper Address?

Self-supervised learning (SSL) has become the bedrock of modern computer vision. The paradigm is simple: pre-train a massive "encoder" on unlabeled data to learn general representations, then fine-tune a small classifier for specific tasks. However, this "pre-train once, use everywhere" model creates a massive security bottleneck.

If an attacker poisons the unlabeled training data with a "Trojan" (a specific trigger like a small patch or a frequency filter), the resulting encoder will learn to associate that trigger with a specific internal representation. Any downstream model built on this encoder will inherit this backdoor, allowing the attacker to force misclassifications at will.

Existing defenses for supervised learning fail here because they rely on class labels ($Y$) and a fixed set of output classes. In the SSL stage, there are no labels, and the defender doesn't know which downstream tasks (e.g., medical imaging vs. autonomous driving) the encoder will eventually support.

Methods

The authors propose SSL-Cleanse, which consists of two main stages: a Detector to find the Trojan and a Mitigator to remove it.

1. The Detector

The detector operates in three steps, as illustrated in Figure 2: The workflow of the SSL-Cleanse detector

Fig. 2: The workflow of SSL-Cleanse detector. Step 1: Unlabeled data samples are pro- cessed through the SSL encoder to compute their representations. The SWK algorithm is then utilized to process representations and determine the number of clusters. Step 2: Using K-Means with the derived cluster number (K) and representation, K clusters are established. Then, the Representation Oriented Trigger Reverse algorithm is employed to generate K trigger patterns. Step 3: Accessing if any of the K triggers are outliers in terms of their size and norm. The identified outlier indicates the encoder is Trojaned.
  • Sliding Window Kneedle (SWK): To replace missing labels, the system clusters the data representations. Standard methods struggle to guess the number of clusters ($K$) in noisy SSL feature spaces. SWK improves upon the classic "Kneedle" algorithm by using a sliding window to smooth out noise, providing a much more accurate estimate of the underlying data structure.
  • Representation-Oriented Trigger Reverse (ROTR): This is the "reverse engineering" phase. For every cluster, the algorithm tries to find the smallest possible modification (a trigger) that would make images from other clusters look like they belong to the target cluster in the feature space.
  • Size-Norm Trigger Outlier Detector (STOD): A real Trojan trigger is usually much smaller or has a more distinct "norm" than the natural variations between clusters. STOD flags these statistical outliers as potential backdoors.

2. The Mitigator

Once a trigger is identified, the Self-supervised Clustering Unlearning (SCU) algorithm kicks in. It fine-tunes the encoder using a "teacher-student" approach. The student model is shown images with the reversed trigger and is forced to produce the same representation as the original "clean" image (provided by a fixed reference model). This effectively teaches the encoder to ignore the malicious trigger.

Datasets

The researchers evaluated their method against 1,200 different encoders (including popular architectures like BYOL, SimCLR, and MoCo V2) using two primary benchmarks:

  • CIFAR-10: A standard small-scale image dataset.
  • ImageNet-100: A subset of the massive ImageNet dataset, containing ~127,000 images across 100 classes.

Key Insights and Ideas

  • Clustering as a Label Proxy: The core "aha" moment is that while SSL lacks labels, the learned feature space is naturally organized into clusters. By treating these clusters as pseudo-classes, the authors could adapt supervised backdoor detection logic to the unsupervised world.
  • Smoothing the "Elbow": As shown in Figure 3, standard methods for finding the optimal number of clusters are highly volatile in SSL. The SWK method provides a significantly more stable "elbow point," which is crucial for the downstream trigger reversal to work. Comparison of SWK and direct search
  • Handling Global Triggers: Unlike previous defenses that only look for small pixel patches, SSL-Cleanse accounts for "global" triggers (like frequency-domain shifts) by monitoring the $l_1$-norm magnitude of the reversed perturbations.
Fig. 3: Comparison of our SWK method and direct search (Kneedle) method on ImageNet-100 dataset. Our SWK method yields more stable and accurate K.

Key Results

  • High Detection Accuracy: SSL-Cleanse achieved an average detection success rate (DACC) of 82.2% on ImageNet-100 across various attack types.
  • Effective Neutralization: Before mitigation, Trojaned models had Attack Success Rates (ASR) as high as 98%. After applying the SCU mitigator, the ASR dropped to an average of 0.3%.
  • Minimal Performance Hit: The "cleansing" process is surgical. The clean accuracy (ACC) of the models only dropped by about 1% on average, meaning the encoder remains useful for legitimate tasks.
  • Efficiency: The entire detection process for ImageNet-100 takes roughly 20 minutes, and mitigation takes about 7 minutes on consumer-grade GPUs (RTX-3090).

Limitations and Future Work

The authors note that their defense requires access to a small portion (roughly 10%) of the unlabeled dataset used for pre-training. While this is a reasonable assumption for model developers or auditors, it might be a hurdle for end-users who only download a compiled weights file.

Additionally, while SSL-Cleanse handles current state-of-the-art attacks like CTRL and SSL-Backdoor, future work could explore "adaptive" attacks where the adversary specifically tries to make the Trojan trigger look like a natural cluster variation to evade the outlier detector.

The source code is available at https://github.com/UCF-ML-Research/SSL-Cleanse.

Summary updated

BibTeX
@inproceedings{zheng2024ssl,
  author = {Mengxin Zheng and Jiaqi Xue and Zihao Wang and Xun Chen and Qian Lou and Lei Jiang and Xiaofeng Wang},
  title = {{SSL-Cleanse: Trojan Detection and Mitigation in Self-Supervised Learning}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-73021-4\_24},
}
Figure