TensorFlow 笔记3--模型的保存与恢复
生活随笔
收集整理的這篇文章主要介紹了
TensorFlow 笔记3--模型的保存与恢复
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
TensorFlow 模型的保存與恢復(fù)
1. 模型的保存
- 定義圖中創(chuàng)建對象:
saver = tf.train.Saver() #保存所有variable
saver = tf.train.Saver([v1,v2])#只保存列表中的variable
saver = tf.train.Saver({‘v1’:v1,’v2’:v2}) #只保存字典中的variable - 運(yùn)行圖中保存模型:
saver.save(sess, “/temp/tfmodel”,step)
2. 模型的恢復(fù)
需重新定義網(wǎng)絡(luò)結(jié)構(gòu)的方法:
- 定義圖中創(chuàng)建對象:
saver = tf.train.Saver() - 運(yùn)行圖中恢復(fù)模型:
saver.restore(sess, “/temp/tfmodel”)
不需重新定義網(wǎng)絡(luò)結(jié)構(gòu)的方法:
sess=tf.InteractiveSession() #restore graph new_saver=tf.train.import_meta_graph('/temp/tfmodel-1000.meta')#restore parameters new_saver.restore(sess,"/temp/tfmodel-1000")graph = tf.get_default_graph() #根據(jù)op的名稱獲得相應(yīng)的參數(shù) x=graph.get_operation_by_name('x_input').outputs[0] #在構(gòu)建圖中添加tf.add_to_collection('predict', y) 以便在加載模型時使用 y=tf.get_collection("predict")[0]總結(jié)
以上是生活随笔為你收集整理的TensorFlow 笔记3--模型的保存与恢复的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java获取单击内容,java – 单
- 下一篇: 查看分支编码_MySQL分支数据库Mar