我使用sagemaker端点部署了一个tensorflow多标签分类模型,如下所示:
predictor = sagemaker_model.deploy(initial_instance_count=1, instance_type="ml.m5.2xlarge", endpoint_name='testing-2')当我从Sag怪-朱庇特实例调用它时,它就会被部署并正常工作:
sample = ['this movie was extremely good']
output=predictor.predict(sample)产出:
{'predictions': [[0.00370046496,
4.32942124e-06,
0.00080883503,
9.25126587e-05,
0.00023958087,
0.000130862]]}但是,我无法从其他笔记本或sagemaker工作室向已部署的端点发送请求。我不确定请求的格式。
我尝试过几种输入格式的变体,但仍然失败。错误消息如下所示:起泡误差
请求:
{
"body": {
"text": "Testing model's prediction on this text"
},
"contentType": "application/json",
"endpointName": "testing-2",
"customURL": "",
"customHeaders": [
{
"Key": "sm_endpoint_name",
"Value": "testing-2"
}
]
}错误:
Error invoking endpoint: Received client error (400) from primary with message "{ "error": "Failed to process element:
0 key: text of 'instances' list. Error: INVALID_ARGUMENT: JSON object: does not have named input: text" }".
See https://us-west-2.console.aws.amazon.com/cloudwatch/home?region=us-west-2#logEventViewer:group=/aws/sagemaker/Endpoints/testing-2
in account 793433463428 for more information.是否有任何方法可以确切地了解模型期望请求格式是什么?
早些时候,我在我的本地系统上有相同的模型,以及我使用这个curl请求测试它的方式:
curl -s -H 'Content-Type: application/json' -d '{"text": "what ugly posts"}' http://localhost:7070/sentiment一切顺利,没有任何问题。
我尝试过不同的格式,并将“文本”键替换为“输入”、“正文”、“nothing”等其他词。
发布于 2022-11-30 01:32:55
根据上面的描述,我假设您正在使用SageMaker TensorFlow容器部署TensorFlow模型。
如果要查看模型所期望的输入,可以使用CLI模型
1
├── keras_metadata.pb
├── saved_model.pb
└── variables
├── variables.data-00000-of-00001
└── variables.index!saved_model_cli show --all --dir {"1"}
在确认了上面的输入名称之后,您可以调用端点,如下所示:
import json
import boto3
client = boto3.client('runtime.sagemaker')
data = {"instances": ['this movie was extremely good']}
response = client.invoke_endpoint(EndpointName=<EndpointName>,
Body=json.dumps(data))
response_body = response['Body']
print(response_body.read())在调用端点时,还可以在Studio中使用相同的有效负载。
https://stackoverflow.com/questions/74597426
复制相似问题