我怎样才能正确使用tf.summary.text?

时间:2017-08-10 19:48:39

标签: python text tensorflow summary tensorboard

我尝试使用此功能将日志文本写入Tensorboard日志文件,但我遇到了一些麻烦。

我想写一个包含字符串的列表(或np.array)。我不能通过这个,因为它不是一个张量,所以我该怎么办呢?

我正在尝试:

hyperparameters = ["learning_rate=1","batch_size=50","optimizer=Adagrad"]

summary_op = tf.summary.text("hyperparameters info", hyperparameters)
summary = session.run(summary_op )

writer.add_summary(summary)

请注意我已经定义了FileWriter并且我已经在运行会话。

1 个答案:

答案 0 :(得分:1)

你可以使用这样的张量:

hyperparams = np.array(["learning_rate=1","batch_size=50","optimizer=Adagrad"])
hyperparams_tensor = tf.constant(hyperparams)

#Or Directly use the tensor, there is no need for np.array() or list
#hyperparams_tensor = tf.constant(["learning_rate=1","batch_size=50","optimizer=Adagrad"])

summary_op = tf.summary.text("hyperparameters info", hyperparams_tensor)
summary = session.run(summary_op)

writer.add_summary(summary)