# 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()

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-07-07
猜你喜欢
  • 2021-12-10
  • 2022-12-23
  • 2022-01-06
  • 2021-10-30
  • 2021-08-21
  • 2022-12-23
相关资源
相似解决方案