2017-08-30 20 views
1

有一種使用Python創建文件的方法,可以通過TensorBoard進行可視化(請參閱here)。我已經嘗試了這個代碼,它運行良好。在TensorFlow的C++ api中,如何使用張量板生成可視化的圖形文件?

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可視化我的計算?

在C++ api中還有一個FileWrite接口,但我還沒有看到任何示例。它是相同的界面?

回答

-1

看起來你想要tensorflow::EventsWritertensorflow/core/util/events_writer.h。您需要手動創建一個Event對象才能使用它。

tf.summary.FileWriter中的python代碼爲您處理了很多細節,但如果絕對必要的話,我建議只使用C++ API ......是否有迫切的理由在C++中實現您的培訓?

0

見我answer here,它給你一個在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; 
} 
相關問題