2016-12-07 4 views
1

Ich möchte die GPU-Beschränkung wie in this topic angewiesen.wie zu implementieren Tensorflow Sitzung Konfiguration

Aber mein Code sieht wie folgt aus:

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 diesem Fall, wie stelle ich die Konfiguration in meinem Code? Ich habe keine direkte sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) Linie hier. Vielen Dank!

Antwort

0

Sie können die Session-Konfiguration übergeben, eine tf.ConfigProto im tf.Session() initializer in der with Aussage:

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 
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 
Verwandte Themen