zoukankan      html  css  js  c++  java
  • 135、TensorFlow SavedModel工具类的使用

    # SavedModelBuilder 类提供了保存多个MetaGraphDef的功能
    # MetaGraph是一个数据流图,加上它的关联变量,资产和标签
    # 一个MetaGraphDef是一个协议缓冲表示区
    # 一个signature是计算图的输入和输出表示
    # 如果assets需要被保存或者写入到磁盘上,当第一个MetaGraphDef被加载的时候
    # asset就可以被提供
    # 如果多个MetaGraphDef有相同的名字,只有第一个名字能够被持久化
    # 每一个MetaGraphDef必须被打上用户标签
    # 并且根据用户标签来加载和保存MetaGraphDef
    # 随着变量的共享,这些标签标注了MetaGraphDef的功能,和在哪一个硬件上面运行的
    import tensorflow as tf
    export_dir = "tmp2/MetaGraphDir"
    builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
    with tf.Session(graph=tf.Graph()) as sess:
        builder.add_meta_graph_and_variables(sess,
                                             ["TRAINING"],
                                             signature_def_map=foo_signatures,
                                             assets_collection=foo_assets
                                             )
    # Add a sencod MetaGraphDef for inference
    with tf.Session(graph=tf.Graph()) as sess:
        builder.add_meta_graph(["SERVING"])
    builder.save()
  • 相关阅读:
    【读书笔记】房龙-人类的故事
    【读书笔记】曼昆-经济学原理:宏观经济学分册
    【读书笔记】曼昆-经济学原理:微观经济学分册
    ES6数组去重
    switch语句
    if语句的优化
    程序的三大结构
    NaN
    js中常见的数据类型
    变量的命名规则
  • 原文地址:https://www.cnblogs.com/weizhen/p/8451518.html
Copyright © 2011-2022 走看看