module 'tensorflow_core._api.v2.config' has no attribute 'list_physical_devices'
时间: 2023-10-11 11:11:56 浏览: 130
This error occurs when you are trying to use the `list_physical_devices` function from the `tensorflow_core._api.v2.config` module, but this function is not available in the module.
To fix this error, you can try using the `list_physical_devices` function from the `tensorflow` module instead. Here's an example:
```
import tensorflow as tf
# get list of all available physical devices
physical_devices = tf.config.list_physical_devices()
# print the list of physical devices
print(physical_devices)
```
This should print a list of all the physical devices available on your system that can be used for running TensorFlow computations.
相关问题
AttributeError: module 'tensorflow_core._api.v2.config' has no attribute 'experimental_list_devices'
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.
AttributeError: module 'tensorflow_core._api.v2.compat.v2' has no attribute 'Session'
这个错误通常是因为 TensorFlow 2.x 版本中没有 `Session` 这个类。而在 TensorFlow 1.x 版本中,我们需要使用 `Session` 来启动计算图。如果你在 TensorFlow 2.x 版本中想要使用 `Session`,你可以使用 `tf.compat.v1.Session()` 来创建一个 TensorFlow 1.x 兼容的会话。但是,建议你修改你的代码以适应 TensorFlow 2.x 的执行方式,例如使用 Eager Execution 或者使用 `tf.function`。
阅读全文