用tensorflow2.0设置
import tensorflow as tf
#查看GPU列表
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
#查看CPU列表
cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
#设置可见设备 即 选择GPU CPU 范围
tf.config.experimental.set_visible_devices(devices=gpus[0:2],device_tyoe='GPU')
#设置需要动态申请时
for gpu in gpus:
tf.config.experimental.set_memory_growth(device=gpu,True)
设置 环境变量 来设置
import os
os.environ['CUDA_VISIBLE_DEVICES']="2,3"