首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试调用tensorflow-hub的预测方法时,在邮递员中找不到错误404

尝试调用tensorflow-hub的预测方法时,在邮递员中找不到错误404
EN

Stack Overflow用户
提问于 2020-12-14 22:15:33
回答 1查看 108关注 0票数 0

我在Postman上测试了一个tensorflow模型,它使用了tensorflow-hub中的https://tfhub.dev/google/universal-sentence-encoder-multilingual/3,知道它在jupyter笔记本上工作得很好,没有任何错误,在发送一个调用predict方法的POST请求后,我在postman中遇到了这个错误。错误:

代码语言:javascript
复制
 "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未找到。这是我的模型:

代码语言:javascript
复制
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)

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

代码语言:javascript
复制
{ 
"signature_name": "serving_default",
 
    "inputs": 
        {
"keras_layer_input":["كلامك جميل ورائع"]
  }
       
     }

我想知道这是否是how hub中的bug,或者如何解决这个问题。谢谢你!!

EN

回答 1

Stack Overflow用户

发布于 2021-01-06 18:38:38

您似乎正在将SavedModel导出到响应邮递员请求的服务器二进制文件。该服务器二进制文件需要链接到来自tensorflow_text的'SentencepieceOp‘,因为您的SavedModel使用它(正如它应该使用的那样)。

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

https://stackoverflow.com/questions/65290557

复制
相关文章

相似问题

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