def get_model_checkpoint(model_dir):
  """Select a checkpoint to use for a given model directory.

  Args:
    model_dir: the directory containing the target model
  Raises:
    ValueError: if there was a problem locating the checkpoint
  Returns:
    This method the "best-checkpoint" checkpoint as exported by
     `BestCheckpointExporter` if present, else the latest checkpoint
  """
  best_dir = os.path.join(model_dir, "export", "best-checkpoint")
  if tf.gfile.Exists(best_dir):
    best_dir_files = tf.gfile.ListDirectory(best_dir)
    if best_dir_files:
      tf.logging.info("Found best export, restoring from there")
      checkpoint_path = None
      for filename in tf.gfile.ListDirectory(best_dir):
        if filename.endswith(".index"):
          checkpoint_path = filename[:-len(".index")]
          break

      if checkpoint_path is None:
        raise ValueError("Unable to find checkpoint in " + best_dir)

      return os.path.join(best_dir, checkpoint_path)

  tf.logging.info("No best export found, restoring most recent")
  return tf.train.latest_checkpoint(model_dir)
Select a checkpoint to use for a given model directory.

  Args:
    model_dir: the directory containing the target model
  Raises:
    ValueError: if there was a problem locating the checkpoint
  Returns:
    This method the "best-checkpoint" checkpoint as exported by
     `BestCheckpointExporter` if present, else the latest checkpoint
  
language/boolq/utils/py_utils.py