eli5 icon indicating copy to clipboard operation
eli5 copied to clipboard

Keras image classifier tutorial issue

Open leszekmp opened this issue 4 years ago • 3 comments

Copying and pasting the code from the tutorial into a notebook. Works fine through the "#check the top 5 indices" section. In the next section, "eli5.show_prediction(model, doc)" code results in the following error:

RuntimeError: tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead.

Tried adding the following two lines:

import tensorflow as tf tf.compat.v1.disable_eager_execution()

Error changes to:

ValueError: Tensor Tensor("Mean:0", shape=(None, 1280), dtype=float32) is not an element of this graph.

Help?!

leszekmp avatar Jul 03 '20 20:07 leszekmp

Hi @leszekmp,

I can run the entire notebook if I try it with

import tensorflow as tf
tf.compat.v1.disable_eager_execution()

What is your tensorflow version? I am using tensorflow==2.2.0

teabolt avatar Jul 04 '20 20:07 teabolt

I'm also using tensorflow 2.2.0.

leszekmp avatar Jul 04 '20 21:07 leszekmp

Could you share more code that you put into your notebook? I'm not sure what's the issue as the notebook works for me when eager execution is disabled.

I think the error is related to the "weights" variable (mean of all the gradients for each activation map) https://github.com/TeamHG-Memex/eli5/blob/master/eli5/keras/gradcam.py#L120. You can search the notebook for 1280 and you'll see that the model has layers with 1280 activation maps near the end of it.

teabolt avatar Jul 06 '20 20:07 teabolt