Created
April 23, 2020 12:30
-
-
Save miki998/74cc8ede47a047550b4886543f27b488 to your computer and use it in GitHub Desktop.
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
#We load the image we want to create adversarial | |
nb_image = 0 | |
img = X_test[nb_image] | |
#Get the correct label | |
label = np.zeros(len(AGE_CLASS)) ; label[int(y_test[nb_image])] = 1. | |
img = img.reshape(1,img.shape[0],img.shape[1],img.shape[2]) | |
img = img.astype(np.float32) | |
#Convert it into tensor | |
tens = tf.convert_to_tensor(img) | |
#Do a feedforward and compute the loss compared to the ground truth | |
prediction = model(tens) | |
loss = loss_object(label,prediction) | |
#Computing the loss gradient as a function of the input | |
gradient = tf.gradients(loss,tens) | |
#Getting the sign of the gradient to know where each pixels should move toward to (or not move at all) | |
signed_grad = tf.sign(gradient) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment