Created
August 14, 2019 16:03
-
-
Save emuccino/cef2252d9121833ad06a8c54829512c1 to your computer and use it in GitHub Desktop.
select_image
This file contains 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
#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