def serving_input_fn():
feature_placeholders = {
'id': tf.placeholder(tf.string, [None], name="id_placeholder"),
'feat': tf.placeholder(tf.float32, [None, FEAT_LEN], name="feat_placeholder"),
#label is not required since serving is only used for inference
}
return input_fn_utils.InputFnOps(
feature_placeholders,
None,
feature_placeholders)
导出模型以使用Tensorflow示例
This tutorial显示如何使用export_savedmodel服务
用估计器实现的宽深模型以及如何将Tensorflow示例输入导出的模型。本质
部分:
from tensorflow.contrib.learn.python.learn.utils import input_fn_utils
serving_input_fn = input_fn_utils.build_parsing_serving_input_fn(feature_spec)
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)
你有两个选择:
导出模型以使用JSON字典
在我的mlengine-boilerplate repository中,我使用它将估计器模型导出到Cloud ML引擎,以便轻松地将其用于在线预测(sample code for the predictions)。基本部分:
导出模型以使用Tensorflow示例
This tutorial显示如何使用
export_savedmodel
服务 用估计器实现的宽深模型以及如何将Tensorflow示例输入导出的模型。本质 部分:这样做:
然后,您可以按批请求具有“predict”签名名称的服务模型。
来源:https://www.tensorflow.org/guide/saved_model#prepare_serving_inputs
如果直接从主分支使用tensorflow,则有一个模块tensorflow.python.estimator.export提供了一个函数:
不幸的是,至少对我来说,它不会走得更远,但我不确定我的模型是否真的正确,所以也许你比我幸运。
或者,对于从pypi安装的当前版本,有以下函数:
但我也不能让他们工作。
也许,我没有正确理解,所以我希望你会有更多的运气。
克里斯
如果直接从主分支使用tensorflow,则有一个模块tensorflow.python.estimator.export提供了一个函数:
不幸的是,至少对我来说,它不会走得更远,但我不确定我的模型是否真的正确,所以也许你比我幸运。
或者,对于从pypi安装的当前版本,有以下函数:
但我也不能让他们工作。
可能,我不太明白,所以我希望你会有更多的运气。
克里斯
相关问题 更多 >
编程相关推荐