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

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

我在 Ubuntu 18.04 上使用 Tensorflow 2.0。在 运行

tf.config.list_physical_devices('GPU')

我收到上述错误。解决方法是什么?

运行 tf.config.experimental.list_physical_devices('GPU') 查看所有 GPU

运行 tf.config.experimental.list_physical_devices(device_type=None) 查看所有设备

您也可以使用tf.test.is_gpu_available()。如果它检测到可用的 gpu,它会说 True。

Tensorflow 2.0 的更新答案应该是 tf.config.list_physical_devices('GPU')