Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Sagemaker training model endpoint API in C#

I have implemented machine learning algorithms through sagemaker.

I have installed SDK for .net, and tried by executing below code.

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 executing this, I am getting validation error as "1 validation error detected: Value at 'body' failed to satisfy constraint: Member must not be null"

Can anyone guide me on how and what more input data I need to pass to call the given API?

EDIT

Further I'd tried by provinding body parameter which contains a MemoryStream written by a '.gz' or '.pkl' file, and it giving me error as : "Error unmarshalling response back from AWS, HTTP content length exceeded 5246976 bytes."

EDIT 1/23/2018

Further I came up with the error message as

ERROR - model server - 'TypeError' object has no attribute 'message'

Thanks

like image 358
Diboliya Avatar asked Jan 21 '18 10:01

Diboliya


1 Answers

Later solved it by Encoding.ASCII.GetBytesas in below code.

 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());
like image 110
Diboliya Avatar answered Sep 21 '22 17:09

Diboliya