是否可以在Python中或通过设置环境变量等来更改默认的会话配置?
具体来说,我想
with tf.Session() as sess:
...
Run Code Online (Sandbox Code Playgroud)
当我与其他工作并行运行小型测试时,耗尽更少的内存.所以我上面的行为与...相同
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:
...
Run Code Online (Sandbox Code Playgroud)
不要以为有办法设置流程范围的默认值,但这是我使用的模式.
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])
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2769 次 |
最近记录: |