简体   繁体   English

SageMaker 端点 AWS Lambda 推理问题

[英]SageMaker endpoint AWS Lambda inference Issue

I've deployed a category trained model and hosted the endpoint.. and trying to inference this, but have a issue.. basically we take a short description ie "laptop screen" this should return a category ie "Hardware" the problem i'm facing is that i just seem to get this error when inferencing this via postman.我已经部署了一个经过类别训练的模型并托管了端点......并试图推断出这一点,但有一个问题......基本上我们采取了一个简短的描述,即“笔记本电脑屏幕”这应该返回一个类别,即“硬件”问题我'我面临的是,当我通过邮递员进行推断时,我似乎只是遇到了这个错误。

ie if i send this {"data":"laptop screen"}即如果我发送这个{"data":"laptop screen"}

i get this error in the body我的身体出现这个错误

{
    "errorMessage": "Expecting value: line 1 column 1 (char 0)",
    "errorType": "JSONDecodeError",
    "stackTrace": [
        [
            "/var/task/lambda_function.py",
            21,
            "lambda_handler",
            "result = json.loads(response['Body'].read().decode())"
        ],
        [
            "/var/lang/lib/python3.6/json/__init__.py",
            354,
            "loads",
            "return _default_decoder.decode(s)"
        ],
        [
            "/var/lang/lib/python3.6/json/decoder.py",
            339,
            "decode",
            "obj, end = self.raw_decode(s, idx=_w(s, 0).end())"
        ],
        [
            "/var/lang/lib/python3.6/json/decoder.py",
            357,
            "raw_decode",
            "raise JSONDecodeError(\"Expecting value\", s, err.value) from None"
        ]
    ]
}

this is my lambda function:这是我的 lambda 函数:

import os
import io
import boto3
import json
import csv

ENDPOINT_NAME = os.environ['ENDPOINT_NAME']
runtime= 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 = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,
                                        ContentType='text/csv',
                                        Body=payload)
    print(response)
    result = json.loads(response['Body'].read().decode())
    
    return result

Ive added this to admin IAM role too我也将此添加到管理员 IAM 角色

{
    "Sid": "VisualEditor0",
    "Effect": "Allow",
    "Action": "sagemaker:InvokeEndpoint",
    "Resource": "*"
}

Any assistance would be ace, i feel im pretty close it works fine when it comes to predicting priority, but need help when predicting category string.任何帮助都是王牌,我觉得我非常接近它在预测优先级时效果很好,但在预测类别字符串时需要帮助。

For your lambda function, I think the error might be with the way you're passing your payload in, take the following code snippet.对于您的 lambda 函数,我认为错误可能与您传入有效负载的方式有关,请使用以下代码片段。

    data = json.loads(json.dumps(event))
    payload = json.dumps(data)
    response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,
                                       ContentType='application/json',
                                       Body=payload)
    result = json.loads(response['Body'].read().decode())

Adjust the payload that you are passing in to use json.dumps() to encode your data properly for the endpoint.调整您传入的有效负载以使用 json.dumps() 为端点正确编码数据。

I work for AWS & my opinions are my own我为 AWS 工作,我的意见是我自己的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM