2017-06-26 3 views

答えて

0

このようなループは明示的に展開されません。つまり、tf.while_loopを100回実行する必要がある場合、グラフにはbody関数が100回呼び出されることはありません。たとえば、テンソルフローを使用してx^N(またはPythonの言葉ではx**N)を計算するとします。

import tensorflow as tf 

N = tf.constant(100) 
i = tf.constant(0) 
x = tf.constant(1.5) 

def body(i, x, x0): 
    return i + 1, x * x0, x0 

output = tf.while_loop(lambda i,x,x0: i < N-1, body, [i, x, x]); 

with tf.Session() as sess: 
    writer = tf.summary.FileWriter("while_loop_example") 
    writer.add_graph(sess.graph) 
    print(sess.run(output)) 

このループの本体は99回実行する必要があります。我々は(「tensorboard --logdir while_loop_example」コマンドを使用して)グラフを見ればしかし、私たちはこれを取得:

enter image description here

私はループの繰り返し回数を変更した場合、グラフは変更されません。

関連する問題