Python 还原保存的模型时尝试使用未初始化的值

Python 还原保存的模型时尝试使用未初始化的值,python,machine-learning,tensorflow,Python,Machine Learning,Tensorflow,我正在尝试恢复保存的模型并进行测试。 但是,我遇到了试图使用未初始化值的问题。我以前读过一些帖子。似乎我无法进行全局初始化。但这个错误似乎很有趣 我的代码是: new_saver = tf.train.import_meta_graph("trained_model_epoch-1.meta") sess=tf.Session() new_saver.restore(sess, './trained_model_epoch-1') print('Test') run_test_model(ses

我正在尝试恢复保存的模型并进行测试。 但是,我遇到了
试图使用未初始化值的问题。我以前读过一些帖子。似乎我无法进行全局初始化。但这个错误似乎很有趣

我的代码是:

new_saver = tf.train.import_meta_graph("trained_model_epoch-1.meta")
sess=tf.Session()
new_saver.restore(sess, './trained_model_epoch-1')
print('Test')
run_test_model(sess,y_out,...... split='Test', N=Ntest)

您是否尝试过使用
tf.train.Saver()

当然,您需要使用saver保存您的模型

saver.save(sess, save_path)

您是否尝试过使用
tf.train.Saver()

当然,您需要使用saver保存您的模型

saver.save(sess, save_path)

我相信您是在直接访问张量/运算(如果它们是在同一脚本中定义的),而不是从恢复的图形中提取它们:

sess = tf.Session()
new_saver.restore(sess, './trained_model_epoch-1')
graph = sess.graph
w1 = graph.get_tensor_by_name("w1:0")  # this tensor is initialized
w2 = graph.get_tensor_by_name("w2:0")  # this tensor is initialized too

我相信您是在直接访问张量/运算(如果它们是在同一脚本中定义的),而不是从恢复的图形中提取它们:

sess = tf.Session()
new_saver.restore(sess, './trained_model_epoch-1')
graph = sess.graph
w1 = graph.get_tensor_by_name("w1:0")  # this tensor is initialized
w2 = graph.get_tensor_by_name("w2:0")  # this tensor is initialized too