parameters: (meta_graph_or_file,
                               clear_devices=False,
                               graph=None,
                               import_scope=None,
                               input_map=None,
                               unbound_inputs_col_name="unbound_inputs",
                               restore_collections_predicate=(lambda key: True))
return_statement: return var_list
docstring: Recreates a `Graph` saved in a `MetaGraphDef` proto.
  
    This function takes a `MetaGraphDef` protocol buffer as input. If
    the argument is a file containing a `MetaGraphDef` protocol buffer ,
    it constructs a protocol buffer from the file content. The function
    then adds all the nodes from the `graph_def` field to the
    current graph, recreates the desired collections, and returns a dictionary of
    all the Variables imported into the name scope.
  
    In combination with `export_scoped_meta_graph()`, this function can be used to
  
    * Serialize a graph along with other Python objects such as `QueueRunner`,
      `Variable` into a `MetaGraphDef`.
  
    * Restart training from a saved graph and checkpoints.
  
    * Run inference from a saved graph and checkpoints.
  
    Args:
      meta_graph_or_file: `MetaGraphDef` protocol buffer or filename (including
        the path) containing a `MetaGraphDef`.
      clear_devices: Boolean which controls whether to clear device information
        from graph_def. Default false.
      graph: The `Graph` to import into. If `None`, use the default graph.
      import_scope: Optional `string`. Name scope into which to import the
        subgraph. If `None`, the graph is imported to the root name scope.
      input_map: A dictionary mapping input names (as strings) in `graph_def` to
        `Tensor` objects. The values of the named input tensors in the imported
        graph will be re-mapped to the respective `Tensor` values.
      unbound_inputs_col_name: Collection name for looking up unbound inputs.
      restore_collections_predicate: a predicate on collection names. A collection
        named c (i.e whose key is c) will be restored iff
        1) `restore_collections_predicate(c)` is True, and
        2) `c != unbound_inputs_col_name`.
  
    Returns:
      A dictionary of all the `Variables` imported into the name scope.
  
    Raises:
      ValueError: If the graph_def contains unbound inputs.
