我正在使用以下命令使用通用句子编码器预训练模型:
import tensorflow as tf
import tensorflow_hub as hub
MODEL_NAME = 'tf-sentence-encoder'
VERSION = 1
SERVE_PATH = './models/{}/{}'.format(MODEL_NAME, VERSION)
with tf.Graph().as_default():
module = hub.Module("https://tfhub.dev/google/universal-sentence-encoder-large/3")
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()
)
如何为 RESTFUL API 重新加载保存的模型?