Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
You can’t perform that action at this time.