小编Joe*_*tsu的帖子

如何服务于张量流模块,特别是通用句子编码器?

我花了几个小时尝试设置Tensorflow-hub模块“通用语句编码器”的Tensorflow服务。这里有一个类似的问题:

如何使用TensorFlow服务使TensorFlow集线器嵌入成为可服务的?

我一直在Windows计算机上执行此操作。

这是我用来构建模型的代码:

import tensorflow as tf
import tensorflow_hub as hub

MODEL_NAME = 'test'
VERSION = 1
SERVE_PATH = './models/{}/{}'.format(MODEL_NAME, VERSION)

with tf.Graph().as_default():
  module = hub.Module("https://tfhub.dev/google/universal-sentence- 
  encoder/1")
  text = tf.placeholder(tf.string, [None])
  embedding = module(text)

  init_op = tf.group([tf.global_variables_initializer(), 
  tf.tables_initializer()])
  with tf.Session() as session:
  session.run(init_op)
    tf.saved_model.simple_save(
    session,
    SERVE_PATH,
    inputs = {"text": text},
    outputs = {"embedding": embedding},
    legacy_init_op = tf.tables_initializer()        
   )
Run Code Online (Sandbox Code Playgroud)

我已经到了运行以下行的地步:

saved_model_cli show --dir ${PWD}/models/test/1 --tag_set serve --signature_def serving_default
Run Code Online (Sandbox Code Playgroud)

给我以下结果:

The given SavedModel SignatureDef contains the following input(s):
inputs['text'] tensor_info:
  dtype: …
Run Code Online (Sandbox Code Playgroud)

python tensorflow tensorflow-serving tensorflow-hub

10
推荐指数
1
解决办法
1852
查看次数