train.py:
prediction = tf.contrib.layers.fully_connected(outputs[:, -1, :], output_dim, activation_fn=None, scope="prediction")
test.py:
prediction = graph.get_tensor_by_name("prediction:0")
在从train.py保存图之后,我想在test.py中恢复预测变量,但没有成功。
‘tf.contrib.layers.fully_connected‘ 没有name参数,只有scope参数。我该如何恢复它呢?
回答:
获取TensorFlow为全连接层定义的名称:
train.py
print(prediction.name)
它会显示类似于prediction/BiasAdd:0
的名称
在test.py中使用这个名称来正确恢复变量