日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TensorFlow 笔记3--模型的保存与恢复

發布時間:2025/3/12 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)
saver = tf.train.Saver() with tf.Session as sess#保存在當前文件夾下的temp文件夾,模型名為tfmodelsaver.save(sess, "/temp/tfmodel", total_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--模型的保存与恢复的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。