Tensorflow:在没有session.run()

时间:2016-11-15 03:59:01

标签: python tensorflow tensorboard

我想知道这是否是直接将scalar_summary添加到SummaryWriter而不使用session.run()来获取摘要。

通常,获取和添加摘要的代码是:

with tf.Session() as sess:
    writer = tf.train.SummaryWriter("./logs", sess.graph)
    merged = tf.merge_all_summaries()
    summary, acc = sess.run([merged, acc_op], feed_dict)
    writer.add_summary(summary, current_step) #Save summary at some checkpoint step

但是,我只想绘制在训练后检索和处理的准确度值和损失值作为张量板上的线图:

with tf.Session() as sess:
    writer = tf.train.SummaryWriter("./logs", sess.graph)
    acc, loss = sess.run([acc_op, loss_op], feed_dict) #Only the get accuracy and loss
    acc = acc*100

    tf.scalar_summary('accuracy', acc)
    tf.scalar_summary('loss', loss)

    merged = tf.merge_all_summaries() #Merge all the summaries into one
    writer.add_summary(merged, current_step) #Save summary at some checkpoint step

上面的代码会打印出这个错误:

TypeError: Parameter to MergeFrom() must be instance of same class: expected Summary got Tensor. for field Event.summary

任何帮助或建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

您必须使用摘要编写器将acc_op和loss_op的系列值写入磁盘,张量板将从中读取。

或者您可以将acc_op和loss_op的值存储到数组中,并在训练结束后绘制它们。