【问题标题】:Change default configuration for TensorFlow Session?更改 TensorFlow Session 的默认配置?
【发布时间】:2016-02-25 10:49:23
【问题描述】:

是否可以在 Python 中或通过设置环境变量等来更改默认 Session 配置?

我特别想要

with tf.Session() as sess:
    ...

当我与其他作业并行运行小型侧面测试时,使用的内存要少得多。所以我希望上面的行为与

gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.1)
config = tf.ConfigProto(gpu_options=gpu_options)
with tf.Session(config=config) as sess:
    ...

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    不要认为有办法设置进程范围的默认值,但这是我使用的模式。

    def create_session():
      config = tf.ConfigProto(log_device_placement=True)
      config.gpu_options.per_process_gpu_memory_fraction=0.3 # don't hog all vRAM
      sess = tf.InteractiveSession("", config=config)
      return sess
    
    sess=create_session()
    a=tf.constant(1)
    b=tf.constant(2)
    sess.run([a+b])
    

    【讨论】:

    • 我正在使用一个直接实例化会话的库,我无法将其更改为使用我的create_session 函数。那么,仍然没有办法在系统范围内配置这个?看到讨论here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 2013-12-16
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多