0
有兩個python文件,第一個用於保存張量流模型 。第二個是用於恢復保存的模型。如何恢復已保存的張量流模型?
問:
當我運行了兩個文件,一個接着一個,它的確定。
當我運行第一個,重新啓動編輯並運行第二個,它 告訴我,w1沒有定義?
我想要做的是:
節省tensorflow模型
恢復保存的模型
這有什麼錯呢?感謝您的幫助?
model_save.py
import tensorflow as tf
w1 = tf.Variable(tf.random_normal(shape=[2]), name='w1')
w2 = tf.Variable(tf.random_normal(shape=[5]), name='w2')
saver = tf.train.Saver()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver.save(sess, 'SR\\my-model')
model_restore.py
import tensorflow as tf
with tf.Session() as sess:
saver = tf.train.import_meta_graph('SR\\my-model.meta')
saver.restore(sess,'SR\\my-model')
print (sess.run(w1))
感謝您親切的回答。 根據您的建議和相關參考文獻, 我剛剛解決了這個問題:) –