Why does this code not produce a log that is readable by tensorboard?

时光怂恿深爱的人放手 提交于 2021-01-28 05:17:32

问题


Using Python (3.6) / Jupyter (5.7.8) on WIndows 10 .. I have tried many simple examples of trying to generate log files for tensorboard including this:

logs_base_dir = "C:/tensorlogs"
%load_ext tensorboard.notebook
# %tensorboard --port=6006 --logdir {logs_base_dir}

os.makedirs(logs_base_dir, exist_ok=True)
%tensorboard --port=6008 --logdir {logs_base_dir}

a = tf.constant([10])
b = tf.constant([20])
c = tf.add(a,b)

with tf.Session() as sess:
    # or creating the writer inside the session
    writer = tf.summary.FileWriter(logs_base_dir, sess.graph)
    print(sess.run(c))

writer.close()
sess.close()

I see a logfile created in the 'C:/tensorlogs' folder called: 'events.out.tfevents.1563219145.DESKTOP-5HG12IB'

I can also see tensorboard running in a separate browser window. On the 'scaler' page it lists the correct source folder 'C:/tensorflow'.

But tensorboard indicate that no session is running.

What am I doing wrong? Is there any way of checking that log file to see if it is legitimate?

Browser window showing tensorboard running - but not finding log file

(Also shows nothing on graph window)

Update: I tried to run tensorboard from the command line using:

tensorboard --logdir='c:/tensorlogs' --port=6006

It has the same behaviour .. page shows in browser with no data. Terminal displays the following messages:

TensorBoard 1.13.1 at http://DESKTOP-5HG12IB:6006 (Press CTRL+C to quit) I0716 06:56:05.074265 3780 _internal.py:122] ::1 - - [16/Jul/2019 06:56:05] "[37mGET /data/experiments HTTP/1.1[0m" 200 - I0716 06:56:05.086722 8400 _internal.py:122] ::1 - - [16/Jul/2019 06:56:05] "[37mGET /data/environment HTTP/1.1[0m" 200 - I0716 06:56:05.088708 3780 _internal.py:122] ::1 - - [16/Jul/2019 06:56:05] "[37mGET /data/plugins_listing HTTP/1.1[0m" 200 - I0716 06:56:05.090195 8400 _internal.py:122] ::1 - - [16/Jul/2019 06:56:05] "[37mGET /data/runs HTTP/1.1[0m" 200 - I0716 06:56:05.099200 3780 _internal.py:122] ::1 - - [16/Jul/2019 06:56:05] "[37mGET /data/plugin/scalars/tags HTTP/1.1[0m" 200 - I0716 06:56:13.198990 3780 _internal.py:122] ::1 - - [16/Jul/2019 06:56:13] "[37mGET / HTTP/1.1[0m" 200 - I0716 06:56:14.169489 3780 _internal.py:122] ::1 - - [16/Jul/2019 06:56:14] "[37mGET /tf-interactive-inference-dashboard/editedexample.png HTTP/1.1[0m" 200 - I0716 06:56:14.170989 8400 _internal.py:122] ::1 - - [16/Jul/2019 06:56:14] "[37mGET /tf-interactive-inference-dashboard/distance.png HTTP/1.1[0m" 200 - I0716 06:56:14.174491 3780 _internal.py:122] ::1 - - [16/Jul/2019 06:56:14] "[37mGET /tf-interactive-inference-dashboard/pdplots.png HTTP/1.1[0m" 200 - I0716 06:56:14.176498 12340 _internal.py:122] ::1 - - [16/Jul/2019 06:56:14] "[37mGET /tf-interactive-inference-dashboard/explorecounterfactuals.png HTTP/1.1[0m" 200 - I0716 06:56:14.281985 12876 _internal.py:122] ::1 - - [16/Jul/2019 06:56:14] "[37mGET /data/experiments HTTP/1.1[0m" 200 - I0716 06:56:14.282483 8400 _internal.py:122] ::1 - - [16/Jul/2019 06:56:14] "[37mGET /data/runs HTTP/1.1[0m" 200 - I0716 06:56:14.282483 12340 _internal.py:122] ::1 - - [16/Jul/2019 06:56:14] "[37mGET /data/environment HTTP/1.1[0m" 200 - .. and lots more ...


回答1:


You might not have the basics about tensorboard so let me explain a bit. You created a graph, and logged it to a file. The only thing your log file will contain is a graph with a single operator (Add) and two inputs.

Logging scalars is often done to track your loss function when training neural networks, this seems like a decent guide.

EDIT

1) Are you sure tensorboard is getting your path correctly? Can you go to your log folder in the terminal and run tensorboard --logdir ./ from there?

2) try using "", I tried using the following commands:

tensorboard --logdir ./
tensorboard --logdir="./"
tensorboard --logdir='./'

The bottom one gave an error in browser displaying nothing, other 2 worked fine. The ./ should be replacable with any folder, I just prefer to go into my folder in terminal on windows, to prevent any path from breaking

3) Have you played around with tensorflow installations, is your tensorboard perhaps not fully compatible with your tensorflow? Have you tried uninstalling every tensorboard / tensorflow package, and installing them again? These are my versions:

tensorboard==1.13.1
tensorflow==1.13.1



回答2:


T.Kelher above supplied the key information to get this working. I am adding this note just to assist others with the same issue:

  1. I completely re-built my anaconda environment running tensorFlow GPU .. several webpages suggested that this can fix the problem I was seeing.

  2. My original code did indeed produce the correct output file .. the error I was seeing was that either tensorBoard was not running, or it was looking in the wrong folder for the log file

  3. One error message from TensorBoard is particularly misleading. The following message seems to be issued not only when there are no log files .. but when tensorboard is not looking in the correct location and, indeed, can't find that location:

    No event files found within logdir '[your named log folder]'

  4. One of the reasons that tensorBoard can't find your folder on Windows is that there is an overloading of syntax. Something like "C:/logfolder" may interpret the "C:" not as a drive letter but as a label for the run. It has been suggested ( https://github.com/tensorflow/tensorflow/issues/7856 ) that you can use "training:c:/logfolder" but I had no success with that.

  5. Finally, following t.Kelher's suggestion I made it work by (a) Running tensorBoard NOT from inside Jupter, but in a terminal window (b) cd'ing into the log folder before starting tensorBoard (c) Using the command:

    tensorboard --logdir=./ --port=6006

(d) Rather than using the URL: http://localhost:6006, using the URL..exactly as displayed by tensorBoard on startup .... http://[my machine name]:6006



来源:https://stackoverflow.com/questions/57046294/why-does-this-code-not-produce-a-log-that-is-readable-by-tensorboard

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