0

While running an old script, after updating keras and tensorflow, I faced the following error:

    module 'keras.backend' has no attribute 'tensorflow_backend'

For the following line of code

    print(K.tensorflow_backend._get_available_gpus())

I come to understand that this could be issue of version mismatches. The corresponding versions of Keras and Tensorflow are

    2.4.3
    2.2.0
    python - 3.7.5

What is the right version compatibiltiy / combination that I should make use of, to overcome this error?

Lakshmi Narayanan
  • 5,220
  • 13
  • 50
  • 92

2 Answers2

4

tensorflow_backend._get_available_gpus() is not available in tensorflow 2.0.

Your best bet is to use tf.config.list_physical_devices or tf.config.experimental.list_physical_devices

GPU_list = tf.config.list_physical_devices('GPU')
# OR
GPU_list = tf.config.experimental.list_physical_devices('GPU')
Chase
  • 5,315
  • 2
  • 15
  • 41
  • The above command return null for me. Does this mean that the GPU is not picked up? @Chase – Lakshmi Narayanan Jul 05 '20 at 15:22
  • @LakshmiNarayanan yes tensorflow is not detecting your GPU. Make sure your GPU is actually supported. Also read https://stackoverflow.com/questions/41402409/tensorflow-doesnt-seem-to-see-my-gpu – Chase Jul 05 '20 at 15:31
  • so you suggest using a lower version? I remember working it once, using tf = 1.10 and Cudnn 9 with python 3.6.3 – Lakshmi Narayanan Jul 05 '20 at 15:54
  • @LakshmiNarayanan I do not suggest using a legacy version like tensorflow 1.0. That would be ignoring the issue at hand rather than acknowledging it. As I said, make sure your GPU is supported – Chase Jul 05 '20 at 17:22
1

you have TensorFlow wrong version

install
TensorFlow Core v2.2.0 Python

this version contains tf.keras.backend.backend()

https://www.tensorflow.org/api_docs/python/tf/keras/backend

I hope this is help

Mr Coder
  • 507
  • 3
  • 13
  • 2
    I think you misunderstand the problem, OP is looking for `tensorflow_backend` inside `keras.backend`, they already have tensorflow 2.0 – Chase Jul 05 '20 at 12:19