def init_from_checkpoint(checkpoint_path,
                         checkpoint_prefix=None,
                         variable_prefix=None,
                         target_variables=None):
  """Initializes all of the variables using `init_checkpoint."""
  tf.logging.info("Loading variables from %s", checkpoint_path)
  checkpoint_variables = {
      name: name for name, _ in tf.train.list_variables(checkpoint_path)
  }
  if target_variables is None:
    target_variables = tf.trainable_variables()
  target_variables = {var.name.split(":")[0]: var for var in target_variables}

  if checkpoint_prefix is not None:
    checkpoint_variables = {
        checkpoint_prefix + "/" + name: varname
        for name, varname in checkpoint_variables.items()
    }
  if variable_prefix is not None:
    target_variables = {
        variable_prefix + "/" + name: var
        for name, var in target_variables.items()
    }

  checkpoint_var_names = set(checkpoint_variables.keys())
  target_var_names = set(target_variables.keys())
  intersected_var_names = target_var_names & checkpoint_var_names
  assignment_map = {
      checkpoint_variables[name]: target_variables[name]
      for name in intersected_var_names
  }
  tf.train.init_from_checkpoint(checkpoint_path, assignment_map)

  log_variables("Loaded variables", intersected_var_names)
  log_variables("Uninitialized variables",
                target_var_names - checkpoint_var_names)
  log_variables("Unused variables", checkpoint_var_names - target_var_names)
Initializes all of the variables using `init_checkpoint.
language/labs/drkit/search_utils.py