Let's go ahead and implement this strategy in code (The code file is available as Adversarial_attack.ipynb in GitHub):
- Read the image of a cat:
import matplotlib.pyplot as plt%matplotlib inlineimg = cv2.imread('/content/cat.JPG')img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)img = cv2.resize(img, (299,299))plt.imshow(img)plt.axis('off')
The plot of the image looks as follows:
- Preprocess the image so that it can then be passed to an inception network:
original_image = cv2.resize(img,(299,299)).astype(float)original_image /= 255.original_image -= 0.5original_image *= 2.original_image = np.expand_dims(original_image, axis=0)