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)