code: def auto_reuse_variable_scope(func):
      """
      A decorator which automatically reuses the current variable scope if the
      function has been called with the same variable scope before.
  
      Example:
  
      .. code-block:: python
  
          @auto_reuse_variable_scope
          def myfunc(x):
              return tf.layers.conv2d(x, 128, 3)
  
          myfunc(x1)  # will inherit parent scope reuse
          myfunc(x2)  # will reuse
          with tf.variable_scope('newscope'):
              myfunc(x3)  # will inherit parent scope reuse
              myfunc(x4)  # will reuse
      """
      used_scope = set()
  
      @functools.wraps(func)
      def wrapper(*args, **kwargs):
          scope = tf.get_variable_scope()
          h = hash((tf.get_default_graph(), scope.name))
          # print("Entering " + scope.name + " reuse: " + str(h in used_scope))
          if h in used_scope:
              if get_tf_version_tuple() >= (1, 5):
                  with tf.variable_scope(
                      scope, reuse=True, auxiliary_name_scope=False
                  ):
                      return func(*args, **kwargs)
              else:
                  ns = tf.get_default_graph().get_name_scope()
                  with tf.variable_scope(
                      scope, reuse=True
                  ), tf.name_scope(ns + "/" if ns else ""):
                      return func(*args, **kwargs)
          else:
              used_scope.add(h)
              return func(*args, **kwargs)
  
      return wrapper
  
file_path: tensorpack/tensorpack/tfutils/scope_utils.py
imports: import functools
  from contextlib import contextmanager
  from ..compat import tfv1
  from ..utils.argtools import graph_memoized
  from ..utils import logger
  from .common import get_tf_version_tuple
label_desc: Use image node_id 1 for calling a global function with example usage: auto_reuse_variable_scope(func) and returns: wrapper, func, func, func