Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Tensorboard from python scipt in virtualenv?

Tensorboard should be started from commnad line like that:

tensorboard --logdir=path

I need to run it from code. Until now I use this:

import os
os.system('tensorboard --logdir=' + path)

However tensorboard do not start because is not included in the system path. I use PyCharm with virtualenv on windows. I don't want to change system paths so the only option is to run it from virtualenv. How to do this?

like image 596
Na Na Avatar asked Sep 02 '25 05:09

Na Na


2 Answers

Using Tensorboard 2 API (2019):

from tensorboard import program

tracking_address = log_path # the path of your log file.

if __name__ == "__main__":
    tb = program.TensorBoard()
    tb.configure(argv=[None, '--logdir', tracking_address])
    url = tb.launch()
    print(f"Tensorflow listening on {url}")

Note: tb.launch() create a daemon thread that will die automatically when your process is finished

like image 164
Daniel Braun Avatar answered Sep 04 '25 19:09

Daniel Braun


Probably a bit late for an answer, but this is what worked for me in Python 3.6.2:

import tensorflow as tf
from tensorboard import main as tb
tf.flags.FLAGS.logdir = "/path/to/graphs/"
tb.main()

That runs tensorboard with the default configuration and looks for graphs and summaries in "/path/to/graphs/". You can of course change the log directory and set as many variables as you like using:

tf.flags.FLAGS.variable = value

Hope it helps.

like image 31
Rive Avatar answered Sep 04 '25 20:09

Rive