AttributeError: module 'tensorflow_core._api.v2.config' has no attribute 'experimental_list_devices'
时间: 2023-10-11 14:11:53 浏览: 277
问题解决:module 'tensorflow.compat.v1' has no attribute '
5星 · 资源好评率100%
This error occurs when you try to use the method `experimental_list_devices()` in TensorFlow 2 but it is not available in the module `tensorflow_core._api.v2.config`. This method was experimental and has been removed in TensorFlow 2.
To solve this error, you can use the method `list_physical_devices()` instead. Here's an example:
```python
import tensorflow as tf
physical_devices = tf.config.list_physical_devices('GPU')
print("Number of GPUs available: ", len(physical_devices))
for device in physical_devices:
print(device)
```
This will print the number of available GPUs and their names. You can also use the method `list_logical_devices()` to get a list of all logical devices available.
阅读全文