【问题标题】:Error 404 not found In postman when trying to call predict method for tensorflow-hub尝试调用 tensorflow-hub 的预测方法时,在邮递员中找不到错误 404
【发布时间】:2021-03-25 04:24:09
【问题描述】:

我正在使用来自 tensorflow-hub 的 https://tfhub.dev/google/universal-sentence-encoder-multilingual/3 在 Postman 上测试一个 tensorflow 模型,我知道它在 jupyter notebook 中完美运行,没有任何错误,我在发送调用 predict 方法的 POST 请求后在 postman 中遇到了这个错误. 错误:

 "error": "{{function_node __inference_signature_wrapper_133703}} {{function_node __inference_signature_wrapper_133703}} {{function_node __inference__wrapped_model_95698}} {{function_node __inference__wrapped_model_95698}} {{function_node __inference_restored_function_body_51031}} {{function_node __inference_restored_function_body_51031}} [_Derived_]{{function_node __inference___call___6286}} {{function_node __inference___call___6286}} Op type not registered \'SentencepieceOp\' in binary running on 329ddc874964. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.) `tf.contrib.resampler` should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed.\n\t [[{{node StatefulPartitionedCall}}]]\n\t [[StatefulPartitionedCall]]\n\t [[sequential/keras_layer/StatefulPartitionedCall]]\n\t [[StatefulPartitionedCall]]\n\t [[StatefulPartitionedCall]]"

状态为 404 未找到。 这是我的模型:

import tensorflow as tf
import numpy as np
import tensorflow_text
import pandas as pd
import random
import tensorflow_hub as hub
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras import losses
from tensorflow.keras import preprocessing
from tensorflow.keras.layers.experimental.preprocessing import TextVectorization
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense, Dropout
from tensorflow.keras.layers import SpatialDropout1D
from tensorflow.keras.layers import Embedding
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences

module_url = "https://tfhub.dev/google/universal-sentence-encoder-multilingual/3"
# Import the Universal Sentence Encoder's TF Hub module
hub_layer = hub.KerasLayer(module_url, input_shape=[], dtype=tf.string, trainable=True)
#some data preprocessing
opt = keras.optimizers.Adam(learning_rate= 0.001) 

model = tf.keras.Sequential()
model.add(hub_layer)
model.add(tf.keras.layers.Dense(32, activation='relu'))
model.add(tf.keras.layers.Dense(16, activation='relu'))
model.add(tf.keras.layers.Dense(1,activation='sigmoid'))
model.layers[0].trainable = False
model.compile(loss='binary_crossentropy',optimizer=opt, metrics=['accuracy'])
model.summary()
history = model.fit(np.array(tweet),np.array(sentiment),
                  validation_split=0.2, epochs=5, batch_size=32)

这是 Postman 中使用 localhost:.../arabtextclasstfhubtest:predict 的请求:

{ 
"signature_name": "serving_default",
 
    "inputs": 
        {
"keras_layer_input":["كلامك جميل ورائع"]
  }
       
     }

我想知道这是否是 tensoflow-hub 中的错误或如何解决此问题。 谢谢!!

【问题讨论】:

  • 您能否分享完整的代码(如果可以分享),包括 POST 命令,以便我们研究它?谢谢!
  • 是的,我会编辑我的问题,谢谢@TensorflowSupport

标签: python tensorflow postman tensorflow-hub


【解决方案1】:

您似乎正在将 SavedModel 导出到响应 Postman 请求的服务器二进制文件。该服务器二进制文件需要从 tensorflow_text 链接到“SentencepieceOp”,因为您的 SavedModel 使用它(应该如此)。

【讨论】:

    猜你喜欢
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 2021-05-12
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    • 2021-05-12
    相关资源
    最近更新 更多