如何向TensorFlow摘要添加任意值?

时间:2016-05-30 16:32:22

标签: logging tensorflow tensorboard

为了将简单值val = 5 test_writer.add_summary(sess.run(tf.scalar_summary('test', val)), global_step) 记录到TensorBoard摘要中,我需要

sess.run(tf.scalar_summary('test', val))

val

真的有必要将function myCtrl($scope){ $scope form ={companyName :"company1",companyAddress:"company address",staff[{name:"men",id:"123"}]} function myCtrl($scope){ enter code here $scope.addDetail=function(){ $scope.form.push({companyName:$scope.comName,companyAddress:$scope.comAddress, staff.name:$scope.nameStaff, staff.id: $scope.idStaff}); }} <input type="text" ng-model="comName" /> <input type="text" ng-model="comAddress" /> <input type="text" ng-model="nameStaff" /> <input type="text" ng-model="idStaff" /> <button ng-click=addDetail()>add<button> 添加为摘要吗?

2 个答案:

答案 0 :(得分:11)

这是使用tf.Summary.FileWriter类的另一个(可能稍微更新)解决方案:

summary_writer = tf.summary.FileWriter(logdir=output_dir)
value = tf.Summary.Value(tag='variable name', simple_value=value)
summary_writer.add_event(summary=tf.summary.Event(tf.Summary([value]),
                         wall_time=time.time(),
                         step=global_step))

然后您可以创建SummarySaverHook:

summary_hook = tf.train.SummarySaverHook(
    summary_writer=summary_writer,
    summary_op=your_summary_op)

您可以将其传递给MonitoredTrainingSession。 summary_op的示例是tf.summary.merge_all()

注意:您必须等待FileWriter刷新才能显示在您的事件文件中。您可以通过调用summary_writer.flush()

强制它

更简单的解决方案:

summary_writer = tf.summary.FileWriter(output_dir)
summary = tf.Summary()
summary.value.add(tag='name of var', simple_value=value)
summary_writer.add_summary(summary, global_step)
summary_writer.flush()

答案 1 :(得分:7)

您可以自己构建摘要,例如

from tensorflow.core.framework import summary_pb2

value = summary_pb2.Summary.Value(tag="Accuracy", simple_value=0.95)
summary = summary_pb2.Summary(value=[value])

然后,您可以在代码中使用summary添加add_summary