python如何查看gpu可以使用
时间: 2024-05-03 20:23:31 浏览: 141
可以通过以下代码查看当前系统中可用的 GPU 设备:
```python
import tensorflow as tf
# 获取可用的 GPU 设备列表
physical_devices = tf.config.list_physical_devices('GPU')
print("可用的 GPU 设备:", len(physical_devices))
# 设置 Tensorflow 在可用的 GPU 上运行
if len(physical_devices) > 0:
tf.config.experimental.set_memory_growth(physical_devices[0], True)
```
执行以上代码后,可以得到当前系统中可用的 GPU 设备数量,以及设置 Tensorflow 在可用的 GPU 上运行。
阅读全文
相关推荐
















