(schedule, run_config, task_manager, options, use_tpu,
                      num_eval_averaging_runs=1, eval_every_steps=-1)
Run the schedule with the given options.

  Available schedules:
  - train: Train up to options["training_steps"], continuing from existing
      checkpoints if available.
  - eval_after_train: First train up to options["training_steps"] then
      evaluate all checkpoints.
  - continuous_eval: Waiting for new checkpoints and evaluate them as they
      become available. This is meant to run in parallel with a job running
      the training schedule but can also run after it.

  Args:
    schedule: Schedule to run. One of: train, continuous_eval, train_and_eval.
    run_config: `tf.contrib.tpu.RunConfig` to use.
    task_manager: `TaskManager` for this run.
    options: Python dictionary will run parameters.
    use_tpu: Boolean whether to use TPU.
    num_eval_averaging_runs: Determines how many times each metric is computed.
    eval_every_steps: Integer determining which checkpoints to evaluate.
Run the schedule with the given options.
Run the schedule with the given options .
def run_with_schedule(schedule, run_config, task_manager, options, use_tpu,
                      num_eval_averaging_runs=1, eval_every_steps=-1):
  """Run the schedule with the given options.

  Available schedules:
  - train: Train up to options["training_steps"], continuing from existing
      checkpoints if available.
  - eval_after_train: First train up to options["training_steps"] then
      evaluate all checkpoints.
  - continuous_eval: Waiting for new checkpoints and evaluate them as they
      become available. This is meant to run in parallel with a job running
      the training schedule but can also run after it.

  Args:
    schedule: Schedule to run. One of: train, continuous_eval, train_and_eval.
    run_config: `tf.contrib.tpu.RunConfig` to use.
    task_manager: `TaskManager` for this run.
    options: Python dictionary will run parameters.
    use_tpu: Boolean whether to use TPU.
    num_eval_averaging_runs: Determines how many times each metric is computed.
    eval_every_steps: Integer determining which checkpoints to evaluate.
  """
  logging.info("Running schedule '%s' with options: %s", schedule, options)
  if run_config.tf_random_seed:
    logging.info("Setting NumPy random seed to %s.", run_config.tf_random_seed)
    np.random.seed(run_config.tf_random_seed)

  result_dir = os.path.join(run_config.model_dir, "result")
  utils.check_folder(result_dir)

  dataset = datasets.get_dataset()
  gan = options["gan_class"](dataset=dataset,
                             parameters=options,
                             model_dir=run_config.model_dir)

  if schedule not in {"train", "eval_after_train", "continuous_eval"}:
    raise ValueError("Schedule {} not supported.".format(schedule))
  if schedule in {"train", "eval_after_train"}:
    train_hooks = [
        gin.tf.GinConfigSaverHook(run_config.model_dir),
        hooks.ReportProgressHook(task_manager,
                                 max_steps=options["training_steps"]),
    ]
    if run_config.save_checkpoints_steps:
      # This replaces the default checkpoint saver hook in the estimator.
      logging.info("Using AsyncCheckpointSaverHook.")
      train_hooks.append(
          hooks.AsyncCheckpointSaverHook(
              checkpoint_dir=run_config.model_dir,
              save_steps=run_config.save_checkpoints_steps))
      # (b/122782388): Remove hotfix.
      run_config = run_config.replace(save_checkpoints_steps=1000000)
    estimator = gan.as_estimator(
        run_config, batch_size=options["batch_size"], use_tpu=use_tpu)
    estimator.train(
        input_fn=gan.input_fn,
        max_steps=options["training_steps"],
        hooks=train_hooks)
    task_manager.mark_training_done()

  if schedule == "continuous_eval":
    # Continuous eval with up to 24 hours between checkpoints.
    checkpoints = task_manager.unevaluated_checkpoints(
        timeout=24 * 3600, eval_every_steps=eval_every_steps)
  if schedule == "eval_after_train":
    checkpoints = task_manager.unevaluated_checkpoints(
        eval_every_steps=eval_every_steps)
  if schedule in {"continuous_eval", "eval_after_train"}:
    _run_eval(
        gan.as_module_spec(),
        checkpoints=checkpoints,
        task_manager=task_manager,
        run_config=run_config,
        use_tpu=use_tpu,
        num_averaging_runs=num_eval_averaging_runs)
def run_with_schedule ( schedule , run_config , task_manager , options , use_tpu , num_eval_averaging_runs = 1 , eval_every_steps = - 1 ) : logging . info ( "Running schedule '%s' with options: %s" , schedule , options ) if run_config . tf_random_seed : logging . info ( "Setting NumPy random seed to %s." , run_config . tf_random_seed ) np . random . seed ( run_config . tf_random_seed ) result_dir = os . path . join ( run_config . model_dir , "result" ) utils . check_folder ( result_dir ) dataset = datasets . get_dataset ( ) gan = options [ "gan_class" ] ( dataset = dataset , parameters = options , model_dir = run_config . model_dir ) if schedule not in { "train" , "eval_after_train" , "continuous_eval" } : raise ValueError ( "Schedule {} not supported." . format ( schedule ) ) if schedule in { "train" , "eval_after_train" } : train_hooks = [ gin . tf . GinConfigSaverHook ( run_config . model_dir ) , hooks . ReportProgressHook ( task_manager , max_steps = options [ "training_steps" ] ) , ] if run_config . save_checkpoints_steps : # This replaces the default checkpoint saver hook in the estimator. logging . info ( "Using AsyncCheckpointSaverHook." ) train_hooks . append ( hooks . AsyncCheckpointSaverHook ( checkpoint_dir = run_config . model_dir , save_steps = run_config . save_checkpoints_steps ) ) # (b/122782388): Remove hotfix. run_config = run_config . replace ( save_checkpoints_steps = 1000000 ) estimator = gan . as_estimator ( run_config , batch_size = options [ "batch_size" ] , use_tpu = use_tpu ) estimator . train ( input_fn = gan . input_fn , max_steps = options [ "training_steps" ] , hooks = train_hooks ) task_manager . mark_training_done ( ) if schedule == "continuous_eval" : # Continuous eval with up to 24 hours between checkpoints. checkpoints = task_manager . unevaluated_checkpoints ( timeout = 24 * 3600 , eval_every_steps = eval_every_steps ) if schedule == "eval_after_train" : checkpoints = task_manager . unevaluated_checkpoints ( eval_every_steps = eval_every_steps ) if schedule in { "continuous_eval" , "eval_after_train" } : _run_eval ( gan . as_module_spec ( ) , checkpoints = checkpoints , task_manager = task_manager , run_config = run_config , use_tpu = use_tpu , num_averaging_runs = num_eval_averaging_runs )