Adversarial Reprogramming of Neural Networks

Gamaleldin F. Elsayed, Ian Goodfellow, Jascha Sohl-Dickstein

TL;DR

Researchers from Google Brain have demonstrated a novel attack called "adversarial reprogramming," which allows an attacker to hijack a pre-trained neural network to perform a completely new task—such as classifying MNIST digits using an ImageNet model—without modifying the model's weights. By adding a single, learned perturbation to all inputs and mapping the original output labels to new ones, an attacker can effectively "program" a frozen model to do their bidding, raising significant concerns about the theft of computational resources and the security of public ML APIs.

What Problem Does This Paper Address?

Traditionally, adversarial attacks fall into two buckets: untargeted attacks, which aim to make a model fail (e.g., misclassifying a cat as anything else), and targeted attacks, which force a specific incorrect output for a specific input.

This paper introduces a third, more sophisticated category: adversarial reprogramming. The authors ask whether an attacker can repurpose a model to perform a new function chosen by the adversary, rather than just forcing a single error. This is analogous to "weird machines" or "parasitic computing" in traditional cybersecurity, where vulnerabilities in a system's logic are exploited to run arbitrary code. In the context of machine learning, this means an attacker could potentially steal expensive GPU cycles from a cloud-based image recognition service to solve CAPTCHAs or perform other unauthorized computations.

Methods

The core of the attack is the creation of an adversarial program—a single additive perturbation that is applied to every input the model receives.

  1. Input Transformation ($h_f$): The attacker takes an input from the new task (e.g., a small 28x28 MNIST digit) and embeds it into the center of a larger image (e.g., 299x299 for Inception V3). The surrounding border consists of the learned adversarial perturbation.
  2. Output Mapping ($h_g$): The attacker creates a hard-coded mapping between the target model's original labels and the new task's labels. For example, the ImageNet class "tench" might be mapped to "1 square," and "goldfish" to "2 squares."
  3. Optimization: The attacker keeps the target model's weights frozen. They use backpropagation to update only the pixels in the adversarial perturbation (the border) to maximize the probability that the model outputs the ImageNet label corresponding to the correct new task label.
Figure 1: Illustration of adversarial reprogramming. (a) Mapping of ImageNet labels to adversar- ial task labels (squares count in an image). (b) Two examples of images from the adversarial task (left) are embedded at the center of an adversarial program (middle), yielding adversarial images (right). The adversarial program shown repurposes an Inception V3 network to count squares in images. (c) Illustration of inference with adversarial images. The network when presented with adversarial images will predict ImageNet labels that map to the adversarial task labels.

Datasets

The authors evaluated the attack on six popular ImageNet classification models (including Inception V3, V4, and ResNet V2). They reprogrammed these models to perform the following tasks:

  • Counting Squares: A synthetic task counting 1 to 10 small white squares in a grid.
  • MNIST: The classic dataset of handwritten digits (0-9).
  • CIFAR-10: A dataset of 10 classes of small natural images (e.g., airplanes, dogs).
  • Shuffled MNIST: A version of MNIST where pixels are randomly permuted to remove all spatial structure, testing if the attack relies on visual similarity to the original training data.

Key Insights and Ideas

  • Exploiting Non-linearity: The authors prove that a purely linear model cannot be reprogrammed in this way. The attack succeeds by exploiting the complex, non-linear interactions between the perturbation and the input data within the deep network.
  • Beyond Transfer Learning: Unlike transfer learning, which requires fine-tuning weights, reprogramming leaves the model untouched. Surprisingly, it works even when the new task data (like Shuffled MNIST) looks nothing like the original ImageNet images.
  • Stealth and Concealment: The attack is flexible. The adversarial program can be limited in size, made nearly imperceptible by restricting the perturbation magnitude, or even hidden inside a "carrier" ImageNet image.
Figure 2: Examples of adversarial programs. Adversarial program which cause Inception V3 ImageNet model to function as (a) MNIST classifier. (b) CIFAR-10 classifier

Key Results

The attack was remarkably successful across different architectures:

  • Counting Squares: Achieved near 100% accuracy on all models.
  • MNIST: Achieved 95.0% to 98.4% accuracy. Even on the "Untrained" (randomly initialized) ResNet V2 50, it reached 93.2%, though other random models performed poorly.
  • CIFAR-10: Achieved 58.5% to 73.1% accuracy. While lower than state-of-the-art specialized models, this is significantly better than chance (10%) and requires zero computation from the attacker at inference time.
  • Defense Resistance: Models trained with adversarial training (a standard defense) remained highly vulnerable, showing only a negligible drop in reprogramming success.

Limitations and Future Work

  • Task Complexity: While successful for MNIST, the accuracy on CIFAR-10 suggests there may be limits to how complex a hijacked task can be relative to the "host" model's capacity.
  • Domain Expansion: This work focused on image classification. The authors suggest that Recurrent Neural Networks (RNNs) might be even more susceptible, as they are theoretically Turing complete and could potentially be reprogrammed to perform arbitrary logic operations.
  • Defenses: Current adversarial defenses are ineffective here. Developing methods to detect when a model is being "repurposed" is a critical next step for securing ML infrastructure.

Summary updated

Abstract

Deep neural networks are susceptible to \emph{adversarial} attacks. In computer vision, well-crafted perturbations to images can cause neural networks to make mistakes such as confusing a cat with a computer. Previous adversarial attacks have been designed to degrade performance of models or cause machine learning models to produce specific outputs chosen ahead of time by the attacker. We introduce attacks that instead {\em reprogram} the target model to perform a task chosen by the attacker---without the attacker needing to specify or compute the desired output for each test-time input. This attack finds a single adversarial perturbation, that can be added to all test-time inputs to a machine learning model in order to cause the model to perform a task chosen by the adversary---even if the model was not trained to do this task. These perturbations can thus be considered a program for the new task. We demonstrate adversarial reprogramming on six ImageNet classification models, repurposing these models to perform a counting task, as well as classification tasks: classification of MNIST and CIFAR-10 examples presented as inputs to the ImageNet model.
BibTeX
@inproceedings{elsayed2019adversarial,
  author = {Gamaleldin F. Elsayed and Ian Goodfellow and Jascha Sohl-Dickstein},
  title = {{Adversarial Reprogramming of Neural Networks}},
  booktitle = {International Conference on Learning Representations},
  year = {2019},
}
Figure