AttributeError: module ‘tensorflow_core._api.v2.config’ has no attribute ‘experimental_list_devices’

基础环境:Anaconda、Keras、tensorflow

问题

报错:

AttributeError: module 'tensorflow_core._api.v2.config' has no attribute 'experimental_list_devices'

原因

定位到 tensorflow_backend.py 这个源文件的第506行,提示没有experimental_list_devices
AttributeError: module ‘tensorflow_core._api.v2.config’ has no attribute ‘experimental_list_devices’_第1张图片

解决

根据报错提示的路径,找到 tensorflow_backend.py 源文件的第506行,将

_LOCAL_DEVICES = tf.config.experimental_list_devices()

改为

devices = tf.config.list_logical_devices()
_LOCAL_DEVICES = [x.name for x in devices]

完美解决!

参考:

  1. module ‘tensorflow_core._api.v2.config’ has no attribute ‘experimental_list_devices’
  2. { AttributeError: module ‘tensorflow_core._api.v2.config’ has no attribute ‘experimental_list_devices’ } how can i solve this error?

你可能感兴趣的:(AttributeError: module ‘tensorflow_core._api.v2.config’ has no attribute ‘experimental_list_devices’)