We have trained a Nasnet model, and deployed the model as an endpoint on AWS Sagemaker successfully. When loading in the model locally, predictions can be made, but I'm not sure the format to pass in images when calling the API endpoint.
For reference, when loaded using tf.keras.load_model, the model's input is as follows:
[<tf.Tensor 'input_2:0' shape=(None, 331, 331, 3) dtype=float32>]
In addition, here is the function used to build the model, containing the model's predict_signature_def
def build(loaded_model, export_dir):
build = builder.SavedModelBuilder(export_dir)
print("INPUT FORMAT:")
print(loaded_model.input)
signature = predict_signature_def(inputs={"inputs": loaded_model.input}, outputs={"score": loaded_model.output})
with K.get_session() as sess:
# Save the meta graph and variables
build.add_meta_graph_and_variables(
sess=sess, tags=[tag_constants.SERVING], signature_def_map={"serving_default": signature})
build.save()
We've tried making API calls to the endpoint in the following format:
client = boto3.client('runtime.sagemaker',
region_name='us-east-1',
aws_access_key_id='ACCESS_KEY',
aws_secret_access_key='SECRET_KEY')
with open("kitchen.jpg", "rb") as image:
f = image.read()
b = bytearray(f)
response = client.invoke_endpoint(EndpointName='ENDPOINT_NAME_HERE',
Body=b)
We tried multiple passing multiple formats for an image in the body (bytearray, base64, numpy array). However, we keep getting the same error from AWS:
Received client error (415) from model with message "{"error": "Unsupported Media Type: Unknown"}".
Does anyone know what the proper image input format should be, or have any suggestions? Thanks