tenSorboard1.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # The following switch allows the program runs locally and in the Agit environment without modifications.
  2. import os
  3. path = os.path.dirname(__file__)
  4. print(path)
  5. if 'CLOUD_PROVIDER' in os.environ and os.environ['CLOUD_PROVIDER'] == 'Agit':
  6. logdir = '/root/.agit'
  7. else:
  8. logdir = './runs'
  9. # setup tensorboard path
  10. import tensorflow as tf
  11. writer = tf.summary.create_file_writer(logdir)
  12. ''' alternative tensorboards
  13. # pytorch tensorboard :
  14. from torch.utils.tensorboard import SummaryWriter
  15. writer = SummaryWriter(log_dir=logdir)
  16. # tensorboardX :
  17. from tensorboardX import SummaryWriter
  18. writer = SummaryWriter(logdir=logdir)
  19. '''
  20. import numpy as np
  21. import time
  22. # a 5 minutes running example, the realtime tensorboard can be viewed in the training page
  23. with writer.as_default():
  24. for n_iter in range(360):
  25. tf.summary.scalar('Loss/train', np.random.random(), n_iter)
  26. tf.summary.scalar('Loss/test', np.random.random(), n_iter)
  27. tf.summary.scalar('Accuracy/train', np.random.random(), n_iter)
  28. tf.summary.scalar('Accuracy/test', np.random.random(), n_iter)
  29. time.sleep(1)