predict = [0.1,0.2]
payload = {
"instances": [
{
"features": predict
}
]
}
response = linear_regressor.predict(json.dumps(payload))
predictions = json.loads(response)
print(json.dumps(predictions, indent=2))
上面的代码能够调用作为线性学习器端点的端点并给出以下结果。
{
"predictions": [
{
"score": 0.13421717286109924
}
]
}
但是当我尝试使用下面的lambda函数调用端点时,
import json
import io
import boto3
client = boto3.client('runtime.sagemaker')
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
#data = json.loads(json.dumps(event))
#payload = data['data']
#print(payload)
response = client.invoke_endpoint(EndpointName='linear-learner-2019-12-12-16-xx-xx-xxx',
ContentType='application/json',
Body=json.dumps(event))
return response
出现以下错误,
An error occurred during JSON serialization of response:
<botocore.response.StreamingBody object at 0x7fc941e7e828> is not JSON serializable
lambda函数的输入相同,
{
"instances": [
{
"features": [
0.1,
0.2
]
}
]
}
不确定是什么原因导致了此问题。任何帮助,将不胜感激,谢谢您。