【问题标题】:Google AutoML video classification batch prediction on custom model via Cloud Function通过 Cloud Function 在自定义模型上进行 Google AutoML 视频分类批量预测
【发布时间】:2020-06-26 10:20:48
【问题描述】:

我们已经使用 Google 的 AutoML 视频分类训练了一个模型,现在尝试通过云功能进行批量预测,我们目前正在使用以下代码,但它返回错误消息:

Error: function terminated. Recommended action: inspect logs for termination reason. Details:
7 PERMISSION_DENIED: The caller does not have permission

以下是nodejs代码:

exports.myFunction = (req, res) => {

  const projectId = 'project-id';
  const location = 'us-central1';
  const modelId = 'model-id';
  const inputUri = 'bucket-uri';
  const outputUri = 'bucket-uri';

  console.log("importing google cloud automl...");

  // Imports the Google Cloud AutoML library
  const {PredictionServiceClient} = require(`@google-cloud/automl`).v1;

  console.log("instantiating PredictionServiceClient...");

  // Instantiates a client
  const client = new PredictionServiceClient();

  console.log("instantiated PredictionServiceClient...");

  async function batchPredict() {
    // Construct request
    const request = {
      name: client.modelPath(projectId, location, modelId),
      inputConfig: {
        gcsSource: {
          inputUris: [inputUri],
        },
      },
      outputConfig: {
        gcsDestination: {
          outputUriPrefix: outputUri,
        },
      },
    };

    console.log("making batch prediction...");
    const [operation] = await client.batchPredict(request);

    console.log("about to run promise...");
    const [response] = await operation.promise();
    console.log(response);

    res.status(200).send("Prediction successfull!");
  }

  // make prediction
  batchPredict();

};

【问题讨论】:

  • 您为 Cloud Functions 的服务帐户分配了哪些角色?您有权限问题。

标签: google-cloud-platform google-cloud-functions


【解决方案1】:

如果你正在使用 “常量客户端 = 新的 PredictionServiceClient();” 然后默认服务帐户用于该过程。 "service-@gcp-sa-automl.iam.gserviceaccount.com"

运行批量预测需要以下权限:

  1. AutoML 管理员
  2. AutoML 预测器
  3. AutoML 服务代理
  4. 存储对象管理

如果您想使用不同的服务帐户,请使用以下代码。

credentials = service_account.Credentials.from_service_account_file("/path/to/service-account-key.json")
const client = new PredictionServiceClient(credentials=credentials)

【讨论】:

    猜你喜欢
    • 2020-07-17
    • 2021-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    • 2020-07-20
    相关资源
    最近更新 更多