Tensorflow 张量板数据

Tensorflow 张量板数据,tensorflow,tensorboard,Tensorflow,Tensorboard,我在TensorBoard输入Tensorflow数据时遇到问题。我会在下面留下我的代码。请通过命令、函数或代码示例来帮助我。您还可以修改我的代码以使其正常工作 import tensorflow as tf import tensorflow.compat.v1 as tfc graph = tfc.get_default_graph() with graph.as_default(): with tf.name_scope('placeholders'): x = t

我在TensorBoard输入Tensorflow数据时遇到问题。我会在下面留下我的代码。请通过命令、函数或代码示例来帮助我。您还可以修改我的代码以使其正常工作

import tensorflow as tf
import tensorflow.compat.v1 as tfc
graph = tfc.get_default_graph()
with graph.as_default():
    with tf.name_scope('placeholders'):
        x = tfc.placeholder(tf.float32, (3, 1))
        y = tfc.placeholder(tf.float32, (3, ))
    with tf.name_scope('weights'):
        W = tf.Variable(tfc.random_normal((1, 1)))
        b = tf.Variable(tfc.random_normal((1,)))
    with tf.name_scope('prediction'):
        y_pred = tf.matmul(x,W) + b
    with tf.name_scope('loss'):
        l = tf.reduce_sum((y-y_pred)**2)
    #Добавить оптимизацию тренировки
    with tf.name_scope('optim'):
        #Задать скорость заучивания .001, как рекомендовано выше.
        train_op = tfc.train.AdamOptimizer(.001).minimize(l)
    with tf.name_scope('summaries'):
        #Запись сводки о переменных(скалярных величинах) в заданный каталог журналов
        tf.summary.scalar('loss', l)

    writer = tf.summary.create_file_writer('/tmp/lr-train')



    n_steps = 1000

    with tfc.Session() as sess:
        sess.run(tfc.global_variables_initializer())
        #Натренировать модель
        with writer.as_default():
            for i in range(n_steps):
                feed_dict = {x: [[1.], [2.], [3.]], y: [2., 3., 4.]}
                _, loss = sess.run([train_op, l], feed_dict=feed_dict)
                tf.summary.scalar('loss', l, i)
                writer.flush()

您能否澄清您希望看到的数据,以及如何(和在哪里)启动TensorBoard而不是运行代码?在
tf.summary.scalar('loss',l,i)
中,您正在执行'l'操作,我认为这应该是session.run
loss
值的结果。