如何使用Sagemaker Java API调用端点? [英] How to use sagemaker java API to invoke a endpoint?

查看:297
本文介绍了如何使用Sagemaker Java API调用端点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行以下示例: tensorflow_abalone_age_predictor_using_layers ,其中abalone_predictor.predict(tensor_proto)用于调用端点并进行预测.我试图使用Java API AmazonSageMakerRuntime来达到相同的效果,但是我不知道如何为InvokeEndPointRequest指定bodycontentType.该文件未按照请求的格式进行详细说明.非常感谢您的帮助!

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