有一种使用Python创建文件的方法,它可以通过TensorBoard进行可视化(参见这里)。我试过这个代码,它运行得很好。
import tensorflow as tf
a = tf.add(1, 2,)
b = tf.multiply(a, 3)
c = tf.add(4, 5,)
d = tf.multiply(c, 6,)
e = tf.multiply(4, 5,)
f = tf.div(c, 6,)
g = tf.add(b, d)
h = tf.multiply(g, f)
with tf.Session() as sess:
print(sess.run(h))
with tf.Session() as sess:
writer = tf.summary.FileWriter("output", sess.graph)
print(sess.run(h))
writer.close()现在我使用TensorFlow API来创建我的计算。如何使用TensorBoard?可视化计算
FileWrite api中也有一个C++接口,但我没有看到任何示例。是同一个界面吗?
发布于 2017-08-30 06:36:32
看来你想要tensorflow::EventsWriter从tensorflow/core/util/events_writer.h。但是,您需要手动创建一个事件对象来使用它。
尽管tf.summary.FileWriter中的python代码为您处理了很多细节,但我建议只在绝对必要时使用C++ API .是否有令人信服的理由来实施您的C++培训?
发布于 2018-02-09 09:43:03
请参阅我的回答这里,它为您提供了c++中的26行代码来执行以下操作:
#include <tensorflow/core/util/events_writer.h>
#include <string>
#include <iostream>
void write_scalar(tensorflow::EventsWriter* writer, double wall_time, tensorflow::int64 step,
const std::string& tag, float simple_value) {
tensorflow::Event event;
event.set_wall_time(wall_time);
event.set_step(step);
tensorflow::Summary::Value* summ_val = event.mutable_summary()->add_value();
summ_val->set_tag(tag);
summ_val->set_simple_value(simple_value);
writer->WriteEvent(event);
}
int main(int argc, char const *argv[]) {
std::string envent_file = "./events";
tensorflow::EventsWriter writer(envent_file);
for (int i = 0; i < 150; ++i)
write_scalar(&writer, i * 20, i, "loss", 150.f / i);
return 0;
}https://stackoverflow.com/questions/45951674
复制相似问题