无法对 google automl 进行预测
Unable to make prediction on google automl
我训练了一个模型,想预测一张新图像的分数。
现在我执行以下函数,但它 returns 出错:
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
当应用程序未被正确身份验证 时,通常会抛出权限错误消息;因此,需要通过使用环境变量或在代码中明确指向您的服务帐户文件来验证您使用的服务帐户是否具有所需的 roles assigned, as well as provide the credentials to your application。请记住,当您在会话中设置环境变量值时,每次会话被删除时它都会被重置。
此外,AutoML Vision 当前需要位置 us-central1,如 API Tutorial. Based on this, you should be fine on this aspect; However, you can take a look on the projects.locations REST 方法中所述,以防万一您想获得有关此配置的其他信息。
您可以使用以下官方文档示例将路径传递给代码中的服务帐户密钥,以及QuickStart指南,以了解更多信息开始使用 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());
}
}
我训练了一个模型,想预测一张新图像的分数。
现在我执行以下函数,但它 returns 出错:
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
当应用程序未被正确身份验证 时,通常会抛出权限错误消息;因此,需要通过使用环境变量或在代码中明确指向您的服务帐户文件来验证您使用的服务帐户是否具有所需的 roles assigned, as well as provide the credentials to your application。请记住,当您在会话中设置环境变量值时,每次会话被删除时它都会被重置。
此外,AutoML Vision 当前需要位置 us-central1,如 API Tutorial. Based on this, you should be fine on this aspect; However, you can take a look on the projects.locations REST 方法中所述,以防万一您想获得有关此配置的其他信息。
您可以使用以下官方文档示例将路径传递给代码中的服务帐户密钥,以及QuickStart指南,以了解更多信息开始使用 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());
}
}