通过python批量预测Google automl

问题描述

我使用stackoverflow以及使用Google Cloud Platform还是很新的,如果不能以正确的格式问这个问题,我深表歉意。我目前在从模型中获取预测时遇到问题。

我已经在Google云平台上训练了多标签automl模型,现在我想使用该模型对新数据条目进行评分。 由于该平台只能同时允许一个条目,因此我想利用python进行批量预测。

我已将数据条目存储在Google云存储桶上的单独的.txt文件中,并创建了一个.txt文件,其中我列出了对这些文件的gs://引用(例如它们在{{3}中的建议}。

我已使用服务帐户中的凭据导出了.json文件,并在代码中指定了ID和路径:

# import API credentials and specify model / path references
path = 'xxx.json'
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = path

model_name = 'xxx'
model_id = 'TCN1234567890'
project_id = '1234567890'
model_full_id = f"https://eu-automl.googleapis.com/v1/projects/{project_id}/locations/eu/models/{model_id}"
input_uri = f"gs://bucket_name/{model_name}/file_list.txt"
output_uri = f"gs://bucket_name/{model_name}/outputs/"
prediction_client = automl.PredictionServiceClient()

然后我正在运行以下代码来获取预测:

# score batch of file_list
gcs_source = automl.GcsSource(input_uris=[input_uri])

input_config = automl.BatchPredictInputConfig(gcs_source=gcs_source)
gcs_destination = automl.GcsDestination(output_uri_prefix=output_uri)
output_config = automl.BatchPredictOutputConfig(
    gcs_destination=gcs_destination
)

response = prediction_client.batch_predict(
    name=model_full_id,input_config=input_config,output_config=output_config
)

print("Waiting for operation to complete...")
print(
    f"Batch Prediction results saved to Cloud Storage bucket. {response.result()}"
)

但是,我遇到以下错误:InvalidArgument:400请求包含无效的参数。

print screen of the error

有人会隐瞒是什么原因导致此问题吗? 任何输入将不胜感激!谢谢!

解决方法

发现了问题!

我需要先将客户端设置为“ eu”环境:

options = ClientOptions(api_endpoint='eu-automl.googleapis.com')
prediction_client = automl.PredictionServiceClient(client_options=options)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...