如何调试“cloudml只支持tf1.0或更高版本,并且模型以SavedModel格式保存。”?

2024-06-30 14:55:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用云ML进行批量预测。我的一些模型可以工作,其他的则不行。我如何调试不起作用的模型?我看到的都是一堆错误:Cloud ML only supports TF 1.0 or above and models saved in SavedModel format.prediction.errors_stats-00000-of-00001中。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: (-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。在


Tags: thenameinfoinputdtoutputsgivenfollowing
3条回答

我也犯了同样的错误,我的命令是:

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

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

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

(2)即使有TF记录,也可以使用gcloud ml engine local predict。假设导出的模型有一个字符串张量输入,其维数为[None],直接输入到ParseExample操作中。在这种情况下,只需遵循标准的jsonapi语法,发送一批包含serialize的字符串tf.示例记录(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很简单:

^{pr2}$

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

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

结果发现问题是由于我的模型被部署在四核CPU上。批量预测不起作用。在单核CPU上部署模型可以解决这个问题。好像是个虫子,我报告了。在

相关问题 更多 >