I am starting with Tensorflow 2.0 and trying to implement Guided BackProp to display Saliency Map. I started by computing the loss between y_pred and y_true of an image, then find gradients of all layers due to this loss.
with tf.GradientTape() as tape:
logits = model(tf.cast(image_batch_val, dtype=tf.float32))
print('`logits` has type {0}'.format(type(logits)))
xentropy = tf.nn.softmax_cross_entropy_with_logits(labels=tf.cast(tf.one_hot(1-label_batch_val, depth=2), dtype=tf.int32), logits=logits)
reduced = tf.reduce_mean(xentropy)
grads = tape.gradient(reduced, model.trainable_variables)
However, I don't know what to do with gradients in order to obtain the Guided Propagation.
I am glad to provide more code if needed.
from How to apply Guided BackProp in Tensorflow 2.0?
No comments:
Post a Comment