CMLE是否提供用于预测的REST API端点?

时间:2018-12-10 22:30:42

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

是否可以通过某种方式访问​​Cloud ML Engine创建的模型的REST API端点?我只看到:

gcloud ml-engine jobs submit prediction $JOB_NAME \
    --model census \
    --version v1 \
    --data-format TEXT \
    --region $REGION \
    --runtime-version 1.10 \
    --input-paths gs://cloud-samples-data/ml-engine/testdata/prediction/census.json \
    --output-path $GCS_JOB_DIR/predictions

1 个答案:

答案 0 :(得分:1)

是的,实际上,有两个API可以做到这一点。

  1. projects.predict call是最简单的方法。您传入request as described here,然后返回结果。不能像gsutil命令一样从GCS接收输入。

  2. 带有projects.jobs.create callpredictionInput and predictionOutput fields可以使用来自GCS的输入进行批量预测。

    您的命令的等效项是:

    POST https://ml.googleapis.com/v1/projects/$PROJECT_ID/jobs
    
    {
      "jobId" : "$JOB_NAME",
      "predictionInput": {
        "dataFormat": "TEXT",
        "inputPaths": "gs://cloud-samples-data/ml-engine/testdata/prediction/census.json",
        "region": "REGION",
        "runtimeVersion": "1.10",
        "modelName": "projects/$PROJECT_ID/models/census"
      },
      "predictionOutput": {
        "outputPath": "$GCS_JOB_DIR/predictions"
      }
    }
    

    这立即返回。使用projects.jobs.get检查成功/失败。