1.列出当前主机的物理显卡GPU或者CPU的列表
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
print(gpus)
打印结果
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
2.设置当前程序可见GPU设备的方法两种方法
方法1
tf.config.experimental.set_visible_devices(devices