tensorflow学习笔记(二十五):ConfigProto&GPU

来源:互联网 发布:2016nba总决赛数据 编辑:程序博客网 时间:2024/05/27 14:14

tensorflow ConfigProto

tf.ConfigProto一般用在创建session的时候。用来对session进行参数配置

with tf.Session(config = tf.ConfigProto(...),...)
#tf.ConfigProto()的参数log_device_placement=True : 是否打印设备分配日志allow_soft_placement=True : 如果你指定的设备不存在,允许TF自动分配设备tf.ConfigProto(log_device_placement=True,allow_soft_placement=True)

控制GPU资源使用率

#allow growthconfig = tf.ConfigProto()config.gpu_options.allow_growth = Truesession = tf.Session(config=config, ...)# 使用allow_growth option,刚一开始分配少量的GPU容量,然后按需慢慢的增加,由于不会释放#内存,所以会导致碎片
# per_process_gpu_memory_fractiongpu_options=tf.GPUOptions(per_process_gpu_memory_fraction=0.7)config=tf.ConfigProto(gpu_options=gpu_options)session = tf.Session(config=config, ...)#设置每个GPU应该拿出多少容量给进程使用,0.4代表 40%

控制使用哪块GPU

~/ CUDA_VISIBLE_DEVICES=0  python your.py#使用GPU0~/ CUDA_VISIBLE_DEVICES=0,1 python your.py#使用GPU0,1#注意单词不要打错
0 0
原创粉丝点击