code: def convert_placeholder_to_const(
      input_graph_def, nodes_to_convert=None
  ):
      """Rename the PlaceHolderWithDefault node to constant
  
      In a frozen graph, PlaceholderWithDefault nodes can be converted to
      Constant op nodes with same value. This will help simplify the graph.
  
      Args:
        input_graph_def: A GraphDef containing a model.
        nodes_to_convert: A list of PlaceholderWithDefault or Placeholder nodes to
          be converted to Constants with their new value.
  
      Returns:
        modified graph with PlaceholderWithDefault node converted to Constant node
      """
  
      input_node_map = {}
      for node in input_graph_def.node:
          if node.name not in input_node_map:
              input_node_map[node.name] = node
          else:
              raise ValueError(
                  "Duplicate node names detected for ", node.name
              )
  
      # create a dictionary of nodes to be converted to Const
      dict_to_change = {}
      for key in PLACEHOLDER_WITH_DEFAULT_LIST:
          dict_to_change[key] = PLACEHOLDER_WITH_DEFAULT_LIST[key]
  
      if nodes_to_convert is not None and len(nodes_to_convert) > 0:
          dict_list = parse_nodes_dict(nodes_to_convert)
          dict_to_change.update(dict_list)
  
      ph_node_list = []
      for ph_node in dict_to_change:
          if not ph_node and ph_node not in input_node_map:
              continue
          ph_node_list.append(ph_node)
  
      # if no nodes found, then nothing to change
      if not ph_node_list:
          tf_logging.warning(
              "No PlaceholderWithDefault nodes found to convert to "
              "Constant. Maybe check the spellings"
          )
          return input_graph_def
  
      result_graph_def = graph_pb2.GraphDef()
      for node in input_graph_def.node:
          is_replaced = False
          new_node = node_def_pb2.NodeDef()
          if (
              node.op == "PlaceholderWithDefault"
              or node.op == "Placeholder"
          ):
              match_key = [
                  find_key
                  for find_key in dict_to_change.keys()
                  if find_key in node.name
              ]
              if len(match_key) > 0:
                  if (
                      dtypes.bool.as_datatype_enum
                      == node.attr["dtype"].type
                  ):
                      new_val_str = dict_to_change[match_key[0]]
                      new_node.op = "Const"
                      new_node.name = node.name
                      new_node.attr["dtype"].CopyFrom(
                          node.attr["dtype"]
                      )
                      new_node.attr["value"].CopyFrom(
                          attr_value_pb2.AttrValue(
                              tensor=tensor_util.make_tensor_proto(
                                  strtobool(new_val_str),
                                  dtype=dtypes.bool,
                                  shape=[],
                              )
                          )
                      )
                      is_replaced = True
                  else:
                      tf_logging.warning(
                          "Not converting to Const. Currently only bool            "
                          " PlaceholderWithDefault or Placeholder can be converted to"
                          " const.             current dtype = ",
                          node.attr["dtype"],
                      )
  
          if not is_replaced:
              new_node.CopyFrom(node)
  
          result_graph_def.node.extend([new_node])
      return result_graph_def
  
imports: import collections
  import math
  import re
  from typing import Mapping, Sequence
  import numpy
  from tensorflow.core.framework import attr_value_pb2
  from tensorflow.core.framework import graph_pb2
  from tensorflow.core.framework import node_def_pb2
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import graph_util
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.platform import flags
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.tools import strip_unused_lib
label_desc: Use image node_id 12 for calling a global function with example usage: convert_placeholder_to_const(input_graph_def, nodes_to_convert) and returns: result_graph_def, input_graph_def