amazon-web-services - 失败的前提条件:表未初始化。在 aws sagemaker 部署的通用句子编码器上
问题描述
我已将 Universal_sentence_encoder_large_3 部署到 aws sagemaker。当我尝试使用已部署的模型进行预测时,我得到Failed precondition: Table not initialized.
了一个错误。我在下面包含了我保存模型的部分:
import tensorflow as tf
import tensorflow_hub as hub
import numpy as np
def tfhub_to_savedmodel(model_name, export_path):
model_path = '{}/{}/00000001'.format(export_path, model_name)
tfhub_uri = 'http://tfhub.dev/google/universal-sentence-encoder-large/3'
with tf.Session() as sess:
module = hub.Module(tfhub_uri)
sess.run([tf.global_variables_initializer(), tf.tables_initializer()])
input_params = module.get_input_info_dict()
dtype = input_params['text'].dtype
shape = input_params['text'].get_shape()
# define the model inputs
inputs = {'text': tf.placeholder(dtype, shape, 'text')}
output = module(inputs['text'])
outputs = {
'vector': output,
}
# export the model
tf.saved_model.simple_save(
sess,
model_path,
inputs=inputs,
outputs=outputs)
return model_path
我看到其他人问过这个问题,但没有发布任何解决方案。这似乎是 tensorflow_hub 句子编码器的常见问题
解决方案
本周早些时候,我在尝试修改此示例Sagemaker notebook时遇到了这个确切的问题。特别是为模型服务的部分。也就是说,predictor.predict()
在 Sagemaker Tensorflow Estimator 上运行。
问题中概述的解决方案对我来说非常有效 - https://github.com/awslabs/amazon-sagemaker-examples/issues/773#issuecomment-509433290
我认为这只是因为只为训练而运行,但如果您想在预测期间运行它,tf.tables_initializer()
则需要通过 指定。legacy_init_op
推荐阅读
- xamarin.forms - VS for Mac 中的 Xamarin.Android 预览问题
- kubernetes - 如何创建从 google kubernetes 引擎集群到外部 IP 地址的端口转发?
- ios - PhoneGap 不显示 iOS 版本
- css - 如何从页面中删除范围编号 ID 元素?
- excel - 如何修复损坏的 (VBA) Excel/XLSM?(通常是“自动化错误(2147467259)未指定错误”)
- postgresql - Postgres 日期范围可以包含无穷大作为上限吗?
- lua - git bash 上的 Lua 不起作用,适用于 CMD 窗口
- reactjs - Webencore 失败:检测到重复的插件/预设
- docker - Docker - 在哪里查看服务规模的完整日志
- c - 比较字符串的有效方法是什么?