How to call the Sagemaker training endpoint API in C #

I implemented machine learning algorithms through sagemaker.

I installed the SDK for .net and tried to execute the code below.

Uri sagemakerEndPointURI = new Uri("https://runtime.sagemaker.us-east-2.amazonaws.com/endpoints/MyEndpointName/invocations"); Amazon.SageMakerRuntime.Model.InvokeEndpointRequest request = new Amazon.SageMakerRuntime.Model.InvokeEndpointRequest(); request.EndpointName = "MyEndpointName"; AmazonSageMakerRuntimeClient aawsClient = new AmazonSageMakerRuntimeClient(myAwsAccessKey,myAwsSecreteKey); Amazon.SageMakerRuntime.Model.InvokeEndpointResponse resposnse= aawsClient.InvokeEndpoint(request); 

By doing this, I get a 1 validation error detected: Value at 'body' failed to satisfy constraint: Member must not be null as " 1 validation error detected: Value at 'body' failed to satisfy constraint: Member must not be null "

Can someone explain to me how and what additional input I need to pass to call this API?

EDIT

Then I tried, specifying the body parameter, which contains the MemoryStream written by the file ".gz" or ".pkl", and it gives me the error: "Error canceling the cancellation of the response from AWS, the length of the HTTP content exceeded 5246976 bytes."

EDIT 1/23/2018

Next I came up with the error message as

ERROR - model server - the TypeError object does not have the 'message' attribute

thanks

+5
source share
2 answers

He later resolved it to Encoding.ASCII.GetBytes , as in the code below.

  byte[] bytes = System.IO.File.ReadAllBytes(@"EXCEL_FILE_PATH"); string listA = ""; while (!reader.EndOfStream) { var line = reader.ReadLine(); listA = listA + line + "\n"; } byte[] bytes = Encoding.ASCII.GetBytes(listA); request.Body = new MemoryStream(bytes); InvokeEndpointResponse response = sagemakerRunTimeClient.InvokeEndpoint(request); string predictions = Encoding.UTF8.GetString(response.Body.ToArray()); 
0
source

As far as I can see, your request lacks both the Body property and the Guy and ContentType clauses, which should refer to the type of input data that you pass to Amazon SageMaker (see the following code: my CSV input file contains one example).

 byte[] content = File.ReadAllBytes("input.csv"); Amazon.SageMakerRuntime.Model.InvokeEndpointRequest request = new Amazon.SageMakerRuntime.Model.InvokeEndpointRequest(); request.EndpointName = "linear-learner-xxxxxxxx-xxxx"; request.ContentType = "text/csv"; request.Body = new MemoryStream(content); AmazonSageMakerRuntimeClient awsClient = new AmazonSageMakerRuntimeClient(accessKey, secretKey); Amazon.SageMakerRuntime.Model.InvokeEndpointResponse response = awsClient.InvokeEndpoint(request); string predictions = Encoding.UTF8.GetString(response.Body.ToArray()); 

As for the byte limit 5246976, this is an API that reaches the maximum allowable length of the response body in the context of a single request. A way to avoid this is to make several calls, rather than transmit large batches of elements for forecasting.

If you use Amazon SageMaker's built-in algorithms, you can check the allowed data format for inputs and outputs at the following address:

https://docs.aws.amazon.com/sagemaker/latest/dg/common-info-all-im-models.html

0
source

Source: https://habr.com/ru/post/1274846/


All Articles