def main(unused_argv):
  if FLAGS.checkpoint is None or not FLAGS.checkpoint:
    raise ValueError(
        'Need to provide a path to checkpoint directory.')
  wmodel = lib_graph.load_checkpoint(FLAGS.checkpoint)
  if FLAGS.eval_logdir is None:
    raise ValueError(
        'Set flag eval_logdir to specify a path for saving eval statistics.')
  else:
    eval_logdir = os.path.join(FLAGS.eval_logdir, 'eval_stats')
    tf.gfile.MakeDirs(eval_logdir)

  evaluator = lib_evaluation.BaseEvaluator.make(
      FLAGS.unit, wmodel=wmodel, chronological=FLAGS.chronological)
  evaluator = lib_evaluation.EnsemblingEvaluator(evaluator, FLAGS.ensemble_size)

  if not FLAGS.sample_npy_path and FLAGS.fold is None:
    raise ValueError(
        'Either --fold must be specified, or paths of npy files to load must '
        'be given, but not both.')
  if FLAGS.fold is not None:
    evaluate_fold(FLAGS.fold, evaluator, wmodel.hparams, eval_logdir)
  if FLAGS.sample_npy_path is not None:
    evaluate_paths([FLAGS.sample_npy_path], evaluator, wmodel.hparams,
                   eval_logdir)
  print('Done')
def main(ckpt, evaldir, unit, chronological, ensemble_size, sample_path,
         folder, index, data_dir):
    checkpoint_dir = ckpt
    if not checkpoint_dir:
        # If a checkpoint directory is not specified, see if there is only one
        # subdir in this folder and use that.
        possible_checkpoint_dirs = tf.gfile.ListDirectory(evaldir)
        possible_checkpoint_dirs = [
            i for i in possible_checkpoint_dirs
            if tf.gfile.IsDirectory(os.path.join(evaldir, i))
        ]
        if EVAL_SUBDIR in possible_checkpoint_dirs:
            possible_checkpoint_dirs.remove(EVAL_SUBDIR)
        if len(possible_checkpoint_dirs) == 1:
            checkpoint_dir = os.path.join(evaldir, possible_checkpoint_dirs[0])
            tf.logging.info('Using checkpoint dir: %s', checkpoint_dir)
        else:
            raise ValueError(
                'Need to provide a path to checkpoint directory or use an '
                'eval_logdir with only 1 checkpoint subdirectory.')
    wmodel = lib_graph.load_checkpoint(checkpoint_dir)
    if evaldir is None:
        raise ValueError(
            'Set flag eval_logdir to specify a path for saving eval statistics.'
        )
    else:
        eval_logdir = os.path.join(evaldir, EVAL_SUBDIR)
        tf.gfile.MakeDirs(eval_logdir)

    evaluator = lib_evaluation.BaseEvaluator.make(unit,
                                                  wmodel=wmodel,
                                                  chronological=chronological)
    evaluator = lib_evaluation.EnsemblingEvaluator(evaluator, ensemble_size)

    if not sample_path and folder is None:
        raise ValueError(
            'Either --fold must be specified, or paths of npy files to load must '
            'be given, but not both.')
    if folder is not None:
        evaluate_fold(folder, evaluator, wmodel.hparams, eval_logdir,
                      checkpoint_dir, index, unit, ensemble_size,
                      chronological, data_dir)
    if sample_path is not None:
        evaluate_paths([sample_path], evaluator, wmodel.hparams, eval_logdir,
                       unit, ensemble_size, chronological)
    tf.logging.info('Done')