如何使用 sagemaker java API 来调用端点? [英] How to use sagemaker java API to invoke a endpoint?
问题描述
我试图运行这个例子:tensorflow_abalone_age_predictor_using_layers,其中abalone_predictor.predict(tensor_proto)
用于调用端点并进行预测.我试图使用 java API AmazonSageMakerRuntime
来达到同样的效果,但我不知道如何指定 body
和 contentType
InvokeEndPointRequest
.该文件没有详细说明请求的格式.非常感谢任何帮助!
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!
推荐答案
我还没有尝试过具体的例子,但下面的代码片段应该可以帮助你调用端点进行预测
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);
我看到您正在尝试创建一个 TensorProto 并传递给端点请求的示例.您可以尝试创建您的调用的TensorProto请求并设置为正文
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
这篇关于如何使用 sagemaker java API 来调用端点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!