我想按照this topic中的说明设置gpu限制。
但我的代码是这样的:
deep_grap = tf.Graph()
with deep_grap.as_default():
### graph definition here
### graph definition here
with tf.Session(graph=deep_grap) as sess:
tf.initialize_all_variables().run()
### more computations here
在这种情况下,如何在我的代码中设置配置?
我这里没有直接sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
行。谢谢!
答案 0 :(得分:0)
您可以在tf.ConfigProto
声明的tf.Session()
初始值设定项中传递会话配置with
:
deep_graph = tf.Graph()
with deep_graph.as_default():
### graph definition here
### graph definition here
config = tf.ConfigProto(gpu_options=...)
with tf.Session(graph=deep_graph, config=config) as sess:
tf.initialize_all_variables().run()
### more computations here
答案 1 :(得分:0)
deep_grap = tf.Graph()
with deep_grap.as_default():
### graph definition here
### graph definition here
init = tf.initialize_all_variables()
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)
cfg = tf.ConfigProto(gpu_options=gpu_options)
with tf.Session(graph=deep_grap, config=cfg) as sess:
sess.run(init)
### more computations here