2016-12-07 7 views
1

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

あなたはwith文でtf.Session()初期化子で、tf.ConfigProtoをセッション構成を渡すことができます。

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 
関連する問題