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"}
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:
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
{
"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.
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.
I work for AWS & my opinions are my own
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.