【问题标题】:How to preprocess data for tensorflow/serving model?如何为张量流/服务模型预处理数据?
【发布时间】:2020-01-13 18:31:57
【问题描述】:

我对 Tensorflow 比较陌生。我使用 Docker 在本地部署了这个模型,但是我输入的数据没有经过预处理,所以它给了我一个错误。这可能是因为我在创建模型时对模型外的数据进行了预处理?

当我输入数据时,我从部署的 tensorflow/serving 通过 Docker 得到这个错误:

{ "error": "Failed to process element: 0 of \'instances\' list. Error: Invalid argument: JSON Value: \"Hello\" Type: String is not of expected type: float" }

这意味着它需要一个标记化的单词数组,因此,[[32],[1]]。类似的东西。

这是我的模型的样子:

    model = tf.keras.Sequential([
            tf.keras.layers.Embedding(
                vocab_size, embedding_dim, input_length=max_length),
            tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(32)),
            tf.keras.layers.Dense(128, activation="relu"),
            tf.keras.layers.Dense(3, activation="softmax")
        ])

如何以与初始训练数据相同的方式对数据进行标记和填充,或者如何将该步骤添加到模型中?

【问题讨论】:

    标签: python docker tensorflow tensorflow-serving


    【解决方案1】:

    更新:

    找了好久,不知道为什么这么久才遇到pickling,用同一个tokenizer对输入请求进行token化的答案就是pickle,所以

    # saving
    with open('tokenizer.pickle', 'wb') as handle:
        pickle.dump(tokenizer, handle, protocol=pickle.HIGHEST_PROTOCOL)
    
    # loading
    with open('tokenizer.pickle', 'rb') as handle:
        tokenizer = pickle.load(handle)
    

    如果需要,可以对填充进行同样的操作。

    【讨论】:

      猜你喜欢
      • 2020-02-29
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-22
      • 1970-01-01
      • 2020-05-29
      • 2021-10-07
      相关资源
      最近更新 更多