Foolbox v0.8.0: A Python toolbox to benchmark the robustness of machine learning models

Jonas Rauber, Wieland Brendel, Matthias BethgearXiv 2017

Abstract

Even today's most advanced machine learning models are easily fooled by almost imperceptible perturbations of their inputs. Foolbox is a new Python package to generate such adversarial perturbations and to quantify and compare the robustness of machine learning models. It is built around the idea that the most comparable robustness measure is the minimum perturbation needed to craft an adversarial example. To this end, Foolbox provides reference implementations of most published adversarial attack methods alongside some new ones, all of which perform internal hyperparameter tuning to find the minimum adversarial perturbation. Additionally, Foolbox interfaces with most popular deep learning frameworks such as PyTorch, Keras, TensorFlow, Theano, and MXNet and allows different adversarial criteria such as targeted misclassification and top-k misclassification as well as different distance measures. The code is licensed under the MIT license and is openly available at https://github.com/bethgelab/foolbox.

Introduction

Deep neural networks are notoriously vulnerable to "adversarial examples"—inputs modified by tiny, often imperceptible perturbations that cause a model to make incorrect predictions. While the research community has proposed numerous "attacks" to identify these vulnerabilities, benchmarking the robustness of different models has historically been a fragmented and inconsistent process.

Before the introduction of Foolbox, researchers faced three primary hurdles: framework silos, where attack code was locked into specific libraries like TensorFlow or PyTorch; implementation variance, where subtle differences in code led to inconsistent results for the same algorithm; and hyperparameter sensitivity, where the effectiveness of an attack depended heavily on manual tuning. Foolbox addresses these issues by providing a unified, framework-agnostic interface for benchmarking adversarial robustness.

Modular Architecture

Foolbox introduces a modular design that separates the components of an adversarial attack into five distinct modules, allowing for high flexibility and extensibility:

  • Models: Wrappers that provide a common interface for major deep learning frameworks, including TensorFlow, PyTorch, Theano, Lasagne, Keras, and MXNet.
  • Criteria: Definitions of what constitutes a successful attack, ranging from simple misclassification to targeted misclassification or reducing confidence below a specific threshold.
  • Distances: Metrics to quantify the size of the perturbation, supporting $L_0, L_2,$ and $L_\infty$ norms.
  • Attacks: Reference implementations of over 15 published algorithms, such as the Gradient Attack, FGSM, DeepFool, and L-BFGS.
  • Adversarial: A class that encapsulates the results, tracking the original input and the smallest perturbation found during the process.

The "Minimum Perturbation" Philosophy

A core innovation of Foolbox is its focus on robustness as a minimum distance metric. The authors argue that the most comparable measure of robustness is the average size of the minimum perturbation required to fool a model.

To achieve this, Foolbox attacks perform internal hyperparameter tuning. Rather than requiring the user to guess the optimal "epsilon" (perturbation magnitude) or step size, Foolbox algorithms automatically search for the smallest perturbation that satisfies the adversarial criterion. This ensures that benchmarks reflect the true vulnerability of the model rather than the configuration quality of the attack.

Advanced Attack Capabilities

Beyond standard gradient-based methods, Foolbox includes support for more complex scenarios:

  • Decision-Based Attacks: The library includes "Boundary Attacks" and "Pointwise Attacks." These are particularly powerful because they do not require access to the model's gradients or class probabilities—only the final predicted label. This makes them ideal for evaluating "black-box" models where internal states are hidden.
  • Composite Models and Transfer Attacks: Users can combine the predictions of one model with the gradients of another. This facilitates transfer attacks, where an attacker uses a differentiable surrogate model to generate perturbations for a target model that might be non-differentiable or otherwise restricted.

Reproducibility and Framework Support

To support the scientific requirement for reproducibility, Foolbox employs a strict semantic versioning system (MAJOR.MINOR.PATCH). Any update that changes benchmark results, even if the underlying algorithm remains the same, triggers a version bump. This allows researchers to cite specific versions of the toolbox to ensure their results can be replicated by others.

At the time of its release, Foolbox successfully interfaced with six major machine learning frameworks, providing a simple and consistent API that significantly lowers the barrier to entry for robustness testing across the ML community.

Limitations

While Foolbox offers a robust suite of tools, it does involve certain trade-offs. The internal hyperparameter tuning and line searches required to find the minimum perturbation can make Foolbox attacks more computationally expensive than "one-shot" attacks found in other libraries. Additionally, certain attacks like "Approximate L-BFGS" rely on numerical gradients, which are only computationally feasible for models with low-dimensional inputs. As deep learning frameworks continue to evolve, the library requires ongoing maintenance to ensure compatibility with the latest API changes in the ecosystem.

Summary updated

BibTeX
@misc{rauber2017foolbox,
  author = {Jonas Rauber and Wieland Brendel and Matthias Bethge},
  title = {{Foolbox v0.8.0: A Python toolbox to benchmark the robustness of machine learning models}},
  year = {2017},
  eprint = {1707.04131},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1707.04131},
}
Figure