打开Tensorboard的具体方法【windows环境】

来源:互联网 发布:制做标志的软件 编辑:程序博客网 时间:2024/04/29 16:27


Tensorboard试了一下午都打不开.错误情况是:

connectex: Therequested address is not valid in its context.

后来得大神指点总算知道自己错在哪里,特来分享一下。


1.首先,我在E盘新建了一个文件夹名为logs。

python代码保存位置为E:\code,具体内容如下:

"""Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly."""from __future__ import print_functionimport tensorflow as tfdef add_layer(inputs, in_size, out_size, activation_function=None):    # add one more layer and return the output of this layer    with tf.name_scope('layer'):        with tf.name_scope('weights'):            Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W')        with tf.name_scope('biases'):            biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b')        with tf.name_scope('Wx_plus_b'):            Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)        if activation_function is None:            outputs = Wx_plus_b        else:            outputs = activation_function(Wx_plus_b, )        return outputs        # define placeholder for inputs to networkwith tf.name_scope('inputs'):    xs = tf.placeholder(tf.float32, [None, 1], name='x_input')    ys = tf.placeholder(tf.float32, [None, 1], name='y_input')# add hidden layerl1 = add_layer(xs, 1, 10, activation_function=tf.nn.relu)# add output layerprediction = add_layer(l1, 10, 1, activation_function=None)# the error between prediciton and real datawith tf.name_scope('loss'):    loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction),                                        reduction_indices=[1]))with tf.name_scope('train'):    train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)sess = tf.Session()# tf.train.SummaryWriter soon be deprecated, use followingif int((tf.__version__).split('.')[1]) < 12 and int((tf.__version__).split('.')[0]) < 1:  # tensorflow version < 0.12    writer = tf.train.SummaryWriter('E:/logs/', sess.graph)else:  # tensorflow version >= 0.12    writer = tf.summary.FileWriter("E:/logs/", sess.graph)# tf.initialize_all_variables() no long valid from# 2017-03-02 if using tensorflow >= 0.12if int((tf.__version__).split('.')[1]) < 12 and int((tf.__version__).split('.')[0]) < 1:    init = tf.initialize_all_variables()else:    init = tf.global_variables_initializer()sess.run(init)

2.跑一下上述代码,在文件夹E:/logs中生成日志文件。 
然后打开cmd,首先进入刚才保存代码的文件夹,即E:\code.这一步至关重要,若未在此文件夹下进行后续操作,即使打开tensorboard也会出现一片空白,空白如下图。


3.在终端中输入命令 
       tensorboard --logdir=E:\logs 

系统会给你一个网址,可是千万不要单纯的把http://0.0.0.0:6006输入自己的浏览器地址栏里,否则就会出现文章开始我说的那个错误,就是下面这样 

而应该在浏览器地址栏里输入的是http://127.0.0.1:6006    
其中127.0.0.1是你的localhost,具体是什么我也不知道,总之你百度一下localhost它会出现百度百科,然后告诉你是127.0.0.1.


最后tensorboard就打开了!图也有了!大功告成。

原创粉丝点击