tensorflow .graph文件未生成(tensorflow .graph file doesn't generated)
这些是示例代码。
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)但是没有生成文件。
These are sample code.
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)it shows message like this,
Tensor("Add:0", shape=(), dtype=int32)However no file generated.
最满意答案
这是一个应该运行的修改后的代码:
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中运行它(建议更新 )将编写器置于顶部并在最后正确关闭它。 还要更改日志目录。
现在,从用于运行脚本的同一目录运行以下命令: tensorboard --logdir=logs 。 浏览浏览器并查看结果。
Here is a modified code, that should run:
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()I removed prints, change the name of the operation to be able to run it in the new version of TF (recommend to update) put the writer on top and closed it properly at the end. Also change the log dir.
Now from the same directory which you used to run a script run the following command: tensorboard --logdir=logs. Navigate the browser and see the results.
更多推荐
发布评论