【TensorFlow】Windows 打開Tensorboard 查看流圖

1.環境準備

打開Anaconda Prompt,執行

conda create -n tensorflow python=3.6

2.激活環境

activate tensorflow

3.查看流圖

執行下述命令:

tensorboard --logdir="D:/tensorflow_learning/my_graph"

其中,logdir是存放events文件的路徑,輸出如下:

C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
TensorBoard 1.12.0 at http://DESKTOP-XXXXXXT:6006 (Press CTRL+C to quit)

打開瀏覽器,將上面的地址粘貼到瀏覽器即可查看,即

http://DESKTOP-XXXXXX:6006

在這裏插入圖片描述

附錄

  • 所使用代碼(參考21個項目玩轉深度學習):
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  8 21:29:32 2020

@author: QiuMingZS
"""

import tensorflow as tf

# import the dataset
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data/', one_hot=True)

# placeholder is used as Tensor, like node
x = tf.placeholder(tf.float32, [None, 784])

# parameters to be trained
W = tf.Variable(tf.zeros([784, 10]))        # weight
b = tf.Variable(tf.zeros([10]))             # bias


y = tf.nn.softmax(tf.matmul(x, W) + b)      # output

y_ = tf.placeholder(tf.float32, [None, 10]) # the real label

# Cross Entropy, used as loss function
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_*tf.log(y)))
# let Cross Entropy down using Gradient Descent
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
# creat a session
sess = tf.InteractiveSession()
# initialize variables before training
tf.global_variables_initializer().run()

print('Start Training ... ')
for _ in range(1000):
    batch_xs, batch_ys=mnist.train.next_batch(100)
    sess.run(train_step, feed_dict={x:batch_xs, y_:batch_ys})

correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
# note: accuracy is a Tensor, not a variable
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x:mnist.test.images, y_:mnist.test.labels}))
writer = tf.summary.FileWriter('./my_graph', sess.graph)
writer.close()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章