Python 运行图形期间出现异常:无法从提要中获取作为字节的元素
我使用beam管道将文本预处理为整型文字包,类似于本例 预处理和培训似乎很有效。我训练了一个简单的线性模型,指向变换函数并进行了实验 保存的_model.pbtxt似乎保存了字典,我的目标是能够在google cloud ml上部署此模型进行预测,并使用原始文本作为输入进行查询:Python 运行图形期间出现异常:无法从提要中获取作为字节的元素,python,tensorflow,google-cloud-ml,Python,Tensorflow,Google Cloud Ml,我使用beam管道将文本预处理为整型文字包,类似于本例 预处理和培训似乎很有效。我训练了一个简单的线性模型,指向变换函数并进行了实验 保存的_model.pbtxt似乎保存了字典,我的目标是能够在google cloud ml上部署此模型进行预测,并使用原始文本作为输入进行查询: {"inputs" : { "title": "E. D. Abbott Ltd", "text" : "Abbott of Farnham E D Abbott Limited was a British coach
{"inputs" : { "title": "E. D. Abbott Ltd", "text" : "Abbott of Farnham E D Abbott Limited was a British coachbuilding business" }}
跑步时
gcloud ml-engine local predict \
--model-dir=$MODEL_DIR \
--json-instances="$DATA_DIR/test.json" \
我得到下面的错误,不知道我做错了什么
源代码/日志
警告:根:元图有多个签名2。支持多个签名
有限的。默认情况下,我们选择命名签名。
错误:root:运行图形期间异常:无法从提要a获取元素
s字节。
回溯(最近一次呼叫最后一次):
文件“lib/googlecloudsdk/command_lib/ml_engine/local_predict.py”,第136行,在
main()
文件“lib/googlecloudsdk/command_lib/ml_engine/local_predict.py”,第131行,mai
N
实例=实例)
文件“/Users/xyz/Downloads/googlecloudsdk/lib/third_party/cloud_ml_引擎
e_sdk/prediction/prediction_lib.py”,第656行,在local_predict中
_,预测=模型。预测(实例)
文件“/Users/xyz/Downloads/googlecloudsdk/lib/third_party/cloud_ml_引擎
e_sdk/prediction/prediction_lib.py”,第553行,预测
输出=self.\u client.predict(列、统计)
文件“/Users/xyz/Downloads/googlecloudsdk/lib/third_party/cloud_ml_引擎
e_sdk/prediction/prediction_lib.py”,预测中第382行
运行图表时出现异常:“+str(e))
prediction_lib.PredictionError:(4,'运行图形时出现异常:无法执行g
源中的et元素作为字节。“)
build_parsing_transforming_serving_input_fn()的文档说,它生成一个输入函数,将转换应用于编码为tf的原始数据。示例为序列化字符串。更复杂的是,该字符串必须进行base64编码才能发送到预测服务(请参阅) 我建议使用build\u default\u transforming\u serving\u input\u fn(),它用于json输入。那么您的json文件应该只有
{ "title": "E. D. Abbott Ltd", "text" : "Abbott of Farnham E D Abbott Limited was a British coachbuilding business" }
{ "title": "another title", "text" : "more text" }
...
无关:如果您将min_eval_frequency设置为高于1的某个值(1000通常是一个好数字),您应该会在培训时看到更好的性能,因此它可以在本地使用gcloud ml engine local predict \--model dir=$model_dir \--json instances=“$DATA_dir/test.json”\但是,在云ML上加载模型并请求预测gcloud ML引擎预测\--model$model\u NAME \--version$version \--json实例=“$DATA\u DIR/test.json”\返回`{“错误”:“预测失败:模型执行期间异常:流产错误(code=StatusCode.INVALID\u参数,详细信息=\”输入大小与签名\“”“}不匹配。知道发生了什么吗?当发送到服务时,请求的正文应该是:{“实例”:[{“标题”:“X”,“文本”:“Y”}。这就是您的吗?
def feature_columns(vocab_size=100000):
result = []
for key in TEXT_COLUMNS:
column = tf.contrib.layers.sparse_column_with_integerized_feature(key, vocab_size, combiner='sum')
result.append(column)
return result
model_fn = tf.contrib.learn.LinearClassifier(
feature_columns=feature_columns(),
n_classes=15,
model_dir=output_dir
)
def get_transformed_reader_input_fn(transformed_metadata,
transformed_data_paths,
batch_size,
mode):
"""Wrap the get input features function to provide the runtime arguments."""
return input_fn_maker.build_training_input_fn(
metadata=transformed_metadata,
file_pattern=(
transformed_data_paths[0] if len(transformed_data_paths) == 1
else transformed_data_paths),
training_batch_size=batch_size,
label_keys=[LABEL_COLUMN],
reader=gzip_reader_fn,
key_feature_name='key',
reader_num_threads=4,
queue_capacity=batch_size * 2,
randomize_input=(mode != tf.contrib.learn.ModeKeys.EVAL),
num_epochs=(1 if mode == tf.contrib.learn.ModeKeys.EVAL else None))
transformed_metadata = metadata_io.read_metadata(
args.transformed_metadata_path)
raw_metadata = metadata_io.read_metadata(args.raw_metadata_path)
train_input_fn = get_transformed_reader_input_fn(
transformed_metadata, args.train_data_paths, args.batch_size,
tf.contrib.learn.ModeKeys.TRAIN)
eval_input_fn = get_transformed_reader_input_fn(
transformed_metadata, args.eval_data_paths, args.batch_size,
tf.contrib.learn.ModeKeys.EVAL)
serving_input_fn = input_fn_maker.build_parsing_transforming_serving_input_fn(
raw_metadata,
args.transform_savedmodel,
raw_label_keys=[],
raw_feature_keys=model.TEXT_COLUMNS)
export_strategy = tf.contrib.learn.utils.make_export_strategy(
serving_input_fn,
default_output_alternative_key=None,
exports_to_keep=5,
as_text=True)
return Experiment(
estimator=model_fn,
train_input_fn=train_input_fn,
eval_input_fn=eval_input_fn,
export_strategies=export_strategy,
eval_metrics=model.get_eval_metrics(),
train_monitors=[],
train_steps=args.train_steps,
eval_steps=args.eval_steps,
min_eval_frequency=1
)
{ "title": "E. D. Abbott Ltd", "text" : "Abbott of Farnham E D Abbott Limited was a British coachbuilding business" }
{ "title": "another title", "text" : "more text" }
...