3

I am using tensorflow on windows and I know that I can run tensorboard manually:

  1. Open an anaconda prompt
  2. Activate the tensorflow environment
  3. Enter the Log directory of the logdir of my tensorflow running in the anaconda prompt
  4. Enter the command ‘tensorboard –logdir=mylogdir’
  5. Open google chrome then enter http://localhost:6006/

I hope to run these 5 steps automatically and hope tensorboard run together when I am traning the model so that I can monitor the training process. I can add the following system call before entering the training process

os.system('C:/CodingSoftware/Anaconda3_py3.5/envs/tensorflow-gpu/python -m tensorflow.tensorboard --logdir='+tf_log_dir)

However the code stop at showing "Starting TensorBoard b'47' at http://0.0.0.0:6006"

Thank you Ayushya below. With your first method, it does not run in parallel. If I start P1 first, it still requires Press CTRL+C before entering the rest of the code

log_dir='E:/PythonCode/BayesianLinearStrategy/LOG'
p1 = Process(target=startTensorboard(log_dir))
p1.start()
p2 = Process(target=RunTFCode)
p2.start()
Ayushya
  • 9,599
  • 6
  • 41
  • 57
hadesmajesty
  • 51
  • 2
  • 6
  • It will stop showing because you've only asked it to start the server and not open the web browser to access the Tensorboard server. You'd need to also open chrome and navigate to localhost. You've kind of answered your own question with your manual steps. – JCooke Jul 03 '17 at 09:29

1 Answers1

1

I believe that you are trying to run tensorboard in parallel with training.

You could use threading or multiprocessing. Here is a modified example from source:

from multiprocessing import Process

def startTensorboard(tf_log_dir):
  os.system('C:/CodingSoftware/Anaconda3_py3.5/envs/tensorflow-gpu/python -m tensorflow.tensorboard --logdir='+tf_log_dir)

if __name__ == '__main__':
  log_dir='E:/PythonCode/BayesianLinearStrategy/LOG'
  p1 = Process(target=startTensorboard(log_dir)) 
  p2 = Process(target=RunTFCode) 
  p1.start()
  p2.start() 
  p1.join() 
  p2.join()
  ...rest of your code

OR

You can use create a bash script which executes those steps you specified in question and simultaneously start the training session. You can run two commands using:

prog1 & prog2 && fg

This will:

  1. Start prog1.
  2. Send it to background, but keep printing its output.
  3. Start prog2, and keep it in foreground, so you can close it with ctrl-c.
  4. When you close prog2, you'll return to prog1's foreground, so you can also close it with ctrl-c.

Edit: Modified python code by adding p1.join() and p2.join().

Ayushya
  • 9,599
  • 6
  • 41
  • 57
  • 1
    if __name__ == '__main__': log_dir='E:/PythonCode/BayesianLinearStrategy/LOG' p1 = Process(target=startTensorboard(log_dir)) p1.start() p2 = Process(target=RunTFCode) p2.start() p1.join() p2.join() – hadesmajesty Jul 04 '17 at 03:25
  • @hadesmajesty I have updated the answer by including the corrections you pointed out. – Ayushya Jul 04 '17 at 03:51
  • Thank you Ayushya. With your first method, it does not run in parallel. If I start P1 first, it still requires Press CTRL+C before entering the rest of the code – hadesmajesty Jul 04 '17 at 05:05
  • I guess we should avoid using join here. An answer at https://stackoverflow.com/a/25391156/6207775 says that join is used to mean "wait for this [thread/process] to complete" which we do not want. – Ayushya Jul 04 '17 at 05:18
  • @hadesmajesty Do let us know if you get this working. – Ayushya Jul 04 '17 at 17:35