Python 正在尝试运行mnist.py。代码运行,但我看到的是';无法连接';浏览器中的消息
我正在运行下面的代码Python 正在尝试运行mnist.py。代码运行,但我看到的是';无法连接';浏览器中的消息,python,tensorflow,tensorflow2.0,tensorboard,Python,Tensorflow,Tensorflow2.0,Tensorboard,我正在运行下面的代码 import os import os.path import shutil import tensorflow as tf LOGDIR = "C:/Users/ryans/mnist_tutorial/" LABELS = os.path.join(os.getcwd(), "labels_1024.tsv") SPRITES = os.path.join(os.getcwd(), "sprite_1024.png") ### MNIST EMBEDDINGS ###
import os
import os.path
import shutil
import tensorflow as tf
LOGDIR = "C:/Users/ryans/mnist_tutorial/"
LABELS = os.path.join(os.getcwd(), "labels_1024.tsv")
SPRITES = os.path.join(os.getcwd(), "sprite_1024.png")
### MNIST EMBEDDINGS ###
mnist = tf.contrib.learn.datasets.mnist.read_data_sets(train_dir=LOGDIR + "data", one_hot=True)
### Get a sprite and labels file for the embedding projector ###
#if not (os.path.isfile(LABELS) and os.path.isfile(SPRITES)):
# print("Necessary data files were not found. Run this command from inside the "
# "repo provided at "
# "https://github.com/dandelionmane/tf-dev-summit-tensorboard-tutorial.")
# exit(1)
# shutil.copyfile(LABELS, os.path.join(LOGDIR, LABELS))
# shutil.copyfile(SPRITES, os.path.join(LOGDIR, SPRITES))
def conv_layer(input, size_in, size_out, name="conv"):
with tf.name_scope(name):
w = tf.Variable(tf.truncated_normal([5, 5, size_in, size_out], stddev=0.1), name="W")
b = tf.Variable(tf.constant(0.1, shape=[size_out]), name="B")
conv = tf.nn.conv2d(input, w, strides=[1, 1, 1, 1], padding="SAME")
act = tf.nn.relu(conv + b)
tf.summary.histogram("weights", w)
tf.summary.histogram("biases", b)
tf.summary.histogram("activations", act)
return tf.nn.max_pool(act, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding="SAME")
def fc_layer(input, size_in, size_out, name="fc"):
with tf.name_scope(name):
w = tf.Variable(tf.truncated_normal([size_in, size_out], stddev=0.1), name="W")
b = tf.Variable(tf.constant(0.1, shape=[size_out]), name="B")
act = tf.matmul(input, w) + b
tf.summary.histogram("weights", w)
tf.summary.histogram("biases", b)
tf.summary.histogram("activations", act)
return act
def mnist_model(learning_rate, use_two_fc, use_two_conv, hparam):
tf.reset_default_graph()
sess = tf.Session()
# Setup placeholders, and reshape the data
x = tf.placeholder(tf.float32, shape=[None, 784], name="x")
x_image = tf.reshape(x, [-1, 28, 28, 1])
tf.summary.image('input', x_image, 3)
y = tf.placeholder(tf.float32, shape=[None, 10], name="labels")
if use_two_conv:
conv1 = conv_layer(x_image, 1, 32, "conv1")
conv_out = conv_layer(conv1, 32, 64, "conv2")
else:
conv_out = conv_layer(x_image, 1, 16, "conv")
flattened = tf.reshape(conv_out, [-1, 7 * 7 * 64])
if use_two_fc:
fc1 = fc_layer(flattened, 7 * 7 * 64, 1024, "fc1")
relu = tf.nn.relu(fc1)
embedding_input = relu
tf.summary.histogram("fc1/relu", relu)
embedding_size = 1024
logits = fc_layer(relu, 1024, 10, "fc2")
else:
embedding_input = flattened
embedding_size = 7*7*64
logits = fc_layer(flattened, 7*7*64, 10, "fc")
with tf.name_scope("xent"):
xent = tf.reduce_mean(
tf.nn.softmax_cross_entropy_with_logits(
logits=logits, labels=y), name="xent")
tf.summary.scalar("xent", xent)
with tf.name_scope("train"):
train_step = tf.train.AdamOptimizer(learning_rate).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))
tf.summary.scalar("accuracy", accuracy)
summ = tf.summary.merge_all()
embedding = tf.Variable(tf.zeros([1024, embedding_size]), name="test_embedding")
assignment = embedding.assign(embedding_input)
saver = tf.train.Saver()
sess.run(tf.global_variables_initializer())
writer = tf.summary.FileWriter(LOGDIR + hparam)
writer.add_graph(sess.graph)
config = tf.contrib.tensorboard.plugins.projector.ProjectorConfig()
embedding_config = config.embeddings.add()
embedding_config.tensor_name = embedding.name
embedding_config.sprite.image_path = SPRITES
embedding_config.metadata_path = LABELS
# Specify the width and height of a single thumbnail.
embedding_config.sprite.single_image_dim.extend([28, 28])
tf.contrib.tensorboard.plugins.projector.visualize_embeddings(writer, config)
for i in range(2001):
batch = mnist.train.next_batch(100)
if i % 5 == 0:
[train_accuracy, s] = sess.run([accuracy, summ], feed_dict={x: batch[0], y: batch[1]})
writer.add_summary(s, i)
if i % 500 == 0:
sess.run(assignment, feed_dict={x: mnist.test.images[:1024], y: mnist.test.labels[:1024]})
saver.save(sess, os.path.join(LOGDIR, "model.ckpt"), i)
sess.run(train_step, feed_dict={x: batch[0], y: batch[1]})
def make_hparam_string(learning_rate, use_two_fc, use_two_conv):
conv_param = "conv=2" if use_two_conv else "conv=1"
fc_param = "fc=2" if use_two_fc else "fc=1"
return "lr_%.0E,%s,%s" % (learning_rate, conv_param, fc_param)
def main():
# You can try adding some more learning rates
for learning_rate in [1E-3, 1E-4]:
# Include "False" as a value to try different model architectures
for use_two_fc in [True]:
for use_two_conv in [False, True]:
# Construct a hyperparameter string for each one (example: "lr_1E-3,fc=2,conv=2")
hparam = make_hparam_string(learning_rate, use_two_fc, use_two_conv)
print('Starting run for %s' % hparam)
# Actually run with the new settings
mnist_model(learning_rate, use_two_fc, use_two_conv, hparam)
print('Done training!')
print('Run `tensorboard --logdir=%s` to see the results.' % LOGDIR)
print('Running on mac? If you want to get rid of the dialogue asking to give '
'network permissions to TensorBoard, you can provide this flag: '
'--host=localhost')
if __name__ == '__main__':
main()
我在这个网站上找到了代码
当我运行代码时,我没有收到任何错误消息,但是当我试图在浏览器窗口中查看结果时,我只看到了这一点
最后,我打开Anaconda提示符并输入以下内容:
tensorboard --logdir="C:/Users/ryans/mnist_tutorial/"
我想所有的日志文件都写对了。请参见下面的屏幕截图
我不确定这一点出了什么问题。我是否没有将浏览器指向正确的本地主机?或者,还有什么问题吗?我看不出我的错误,但很明显这里出了问题。思想?谢谢 你应该跑步
tensorboard --logdir=<directory with logs>
tensorboard--logdir=
在您的情况下,应该是C:/Users/ryans/mnist\u tutorial/您应该运行
tensorboard --logdir=<directory with logs>
tensorboard--logdir=
在你的例子中应该是C:/Users/ryans/mnist\u tutorial/谢谢,我打开了命令提示符(Anaconda提示符),运行了你给我的代码,得到了同样的结果。我刚刚更新了我原来的帖子。我一定错过了一些简单的东西,但不确定那是什么。看来它应该有用。请尝试browserNope中的localhost:6006。就像以前一样。无法连接Firefox无法在localhost:6006上建立与服务器的连接。我刚刚让它工作起来!我必须在命令提示符下“conda update conda”,并在命令提示符下“spyder--reset”。我还必须得到最新的C++分布式。谢谢,我打开了命令提示符(Anaconda提示符),运行了你给我的代码,得到了同样的结果。我刚刚更新了我原来的帖子。我一定错过了一些简单的东西,但不确定那是什么。看来它应该有用。请尝试browserNope中的localhost:6006。就像以前一样。无法连接Firefox无法在localhost:6006上建立与服务器的连接。我刚刚让它工作起来!我必须在命令提示符下“conda update conda”,并在命令提示符下“spyder--reset”。我还必须得到最新的C++分布式。链接: