gpt4 book ai didi

python - TensorFlow freeze_graph.py : The name 'save/Const:0' refers to a Tensor which does not exist

转载 作者:太空狗 更新时间:2023-10-29 17:33:08 24 4
gpt4 key购买 nike

我目前正在尝试将经过训练的 TensorFlow 模型导出为 ProtoBuf 文件,以便在 Android 上将其与 TensorFlow C++ API 一起使用。因此,我正在使用 freeze_graph.py脚本。

我使用 tf.train.write_graph 导出了我的模型:

tf.train.write_graph(graph_def, FLAGS.save_path, out_name, as_text=True)

我正在使用通过 tf.train.Saver 保存的检查点。

我按照脚本顶部的描述调用 freeze_graph.py。编译后运行

bazel-bin/tensorflow/python/tools/freeze_graph \
--input_graph=<path_to_protobuf_file> \
--input_checkpoint=<model_name>.ckpt-10000 \
--output_graph=<output_protobuf_file_path> \
--output_node_names=dropout/mul_1

这给了我以下错误信息:

TypeError: Cannot interpret feed_dict key as Tensor: The name 'save/Const:0' refers to a Tensor which does not exist. The operation, 'save/Const', does not exist in the graph.

如错误所述,我导出的模型中没有张量 save/Const:0。但是,freeze_graph.py 的代码表明可以通过标志 filename_tensor_name 指定此张量名称。不幸的是,我找不到任何关于这个张量应该是什么以及如何为我的模型正确设置它的信息。

有人可以告诉我如何在导出的 ProtoBuf 模型中生成 save/Const:0 张量,或者如何正确设置标志 filename_tensor_name 吗?

最佳答案

--filename_tensor_name 标志用于指定在构造 tf.train.Saver 时创建的占位符张量的名称。适合您的模型。*

在您的原始程序中,您可以打印出 saver.saver_def.filename_tensor_name 的值,以获得您应该为此标志传递的值。您可能还想打印 saver.saver_def.restore_op_name 的值以获取 --restore_op_name 标志的值(因为我怀疑默认值不正确你的图表)。

或者,tf.train.SaverDef protocol buffer包括重建这些标志的相关信息所需的所有信息。如果您愿意,可以将 saver.saver_def 写入文件,并将该文件的名称作为 --input_saver 标志传递给 freeze_graph.py.


* tf.train.Saver 的默认名称范围是 "save/",占位符是 actually a tf.constant()其名称默认为 "Const:0",这解释了为什么标志默认为 "save/Const:0"

关于python - TensorFlow freeze_graph.py : The name 'save/Const:0' refers to a Tensor which does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39468640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com