查看GPU是否可用

tf.config:GPU 的使用与分配(转载) - 三年一梦 - 博客园 (cnblogs.com)

import tensorflow as tf

version = tf.__version__
gpu_ok = tf.test.is_gpu_available()
# tf.config.list_physical_devices('GPU') # 也可以
print("tf version:", version, "\nuse GPU", gpu_ok)
print(tf.test.is_built_with_cuda())

gpus = tf.config.list_physical_devices(device_type='GPU')  # [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
cpus = tf.config.list_physical_devices(device_type='CPU')  # [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]
print(gpus)
print(cpus)
上一篇:linux系统中查看逻辑cpu个数、物理cpu个数、每个cpu的核心数、cpu型号


下一篇:Linux系统强大的查找命令find用法