Display image of graph in TensorFlow?

前端 未结 2 882
借酒劲吻你
借酒劲吻你 2020-12-29 05:38

I wrote a simple script to calculate the golden ratio from 1,2,5. Is there a way to actually produce a visual through tensorflow (possibly with the aid of matplotlib<

2条回答
  •  -上瘾入骨i
    2020-12-29 06:14

    This is exactly what tensorboard was created for. You need to slightly modify your code to store the information about your graph.

    import tensorflow as tf
    C_1 = tf.constant(5.0)
    C_2 = tf.constant(1.0)
    C_3 = tf.constant(2.0)
    
    golden_ratio = (tf.sqrt(C_1) + C_2)/C_3
    
    with tf.Session() as sess:
        writer = tf.summary.FileWriter('logs', sess.graph)
        print sess.run(golden_ratio)
        writer.close()
    

    This will create a logs folder with event files in your working directory. After this you should run tensorboard from your command line tensorboard --logdir="logs" and navigate to the url it gives you (http://127.0.0.1:6006). In your browser go to GRAPHS tab and enjoy your graph.

    You will use TB a lot if you are going to do anything with TF. So it makes sense to learn about it more from official tutorials and from this video.

提交回复
热议问题