4

I want to set the gpu limitation as instructed in this topic.

But my code goes like this:

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

In this case, how do I set the configuration in my code? I don't have a direct sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))line here. Thanks!

Community
  • 1
  • 1
user3768495
  • 3,399
  • 7
  • 28
  • 55

2 Answers2

0

You can pass the session configuration, a tf.ConfigProto in the tf.Session() initializer in the with statement:

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
mrry
  • 123,190
  • 25
  • 396
  • 396
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
fabrizioM
  • 44,184
  • 15
  • 95
  • 115