code: def reachable_nodes(*nodes):
      """
      Find all nodes reachable from `nodes` in the implicit tf.Graph
      to which they belong.
  
      Both tensors and their underlying operation is returned.
      """
  
      nodes = flatten(nodes)
      reachable = set(nodes)
      queue = list(nodes)
  
      while queue:
          node = queue.pop(0)
  
          if isinstance(node, tf.Tensor):
              subnode = node.op
              if subnode not in reachable:
                  reachable.add(subnode)
                  queue.append(subnode)
              continue
  
          if isinstance(node, tf.Operation):
              for subnode in list(node.inputs) + list(
                  node.control_inputs
              ):
                  if subnode not in reachable:
                      reachable.add(subnode)
                      queue.append(subnode)
              continue
  
          raise TypeError(
              "Don't know how to process {} of type {}".format(
                  node, type(node)
              )
          )
  
      return reachable
  
imports: import tensorflow
label_desc: Use image node_id 2 for calling a global function with example usage: reachable_nodes() and returns: reachable