加载冻结推理图以进行张量优化时无法导入元图

时间:2019-03-26 11:49:41

标签: python tensorflow tensorrt

我正在尝试使用tensorrt优化训练有素的冻结推理图。

https://docs.nvidia.com/deeplearning/dgx/integrate-tf-trt/index.html#using-savedmodel

with tf.Graph().as_default() as tf_graph:                                                  
    with tf.Session() as tf_sess:
        with tf.gfile.GFile(path, 'rb') as f:                           
            graph_def = tf.GraphDef()
            graph_def.ParseFromString(f.read())
        infer_graph=  trt.create_inference_graph(
                                              graph_def,                                                                                                                        
                                              outputs=outputs_,
                                              is_dynamic_op=False,
                                     max_workspace_size_bytes=1<<30,
                                               precision_mode='FP16')

Error:

->  362    transformed_graph_def = tf_optimizer.OptimizeGraph(session_config_with_trt, grappler_meta_graph_def, graph_id=b"tf_graph")

/home/dell/.local/lib/python2.7/site-packages/tensorflow/python/grappler/tf_optimizer.pyc in 

-> 41 tf_opt.TF_OptimizeGraph(cluster.tf_cluster,config_proto.SerializeToString(),metagraph.SerializeToString(),verbose, graph_id, status)


/home/dell/.local/lib/python2.7/site-packages/tensorflow/python/framework/errors_impl.pyc in __exit__(self, type_arg, value_arg, traceback_arg)

--> 528  
c_api.TF_GetCode(self.status.status))

529
# Delete the underlying status object from memory otherwise it stays alive

530
# as there is a reference to status from this from the traceback due to

InvalidArgumentError: Failed to import metagraph, check error log for more info.

1 个答案:

答案 0 :(得分:0)

我押注在图定义内找不到提取节点。从TensorFlow日志中(不谈论您的问题中包含的追溯),您可能会看到一行内容:

E tensorflow/core/grappler/grappler_item_builder.cc:631] Fetch node <outputs_> doesn't exist in graph

您可以通过更正输出节点的名称(outputs_变量)来解决此问题。

如果您不是神经网络的作者,则使用TensorBoard检查图形有助于查找正确的节点名称。