rha*_*l80 2 tensorflow tensorflow-serving google-cloud-ml google-cloud-ml-engine
我刚刚完成模型的训练,却发现我导出的服务模型存在签名问题。我如何更新它们?
(一个常见问题是为 CloudML Engine 设置错误的形状)。
别担心——您不需要重新训练您的模型。也就是说,还有一些工作要做。您将创建一个新的(已更正的)服务图,将检查点加载到该图中,然后导出该图。
例如,假设您添加了一个占位符,但没有设置形状,即使您打算这样做(例如,在 CloudML 上运行)。在这种情况下,您的图表可能如下所示:
x = tf.placeholder(tf.float32)
y = foo(x)
...
Run Code Online (Sandbox Code Playgroud)
要纠正这个问题:
# Create the *correct* graph
with tf.Graph().as_default() as new_graph:
x = tf.placeholder(tf.float32, shape=[None])
y = foo(x)
saver = tf.train.Saver()
# (Re-)define the inputs and the outputs.
inputs = {"x": tf.saved_model.utils.build_tensor_info(x)}
outputs = {"y": tf.saved_model.utils.build_tensor_info(y)}
signature = tf.saved_model.signature_def_utils.build_signature_def(
inputs=inputs,
outputs=outputs,
method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME
)
with tf.Session(graph=new_graph) as session:
# Restore the variables
vars_path = os.path.join(old_export_dir, 'variables', 'variables')
saver.restore(session, vars_path)
# Save out the corrected model
b = builder.SavedModelBuilder(new_export_dir)
b.add_meta_graph_and_variables(session, ['serving_default'], signature)
b.save()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5182 次 |
| 最近记录: |