tensorflow .graph文件未生成(tensorflow .graph file doesn't generated)

编程入门 行业动态 更新时间:2024-10-25 14:32:28
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.

更多推荐

本文发布于:2023-07-27 15:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292398.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   graph   tensorflow   file   generated

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!