【发布时间】:2022-06-24 13:28:31
【问题描述】:
我正在学习here 教程,但我没有将模型保存在本地,而是使用顶点 AI 并将模型上传到 AI 平台(遵循教程 here)。当我尝试运行预测时,我收到错误消息InvalidArgument: 400 { "error": "Failed to process element: 0 key: examples of 'instances' list. Error: Invalid argument: JSON Value: 10 Type: Number is not of expected type: string" }:
aiplatform.init(project=GOOGLE_CLOUD_PROJECT, location=GOOGLE_CLOUD_REGION)
# The AI Platform services require regional API endpoints.
client_options = {
'api_endpoint': GOOGLE_CLOUD_REGION + '-aiplatform.googleapis.com'
}
# Initialize client that will be used to create and send requests.
client = aiplatform.gapic.PredictionServiceClient(client_options=client_options)
features = {
'culmen_length_mm': tf.train.Feature(float_list=tf.train.FloatList(value=[49.9])),
'culmen_depth_mm': tf.train.Feature(float_list=tf.train.FloatList(value=[16.1])),
'flipper_length_mm': tf.train.Feature(float_list=tf.train.FloatList(value=[213])),
'body_mass_g': tf.train.Feature(float_list=tf.train.FloatList(value=[5400])),
}
example_proto = tf.train.Example(features=tf.train.Features(feature=features))
examples = example_proto.SerializeToString()
endpoint = client.endpoint_path(
project=GOOGLE_CLOUD_PROJECT,
location=GOOGLE_CLOUD_REGION,
endpoint=ENDPOINT_ID,
)
# Send a prediction request and get response.
client.predict(endpoint=endpoint, instances=[{"examples": [examples]}])
我尝试了上述各种不同的组合,但仍然得到 400 多个。我正在查看this 的帖子,但端点/metadata 不存在。我也在查看this 关于如何格式化 json 的文档,但它并没有告诉我与此示例相关的太多信息。如何检查任何特定 API 的预测请求格式?
【问题讨论】:
-
你能打印输出吗:
print(type(examples)) -
SerializeToString根据this返回字节串
标签: tensorflow google-ai-platform google-cloud-vertex-ai