简体   繁体   中英

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

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?

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')

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM