2017-06-03 44 views
0

這些是示例代碼。tensorflow .graph文件不生成

import tensorflow as tf 

const1 = tf.constant(2) 
const2 = tf.constant(3) 
add_op = tf.add(const1,const2) 
mul_op = tf.mul(add_op,const2) 

with tf.Session() as sess: 

result,result2 = sess.run([mul_op,add_op]) 
print(result) 
print(result2) 

tf.train.SummaryWriter('./',sess.graph) 

它顯示這樣的消息,

Tensor("Add:0", shape=(), dtype=int32) 

但是沒有產生文件。

回答

1

這裏是一個修改後的代碼,應該運行:

import tensorflow as tf 

const1 = tf.constant(2) 
const2 = tf.constant(3) 
add_op = tf.add(const1,const2) 
mul_op = tf.multiply(add_op,const2) # probably you use old version of TF 

with tf.Session() as sess: 
    writer = tf.summary.FileWriter('logs', sess.graph) 
    result,result2 = sess.run([mul_op,add_op]) 
    writer.close() 

我刪除打印,改變操作的名稱,以便能夠在TF的新版本上運行它(建議update)放作家在上面,並在最後關閉它。還要更改日誌目錄。

現在從您用來運行腳本的同一個目錄運行以下命令:tensorboard --logdir=logs。瀏覽瀏覽器並查看結果。

+0

謝謝我的版本是0.10rc,所以我會更新版本1 – whitebear