通用语句编码器中的Tensorflow会话错误

问题描述 投票:0回答:1

我为通用句子编码器提供了以下代码,一旦我将模型加载到烧瓶中并尝试将其加载,它就会给出以下错误(检查如下):'''

import tensorflow.compat.v1 as tf tf.disable_v2_behavior() module_url = "https://tfhub.dev/google/universal-sentence-encoder-large/5" model_2 = hub.load(module_url) print ("module %s loaded" % module_url) def embed(input): return model_2(input) def universalModel(messages): accuracy = [] similarity_input_placeholder = tf.placeholder(tf.string, shape=(None)) similarity_message_encodings = embed(similarity_input_placeholder) with tf.Session() as session: session.run(tf.global_variables_initializer()) session.run(tf.tables_initializer()) message_embeddings_ = session.run(similarity_message_encodings, feed_dict={similarity_input_placeholder: messages}) corr = np.inner(message_embeddings_, message_embeddings_) accuracy.append(corr[0,1]) # print(corr[0,1]) return "%.2f" % accuracy[0]

'''

使用烧瓶烧瓶api中的模型时出现以下错误:tensorflow.python.framework.errors_impl.InvalidArgumentError:图形无效,包含一个带有1个节点的循环,包括:StatefulPartitionedCall

尽管此代码可以正常运行,但在colab笔记本中。

我正在使用tensorflow版本2.2.0。

我为通用语句编码器提供以下代码,一旦将模型加载到flask api中并尝试点击它,它就会产生以下错误(检查如下:'''import tensorflow.compat.v1 ...
python tensorflow tensorflow2.0 tensorflow-serving sentence-similarity
1个回答
0
投票
import tensorflow.compat.v1 as tf tf.disable_v2_behavior()
© www.soinside.com 2019 - 2024. All rights reserved.