繁体   English   中英

GCP Vertex AI Endpoint 返回空预测数组

[英]GCP Vertex AI Endpoint returning empty prediction array

KFP 管道作业成功执行,但在到达端点时,得到一个空的预测数组 ([])。 我怀疑问题出在 model 上传中,其中 model 没有以某种方式正确注册。 任何提示表示赞赏。

上传 model 部署任务的代码:

    #Import a model programmatically
    model_upload = aiplatform.Model.upload(
        display_name = DISPLAY_NAME, 
        serving_container_image_uri = serving_container_image_uri,
        serving_container_health_route="/health_check",
        serving_container_predict_route="/predict",
        serving_container_ports=[8080],
        serving_container_environment_variables={
            "MODEL_NAME": MODEL_NAME,
        },       
    )

获取预测的代码:

response = endpoint.predict({"user_id": 150})
# response = endpoint.predict({"instances":{"user_id": 150}})
response

回复:

Prediction(predictions=[], deployed_model_id='4656867150235959296', explanations=None)

TLDR:

检查您的处理程序 output 是否在满足要求的响应中返回格式正确且没有多余斜杠 ( \ ) 的字符串。

或者使用raw predict而不是predict调用。 指导


调试步骤:

我也有这个问题,我使用 Vertex AI 自定义服务容器方法并调用endpoint.predict(instances=[{...}]).predictions只返回一个空列表: []

Even though, when using raw predict from the Python SDK or via REST endpoint , it returned a valid response for the data JSON key:

Python SDK 响应:

"{\"predictions\": \"[{\\\"key1\\\": \\\"string1\\\", \\\"key2\\\": [\\\"string2\\\"], \\\"key3\\\": 0.0}]\"}"

REST API 响应:

{"predictions": "[{\"key1\": \"string1\", \"key2\": [\"string2\"], \"key3\": 0.0}]"}

但是,在这两种情况下,您都可以看到响应中有额外的斜杠 ( \ )。 这意味着这是一个格式问题


解决方案:

事实证明,在我的处理程序的后处理步骤中,我做了以下事情:

prediction_result = {
            "key1": value1,
            "key2": value2,
            "key3": value3,
        }
array = np.array([prediction_result])

return json.dumps({"predictions": array.tolist()})

将其更改为以下解决了我的问题:

prediction_result = {
            "key1": value1,
            "key2": value2,
            "key3": value3,
        }

return json.dumps({"predictions": [prediction_result]})

然后调用endpoint.predict(instances=[{...}]).predictions为我返回以下列表:

[{'key1': 'string1',
  'key2': ['string2'],
  'key3': 0.0}]

修复后,来自raw predict的响应不再包含额外的斜杠 ( \ )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM