【问题标题】:Graph creation problems in Tensorboard from Google Developers videos来自 Google Developers 视频的 Tensorboard 中的图形创建问题
【发布时间】:2018-05-10 22:12:00
【问题描述】:

所以我在 youtube 上观看 Google Developers 视频 Hands-on TensorBoard (TensorFlow Dev Summit 2017) 我在6:01 重新创建他的图表时遇到了很多问题。

以下是我的代码:

import tensorflow as tf

#1. add some name for w and b
#2. apply name scope

def conv_layer(input, channels_in, channels_out, name = "conv"):
    with tf.name_scope(name): 
        w = tf.Variable(tf.zeros([5, 5, channels_in, channels_out]), name = "W")
        b = tf.Variable(tf.zeros([channels_out]), name = "B")
        conv = tf.nn.conv2d(input, w, strides=[1, 1, 1, 1], padding="SAME")
        act = tf.nn.relu(conv + b)
        return act

#1. add some name for w and b
#2. apply name scope

def fc_layer(input, channels_in, channels_out, name = "fc"):
    with tf.name_scope(name):
        w = tf.Variable(tf.zeros([channels_in, channels_out]), name = "W")
        b = tf.Variable(tf.zeros([channels_out]), name = "B")
        act = tf.nn.relu(tf.matmul(input,w) + b)
        return act

#1. add some name for placeholders, cov layer, fc, logits
#2. apply name scope

# Setup placeholders, and reshape the data
x = tf.placeholder(tf.float32, shape=[None, 784], name = "x")
y = tf.placeholder(tf.float32, shape=[None, 10], name = "labels")
x_image = tf.reshape(x, [-1, 28, 28, 1])

conv1 = conv_layer(x_image, 1, 32, "conv1")
pool1 = tf.nn.max_pool(conv1, ksize=[1,2,2,1], strides = [1,2,2,1], padding = "SAME")

conv2 = conv_layer(pool1, 32, 64, "conv2")
pool2 = tf.nn.max_pool(conv2, ksize=[1,2,2,1], strides = [1,2,2,1], padding = "SAME")
flattened = tf.reshape(pool2, [-1, 7*7*64])

fcl = fc_layer(flattened, 7*7*64, 1024, "fcl")
logits = fc_layer(fcl, 1024, 10, "fc2")

added name scope and changed the name for cross_entropyu

with tf.name_scope("xent"):
    xent = tf.reduce_mean(
        tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels = y))


#cross_entropy = tf.reduce_mean(
#    tf.nn.softmax_cross_entropy_with_logits(logits = logits, labels = y))

with tf.name_scope("train"):
    train_step = tf.train.AdamOptimizer(1e-4).minimize(xent)

with tf.name_scope("accuracy"):
    correct_prediction = tf.equal(tf.argmax(logits, 1), tf.argmax(y,1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))


sess = tf.Session()
sess.run(tf.global_variables_initializer())

writer = tf.summary.FileWriter("/Users/jianxiongji/graphs/change3/")
writer.add_graph(sess.graph)

我的图表看起来像 this,但他在演示文稿中的内容像 this

我很困惑;也许我错过了一些东西或者只是明显错误,但是当我运行它时上面的代码中没有显示错误。

我要提前感谢大家对我的帮助。如果您能提供一些关于 tensorboard 的好教程或材料,我将不胜感激。

【问题讨论】:

    标签: python tensorflow tensorboard


    【解决方案1】:

    我已经运行了您的代码 sn-p 并且 tensorboard 显示的图表与视频中的完全一样。所以代码是正确的。您的图片很可能是另一个图表。造成这种情况的原因有很多:

    • xentaccuracy 名称范围,还有xent_1accuracy_1。这种重复意味着您已经定义了两次 xentaccuracy(例如,这在 jupyther 中很容易实现)。
    • VariableVariable_1、...、Variable_7,但所有变量都有名称。

    因此,tensorboard 可能会查看您早期尝试重新创建图表的尝试。尝试清理您的日志目录并进行干净运行。然后确保使用--logdir /Users/jianxiongji/graphs/change3/ 调用张量板。如果您使用的是 jupyther,请重新启动后端并重建所有单元格。

    【讨论】:

      猜你喜欢
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-08
      • 2015-02-24
      相关资源
      最近更新 更多