Last active
January 12, 2018 23:27
-
-
Save neale/d5ed607d00a1ef8b76c704e25bcc70f6 to your computer and use it in GitHub Desktop.
lbfgs_test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import foolbox | |
import keras | |
import numpy | |
from keras.applications.resnet50 import ResNet50 | |
import matplotlib.pyplot as plt | |
import scipy.misc | |
# instantiate model | |
keras.backend.set_learning_phase(0) | |
kmodel = ResNet50(weights='imagenet') | |
preprocessing = (numpy.array([104, 116, 123]), 1) | |
fmodel = foolbox.models.KerasModel(kmodel, bounds=(0, 255), preprocessing=preprocessing) | |
path = 'ILSVRC2012_val_00017762.JPEG' | |
# get source image and label | |
image = scipy.misc.imread(path) | |
image = scipy.misc.imresize(image, (224, 224)) | |
label = numpy.argmax(fmodel.predictions(image)) | |
attack = foolbox.attacks.LBFGSAttack(fmodel) | |
adversarial = attack(image[:,:,::-1], label, unpack=False) | |
#attack not applied | |
plt.imshow(adversarial.image[:,:,::-1]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment