How to create a Tensorflow Tensorboard Empty Graph

冷暖自知 提交于 2019-11-29 09:18:50

TensorBoard is a tool for visualizing the TensorFlow graph and analyzing recorded metrics during training and inference. The graph is created using the Python API, then written out using the tf.train.SummaryWriter.add_graph() method. When you load the file written by the SummaryWriter into TensorBoard, you can see the graph that was saved, and interactively explore it.

However, TensorBoard is not a tool for building the graph itself. It does not have any support for adding nodes to the graph.

Novak

Starting from the following Code Example, I can add one line as shown below:

import tensorflow as tf
import numpy as np
sess = tf.InteractiveSession()  #define a session
# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(100).astype("float32")
y_data = x_data * 0.1 + 0.3

# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but Tensorflow will
# figure that out for us.)
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b

# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

# Before starting, initialize the variables.  We will 'run' this first.
init = tf.initialize_all_variables()

# Launch the graph.
sess = tf.Session()
sess.run(init)

#### ----> ADD THIS LINE <---- ####
writer = tf.train.SummaryWriter("/tmp/test", sess.graph)

# Fit the line.
for step in xrange(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(W), sess.run(b))

# Learns best fit is W: [0.1], b: [0.3]

And then run tensorboard from the command line, pointing to the appropriate directory. This shows a complete call for the SummaryWriter. It is important to note the following things:

  1. SummaryWriter is passed a Session, and so must happen after the Session (or InteractiveSession) is created
  2. That Session may be created early in the program, but when the Session is passed to the SummaryWriter, the graph as it exists at that point is written to the file that the TensorBoard will use.

In this page, there is a very simple code that you can use to test your installation: http://tensorflow.org/get_started

I included this line

tf.train.write_graph(sess.graph_def, '/home/daniel/Documents/Projetos/Prorum/ProgramasEmPython/TestingTensorFlow/fileGraph', 'graph.pbtxt')

After this "sess.run(init)"

This will generate a file that you have to upload to the "TensorBoard".

In order to open the TensorBoard, supposing that it is installed in your computer (it must be if you use pip to install), I used the terminal of Ubuntu and wrote:

"tensorboard --logdir nameOfDirectory"

Then, you should open your browser in Port 6006:

http://localhost:6006/

This will open the TensorBoard. I went to the "Graph Menu" and uploaded the file. It generated this figure below:

So, what I have done is to transfer the model I created in Python to TensorBoard. I believe that it is possible to create an empty one, if no model is created (only the session is initiated). However, I am not sure if you are able to change this directly in the TensorBoard.

I have answered before this question here in Portuguese with more details for Brazilian users. Maybe it can be useful for other people: http://prorum.com/index.php/1843/recentemente-plataforma-aprendizagem-primeira-impressao

i solved by on windows:

       file_writer = tf.summary.FileWriter("output", sess.graph)

for that directory "output". I opened command on windows.

typed

tensorboard --logdir="C:\Users\kiran\machine Learning\output"

my mistake was on that line..

The graphs in TensorBoard do not show up if you are using Firefox. You have to install Chrome.

result wanted

An empty graph that can add nodes, editable.

I think you will find the Orange tool useful. It allows you to drag and drop various nodes and implement algorithms via GUI.

I had to use

python -m tensorflow.tensorboard --logdir="C:\tmp\tensorflow\.."

somehow tensorboard --logdir didn't work.

My environment

OS: Windows 7, Python 3.5, and Tensorflow 1.1.0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!