code: def _replace_global_by_local(kwargs):
      if "collections" in kwargs:
          collections = kwargs["collections"]
      if not collections:
          collections = {tfv1.GraphKeys.GLOBAL_VARIABLES}
      else:
          collections = set(collections.copy())
      collections.remove(tfv1.GraphKeys.GLOBAL_VARIABLES)
      collections.add(tfv1.GraphKeys.LOCAL_VARIABLES)
      kwargs["collections"] = list(collections)
  
imports: import operator
  from contextlib import contextmanager
  import tensorflow
  import threading
  from ..compat import tfv1
  from ..tfutils.common import get_tf_version_tuple
  from ..tfutils.scope_utils import cached_name_scope, under_name_scope
  from ..tfutils.varreplace import custom_getter_scope
  from ..utils import logger
  from ..utils.argtools import call_only_once
label_desc: Use image node_id 1 for calling a global function with example usage: _replace_global_by_local(kwargs) without return types