参考 tf.graph_util.import_graph_def - 云+社区 - 腾讯云
Imports the graph from graph_def into the current default Graph. (deprecated arguments)
Aliases:
- tf.compat.v1.graph_util.import_graph_def
- tf.compat.v1.import_graph_def
- tf.compat.v2.graph_util.import_graph_def
- tf.compat.v2.import_graph_def
- tf.import_graph_def
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 guide:
Warning: SOME ARGUMENTS ARE DEPRECATED: (op_dict). They will be removed in a future version. Instructions for updating: Please file an issue at https://github.com/tensorflow/tensorflow/issues if you depend on this feature.
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: AGraphDefproto containing operations to be imported into the default graph.input_map: A dictionary mapping input names (as strings) ingraph_deftoTensorobjects. The values of the named input tensors in the imported graph will be re-mapped to the respectiveTensorvalues.return_elements: A list of strings containing operation names ingraph_defthat will be returned asOperationobjects; and/or tensor names ingraph_defthat will be returned asTensorobjects.name: (Optional.) A prefix that will be prepended to the names ingraph_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.) AnOpListproto with the (possibly stripped) list ofOpDefs used by the producer of the graph. If provided, unrecognized attrs for ops ingraph_defthat have their default value according toproducer_op_listwill be removed. This will allow some moreGraphDefs produced by later binaries to be accepted by earlier binaries.
Returns:
- A list of
Operationand/orTensorobjects from the imported graph, corresponding to the names inreturn_elements, and None ifreturns_elementsis None.
Raises:
TypeError: Ifgraph_defis not aGraphDefproto,input_mapis not a dictionary mapping strings toTensorobjects, orreturn_elementsis not a list of strings.ValueError: Ifinput_map, orreturn_elementscontains names that do not appear ingraph_def, orgraph_defis not well-formed (e.g. it refers to an unknown tensor).
该博客介绍了如何使用`tf.graph_util.import_graph_def`函数将TensorFlow1.x的GraphDef导入到TensorFlow2.x中。此功能允许将序列化的GraphDef协议缓冲区导入到默认图中,并从中提取Tensor和Operation对象。文章强调了在TensorFlow版本升级过程中,如何处理已废弃的参数,并提供了代码示例来说明如何映射输入、指定返回元素以及处理可能的错误。
1825

被折叠的 条评论
为什么被折叠?



