【问题标题】:Unable to make prediction on google automl无法对 google automl 进行预测
【发布时间】:2018-09-15 17:32:23
【问题描述】:

我训练了一个模型,想预测一张新图像的分数。

现在我执行以下函数,但它返回错误:

google.api_core.exceptions.PermissionDenied: 403 Permission 'automl.models.predict' denied on resource 'projects/project_id/locations/us-central1/models/model_id' (or it may not exist).

我不确定是不是因为位置不正确,即 us-central1?要检查的 gcloud 命令是什么?

如何解决这个问题?

非常感谢。

def get_prediction(content, project_id, model_id):

    prediction_client = automl_v1beta1.PredictionServiceClient()
    name = 'projects/{}/locations/us-central1/models/{}'.format(project_id, model_id)
    payload = {'image': {'image_bytes': content }}
    params = {}
    request = prediction_client.predict(name, payload, params)
    return request  # waits till request is returned

【问题讨论】:

    标签: python google-app-engine google-cloud-automl-nl


    【解决方案1】:

    权限错误消息通常在应用程序未正确验证时抛出;因此,需要通过使用环境变量或在代码中显式指向您的服务帐户文件来验证您正在使用的服务帐户是否具有所需的roles assignedprovide the credentials to your application。请记住,当您在会话中设置环境变量值时,每次会话被删除时都会重置它。

    此外,AutoML Vision 目前需要位置 us-central1,如 API Tutorial 中所述。基于此,您在这方面应该没问题;但是,如果您想获取有关此配置的更多信息,可以查看 projects.locations REST 方法。

    您可以使用以下官方文档示例在代码中传递服务帐户密钥的路径,以及QuickStart 指南,以了解有关开始使用 AutoML 所需配置的更多信息视觉服务。

    namespace Google\Cloud\Samples\Auth;
    
    // Imports the Google Cloud Storage client library.
    use Google\Cloud\Storage\StorageClient;
    
    function auth_cloud_explicit($projectId, $serviceAccountPath)
    {
        # Explicitly use service account credentials by specifying the private key
        # file.
        $config = [
            'keyFilePath' => $serviceAccountPath,
            'projectId' => $projectId,
        ];
        $storage = new StorageClient($config);
    
        # Make an authenticated API request (listing storage buckets)
        foreach ($storage->buckets() as $bucket) {
            printf('Bucket: %s' . PHP_EOL, $bucket->name());
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-10-25
      • 1970-01-01
      • 2020-07-17
      • 2020-08-29
      • 2020-10-23
      • 2019-09-08
      • 2021-06-03
      • 2020-12-08
      • 2013-01-03
      相关资源
      最近更新 更多