code: def global_vars_init_or_restore(var_list=None):
      """
      For any scope added to RESTORABLE collection:
      variable will be restored from a checkpoint if it exists in the
      specified checkpoint and no scope ancestor can restore it.
      """
      if var_list is None:
          var_list = tf.global_variables()
      restorable = sorted(
          tf.get_collection(RESTORABLE), key=lambda x: x[0]
      )
      restored_vars = {}
      for scope, checkpoint_name, checkpoint_scope in restorable:
          variables_in_scope = tf.get_collection(
              tf.GraphKeys.GLOBAL_VARIABLES, scope=scope
          )
          checkpoint_file = resolve_checkpoint(checkpoint_name)
          variables_in_file = [
              v for (v, _) in list_variables(checkpoint_file)
          ]
          rename = lambda x: x.replace(scope, checkpoint_scope).replace(
              ":0", ""
          )
          to_restore = [
              v
              for v in variables_in_scope
              if v in var_list and rename(v.name) in variables_in_file
          ]
          for var in to_restore:
              if var in restored_vars:
                  continue
              if "/" in rename(var.name):
                  checkpoint_subscope, var_name = rename(
                      var.name
                  ).rsplit("/", 1)
              else:
                  checkpoint_subscope, var_name = None, rename(var.name)
              initializer = restore_initializer(
                  checkpoint_name, var_name, checkpoint_subscope
              )
              restored_vars[var] = tf.assign(
                  var, initializer(var.shape, dtype=var.dtype)
              )
      init_others = tf.variables_initializer(
          [v for v in var_list if v not in restored_vars]
      )
      restore_op = tf.group(init_others, *list(restored_vars.values()))
      return restore_op
  
imports: from __future__ import absolute_import, print_function
  import tensorflow
  from tensorflow.contrib.framework import list_variables
  from niftynet.io.misc_io import image3_axial, image3_coronal, image3_sagittal, resolve_checkpoint
  from niftynet.utilities import util_common
  from niftynet.utilities.restore_initializer import restore_initializer
label_desc: Use image node_id 1 for calling a global function with example usage: global_vars_init_or_restore(var_list) and returns: restore_op