原文:foolbox
作者:Jonas Rauber && Wieland Brendel
翻译:Vincent
Foolbox简介
Foolbox是一个Python工具箱,它可以创建一些对抗样本从而来迷惑神经网络。 它需要Python,NumPy和SciPy。
安装
pip install foolbox
我们测试的时候使用的是Python 2.7、3.5和3.6版本。当然Python其它版本也可以工作。但是我们建议使用Python 3版本!
文档
可在readthedocs上获取文档:http://foolbox.readthedocs.io/
样例
import foolbox
import keras
from keras.applications.resnet50 import ResNet50, preprocess_input
# instantiate model
keras.backend.set_learning_phase(0)
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)
adversarial = attack(image, label)
其它一系列深度学习的接口也是可以用的,例如TensorFlow,PyTorch,Theano,Lasagne和MXNet等。
model = foolbox.models.TensorFlowModel(images, logits, bounds=(0, 255))
model = foolbox.models.PyTorchModel(torchmodel, bounds=(0, 255), num_classes=1000)
# etc.
不同的对抗标准,例如Top-k,特定的Target Class或Original Class、Target Class的目标概率值可以传递给attack,例如:
criterion = foolbox.criteria.TargetClass(22)
attack = foolbox.attacks.FGSM(fmodel, criterion)