How to use sagemaker java API to invoke a endpoint?

和自甴很熟 提交于 2019-12-24 00:43:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!