可参考
tensorflow如何使用gpu_浅冲一下的博客-CSDN博客_tensorflow gpu
import tensorflow as tf
# 查看gpu和cpu的数量
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
print(gpus, cpus)
tf.config.experimental.list_physical_devices(device_type='GPU')
## 设置GPU方法2
import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0,1"