docstring_summary: Recreates a `Graph` saved in a `MetaGraphDef` proto.
docstring_tokens: Recreates a Graph saved in a MetaGraphDef proto .
function: def import_scoped_meta_graph(meta_graph_or_file,
                               clear_devices=False,
                               graph=None,
                               import_scope=None,
                               input_map=None,
                               unbound_inputs_col_name="unbound_inputs",
                               restore_collections_predicate=(lambda key: True)):
    """Recreates a `Graph` saved in a `MetaGraphDef` proto.
  
    This function takes a `MetaGraphDef` protocol buffer as input. If
    the argument is a file containing a `MetaGraphDef` protocol buffer ,
    it constructs a protocol buffer from the file content. The function
    then adds all the nodes from the `graph_def` field to the
    current graph, recreates the desired collections, and returns a dictionary of
    all the Variables imported into the name scope.
  
    In combination with `export_scoped_meta_graph()`, this function can be used to
  
    * Serialize a graph along with other Python objects such as `QueueRunner`,
      `Variable` into a `MetaGraphDef`.
  
    * Restart training from a saved graph and checkpoints.
  
    * Run inference from a saved graph and checkpoints.
  
    Args:
      meta_graph_or_file: `MetaGraphDef` protocol buffer or filename (including
        the path) containing a `MetaGraphDef`.
      clear_devices: Boolean which controls whether to clear device information
        from graph_def. Default false.
      graph: The `Graph` to import into. If `None`, use the default graph.
      import_scope: Optional `string`. Name scope into which to import the
        subgraph. If `None`, the graph is imported to the root name scope.
      input_map: A dictionary mapping input names (as strings) in `graph_def` to
        `Tensor` objects. The values of the named input tensors in the imported
        graph will be re-mapped to the respective `Tensor` values.
      unbound_inputs_col_name: Collection name for looking up unbound inputs.
      restore_collections_predicate: a predicate on collection names. A collection
        named c (i.e whose key is c) will be restored iff
        1) `restore_collections_predicate(c)` is True, and
        2) `c != unbound_inputs_col_name`.
  
    Returns:
      A dictionary of all the `Variables` imported into the name scope.
  
    Raises:
      ValueError: If the graph_def contains unbound inputs.
    """
    if context.in_eager_mode():
      raise ValueError("Exporting/importing meta graphs is not supported when "
                       "eager execution is enabled.")
    if isinstance(meta_graph_or_file, meta_graph_pb2.MetaGraphDef):
      meta_graph_def = meta_graph_or_file
    else:
      meta_graph_def = read_meta_graph_file(meta_graph_or_file)
  
    if unbound_inputs_col_name:
      for key, col_def in meta_graph_def.collection_def.items():
        if key == unbound_inputs_col_name:
          kind = col_def.WhichOneof("kind")
          field = getattr(col_def, kind)
          if field.value and (
              not input_map or
              sorted([compat.as_str(v) for v in field.value]) !=
              sorted(input_map)):
            raise ValueError("Graph contains unbound inputs: %s. Must "
                             "provide these inputs through input_map." %
                             ",".join([compat.as_str(v) for v in field.value
                                       if not input_map or v not in input_map]))
          break
  
    # Sets graph to default graph if it's not passed in.
    graph = graph or ops.get_default_graph()
  
    # Gathers the list of nodes we are interested in.
    with graph.as_default():
      producer_op_list = None
      if meta_graph_def.meta_info_def.HasField("stripped_op_list"):
        producer_op_list = meta_graph_def.meta_info_def.stripped_op_list
      input_graph_def = meta_graph_def.graph_def
      # Remove all the explicit device specifications for this node. This helps to
      # make the graph more portable.
      if clear_devices:
        for node in input_graph_def.node:
          node.device = ""
      importer.import_graph_def(
          input_graph_def, name=(import_scope or ""), input_map=input_map,
          producer_op_list=producer_op_list)
  
      scope_to_prepend_to_names = "/".join(
          [part for part in [graph.get_name_scope(), import_scope] if part])
  
      # Restores all the other collections.
      for key, col_def in meta_graph_def.collection_def.items():
        # Don't add unbound_inputs to the new graph.
        if key == unbound_inputs_col_name:
          continue
        if not restore_collections_predicate(key):
          continue
  
        kind = col_def.WhichOneof("kind")
        if kind is None:
          logging.error("Cannot identify data type for collection %s. Skipping.",
                        key)
          continue
        from_proto = ops.get_from_proto_function(key)
        if from_proto and kind == "bytes_list":
          proto_type = ops.get_collection_proto_type(key)
          for value in col_def.bytes_list.value:
            proto = proto_type()
            proto.ParseFromString(value)
            graph.add_to_collection(
                key, from_proto(proto, import_scope=scope_to_prepend_to_names))
        else:
          field = getattr(col_def, kind)
          if key in _COMPAT_COLLECTION_LIST:
            logging.warning(
                "The saved meta_graph is possibly from an older release:\n"
                "'%s' collection should be of type 'byte_list', but instead "
                "is of type '%s'.", key, kind)
          if kind == "node_list":
            for value in field.value:
              col_op = graph.as_graph_element(
                  ops.prepend_name_scope(value, scope_to_prepend_to_names))
              graph.add_to_collection(key, col_op)
          elif kind == "int64_list":
            # NOTE(opensource): This force conversion is to work around the fact
            # that Python2 distinguishes between int and long, while Python3 has
            # only int.
            for value in field.value:
              graph.add_to_collection(key, int(value))
          else:
            for value in field.value:
              graph.add_to_collection(
                  key, ops.prepend_name_scope(value, scope_to_prepend_to_names))
  
      var_list = {}
      variables = graph.get_collection(ops.GraphKeys.GLOBAL_VARIABLES,
                                       scope=scope_to_prepend_to_names)
      for v in variables:
        var_list[ops.strip_name_scope(v.name, scope_to_prepend_to_names)] = v
  
    return var_list
