我们必须将表初始值设定项op作为
main_op
assets_collection
在我们的召唤中
add_meta_graph_and_variables
:
init_op = tf.tables_initializer()
with tf.Session() as sess:
sess.run([tf.global_variables_initializer(), init_op])
example_result = sess.run(
my_model,
feed_dict=###snip###
)
然后
export_builder.add_meta_graph_and_variables(
sess,
[tf.saved_model.tag_constants.SERVING],
main_op = init_op,
assets_collection=tf.get_collection(tf.GraphKeys.ASSET_FILEPATHS),
signature_def_map={
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: sig
}
)
作为一种(可以说是更简单的)替代方案,我们可以使用
simple_save