恢复模型Tensorflow后训练操作未加载

时间:2019-04-01 09:02:53

标签: python tensorflow

我已经尝试过:

saver = tf.train.import_meta_graph(tf.train.latest_checkpoint(model_path)+".meta")

sess  = tf.Session()
if(tf.train.checkpoint_exists(tf.train.latest_checkpoint(model_path))):
    saver.restore(sess, tf.train.latest_checkpoint(model_path))
    print(tf.train.latest_checkpoint(model_path) + "Session Loaded for Testing")     
graph = tf.get_default_graph()
X = graph.get_tensor_by_name('input:0')
y = graph.get_tensor_by_name('output:0')
loss = tf.reduce_mean(tf.square(outputs - y)) # loss function = mean squared error
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate) 
training_op = optimizer.minimize(loss))

我遇到以下错误:

ValueError: Duplicate node name in graph: 'rnn/multi_rnn_cell/cell_0/layer0/kernel/Adam'

我尝试使用错误中提到的名称:

optimizer = graph.get_operation_by_name("rnn/multi_rnn_cell/cell_0/layer0/kernel/Adam")

然后我收到此错误:

AttributeError: 'Operation' object has no attribute 'minimize'

请让我知道如何从模型访问training_op

0 个答案:

没有答案