通过CloudML获取TFrecord的批量预测

发布于 2021-01-29 14:59:22

我遵循了这个很棒的教程,并成功地在CloudML上训练了一个模型。我的代码还离线进行预测,但是现在我正在尝试使用Cloud
ML进行预测并遇到一些问题。

为了部署我的模型,我遵循了本教程。现在,我有一个生成TFRecordsvia的代码,apache_beam.io.WriteToTFRecord并且我想对此进行预测TFRecords。为此,我关注本文,我的命令如下所示:

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

但是我只有错误: 'Exception during running the graph: Expected serialized to be a scalar, got shape: [64]

看起来它期望数据采用不同的格式。我在这里找到了JSON的格式规范,但找不到如何使用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
关注者
0
被浏览
60
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

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

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

    这可能需要重新处理图形。例如,我看到输出的形状被硬编码为[1,1]。最外面的尺寸应该是None,这在您固定占位符时可能会自动发生,或者可能需要进行其他更改。

    给定输出的名称是probabilities,我还希望最里面的维度> 1,即要预测的类数,因此类似[None, NUM_CLASSES]



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看