擅长:python、mysql、java
<p>这样做:</p>
<pre><code>your_feature_spec = {
"some_feature": tf.FixedLenFeature([], dtype=tf.string, default_value=""),
"some_feature": tf.VarLenFeature(dtype=tf.string),
}
def _serving_input_receiver_fn():
serialized_tf_example = tf.placeholder(dtype=tf.string, shape=None,
name='input_example_tensor')
# key (e.g. 'examples') should be same with the inputKey when you
# buid the request for prediction
receiver_tensors = {'examples': serialized_tf_example}
features = tf.parse_example(serialized_tf_example, your_feature_spec)
return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)
estimator.export_savedmodel(export_dir, _serving_input_receiver_fn)
</code></pre>
<p>然后,您可以按批请求具有“predict”签名名称的服务模型。</p>
<p>来源:<a href="https://www.tensorflow.org/guide/saved_model#prepare_serving_inputs" rel="noreferrer">https://www.tensorflow.org/guide/saved_model#prepare_serving_inputs</a></p>