如何解决通过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请求包含无效的参数。
有人会隐瞒是什么原因导致此问题吗? 任何输入将不胜感激!谢谢!
解决方法
发现了问题!
我需要先将客户端设置为“ eu”环境:
options = ClientOptions(api_endpoint='eu-automl.googleapis.com')
prediction_client = automl.PredictionServiceClient(client_options=options)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。