我在尝试解决另一个错误时遇到了这个问题。第一个错误(原始问题)是,当我尝试还原元图时,我会得到Cannot find KeyError: "The name 'multi_rnn_cell_6' refers to an Operation not in the graph."。在尝试为该问题创建MVCE时,我发现了此错误。
创建一些操作,保存元图和变量,然后尝试加载图和变量的简单脚本失败。该问题似乎与TF使用的格式有关。
import tensorflow as tf
import numpy as np
import os
import glob
class ImportIssue(object):
def __init__(self,load=False,model_scope = 'model',checkpoint='checkpoint'):
try:
os.makedirs(checkpoint)
except:
pass
save_file = os.path.join(checkpoint,'model')
print("Save file: {}".format(save_file))
graph = tf.Graph()
with graph.as_default():
if load:
# load model if requested
model_to_load = "{}.meta".format(tf.train.latest_checkpoint(checkpoint))
print("Loading model: {}".format(model_to_load))
rest = tf.train.import_meta_graph(model_to_load)
else:
# else create one
with tf.variable_scope(model_scope):
inputs = tf.placeholder(shape=(None,10,10),dtype=tf.float32)
cell …Run Code Online (Sandbox Code Playgroud)