在写tf.GPUOptions之前有必要提一下tf.ConfigProto。tf.ConfigProto个别在tf建设session的时候,以config的参数传入的形式来进行session的配置。而tf.GPUOptions是作为tf.ConfigProto的参数来限度GPU资源的利用。

tf.GPUOptions应用

当多人应用同一服务器,若是一个人占用了所有GPU资源,这就有点不适合了。。。
以下两种办法能够正当的并行分配资源,多人应用训练互不打搅。

1.动静申请显存

with tf.Graph().as_default(), tf.Session(config=tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True))) as sess:#config=tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True)) for automatically applying the GPU memory# Placeholders# inside of sess......

2.给GPU的显存利用率设置阈值

with tf.Graph().as_default(), tf.Session(config=tf.ConfigProto(gpu_options=tf.GPUOptions(per_process_gpu_memory_fraction=0.7))) as sess:# Placeholders# inside of sess......

除了以上办法还能够简略粗犷的在Python源文件运行的时候指定GPU ID
CUDA_VISIBLE_DEVICES=1 python test.py