gpt4 book ai didi

python - 通过 CloudML 获取 TFrecords 的批量预测

转载 作者:行者123 更新时间:2023-11-30 08:57:59 28 4
gpt4 key购买 nike

我关注了this great tutorial并成功训练了一个模型(在 CloudML 上)。我的代码也可以离线进行预测,但现在我尝试使用 Cloud ML 进行预测,但遇到了一些问题。

为了部署我的模型,我遵循 this tutorial 。现在我有一个通过 apache_beam.io.WriteToTFRecord 生成 TFRecords 的代码,我想对这些 TFRecords 进行预测。为此,我关注 this article ,我的命令如下所示:

gcloud ml-engine jobs submit prediction $JOB_ID --model $MODEL --input-paths gs://"$FILE_INPUT".gz --output-path gs://"$OUTPUT"/predictions --region us-west1 --data-format TF_RECORD_GZIP

但我只收到错误:'运行图表期间出现异常:预期序列化为标量,得到的形状:[64]

它似乎需要不同格式的数据。我找到了 JSON here 的格式规范,但找不到如何使用 TFrecords 执行此操作。

更新:这是 saved_model_cli show --all --dir 的输出

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['prediction']:
The given SavedModel SignatureDef contains the following input(s):
inputs['example_proto'] tensor_info:
dtype: DT_STRING
shape: unknown_rank
name: input:0
The given SavedModel SignatureDef contains the following output(s):
outputs['probability'] tensor_info:
dtype: DT_FLOAT
shape: (1, 1)
name: probability:0
Method name is: tensorflow/serving/predict

signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['example_proto'] tensor_info:
dtype: DT_STRING
shape: unknown_rank
name: input:0
The given SavedModel SignatureDef contains the following output(s):
outputs['probability'] tensor_info:
dtype: DT_FLOAT
shape: (1, 1)
name: probability:0
Method name is: tensorflow/serving/predict

最佳答案

导出模型时,需要确保它是“可批量”的,即输入Placeholder的外部尺寸具有shape=[None],例如,

input = tf.Placeholder(dtype=tf.string, shape=[None])
...

这可能需要稍微修改一下图表。例如,我看到输出的形状被硬编码为 [1,1]。最外面的尺寸应该是None,这可能会在您修复占位符时自动发生,或者可能需要其他更改。

鉴于输出的名称是概率,我还希望最里面的维度>1,即预测的类的数量,所以类似于[None, NUM_CLASSES ]

关于python - 通过 CloudML 获取 TFrecords 的批量预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52303403/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com