可视化之plot

来自软件实验室
跳转至: 导航搜索

可视化简单说就是把数据通过图,表等展示出来,使用者可以通过眼睛就可以直观看出。 tensorflow提供了数据可视化的工具--TensorBoard,有了TensorBoard,可以直观的看出tensorflow程序的基本流程图,数据的变化趋势,等。 使用的话,就是在源代码的基础之上加点操作,然后执行,生成日志文件,tensorBoard通过运行这个文件,可视化就完成了,共三步: 第一步:

   with tf.name_scope('name'):

放在各变量的上一行,如:

        with tf.name_scope('weights'):
            Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W')

如果一个scope下面有几个变量,多放几个,只要遵守python格式就行

 with tf.name_scope('layer'):
        with tf.name_scope('weights'):
            Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W')
        with tf.name_scope('biases'):
            biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b')
        with tf.name_scope('Wx_plus_b'):
            Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)

上面代码就是说,一个layer层有weights,biases,Wx_plus_b几个隐藏变量,注意每个变量必须加一个名字。

第二步:

   writer = tf.summary.FileWriter("logs/", sess.graph)
   

然后会生成一个log文件夹,里面是一个日志文件(如;events.out.tfevents.1484583056) 第三步:

tengxing@tengxing-Lenovo-Y50-70:~/workspace/python/demo/python_3$ l
logs/  tensorboard_1.py  tensorboard.py
tengxing@tengxing-Lenovo-Y50-70:~/workspace/python/demo/python_3$ tensorboard --logdir=logs
W tensorflow/core/platform/cpu_feature_guard.cc:95] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:95] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:95] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:95] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
Starting TensorBoard 39 on port 6006
(You can navigate to http://127.0.0.1:6006)

浏览器打开
Tensorplot.png

面板上还有一些功能,就步一一说了,自己能看得懂。

Tensorflow graphs.png