To install Foolbox in editable mode, see the installation instructions under Contributing to Foolbox.

Running Tests


To run the tests, you need to have pytest and pytest-cov installed. Afterwards, you can simply run pytest in the root folder of the project.


Foolbox follows the PEP 8 style guide for Python code. To check for violations, we use flake8 and run it like this:

flake8 --ignore E402,E741 .

New Adversarial Attacks

Foolbox makes it easy to develop new adversarial attacks that can be applied to arbitrary models.

To implement an attack, simply subclass the Attack class, implement the __call__() method and decorate it with the :decorator:`call_decorator`. The :decorator:`call_decorator` will make sure that your __call__() implementation will be called with an instance of the Adversarial class. You can use this instance to ask for model predictions and gradients, get the original image and its label and more. In addition, the Adversarial instance automatically keeps track of the best adversarial amongst all the images tested by the attack. That way, the implementation of the attack can focus on the attack logic.