philipperemy/keract

AttributeError: 'Model' object has no attribute '_standardize_user_data' with nightly build of tensorflow 2.2.

liuxingbaoyu opened this issue · 10 comments

Hello, in the latest version of tensorflow, 'Model' object has no attribute '_standardize_user_data', is there any way? Thank you!

@liuxingbaoyu update to the latest tensorflow and tell me if it solves the issue.

@philipperemy Still exists, I am using tf-nightly-gpu 2.2.0-dev20200418.

@liuxingbaoyu I found why. You're using the nightly version and it seems that this function was removed in the 2.2+ version. Currently, when you pip install tensorflow, it fetches the 2.1.0 and it works with this version (which is the latest version).

With pip install tf-nightly it fails:

Traceback (most recent call last):
  File "vgg16.py", line 38, in <module>
    activations = keract.get_activations(model, image)
  File "/Users/premy/PycharmProjects/keract/keract/keract.py", line 153, in get_activations
    activations = _evaluate(model, layer_outputs, x, y=None, auto_compile=auto_compile)
  File "/Users/premy/PycharmProjects/keract/keract/keract.py", line 47, in _evaluate
    return eval_fn(model._feed_inputs)
  File "/Users/premy/PycharmProjects/keract/keract/keract.py", line 42, in eval_fn
    return K.function(k_inputs, nodes_to_evaluate)(model._standardize_user_data(x, y))
AttributeError: 'Model' object has no attribute '_standardize_user_data'

I have no clear idea how to fix it.

Try to use TF 2.1.0 for now. When it becomes official, I'll check more in depth.

@philipperemy
This seems to work.

outputs = [
    layer.output for layer in model.layers
]

activations_model = tf.keras.models.Model(model.inputs, outputs=outputs)
activations_model.compile(optimizer='adam', loss='categorical_crossentropy')
activations = activations_model.predict(np.array(sample[0][:1]))

m={}

for i in range(len(activations)):
    m[model.layers[i].name]=activations[i]

keract.display_activations(m)

Quoted from: https://www.sicara.ai/blog/2019-08-28-interpretability-deep-learning-tensorflow

@liuxingbaoyu cool thanks for sharing!

@philipperemy Glad to help you!

@philipperemy

Try to use TF 2.1.0 for now. When it becomes official, I'll check more in depth.

pip install tensorflow now fetches the 2.2.0 and the error described above persists.

To add to @theowoo I'm getting the same issue

@theowoo @sixsamuraisoldier I've added a constraint to use 2.1.0 at most for now.
I'll have to look more into it when I have time.

@liuxingbaoyu fix worked for me! thanks!