aws / aws/amazon-sagemaker-examples
Input preprocessing for inference call inside Sagemaker
- Dominant language
- Jupyter Notebook
- Stars
- 11k
- Forks
- 7k
- Avg merge
- 8h 29m
- Merged PRs (30d)
- 8
Description
I have a pretrained Keras model (tensorflow backend) - `model.json` and `model-weight.hdf5` which I was able to deploy using [this tutorial](https://aws.amazon.com/blogs/machine-learning/deploy-trained-keras-or-tensorflow-models-using-amazon-sagemaker/). The tutorial converts those files to `protobuf` format and creates `model.tar.gz` and puts it in S3
I can call the deployed endpoint from a boto client code in my local machine. The client code does some preprocessing before calling the endpoint. I need to put this preprocessing portion of the code inside Sagemaker. I am assuming I need to update the entry point file `train.py` to have the preprocessing code. But I am not sure how. Should I override `input_fn`? If so how?
Below is the client side preprocessing code that I need to put inside sagemaker instead of a separate client
```
img_path = 'shoe.jpg' # path to a local image downloaded from S3
img = image.load_img(img_path, target_size=(256, 256))
img_data = image.img_to_array(img)
img_data = np.expand_dims(img_data, axis=0)
img_data = preprocess_input(img_data)
data = img_data.tolist()
```
Right now, I invoke the endpoint like below which I understand that the Body portion will change to a JSON payload of S3 data download link.
`response = client.invoke_endpoint(EndpointName=endpoint_name, Body=json.dumps(data))`
Contributor guide
Assessment
This issue has not been assessed yet.