通过Cloud Function在自定义模型上进行Google AutoML视频分类批量预测



我们已经使用谷歌的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();
};

如果您使用"const client=new 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)

相关内容

  • 没有找到相关文章

最新更新