function_tokens: def import_scoped_meta_graph ( meta_graph_or_file , clear_devices = False , graph = None , import_scope = None , input_map = None , unbound_inputs_col_name = "unbound_inputs" , restore_collections_predicate = ( lambda key : True ) ) : if context . in_eager_mode ( ) : raise ValueError ( "Exporting/importing meta graphs is not supported when " "eager execution is enabled." ) if isinstance ( meta_graph_or_file , meta_graph_pb2 . MetaGraphDef ) : meta_graph_def = meta_graph_or_file else : meta_graph_def = read_meta_graph_file ( meta_graph_or_file ) if unbound_inputs_col_name : for key , col_def in meta_graph_def . collection_def . items ( ) : if key == unbound_inputs_col_name : kind = col_def . WhichOneof ( "kind" ) field = getattr ( col_def , kind ) if field . value and ( not input_map or sorted ( [ compat . as_str ( v ) for v in field . value ] ) != sorted ( input_map ) ) : raise ValueError ( "Graph contains unbound inputs: %s. Must " "provide these inputs through input_map." % "," . join ( [ compat . as_str ( v ) for v in field . value if not input_map or v not in input_map ] ) ) break # Sets graph to default graph if it's not passed in. graph = graph or ops . get_default_graph ( ) # Gathers the list of nodes we are interested in. with graph . as_default ( ) : producer_op_list = None if meta_graph_def . meta_info_def . HasField ( "stripped_op_list" ) : producer_op_list = meta_graph_def . meta_info_def . stripped_op_list input_graph_def = meta_graph_def . graph_def # Remove all the explicit device specifications for this node. This helps to # make the graph more portable. if clear_devices : for node in input_graph_def . node : node . device = "" importer . import_graph_def ( input_graph_def , name = ( import_scope or "" ) , input_map = input_map , producer_op_list = producer_op_list ) scope_to_prepend_to_names = "/" . join ( [ part for part in [ graph . get_name_scope ( ) , import_scope ] if part ] ) # Restores all the other collections. for key , col_def in meta_graph_def . collection_def . items ( ) : # Don't add unbound_inputs to the new graph. if key == unbound_inputs_col_name : continue if not restore_collections_predicate ( key ) : continue kind = col_def . WhichOneof ( "kind" ) if kind is None : logging . error ( "Cannot identify data type for collection %s. Skipping." , key ) continue from_proto = ops . get_from_proto_function ( key ) if from_proto and kind == "bytes_list" : proto_type = ops . get_collection_proto_type ( key ) for value in col_def . bytes_list . value : proto = proto_type ( ) proto . ParseFromString ( value ) graph . add_to_collection ( key , from_proto ( proto , import_scope = scope_to_prepend_to_names ) ) else : field = getattr ( col_def , kind ) if key in _COMPAT_COLLECTION_LIST : logging . warning ( "The saved meta_graph is possibly from an older release:\n" "'%s' collection should be of type 'byte_list', but instead " "is of type '%s'." , key , kind ) if kind == "node_list" : for value in field . value : col_op = graph . as_graph_element ( ops . prepend_name_scope ( value , scope_to_prepend_to_names ) ) graph . add_to_collection ( key , col_op ) elif kind == "int64_list" : # NOTE(opensource): This force conversion is to work around the fact # that Python2 distinguishes between int and long, while Python3 has # only int. for value in field . value : graph . add_to_collection ( key , int ( value ) ) else : for value in field . value : graph . add_to_collection ( key , ops . prepend_name_scope ( value , scope_to_prepend_to_names ) ) var_list = { } variables = graph . get_collection ( ops . GraphKeys . GLOBAL_VARIABLES , scope = scope_to_prepend_to_names ) for v in variables : var_list [ ops . strip_name_scope ( v . name , scope_to_prepend_to_names ) ] = v return var_list