parameters: (make_metrics, hparams, make_hooks=None, eval_dir=None)
docstring: Evaluate a general model.
  
    Args:
      make_metrics: Function returning a list of `(accuracies, updates)` pairs
        as produced by the metrics module (see `sigmoid_eval` for examples).
      hparams: Hyperparameters.
      make_hooks: Optional, function to create additional hooks.
      eval_dir: Optional string for the directory where the evaluation results
                should be written to.
  
    Raises:
      ValueError: If flags are missing or invalid.
docstring_summary: Evaluate a general model.
docstring_tokens: Evaluate a general model .
function: def general_eval(make_metrics, hparams, make_hooks=None, eval_dir=None):
    """Evaluate a general model.
  
    Args:
      make_metrics: Function returning a list of `(accuracies, updates)` pairs
        as produced by the metrics module (see `sigmoid_eval` for examples).
      hparams: Hyperparameters.
      make_hooks: Optional, function to create additional hooks.
      eval_dir: Optional string for the directory where the evaluation results
                should be written to.
  
    Raises:
      ValueError: If flags are missing or invalid.
    """
    if hparams.use_averages:
      raise NotImplementedError('Figure out how to eval with Polyak averaging')
    train_dir = mode_dir('train')
    if eval_dir is None:
      eval_dir = mode_dir('eval')
  
    if not tf.gfile.Exists(eval_dir):
      tf.gfile.MakeDirs(eval_dir)
    if hparams.seed:
      tf.set_random_seed(hparams.seed)
    num_evals = (hparams.eval_examples - 1) // hparams.eval_batch_size + 1
  
    # Configure keras
    keras.backend.set_learning_phase(0)
    keras.backend.manual_variable_initialization(True)
  
    hooks = [
        training.StopAfterNEvalsHook(num_evals),
        training.SummaryAtEndHook(
            log_dir=eval_dir, summary_op=tf.summary.merge_all())
    ]
  
    with tf.device(tf.train.replica_device_setter(FLAGS.ps_tasks,
                                                  merge_devices=True)):
      # Generate metrics
      with tf.variable_scope(tf.get_variable_scope()):
        metric_ops = make_metrics()
  
      # Evaluate
      accuracies, updates = zip(*metric_ops)
  
      if make_hooks is not None:
        with tf.variable_scope(tf.get_variable_scope(), reuse=True):
          hooks.extend(make_hooks())
  
      training.evaluate_repeatedly(
          checkpoint_dir=train_dir,
          master=FLAGS.super_master,
          eval_ops=updates,
          final_ops=accuracies,
          eval_interval_secs=FLAGS.eval_interval_secs,
          hooks=hooks,
          max_number_of_evaluations=hparams.max_evals)
function_tokens: def general_eval ( make_metrics , hparams , make_hooks = None , eval_dir = None ) : if hparams . use_averages : raise NotImplementedError ( 'Figure out how to eval with Polyak averaging' ) train_dir = mode_dir ( 'train' ) if eval_dir is None : eval_dir = mode_dir ( 'eval' ) if not tf . gfile . Exists ( eval_dir ) : tf . gfile . MakeDirs ( eval_dir ) if hparams . seed : tf . set_random_seed ( hparams . seed ) num_evals = ( hparams . eval_examples - 1 ) // hparams . eval_batch_size + 1 # Configure keras keras . backend . set_learning_phase ( 0 ) keras . backend . manual_variable_initialization ( True ) hooks = [ training . StopAfterNEvalsHook ( num_evals ) , training . SummaryAtEndHook ( log_dir = eval_dir , summary_op = tf . summary . merge_all ( ) ) ] with tf . device ( tf . train . replica_device_setter ( FLAGS . ps_tasks , merge_devices = True ) ) : # Generate metrics with tf . variable_scope ( tf . get_variable_scope ( ) ) : metric_ops = make_metrics ( ) # Evaluate accuracies , updates = zip ( * metric_ops ) if make_hooks is not None : with tf . variable_scope ( tf . get_variable_scope ( ) , reuse = True ) : hooks . extend ( make_hooks ( ) ) training . evaluate_repeatedly ( checkpoint_dir = train_dir , master = FLAGS . super_master , eval_ops = updates , final_ops = accuracies , eval_interval_secs = FLAGS . eval_interval_secs , hooks = hooks , max_number_of_evaluations = hparams . max_evals )