gpt4 book ai didi

python - tensorflow 中的 freeze_graph : AssertionError: y_ is not in graph

转载 作者:太空宇宙 更新时间:2023-11-03 14:53:54 24 4
gpt4 key购买 nike

在 Tensorflow 中,训练模型后,我将其保存为:

with tf.Session() as session:
/**
------- Model training code goes here ------
**/
tf.train.write_graph(session.graph_def, '.', '../har.pbtxt')
saver.save(session,save_path = "../har.ckpt")

并卡住并保存优化后的模型:

from tensorflow.python.tools import freeze_graph
from tensorflow.python.tools import optimize_for_inference_lib

freeze_graph.freeze_graph(input_graph = "../har.pbtxt", input_saver = "",
input_binary = False, input_checkpoint = "../har.ckpt", output_node_names = "y_",
restore_op_name = "save/restore_all", filename_tensor_name = "save/Const:0",
output_graph = "frozen_har.pb", clear_devices = True, initializer_nodes = "")

input_graph_def = tf.GraphDef()
with tf.gfile.Open(output_frozen_graph_name, "r") as f:
data = f.read()
input_graph_def.ParseFromString(data)

output_graph_def = optimize_for_inference_lib.optimize_for_inference(
input_graph_def,
["input"],
["y_"],
tf.float32.as_datatype_enum)

f = tf.gfile.FastGFile("optimized_frozen_har.pb", "w")
f.write(output_graph_def.SerializeToString())

但是,我得到了错误:

Traceback (most recent call last):
File "C:\Users\asus\Desktop\cnn.py", line 176, in output_graph = "frozen_har.pb", clear_devices = True, initializer_nodes = "")
File "C:\Users\asus\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\tools\freeze_graph.py", line 122, in freeze_graph variable_names_blacklist=variable_names_blacklist) File "C:\Users\asus\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\graph_util_impl.py", line 202, in convert_variables_to_constants inference_graph = extract_sub_graph(input_graph_def, output_node_names)
File "C:\Users\asus\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\graph_util_impl.py", line 141, in extract_sub_graph assert d in name_to_node_map, "%s is not in graph" % d AssertionError: y_ is not in graph

我在我的代码中定义了 y_ 作为输出:

y_ = tf.nn.softmax(tf.matmul(f, out_weights) + out_biases)

问题是什么?

最佳答案

当你使用时,

y_ = tf.nn.softmax(tf.matmul(f, out_weights) + out_biases)

y_ 不是张量的名称。请使用以下内容将张量明确命名为 y_。

y_ = tf.nn.softmax(tf.matmul(f, out_weights) + out_biases, name="y_")

关于python - tensorflow 中的 freeze_graph : AssertionError: y_ is not in graph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44181362/

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