“张量”这个名称是指不存在的张量。“张量”运算在图中不存在

2024-04-25 17:14:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道,这个问题已经被问过了,但没有一个对我有用。 我正在恢复我以前保存的模型。我使用了经典的TF saver和SavedModel。但装载时的问题依然存在。我得到的错误信息如下:

"The name 'train_op:0' refers to a Tensor which does not exist. The operation, 'train_op', does not exist in the graph."

我知道火车不在恢复模型图中,但我不知道为什么。 我正在创建train_op变量并为其指定一个名称:train_op = optimizer.apply_gradients(grads_and_vars, global_step=global_step, name="train_op")。我正在使用simple\u save保存模型:

tf.saved_model.simple_save(sess,
            model_file,
            inputs={"x": X, "y": y},
            outputs={"z": loss})

我是这样加载模型的:

^{pr2}$

以下是显示模型的代码行:

 _, summary = sess.run(["train_op:0", "summary_op:0"], feed_dict={"X-input:0": X_batch, "y-input:0": y_batch}, run_metadata=run_metadata)

我真的不明白这个问题。{cd2>对其他变量来说,这不是一个特定的问题。在

谢谢!在


Tags: therunname模型modelsavestepnot