Unifying Gradients to Improve Real-world Robustness for Deep Networks

Yingwen Wu, Sizhe Chen, Kun Fang, Xiaolin Huang

TL;DR

The authors present Unifying Gradients (UniG), a plug-and-play defense mechanism that protects deep neural networks against black-box score-based query attacks (SQAs). By artfully altering model outputs during inference, UniG misleads attackers into pursuing a weak, universal attack direction rather than highly destructive, image-specific paths. Crucially, it achieves state-of-the-art robustness while maintaining the model's original accuracy on clean data.

What Problem Does This Paper Address?

Deep Neural Networks (DNNs) are notoriously vulnerable to adversarial examples—subtly altered inputs designed to fool them. In real-world applications, models are typically deployed behind APIs, shielding their internal parameters from attackers. However, attackers can still exploit these systems using Score-based Query Attacks (SQAs). By repeatedly querying the model and analyzing how the output probabilities change, an attacker can estimate the model's gradients and craft a successful adversarial image.

Standard defenses like Adversarial Training (AT) or Randomness Injection (RI) attempt to mitigate this by lowering model confidence or adding random noise to the outputs. Unfortunately, this introduces a severe accuracy-robustness trade-off: it degrades the model's performance on clean data and distorts output probabilities, which can break downstream applications that rely on accurate confidence scores.

Methods

Instead of hiding gradients or injecting random noise, UniG combats SQAs by manipulating the gradient information leaked through consecutive queries.

The core idea is to force the gradients of different data samples to align toward a single, Universal Adversarial Perturbation (UAP) direction. Because UAPs are sample-independent, they are inherently much less aggressive and harder for an attacker to optimize than image-specific perturbations. When an SQA attempts to map the gradient space, UniG tricks its attack trajectory away from vulnerable directions and onto this harmless, dead-end path.

Method flowchart and output changes compared to SOTA defenses

To implement this efficiently without retraining the entire network, the authors introduce a lightweight, plug-and-play Hadamard product module ($A$) into the penultimate layer of a pre-trained DNN. During inference, when a batch of test data arrives, module $A$ is optimized on the fly using a novel gradient unification loss. This loss minimizes the variance of the feature gradients across the batch while ensuring the forward outputs remain virtually unchanged ($\hat{f} \approx f$). Remarkably, this optimization requires only a single iteration step, making it highly efficient.

Datasets

The authors evaluated UniG using two standard computer vision benchmarks:

  • CIFAR10: The entire test set was used to evaluate robustness and accuracy.
  • ImageNet: A subset of 1,000 randomly selected images (one per class) from the validation set was used due to the high computational cost of running query-based attacks at scale.

Key Insights and Ideas

  • Judo-style Defense: Instead of resisting the attacker's gradient estimation queries, UniG uses the attacker's momentum against them by feeding them deliberately twisted, uninformative gradient directions.
  • Exploiting UAP Weakness: The defense relies on the empirical fact that universal perturbations are significantly less destructive than tailored, image-specific ones. By forcing the model to behave as if its vulnerabilities are universal, the attacker is funneled into a much weaker attack strategy.
  • Breaking the Trade-Off: Because the module only slightly modifies features to distort the backward gradient path, it preserves the forward classification accuracy. This effectively breaks the traditional accuracy-robustness trade-off that plagues adversarial training.

Key Results

UniG was tested against 5 popular SQAs (including Square and SimBA), 2 adaptive attacks, and 7 baseline defenses.

  • Superior Robustness: On CIFAR10, UniG maintained 77.80% accuracy under a 2,500-query Square attack, outperforming the state-of-the-art adversarially trained model, which dropped to 67.34%.
  • Preserved Clean Accuracy: UniG maintained a clean accuracy of 94.26% on CIFAR10 and 78.47% on ImageNet, matching the performance of undefended vanilla models.
  • Minimal Output Distortion: UniG achieved the smallest modification of model outputs (measured by logit difference) among all tested defenses, making it highly compatible with downstream tasks.
  • High Efficiency: Compared to other test-time dynamic defenses like DENT, which require optimizing the entire network (7.78 GMACs), UniG only optimizes its small plug-in module, requiring just 0.55 GMACs.
Fig. 2. (a) Objective function value (UniG Loss in Eq. (4)) w.r.t iteration step of our defense model. Since each forward calculation the loss is re-optimized with the current test data, we randomly choose one forward process to present the loss change. (b) Margin loss w.r.t Query times of four compared defenses under Square attack. A higher loss means a more robust network.

Limitations and Future Work

The primary limitation of UniG is its reliance on batch optimization. Because the gradient unification loss calculates variance across multiple samples, the defense is naturally suited for batch processing. If a deployed model receives only a single image at a time, the defense's effectiveness decreases.

To mitigate this, the authors suggest a workaround where a single test image is cascaded alongside a small set of dummy training samples during inference. While experiments showed this approach still outperforms standard noise injection defenses, optimizing UniG natively for single-sample real-time queries remains an open avenue for future research.

Summary updated

Abstract

The wide application of deep neural networks (DNNs) demands an increasing amount of attention to their real-world robustness, i.e., whether a DNN resists black-box adversarial attacks, among which score-based query attacks (SQAs) are most threatening since they can effectively hurt a victim network with the only access to model outputs. Defending against SQAs requires a slight but artful variation of outputs due to the service purpose for users, who share the same output information with SQAs. In this paper, we propose a real-world defense by Unifying Gradients (UniG) of different data so that SQAs could only probe a much weaker attack direction that is similar for different samples. Since such universal attack perturbations have been validated as less aggressive than the input-specific perturbations, UniG protects real-world DNNs by indicating attackers a twisted and less informative attack direction. We implement UniG efficiently by a Hadamard product module which is plug-and-play. According to extensive experiments on 5 SQAs, 2 adaptive attacks and 7 defense baselines, UniG significantly improves real-world robustness without hurting clean accuracy on CIFAR10 and ImageNet. For instance, UniG maintains a model of 77.80% accuracy under 2500-query Square attack while the state-of-the-art adversarially-trained model only has 67.34% on CIFAR10. Simultaneously, UniG outperforms all compared baselines in terms of clean accuracy and achieves the smallest modification of the model output. The code is released at https://github.com/snowien/UniG-pytorch.
BibTeX
@article{wu2023unifying,
  author = {Yingwen Wu and Sizhe Chen and Kun Fang and Xiaolin Huang},
  title = {{Unifying Gradients to Improve Real-world Robustness for Deep Networks}},
  journal = {ACM Trans. Intell. Syst. Technol.},
  year = {2023},
  doi = {10.1145/3617895},
}
Figure