首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Tensorflow服务从输入函数转换数据

Tensorflow服务从输入函数转换数据
EN

Stack Overflow用户
提问于 2019-03-21 07:55:04
回答 1查看 521关注 0票数 0

目前我正在开发一个tensorflow模型。该模型根据2个字符串和一个数字对情况进行分类。所以我的占位符如下所示:

代码语言:javascript
运行
复制
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服务于这个模型,代码如下:

代码语言:javascript
运行
复制
    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编码的张量,并将其提供给我的模型吗?在训练我的模型时,我只是在喂它们之前用一个函数对它们进行了转换。在服务时,这似乎是不可能的,因为我只能定义输入函数,而不能定义输入数据流。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-09 22:49:01

tf.one_hot提供了一种热编码。

但是,更广泛地说,您需要协调训练和服务以使用相同的索引。Tensorflow Transform提供了在训练数据处理阶段执行许多转换(单热、缩放、分段)的方法,包括单热编码,并将转换保存为模型图的一部分,因此在服务时自动重新应用相同的转换,从而节省了您的手动工作。通过下面的链接查看他们的示例:

示例: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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55271842

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档