如何调试“Cloud ML仅支持TF 1.0或更高版本以及以SavedModel格式保存的模型。”?

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

我使用Cloud ML进行批量预测。我的一些模型有效,有些则没有。我如何调试不起作用的模型?我看到的一切都是一堆错误:Cloud ML only supports TF 1.0 or above and models saved in SavedModel format.中的prediction.errors_stats-00000-of-00001saved_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: (-1)
    name: input:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['id'] tensor_info:
    dtype: DT_STRING
    shape: (-1)
    name: id:0
    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: (-1)
    name: input:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['id'] tensor_info:
    dtype: DT_STRING
    shape: (-1)
    name: id:0
    outputs['label'] tensor_info:
    dtype: DT_INT64
    shape: (-1)
    name: label:0
    outputs['probability'] tensor_info:
    dtype: DT_FLOAT
    shape: (-1, 1)
    name: probability:0
  Method name is: tensorflow/serving/predict

更新:我的数据是TF记录的形式,所以我不能做gcloud ml-engine local predict

python tensorflow google-cloud-ml
3个回答
0
投票

(1)您在部署模型时是否指定了--runtime-version?默认情况下,它是1.0,但可能你需要TensorFlow版本1.8或类似的东西。如果您的模型使用1.0之后添加的ops,您可能会收到此消息。

(2)即使使用TF Records,你也可以使用gcloud ml-engine本地预测。据推测,导出的模型具有单个字符串张量输入,其维度[无]直接提供给ParseExample操作。在这种情况下,您只需按照标准JSON API语法发送一批包含serialize tf.Example记录的字符串(base64对它们进行编码并使用语法来表示):

  {"instances": [{"b64": base64.b64encode(example1), {"b64": base64.b64encode(example2}}, ...]}

另一个(更好的)选项重新导出它(不必重新训练,你总是可以通过编写一些带有几行的脚本来导出检查点或SavedModel来加载模型并导出新模型)而不是使用build_parsing_transforming_serving_input_receiver_fn使用build_default_transforming_serving_input_receiver_fn。然后你的JSON很简单:

{"instances": [{"input_name": [10,3,5,6]}]} 

如果您只有一个输入,则可以进一步简化为:

{"instances": [[10,3,5,6]]} 

0
投票

事实证明,问题是由于我的模型部署在四核CPU上。批量预测不起作用。在单核CPU上部署模型可以解决问题。这似乎是一个错误,我报道。


0
投票

我得到了同样的错误,我的命令是:

gcloud ml-engine local predict --model-dir $MODEL_DIR --json-instances $JSON_INSTANCES --verbosity debug

问题是我的$MODEL_DIR指向错误的模型目录。确保模型在SavedModel format

© www.soinside.com 2019 - 2024. All rights reserved.