首页 > 其他 > 详细

tensorboard使用

时间:2020-01-31 19:51:59      阅读:67      评论:0      收藏:0      [点我收藏+]
import os
os.environ[‘TF_CPP_MIN_LOG_LEVEL‘] = ‘2‘

import tensorflow as tf

#tensorboard --logdir="./"

def linearregression():

    with tf.variable_scope("original_data"):
        X = tf.random_normal([100,1],mean=0.0,stddev=1.0)
        y_true = tf.matmul(X,[[0.8]]) + [[0.7]]

    with tf.variable_scope("linear_model"):
        weights = tf.Variable(initial_value=tf.random_normal([1,1]))
        bias = tf.Variable(initial_value=tf.random_normal([1,1]))
        y_predict = tf.matmul(X,weights)+bias

    with tf.variable_scope("loss"):
        loss = tf.reduce_mean(tf.square(y_predict-y_true))

    with tf.variable_scope("optimizer"):
        optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01).minimize(loss)

    #收集观察张量
    tf.summary.scalar("losses",loss)
    tf.summary.histogram("weight",weights)
    tf.summary.histogram("biases",bias)
    #合并收集的张量
    merge = tf.summary.merge_all()

    init = tf.global_variables_initializer()

    with tf.Session() as sess:
        sess.run(init)
        filewriter = tf.summary.FileWriter("./tmp",graph=sess.graph)
        for i in range(1000):
            sess.run(optimizer)
            print("loss:", sess.run(loss))
            print("weight:", sess.run(weights))
            print("bias:", sess.run(bias))
            summary = sess.run(merge)
            filewriter.add_summary(summary,i)

if __name__ == ‘__main__‘:
    linearregression()

  技术分享图片

 

tensorboard使用

原文:https://www.cnblogs.com/LiuXinyu12378/p/12246318.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!