TensorFlow 笔记3--模型的保存与恢复
生活随笔
收集整理的這篇文章主要介紹了
TensorFlow 笔记3--模型的保存与恢复
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
TensorFlow 模型的保存與恢復
1. 模型的保存
- 定義圖中創建對象:
saver = tf.train.Saver() #保存所有variable
saver = tf.train.Saver([v1,v2])#只保存列表中的variable
saver = tf.train.Saver({‘v1’:v1,’v2’:v2}) #只保存字典中的variable - 運行圖中保存模型:
saver.save(sess, “/temp/tfmodel”,step)
2. 模型的恢復
需重新定義網絡結構的方法:
- 定義圖中創建對象:
saver = tf.train.Saver() - 運行圖中恢復模型:
saver.restore(sess, “/temp/tfmodel”)
不需重新定義網絡結構的方法:
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() #根據op的名稱獲得相應的參數 x=graph.get_operation_by_name('x_input').outputs[0] #在構建圖中添加tf.add_to_collection('predict', y) 以便在加載模型時使用 y=tf.get_collection("predict")[0]總結
以上是生活随笔為你收集整理的TensorFlow 笔记3--模型的保存与恢复的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java获取单击内容,java – 单
- 下一篇: 树莓派的使用