使用TensorFlow测试GPU可用性
TensorFlow是一款强大的人工智能框架,可以通过在GPU上运行以提高性能。为了确保你的GPU可以正常工作,你可以使用以下TensorFlow-GPU测试代码。首先,确保已经安装了TensorFlow和相关的GPU驱动。然后,运行以下代码来检查GPU是否可用:
import tensorflow as tf
# 获取可见的GPU设备
visible_devices = tf.config.experimental.list_physical_devices('GPU')
print('可见的GPU设备:', visible_devices)
# 检查GPU是否可用
gpu_available = tf.test.is_gpu_available(cuda_only=False, min_cuda_compute_capability=None)
print('GPU是否可用:', gpu_available)
如果一切正常,你将看到可见的GPU设备的信息以及GPU是否可用的结果。这有助于确保你的TensorFlow可以充分利用GPU加速,提高深度学习模型的训练速度。
下载地址
用户评论