美文网首页tensorflow技术解析与实战——阅读笔记
tensorflow初探二之使用tensorboard实现可视化

tensorflow初探二之使用tensorboard实现可视化

作者: 欠我的都给我吐出来 | 来源:发表于2019-01-29 15:14 被阅读0次

    Tensorboard

    对于自己写的tensorflow程序,可以是使用tensorboard实现可视化。目前掌握的使用是:

    1. 编写代码
    #!/usr/bin/env python3
    import tensorflow as tf
    import numpy as np
    import os
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' 
    
    ## prepare the original data
    with tf.name_scope('data'):
         x_data = np.random.rand(100).astype(np.float32)
         y_data = 0.3*x_data+0.1
    ##creat parameters
    with tf.name_scope('parameters'):
         weight = tf.Variable(tf.random_uniform([1],-1.0,1.0))
         bias = tf.Variable(tf.zeros([1]))
    ##get y_prediction
    with tf.name_scope('y_prediction'):
         y_prediction = weight*x_data+bias
    ##compute the loss
    with tf.name_scope('loss'):
         loss = tf.reduce_mean(tf.square(y_data-y_prediction))
    ##creat optimizer
    optimizer = tf.train.GradientDescentOptimizer(0.5)
    #creat train ,minimize the loss 
    with tf.name_scope('train'):
         train = optimizer.minimize(loss)
    #creat init
    with tf.name_scope('init'): 
         init = tf.global_variables_initializer()
    ##creat a Session 
    sess = tf.Session()
    ##initialize
    writer = tf.summary.FileWriter("logs/", sess.graph)
    sess.run(init)
    ## Loop
    for step  in  range(101):
        sess.run(train)
        if step %10==0 :
            print(step ,'weight:',sess.run(weight),'bias:',sess.run(bias))
    
    1. 运行代码
    python 1.py
    
    1. 使用tensorboard命令
    tensorboard --logdir logs
    
    1. 打开localhost:6006端口


      tensorboard界面

    未来遇到实际问题再来研究

    相关文章

      网友评论

        本文标题:tensorflow初探二之使用tensorboard实现可视化

        本文链接:https://www.haomeiwen.com/subject/wquxsqtx.html