zoukankan      html  css  js  c++  java
  • tensorflow 模型保存

    1、首先 

    saver = tf.train.Saver(max_to_keep=1)
    新建一个saver,max_to_keep是说只保留最后一轮的训练结果


    2、使用save方法保存模型
    saver.save(sess,"./model_test/"+"CNN_model_test.ckpt")

    然后会在./model_test文件夹下生成这么四个文件:

    meta文件保存的是图结构,meta文件是pb(protocol buffer)格式文件,包含变量、op、集合等。这个保存了计算图的结构

    ckpt文件是二进制文件,保存了所有的weights、biases、gradients等变量。在tensorflow 0.11之前,保存在.ckpt文件中。0.11后,通过两个文件保存,如:

    MyModel.data-00000-of-00001

    MyModel.index

    checkpoint文件,该文件是个文本文件,里面记录了保存的最新的checkpoint文件以及其它checkpoint文件列表。在inference时,可以通过修改这个文件,指定使用哪个model

    加载模型:

    加载图:

    new_saver = tf.train.import_meta_graph("./model/CNN_model.ckpt.meta")
    加载参数:
    new_saver.restore(sess,tf.train.latest_checkpoint('./model'))
    接下来就可以使用了
    如果是在同一个文件中:
    new_saver = tf.train.Saver()
    new_saver.restore(sess,"./model/"+"CNN_model.ckpt")这样就够了


    参考链接:

    https://blog.csdn.net/huachao1001/article/details/78501928

    
    
  • 相关阅读:
    mac地址绑定
    解决php函数json_encode转换后中文被编码为unicode
    json格式转数组注意事项
    leetcode[93] Restore IP Addresses
    leetcode[92] Reverse Linked List II
    leetcode[91] Subsets II
    leetcode[90] Decode Ways
    leetcode[89] Merge Sorted Array
    leetcode[88] Gray Code
    leetcode[87] Partition List
  • 原文地址:https://www.cnblogs.com/earendil/p/9264314.html
Copyright © 2011-2022 走看看