code: def strip_unused(
      input_graph_def,
      input_tensor_names,
      output_tensor_names,
      placeholder_type_enum,
  ):
      """Removes unused nodes from a GraphDef.
  
      Args:
        input_graph_def: A graph with nodes we want to prune.
        input_tensor_names: A list of the nodes we use as inputs.
        output_tensor_names: A list of the output nodes.
        placeholder_type_enum: The AttrValue enum for the placeholder data type, or
            a list that specifies one value per input node name.
  
      Returns:
        A `GraphDef` with all unnecessary ops removed. and a map containing the old input
        names to the new input names
  
      Raises:
        ValueError: If any element in `input_node_names` refers to a tensor instead
          of an operation.
        KeyError: If any element in `input_node_names` is not found in the graph.
      """
  
      from tensorflow.core.framework import attr_value_pb2
      from tensorflow.core.framework import graph_pb2
      from tensorflow.core.framework import node_def_pb2
  
      for name in input_tensor_names:
          if ":" not in name:
              invalidInputError(
                  False,
                  "Input '%s' appears to refer to a Operation,"
                  " not a Tensor." % name,
              )
  
      old2new = {}
  
      # Here we replace the nodes we're going to override as inputs with
      # placeholders so that any unused nodes that are inputs to them are
      # automatically stripped out by extract_sub_graph().
      not_found = {name for name in input_tensor_names}
      input_node_names = {
          name.split(":")[0] for name in input_tensor_names
      }
      output_node_names = list(
          {name.split(":")[0] for name in output_tensor_names}
      )
      inputs_replaced_graph_def = graph_pb2.GraphDef()
      for node in input_graph_def.node:
          if node.name not in input_node_names:
              for i in range(len(node.input)):
                  if _append_port(node.input[i]) in input_tensor_names:
                      old_name = _append_port(node.input[i])
                      not_found.remove(old_name)
                      new_input_name = node.input[i].replace(":", "_")
                      placeholder_node = node_def_pb2.NodeDef()
                      placeholder_node.op = "Placeholder"
                      placeholder_node.name = new_input_name
                      if isinstance(placeholder_type_enum, list):
                          input_node_index = input_tensor_names.index(
                              old_name
                          )
                          placeholder_node.attr["dtype"].CopyFrom(
                              attr_value_pb2.AttrValue(
                                  type=placeholder_type_enum[
                                      input_node_index
                                  ]
                              )
                          )
                      else:
                          placeholder_node.attr["dtype"].CopyFrom(
                              attr_value_pb2.AttrValue(
                                  type=placeholder_type_enum
                              )
                          )
                      if "_output_shapes" in node.attr:
                          placeholder_node.attr[
                              "_output_shapes"
                          ].CopyFrom(node.attr["_output_shapes"])
                      node.input[i] = new_input_name
                      old2new[old_name] = new_input_name + ":0"
                      inputs_replaced_graph_def.node.extend(
                          [placeholder_node]
                      )
              inputs_replaced_graph_def.node.extend(
                  [copy.deepcopy(node)]
              )
  
      if not_found:
          invalidInputError(
              False,
              "The following input nodes were not found: %s\n"
              % not_found,
          )
      import bigdl.dllib.utils.tf_graph_util as graph_util
  
      output_graph_def = graph_util.extract_sub_graph(
          inputs_replaced_graph_def, output_node_names
      )
      return output_graph_def, old2new
  
file_path: BigDL/python/dllib/src/bigdl/dllib/utils/tf.py
imports: import os
  import json
  import copy
  import tempfile
  import re
  import shutil
  from bigdl.dllib.utils.file_utils import put_local_file_to_remote, get_remote_file_to_local, get_file_list, is_local_path
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 6 for calling a global function with example usage: strip_unused(input_graph_def, input_tensor_names, output_tensor_names, placeholder_type_enum) and returns: output_graph_def,  old2new