構建 SavedModel
協議緩衝區並保存變量和資產。
用法
tf.compat.v1.saved_model.Builder(
export_dir
)
SavedModelBuilder
類提供了構建SavedModel
協議緩衝區的函數。具體來說,這允許將多個元圖保存為單個 language-neutral SavedModel
的一部分,同時共享變量和資產。
要構建 SavedModel,第一個元圖必須與變量一起保存。隨後的元圖將與其圖定義一起保存。如果資產需要保存並寫入或複製到磁盤,可以在添加元圖def時提供。如果多個元圖定義與同名資產相關聯,則僅保留第一個版本。
添加到 SavedModel 的每個元圖都必須使用標簽進行注釋。標簽提供了一種方法來識別要加載和恢複的特定元圖,以及共享的變量和資產集。
SavedModelBuilder
的典型用法:
...
builder = tf.compat.v1.saved_model.Builder(export_dir)
with tf.compat.v1.Session(graph=tf.Graph()) as sess:
...
builder.add_meta_graph_and_variables(sess,
["foo-tag"],
signature_def_map=foo_signatures,
assets_collection=foo_assets)
...
with tf.compat.v1.Session(graph=tf.Graph()) as sess:
...
builder.add_meta_graph(["bar-tag", "baz-tag"])
...
builder.save()
注意:此函數隻能通過 v1 兼容性庫作為 tf.compat.v1.saved_model.builder.SavedModelBuilder 或 tf.compat.v1.saved_model.Builder 使用。 Tensorflow 2.0 將引入一種基於對象的新方法來創建 SavedModel。
相關用法
- Python tf.compat.v1.saved_model.simple_save用法及代碼示例
- Python tf.compat.v1.saved_model.signature_def_utils.MethodNameUpdater用法及代碼示例
- Python tf.compat.v1.saved_model.load用法及代碼示例
- Python tf.compat.v1.strings.length用法及代碼示例
- Python tf.compat.v1.scatter_min用法及代碼示例
- Python tf.compat.v1.summary.merge用法及代碼示例
- Python tf.compat.v1.size用法及代碼示例
- Python tf.compat.v1.scatter_add用法及代碼示例
- Python tf.compat.v1.summary.FileWriter用法及代碼示例
- Python tf.compat.v1.scatter_div用法及代碼示例
- Python tf.compat.v1.space_to_batch用法及代碼示例
- Python tf.compat.v1.string_split用法及代碼示例
- Python tf.compat.v1.squeeze用法及代碼示例
- Python tf.compat.v1.set_random_seed用法及代碼示例
- Python tf.compat.v1.sparse_to_dense用法及代碼示例
- Python tf.compat.v1.sparse_segment_sum用法及代碼示例
- Python tf.compat.v1.scatter_update用法及代碼示例
- Python tf.compat.v1.sparse_split用法及代碼示例
- Python tf.compat.v1.string_to_number用法及代碼示例
- Python tf.compat.v1.scatter_nd_sub用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.saved_model.Builder。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。