确定GCMLE模型中所需的占位符

时间:2017-12-05 21:31:46

标签: google-cloud-platform google-cloud-ml

几周前我已经部署了一个模型,我已经忘记了模型需要哪些输入功能(是的,我知道我应该更好地跟踪这个)。当我运行以下命令时

gcloud ml-engine predict \
--model $MODEL_NAME \
--version v1 \
--json-instances \
../test.json

我得到以下错误:

{
  "error": "Prediction failed: Exception during model execution: AbortionError(code=StatusCode.INVALID_ARGUMENT, details=\"input size does not match signature\")"
}

我知道我的问题是因为有一些"要求"我没有包含在我的json请求(test.json)中的占位符,但我无法找到任何方法来追溯找出丢失的占位符。

问题与此question的问题相同,海报能够在包含失踪的"阈值"时提交预测。张量。

查看给定模型的预期输入的最简单方法是什么?

2 个答案:

答案 0 :(得分:2)

服务本身还不允许您查询模型的签名,因此我建议尽可能使用saved_model_cli(假设您没有删除原始模型)。类似的东西:

gcloud ml-engine versions describe v1 --model census | grep deploymentUri

将输出如下内容:

deploymentUri: gs://my_bucket/path/to/Servo/1488268526779

现在,使用saved_model_cli

saved_model_cli show --all --dir gs://my_bucket/path/to/Servo/1488268526779

将输出如下内容:

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

signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['age'] tensor_info:
    dtype: DT_FLOAT
    shape: (-1)
    name: Placeholder_8:0
inputs['capital_gain'] tensor_info:
    dtype: DT_FLOAT
    shape: (-1)
    name: Placeholder_10:0
inputs['capital_loss'] tensor_info:
    dtype: DT_FLOAT
    shape: (-1)
    name: Placeholder_11:0
inputs['education'] tensor_info:
    dtype: DT_STRING
    shape: (-1)
    name: Placeholder_2:0
inputs['education_num'] tensor_info:
    dtype: DT_FLOAT
    shape: (-1)
    name: Placeholder_9:0
inputs['gender'] tensor_info:
    dtype: DT_STRING
    shape: (-1)
    name: Placeholder:0
inputs['hours_per_week'] tensor_info:
    dtype: DT_FLOAT
    shape: (-1)
    name: Placeholder_12:0
inputs['marital_status'] tensor_info:
    dtype: DT_STRING
    shape: (-1)
    name: Placeholder_3:0
inputs['native_country'] tensor_info:
    dtype: DT_STRING
    shape: (-1)
    name: Placeholder_7:0
inputs['occupation'] tensor_info:
    dtype: DT_STRING
    shape: (-1)
    name: Placeholder_6:0
inputs['race'] tensor_info:
    dtype: DT_STRING
    shape: (-1)
    name: Placeholder_1:0
inputs['relationship'] tensor_info:
    dtype: DT_STRING
    shape: (-1)
    name: Placeholder_4:0
inputs['workclass'] tensor_info:
    dtype: DT_STRING
    shape: (-1)
    name: Placeholder_5:0
The given SavedModel SignatureDef contains the following output(s):
outputs['classes'] tensor_info:
    dtype: DT_INT64
    shape: (-1)
    name: predictions/classes:0
outputs['logistic'] tensor_info:
    dtype: DT_FLOAT
    shape: (-1, 1)
    name: predictions/logistic:0
outputs['logits'] tensor_info:
    dtype: DT_FLOAT
    shape: (-1, 1)
    name: add:0
outputs['probabilities'] tensor_info:
    dtype: DT_FLOAT
    shape: (-1, 2)
    name: predictions/probabilities:0
Method name is: tensorflow/serving/predict

答案 1 :(得分:0)

假设您有与保存模型关联的张量流图。如果您可以打印图形(以文本格式打印protobuffer)或使用工具进行可视化,您可以看到" signature_def"图表中的字段。这应该告诉您图表的输入和输出。您可以将请求中发送的张量与图表所需的输入进行比较。