Beispiel #1
0
def setup_eval_dir(logdir, config_timeout_seconds=1):
  """Setups directory for evaluation."""
  tf.io.gfile.makedirs(logdir)
  tf.io.gfile.makedirs(os.path.join(logdir, 'eval_logs'))
  config_path = os.path.join(logdir, 'config.yml')
  while not tf.io.gfile.exists(config_path):
    logging.info('Waiting for config to exist. Going to sleep '
                 ' %s for  secs.', config_timeout_seconds)
    time.sleep(config_timeout_seconds)

  while True:
    with tf.io.gfile.GFile(config_path, 'r') as config_file:
      config_dict = yaml.safe_load(config_file)
    if config_dict is None:
      time.sleep(config_timeout_seconds)
    else:
      break
  CONFIG.update(config_dict)
Beispiel #2
0
def setup_train_dir(logdir):
  """Setups directory for training."""
  tf.io.gfile.makedirs(logdir)
  config_path = os.path.join(logdir, 'config.yml')
  if not os.path.exists(config_path):
    logging.info(
        'Using config from config.py as no config.yml file exists in '
        '%s', logdir)
    with  tf.io.gfile.GFile(config_path, 'w') as config_file:
      config = dict([(k, to_dict(v)) for k, v in CONFIG.items()])
      yaml.safe_dump(config, config_file, default_flow_style=False)
  else:
    logging.info('Using config from config.yml that exists in %s.', logdir)
    with tf.io.gfile.GFile(config_path, 'r') as config_file:
      config_dict = yaml.safe_load(config_file)
    CONFIG.update(config_dict)

  train_logs_dir = os.path.join(logdir, 'train_logs')
  if os.path.exists(train_logs_dir) and not FLAGS.force_train:
    raise ValueError('You might be overwriting a directory that already '
                     'has train_logs. Please provide a new logdir name in '
                     'config or pass --force_train while launching script.')
  tf.io.gfile.makedirs(train_logs_dir)