问题
I was trying to run this example: tensorflow_abalone_age_predictor_using_layers
, in which abalone_predictor.predict(tensor_proto)
is used to call the endpoint and make the prediction. I was trying to use the java API AmazonSageMakerRuntime
to achieve the same effect, but I don't know how to specify the body
and contentType
for the InvokeEndPointRequest
. The document is not in detailed abou the format of the request. Greatly appreciate any piece of help!
回答1:
I have not tried the specific example but the below snippet should help you to invoke the endpoint for predictions
InvokeEndpointRequest invokeEndpointRequest = new InvokeEndpointRequest();
invokeEndpointRequest.setContentType("application/x-image");
ByteBuffer buf = ByteBuffer.wrap(image);
invokeEndpointRequest.setBody(buf);
invokeEndpointRequest.setEndpointName(endpointName);
invokeEndpointRequest.setAccept("application/json");
AmazonSageMakerRuntime amazonSageMaker = AmazonSageMakerRuntimeClientBuilder.defaultClient();
InvokeEndpointResult invokeEndpointResult = amazonSageMaker.invokeEndpoint(invokeEndpointRequest);
I see the example you are trying creates a TensorProto and passes to the endpoint request. You can try to create a TensorProto of your invoke request and set as the body
回答2:
Just figured I can override the input_fn to convert the request body string to something can be fed to the model, in this case a TensorProto object.
来源:https://stackoverflow.com/questions/51309523/how-to-use-sagemaker-java-api-to-invoke-a-endpoint