c# - 如何在 C# 中调用 Sagemaker 训练模型端点 API

标签 c# amazon-web-services amazon-s3 sparkr amazon-sagemaker

我已经通过 sagemaker 实现了机器学习算法。

我已经为 .net 安装了 SDK,并通过执行以下代码进行了尝试。

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);

通过执行此操作,我收到验证错误,因为“检测到 1 个验证错误:'body' 处的值未能满足约束:成员不得为 null

谁能指导我如何以及需要传递哪些输入数据来调用给定的 API?

编辑

此外,我还尝试提供包含由“.gz”或“.pkl”文件写入的 MemoryStream 的正文参数,它给我的错误是:“从 AWS 解码响应时出错,HTTP 内容长度超过 5246976字节。”

编辑 2018 年 1 月 23 日

此外,我想出了错误消息作为

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

谢谢

最佳答案

后来通过 Encoding.ASCII.GetBytes 解决了这个问题,如下面的代码。

 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());

关于c# - 如何在 C# 中调用 Sagemaker 训练模型端点 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48365866/

相关文章:

amazon-web-services - 如何重命名AWS S3存储桶

amazon-web-services - Claudia.js 自动生成的 lambda 函数未显示在 AWS 控制台上

android - 使用 transferobserver android 设置 aws 对象的权限

c# - 资源解释为脚本但使用 MIME 类型 application/json 传输。 &解析器错误

c# - 将 FTP 服务器上现有的文件附加到 C# .NET 中的邮件

c# - 如何根据 Active Directory 联合身份验证服务 (ADFS) 验证用户名和密码?

c# - 如何防止列表中的项目在未填写且应为 "0"时返回 "null"?

amazon-web-services - AWS Beanstalk 和 IPset

python-3.x - 如何在 sagemaker notebook 中打开存储在 S3 存储桶中的模型 tarfile?

amazon-web-services - Amazon S3 异常 : "The specified key does not exist"