【发布时间】:2019-02-08 04:46:57
【问题描述】:
在 AWS Sagemaker 上部署 scikit 模型后,我使用以下方法调用我的模型:
import pandas as pd
payload = pd.read_csv('test3.csv')
payload_file = io.StringIO()
payload.to_csv(payload_file, header = None, index = None)
import boto3
client = boto3.client('sagemaker-runtime')
response = client.invoke_endpoint(
EndpointName= endpoint_name,
Body= payload_file.getvalue(),
ContentType = 'text/csv')
import json
result = json.loads(response['Body'].read().decode())
print(result)
上面的代码完美运行,但是当我尝试时:
payload = np.array([[100,5,1,2,3,4]])
我得到错误:
ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500) from container-1 with message
"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>500 Internal Server Error</title> <h1>
Internal Server Error</h1> <p>The server encountered an internal error and was unable to complete your request.
Either the server is overloaded or there is an error in the application.</p>
Scikit-learn SageMaker Estimators and Models 中提到,
SageMaker Scikit-learn 模型服务器提供默认实现 输入_fn。此函数反序列化 JSON、CSV 或 NPY 编码数据 到 NumPy 数组中。
我想知道如何修改默认值以接受 2D numpy 数组,以便将其用于实时预测。
有什么建议吗?我尝试使用 Inference Pipeline with Scikit-learn and Linear Learner 作为参考,但无法用 Scikit 模型替换线性学习器。我收到了同样的错误。
【问题讨论】:
标签: python amazon-web-services numpy machine-learning scikit-learn