【发布时间】: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