如您所知,对于新版本的tf服务,它不再支持过去由SessionBundle导出的模型格式,但现在支持SavedModelBuilder。
我想最好从旧的模型格式还原会话,然后通过SavedModelBuilder导出它。您可以使用它指示模型的版本。
def export_saved_model(version, path, sess=None):
tf.app.flags.DEFINE_integer('version', version, 'version number of the model.')
tf.app.flags.DEFINE_string('work_dir', path, 'your older model directory.')
tf.app.flags.DEFINE_string('model_dir', '/tmp/model_name', 'saved model directory')
FLAGS = tf.app.flags.FLAGS
# you can give the session and export your model immediately after training
if not sess:
saver = tf.train.import_meta_graph(os.path.join(path, 'xxx.ckpt.meta'))
saver.restore(sess, tf.train.latest_checkpoint(path))
export_path = os.path.join(
tf.compat.as_bytes(FLAGS.model_dir),
tf.compat.as_bytes(str(FLAGS.version)))
builder = tf.saved_model.builder.SavedModelBuilder(export_path)
# define the signature def map here
# ...
legacy_init_op = tf.group(tf.tables_initializer(), name='legacy_init_op')
builder.add_meta_graph_and_variables(
sess, [tf.saved_model.tag_constants.SERVING],
signature_def_map={
'predict_xxx':
prediction_signature
},
legacy_init_op=legacy_init_op
)
builder.save()
print('Export SavedModel!')
您可以在tf服务示例中找到上述代码的主要部分。最终,它将以可提供的格式生成SavedModel。
0
我正在按照本教程使用对象检测模型使用
tensorflow serving
。我正在使用tensorflow对象检测来生成模型。我创建了使用冷冻模型这个出口(生成的冷冻样板工程使用python脚本)。冻结的图形目录具有以下内容(
variables
目录中没有内容)现在,当我尝试使用以下命令为模型提供服务时,
它总是告诉我