code: def assign_from_checkpoint_fn(
      model_path,
      var_list,
      ignore_missing_vars=False,
      reshape_variables=False,
  ):
      """Returns a function that assigns specific variables from a checkpoint.
  
      If ignore_missing_vars is True and no variables are found in the checkpoint
      it returns None.
  
      Args:
        model_path: The full path to the model checkpoint. To get latest checkpoint
          use `model_path = tf.train.latest_checkpoint(checkpoint_dir)`
        var_list: A list of `Variable` objects or a dictionary mapping names in the
          checkpoint to the corresponding variables to initialize. If empty or
          `None`, it would return `no_op(), None`.
        ignore_missing_vars: Boolean, if True it would ignore variables missing in
          the checkpoint with a warning instead of failing.
        reshape_variables: Boolean, if True it would automatically reshape variables
          which are of different shape then the ones stored in the checkpoint but
          which have the same number of elements.
  
      Returns:
        A function that takes a single argument, a `tf.compat.v1.Session`, that
        applies the
        assignment operation. If no matching variables were found in the checkpoint
        then `None` is returned.
  
      Raises:
        ValueError: If var_list is empty.
      """
      if not var_list:
          raise ValueError("var_list cannot be empty")
      if ignore_missing_vars:
          reader = pywrap_tensorflow.NewCheckpointReader(model_path)
          if isinstance(var_list, dict):
              var_dict = var_list
          else:
              var_dict = {var.op.name: var for var in var_list}
          available_vars = {}
          for var in var_dict:
              if reader.has_tensor(var):
                  available_vars[var] = var_dict[var]
              else:
                  logging.warning(
                      "Variable %s missing in checkpoint %s",
                      var,
                      model_path,
                  )
          var_list = available_vars
      if var_list:
          saver = tf_saver.Saver(
              var_list,
              reshape=reshape_variables,
              write_version=saver_pb2.SaverDef.V1,
          )
  
          def callback(session):
              saver.restore(session, model_path)
  
          return callback
      else:
          logging.warning("No Variables to restore")
          return None
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import re
  from .arg_scope import add_arg_scope
  from tensorflow.core.protobuf import saver_pb2
  from tensorflow.python import pywrap_tensorflow
  from tensorflow.python.framework import device
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import resource_loader
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.training import saver
  from tensorflow.python.training import training_util
  from tensorflow.python.util.deprecation import deprecated
label_desc: Use image node_id 23 for calling a global function with example usage: assign_from_checkpoint_fn(model_path, var_list, ignore_missing_vars, reshape_variables) and returns: callback, None