Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Python toolbox to create adversarial examples that fool neural networks

Project description


Foolbox is a Python toolbox to create adversarial examples that fool neural networks. It requires Python 3, NumPy and SciPy.


pip install foolbox


Documentation is available on readthedocs:


import foolbox
import keras
from keras.applications.resnet50 import ResNet50, preprocess_input

# instantiate model
kmodel = ResNet50(weights='imagenet')
fmodel = foolbox.models.KerasModel(kmodel, bounds=(0, 255), preprocess_fn=preprocess_input)

# get source image and label
image, label = foolbox.utils.imagenet_example()

# apply attack on source image
attack  = foolbox.attacks.FGSM(fmodel)
adv_img = attack(image=image, label=label)

Interfaces for a range of other deeplearning packages such as TensorFlow, PyTorch and Lasagne are available, e.g.

model = foolbox.models.PyTorchModel(torchmodel)

Different adversarial criteria such as Top-k, specific target classes or target probability levels can be passed to the attack, e.g.

criterion = foolbox.criteria.TargetClass(22)
attack    = foolbox.attacks.FGSM(fmodel, criterion)


Foolbox is a work in progress and any input is welcome.


If you find Foolbox useful for your scientific work, please consider citing it in resulting publications. We will soon publish a technical paper and will provide the citation here.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
foolbox-0.4.1.tar.gz (199.8 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page