zoukankan      html  css  js  c++  java
  • Tensorflow之tensorboard可视化

    首先简单认识tensorboard

    简单的生成tensorboard文件

    #!/usr/bin/env python2
    # -*- coding: utf-8 -*-
    """
    tensorboard 可视化生成tensorboard文件
    """
    import tensorflow as tf
    
    def add_layer(inputs, in_size, out_size, activation_function=None):
        # add one more layer and return the output of this layer
        Weights = tf.Variable(tf.random_normal([in_size, out_size]))
        biases = tf.Variable(tf.zeros([1, out_size]) + 0.1)
        Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)
        if activation_function is None:
            outputs = Wx_plus_b
        else:
            outputs = activation_function(Wx_plus_b, )
        return outputs
    
    # define placeholder for inputs to network
    xs = tf.placeholder(tf.float32, [None, 1])
    ys = tf.placeholder(tf.float32, [None, 1])
    
    # add hidden layer
    l1 = add_layer(xs, 1, 10, activation_function=tf.nn.relu)
    # add output layer
    prediction = add_layer(l1, 10, 1, activation_function=None)
    # the error between prediciton and real data
    loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction),
                                        reduction_indices=[1]))
    train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)
    sess = tf.Session()
    
    """
    tensorboard文件生成的位置,文件位置为../logs
    """
    writer = tf.summary.FileWriter("../logs/", sess.graph)
    
    # important step
    sess.run(tf.initialize_all_variables())

    运行程序后, 可以在tensorboard文件生成的位置的文件夹下找到名为events.out.tfevents.1499943764.m类似的文件

    打开终端输入:

    tensorboard --logdir='../logs/'

    logdir为程序中定义的log的文件夹路径

    看到如下运行结果

    $ tensorboard --logdir='../logs/'
    Starting TensorBoard 41 on port 6006

     

    打开浏览器输入http://0.0.0.0:6006, 即可打开可视化界面,左下角有文件的路径

    上面只是生成了一个界面,下面详细的定义每个tensorboard中每个标签页输出的图像

  • 相关阅读:
    websocket协议
    vue组件之间的传值
    vue中非父子组件的传值bus的使用
    $.proxy的使用
    弹性盒模型display:flex
    箭头函数与普通函数的区别
    粘贴到Excel的图片总是有些轻微变形
    centos rhel 中文输入法的安装
    vi ,默认为 .asm .inc 采用nasm的语法高亮
    how-to-convert-ppk-key-to-openssh-key-under-linux
  • 原文地址:https://www.cnblogs.com/xmeo/p/7162018.html
Copyright © 2011-2022 走看看