简体   繁体   English

无法在Google Automl上进行预测

[英]Unable to make prediction on google automl

I trained a model and would like to predict the score of a new image. 我训练了一个模型,并希望预测新图像的分数。

Now I execute the following function but it returns an error: 现在,我执行以下函数,但返回错误:

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).

I am not sure if it is due to incorrect location, ie us-central1? 我不确定这是否是由于位置不正确引起的,即us-central1? What is the gcloud command to check? 什么是gcloud命令要检查?

How to solve this problem? 如何解决这个问题呢?

Thank you very much. 非常感谢你。

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

The permission error messages are usually thrown when the application is not being authenticated correctly; 当未正确验证应用程序时,通常会抛出权限错误消息。 Therefore, it is required to verify that the service account you are using has the required roles assigned , as well as provide the credentials to your application by using environment variables or explicitly point to your service account file in code. 因此,需要验证您正在使用的服务帐户是否已分配了必需的角色 ,并需要通过使用环境变量或在代码中显式指向您的服务帐户文件来向应用程序提供凭据 Keep in mind that when you set an environment variable value in a session, it is reset every time the session is dropped. 请记住,在会话中设置环境变量值时,每次删除会话时都会重置该值。

Additionally, AutoML Vision currently requires the location us-central1 , as mentioned in the API Tutorial . 此外,如API教程中所述, AutoML Vision当前需要位置us-central1 Based on this, you should be fine on this aspect; 基于此,您在这方面应该没问题; However, you can take a look on the projects.locations REST methods in case you want to get additional information about this config. 但是,如果您想获取有关此配置的其他信息,则可以看一下projects.locations REST方法。

You can use the following official documentation example to Pass the path to the service account key in code , as well as the QuickStart guide, to know more about the required configuration to begin using AutoML Vision service. 您可以使用以下官方文档示例将路径传递给代码中的服务帐户密钥以及《 快速入门》指南,以了解更多有关开始使用AutoML Vision服务所需的配置的信息。

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());
    }
}

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

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