How to "reset" tensorboard data after killing tensorflow instance

TensorflowTensorboard

Tensorflow Problem Overview


I'm testing different hyperparameters for a cnn model I built, but I'm having a small annoyance when viewing the summaries in Tensorboard. The problem seems to be that the data is just "added" in consecutive runs, so the functions result in a weird superposition unless I see the information as "relative" instead of "by step". See here:

X Type: Step

X Type: Relative

I've tried killing tensorboard's process and erasing the log files, but it seems it is not enough.

So the question is, how do I reset this information?

Thanks!!

Tensorflow Solutions


Solution 1 - Tensorflow

Note: The solution you've posted (erase TensorBoard's log files and kill the process) will work, but it isn't preferred, because it destroys historical information about your training.

Instead, you can have each new training job write to a new subdirectory (of your top-level log directory). Then, TensorBoard will consider each job a new "run" and will create a nice comparison view so you can see how the training differed between iterations of your model.

In the following an example from https://www.tensorflow.org/tensorboard/get_started:

model = create_model()
...
model.compile(...)

log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)

model.fit(..., callbacks=[tensorboard_callback])

Solution 2 - Tensorflow

Yes, I believe ultimately this aspect is positive.
As an example, in my script I automate new run logs via datetime:

from datetime import datetime
now = datetime.now()
logdir = "tf_logs/.../" + now.strftime("%Y%m%d-%H%M%S") + "/"

Then when running TensorBoard you can click the different runs on and off provided you ran TensorBoard in the parent directory.

If you know you don't care about a previous run and want it out of your life, then yes, you need to remove the event files and restart TensorBoard.

Solution 3 - Tensorflow

Ok, for some reason it didn't work before but now it did:

You must erase Tensorboard's log files AND kill its process

After killing the process run fuser 6006/tcp -k to free port 6006 (if you're in linux) and fire tensorboard again.

Solution 4 - Tensorflow

I had a similar problem, but with a duplication of computational graphs: they've just added in tensorboard when I called

writer.add_graph(graph=sess.graph)

In my case, it wasn't about log files but about Jupyter Notebook context.

I figured out that after multiple runs of a Jupyter cell with a Graph definition the graph hasn't been reset but appeared in the context as a duplicate, so I added

tf.reset_default_graph()

before the start of building a computational graph.

Hope it will help.

Solution 5 - Tensorflow

I just figured out the solution to this problem. Just put each Events.out file in a separate folder inside your log directory. And you will get a nice visualization in tensorboard with each run in a different color.

Solution 6 - Tensorflow

Add the following snippet to your code and it should automatically reset your tensorboard.

if tf.gfile.Exists(dirpath):
   tf.gfile.DeleteRecursively(dirpath) 

This will delete the previous logs.

Solution 7 - Tensorflow

Had a similar issue, which threw an error: 'You must feed a value for placeholder tensor 'dense_input' with dtype float and shape'. This specific issue was discussed here. The suggestion that worked for me used:

from keras.backend import clear_session
# Before instantiating a tf.data.Dataset obj & before model creation, call:
clear_session()

Also make sure you're using unique names for each model's TensorBoard log_dir. Then to view all models, run TensorBoard from terminal at the parent dir of the logs files, I.e.:

tensorboard --logdir <projDir>/logs/tf_log

Solution 8 - Tensorflow

This automatically deletes the log directory.

import shutil

shutil.rmtree('log_dir', ignore_errors=True)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmathetesView Question on Stackoverflow
Solution 1 - TensorflowdandelionView Answer on Stackoverflow
Solution 2 - TensorflowSuaveSourisView Answer on Stackoverflow
Solution 3 - TensorflowmathetesView Answer on Stackoverflow
Solution 4 - TensorflowStanislav TsepaView Answer on Stackoverflow
Solution 5 - TensorflowAbdo EldesokeyView Answer on Stackoverflow
Solution 6 - TensorflowPrakash VanapalliView Answer on Stackoverflow
Solution 7 - TensorflowCubeBot88View Answer on Stackoverflow
Solution 8 - Tensorflowuser2386301View Answer on Stackoverflow