tf.graph_util.import_graph_def
Stay organized with collections
Save and categorize content based on your preferences.
Imports the graph from graph_def
into the current default Graph
. (deprecated arguments)
tf.graph_util.import_graph_def(
graph_def,
input_map=None,
return_elements=None,
name=None,
op_dict=None,
producer_op_list=None
)
Used in the notebooks
This function provides a way to import a serialized TensorFlow
GraphDef
protocol buffer, and extract individual objects in the GraphDef
as
tf.Tensor
and tf.Operation
objects. Once extracted,
these objects are placed into the current default Graph
. See
tf.Graph.as_graph_def
for a way to create a GraphDef
proto.
Args |
graph_def
|
A GraphDef proto containing operations to be imported into
the default graph.
|
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.
|
return_elements
|
A list of strings containing operation names in
graph_def that will be returned as Operation objects; and/or
tensor names in graph_def that will be returned as Tensor objects.
|
name
|
(Optional.) A prefix that will be prepended to the names in
graph_def . Note that this does not apply to imported function names.
Defaults to "import" .
|
op_dict
|
(Optional.) Deprecated, do not use.
|
producer_op_list
|
(Optional.) An OpList proto with the (possibly stripped)
list of OpDef s used by the producer of the graph. If provided,
unrecognized attrs for ops in graph_def that have their default value
according to producer_op_list will be removed. This will allow some more
GraphDef s produced by later binaries to be accepted by earlier binaries.
|
Returns |
A list of Operation and/or Tensor objects from the imported graph,
corresponding to the names in return_elements ,
and None if returns_elements is None.
|
Raises |
TypeError
|
If graph_def is not a GraphDef proto,
input_map is not a dictionary mapping strings to Tensor objects,
or return_elements is not a list of strings.
|
ValueError
|
If input_map , or return_elements contains names that
do not appear in graph_def , or graph_def is not well-formed (e.g.
it refers to an unknown tensor).
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.graph_util.import_graph_def\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/framework/importer.py#L358-L416) |\n\nImports the graph from `graph_def` into the current default `Graph`. (deprecated arguments)\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.import_graph_def`](https://www.tensorflow.org/api_docs/python/tf/graph_util/import_graph_def)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.graph_util.import_graph_def`](https://www.tensorflow.org/api_docs/python/tf/graph_util/import_graph_def), [`tf.compat.v1.import_graph_def`](https://www.tensorflow.org/api_docs/python/tf/graph_util/import_graph_def)\n\n\u003cbr /\u003e\n\n tf.graph_util.import_graph_def(\n graph_def,\n input_map=None,\n return_elements=None,\n name=None,\n op_dict=None,\n producer_op_list=None\n )\n\n### Used in the notebooks\n\n| Used in the guide |\n|----------------------------------------------------------------------------------------|\n| - [Migrating your TFLite code to TF2](https://www.tensorflow.org/guide/migrate/tflite) |\n\n| **Deprecated:** SOME ARGUMENTS ARE DEPRECATED: `(op_dict)`. They will be removed in a future version. Instructions for updating: Please file an issue at \u003chttps://github.com/tensorflow/tensorflow/issues\u003e if you depend on this feature.\n\nThis function provides a way to import a serialized TensorFlow\n[`GraphDef`](https://www.tensorflow.org/code/tensorflow/core/framework/graph.proto)\nprotocol buffer, and extract individual objects in the `GraphDef` as\n[`tf.Tensor`](../../tf/Tensor) and [`tf.Operation`](../../tf/Operation) objects. Once extracted,\nthese objects are placed into the current default `Graph`. See\n[`tf.Graph.as_graph_def`](../../tf/Graph#as_graph_def) for a way to create a `GraphDef`\nproto.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `graph_def` | A `GraphDef` proto containing operations to be imported into the default graph. |\n| `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. |\n| `return_elements` | A list of strings containing operation names in `graph_def` that will be returned as `Operation` objects; and/or tensor names in `graph_def` that will be returned as `Tensor` objects. |\n| `name` | (Optional.) A prefix that will be prepended to the names in `graph_def`. Note that this does not apply to imported function names. Defaults to `\"import\"`. |\n| `op_dict` | (Optional.) Deprecated, do not use. |\n| `producer_op_list` | (Optional.) An `OpList` proto with the (possibly stripped) list of `OpDef`s used by the producer of the graph. If provided, unrecognized attrs for ops in `graph_def` that have their default value according to `producer_op_list` will be removed. This will allow some more `GraphDef`s produced by later binaries to be accepted by earlier binaries. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A list of `Operation` and/or `Tensor` objects from the imported graph, corresponding to the names in `return_elements`, and None if `returns_elements` is None. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `TypeError` | If `graph_def` is not a `GraphDef` proto, `input_map` is not a dictionary mapping strings to `Tensor` objects, or `return_elements` is not a list of strings. |\n| `ValueError` | If `input_map`, or `return_elements` contains names that do not appear in `graph_def`, or `graph_def` is not well-formed (e.g. it refers to an unknown tensor). |\n\n\u003cbr /\u003e"]]