zoukankan      html  css  js  c++  java
  • tensorboard

    import tensorflow as tf
    import numpy as np
    from matplotlib import pyplot as plt
    
    # 清除
    tf.reset_default_graph()
    logdir = 'log'
    plt.figure()
    
    x_data = np.random.rand(1000).astype(np.float32)
    y_data = x_data * 8 + 1.5
    
    plt.plot(x_data, y_data)
    plt.show()
    x = tf.placeholder(tf.float32)
    y = tf.placeholder(tf.float32)
    
    w = tf.Variable(tf.random_normal([1]), tf.float32)
    b = tf.Variable(tf.random_normal([1]), tf.float32)
    
    y_pre = tf.multiply(x, w) + b
    
    loss = tf.reduce_sum(tf.pow((y - y_pre), 2))
    train = tf.train.GradientDescentOptimizer(0.01).minimize(loss)
    
    init = tf.global_variables_initializer()
    
    with tf.Session() as sess:
        sess.run(init)
        for i in range(1000):
            sess.run(train, feed_dict={x: x_data[i], y: y_data[i]})
            if i % 50 == 0:
                print(sess.run(loss, feed_dict={x: x_data[i], y: y_data[i]}))
    
        writer = tf.summary.FileWriter(logdir, tf.get_default_graph())
        writer.close()

    1. tf.reset_default_graph() 是清除default gragh 和不断增加的节点

    2.定义一个writer,参数为log的地址,和图形这里我们直接用get_default_graph()来获得tensorflow默认生成的图

    3.需要把write 关闭了

    还可以使用

    writer = tf.summary.FileWriter('log')

    然后

    writer.add_graph(sess.graph)

  • 相关阅读:
    简单图表分析(2/2)
    简单图表分析(1/2)
    juqery dragsort使用遇到的问题
    移动端实战总结
    CSS VS JS动画,哪个更快[译]
    HTML5移动端图片上传模块
    移动端使用rem适配及相关问题
    再谈vertical-align与line-height
    Javascript中的Promise
    Retina屏实现1px边框
  • 原文地址:https://www.cnblogs.com/francischeng/p/9813037.html
Copyright © 2011-2022 走看看