sagemaker-pipeline
sagemaker-pipeline copied to clipboard
[Article request] Chalice with TF Serving payload format
Hi, I've followed along with your Medium article successfully. I've also done this sagemaker tutorial: tensorflow_bring_your_own/tensorflow_bring_your_own.ipynb. The format required to send an image to the TF Serving RESTful endpoint in this tutorial is:
import json
import numpy as np
from PIL import Image
img_path = './img.jpg'
image = np.asarray(Image.open(img_path)).astype(np.float32)
image = np.expand_dims(image, axis=0)
data = {'instances': image}
data = json.dumps({k: _ndarray_to_list(v) for k, v in six.iteritems(data)}) # or sagemaker.predictor.json_serializer
request_args = {}
request_args['Body'] = data
request_args['EndpointName'] = 'my-endpoint-name'
request_args['ContentType'] = 'application/json'
request_args['Accept'] = 'application/json'
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(**request_args)
I'm struggling to figure out how I can send either a jpg or image as numpy array to Chalice in order to preprocess the image into this format required for TF serving. Any chance you might be able to help?