Skip to content

Instantly share code, notes, and snippets.

@emuccino
Created August 14, 2019 16:03
Show Gist options
  • Save emuccino/cef2252d9121833ad06a8c54829512c1 to your computer and use it in GitHub Desktop.
Save emuccino/cef2252d9121833ad06a8c54829512c1 to your computer and use it in GitHub Desktop.
select_image
#select image to create an adversarial example from
img = x_train[0:1]
plt.imshow(img.reshape((28,28)),vmin=0., vmax=1.)
plt.show()
#varify accurate classificaiton
prediction = mnist_model.predict(img)[0]
print(prediction)
#applying random noise does not fool the classifier
quantized_noise = np.round(np.random.normal(loc=0.0, scale=0.3, size=img.shape) * 255.) / 255.
noisy_img = np.clip(img + quantized_noise, 0., 1.)
plt.imshow(noisy_img.reshape((28,28)),vmin=0., vmax=1.)
plt.show()
noisy_prediction = mnist_model.predict(noisy_img)[0]
print(noisy_prediction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment