Skip to content
Advertisement

How to generate CNN heatmaps using built-in Keras in TF2.0 (tf.keras)

I used to generate heatmaps for my Convolutional Neural Networks, based on the stand-alone Keras library on top of TensorFlow 1. That worked fine, however, after my switch to TF2.0 and built-in tf.keras implementation (with eager execution) I cannot use my old heatmap generation code any longer.

So I re-wrote parts of my code for TF2.0 and ended up with the following:

JavaScript

But now the following line:

JavaScript

leads to this error message:

JavaScript

I always used Keras and did not work with TF directly, so I am bit lost here.
Any ideas what could be the problem here?


PS: If you want to c&p this code, you can create the VGG16-based model like so:

JavaScript

Advertisement

Answer

At the end of the GradientTape loop, conv_output and grads already holds the value. The iterate function is no longer need to compute the values.

Working example below:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement