来自输入函数的 Tensorflow 服务转换数据
Tensorflow Serving Transform data from input function
目前我正在研究张量流模型。该模型根据 2 个字符串和一个数字对情况进行分类。所以我的占位符如下所示:
Input1 = tf.placeholder("string", shape=None, name="string1")
Input2 = tf.placeholder("string", shape=None, name="string2")
Input3 = tf.placeholder("float", shape=None, name="distance")
label = tf.placeholder("int64", shape=None, name="output")
我想使用 Tensorflow Serving 为这个模型提供服务,代码如下:
signature_definition = tf.saved_model.signature_def_utils.build_signature_def(
inputs={'input1': model_input1, 'input2': model_input2, 'input3': model_input3},
outputs={'outputs': model_output},
method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME)
builder = tf.saved_model.builder.SavedModelBuilder(SERVE_PATH)
builder.add_meta_graph_and_variables(
sess, [tf.saved_model.tag_constants.SERVING],
signature_def_map={
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
signature_definition
})
但是我写的模型想要字符串作为 one_hot 编码输入。有人知道如何将输入张量转换为 one_hot 编码张量,并将其提供给我的模型吗?
在训练我的模型时,我只是在喂养它们之前用一个函数对它们进行了转换。这在服务时似乎是不可能的,因为我只能定义一个输入函数,而不是输入数据的流。
tf.one_hot 提供唯一的热编码。
但是,更广泛地说,您需要协调训练和服务以使用相同的索引。 Tensorflow Transform 提供了在训练数据处理阶段进行多种转换(one-hot、scale、bucketize)的方法,包括 one-hot 编码,并将转换保存为模型图的一部分,因此自动重新应用相同的转换在服务时间,为您节省体力劳动。使用下面的 link 查看他们的示例:
示例:https://www.tensorflow.org/tfx/transform/tutorials/TFT_simple_example
示例 2:https://github.com/tensorflow/transform/blob/master/examples/sentiment_example.py
完整 Python API: https://www.tensorflow.org/tfx/transform/api_docs/python/tft
您要查找的函数是tft.compute_and_apply_vocabulary。
目前我正在研究张量流模型。该模型根据 2 个字符串和一个数字对情况进行分类。所以我的占位符如下所示:
Input1 = tf.placeholder("string", shape=None, name="string1")
Input2 = tf.placeholder("string", shape=None, name="string2")
Input3 = tf.placeholder("float", shape=None, name="distance")
label = tf.placeholder("int64", shape=None, name="output")
我想使用 Tensorflow Serving 为这个模型提供服务,代码如下:
signature_definition = tf.saved_model.signature_def_utils.build_signature_def(
inputs={'input1': model_input1, 'input2': model_input2, 'input3': model_input3},
outputs={'outputs': model_output},
method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME)
builder = tf.saved_model.builder.SavedModelBuilder(SERVE_PATH)
builder.add_meta_graph_and_variables(
sess, [tf.saved_model.tag_constants.SERVING],
signature_def_map={
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
signature_definition
})
但是我写的模型想要字符串作为 one_hot 编码输入。有人知道如何将输入张量转换为 one_hot 编码张量,并将其提供给我的模型吗? 在训练我的模型时,我只是在喂养它们之前用一个函数对它们进行了转换。这在服务时似乎是不可能的,因为我只能定义一个输入函数,而不是输入数据的流。
tf.one_hot 提供唯一的热编码。
但是,更广泛地说,您需要协调训练和服务以使用相同的索引。 Tensorflow Transform 提供了在训练数据处理阶段进行多种转换(one-hot、scale、bucketize)的方法,包括 one-hot 编码,并将转换保存为模型图的一部分,因此自动重新应用相同的转换在服务时间,为您节省体力劳动。使用下面的 link 查看他们的示例:
示例:https://www.tensorflow.org/tfx/transform/tutorials/TFT_simple_example
示例 2:https://github.com/tensorflow/transform/blob/master/examples/sentiment_example.py
完整 Python API: https://www.tensorflow.org/tfx/transform/api_docs/python/tft
您要查找的函数是tft.compute_and_apply_vocabulary。