Skip to content

Instantly share code, notes, and snippets.

@shayaf84
Last active November 20, 2021 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shayaf84/577277b5717e03d2805cc8a2cd221dcd to your computer and use it in GitHub Desktop.
Save shayaf84/577277b5717e03d2805cc8a2cd221dcd to your computer and use it in GitHub Desktop.
def gradient(images, targetClassindex):
#Computes gradient of probabilities with respect to images
with tf.GradientTape() as gradRecord:
gradRecord.watch(images)
logits = vgg(images)
probs = tf.nn.softmax(logits, axis=-1)[:, targetClassindex]
return gradRecord.gradient(probs, images)
computedGradients = gradient(interpolatedImages,684)
#ImageNet Index for Oboe is 683, so add 1 to receive the value to stop at.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment