尝试在Sagemaker笔记本实例中进行预测时,Sagemaker Endpoint返回错误

时间:2020-07-16 16:00:18

标签: python amazon-web-services machine-learning amazon-sagemaker

我已经在sagemaker上部署了一个推理管道端点,但是现在当我尝试进行预测调用时,却收到一条错误消息,并且据我所知,我正在遵循此处显示的示例: https://github.com/awslabs/amazon-sagemaker-examples/blob/master/sagemaker-python-sdk/scikit_learn_inference_pipeline/Inference%20Pipeline%20with%20Scikit-learn%20and%20Linear%20Learner.ipynb

进行端点调用的代码在这里:

from sagemaker.predictor import json_serializer, csv_serializer, json_deserializer, RealTimePredictor
from sagemaker.content_types import CONTENT_TYPE_CSV, CONTENT_TYPE_JSON

predictor = RealTimePredictor(
    endpoint='Boston-inf-pipeline-July09-endpoint',
    sagemaker_session=sagemaker_session,
    serializer=csv_serializer,
    content_type=CONTENT_TYPE_CSV,
    accept=CONTENT_TYPE_CSV)


from sklearn.pipeline import Pipeline
from sklearn.preprocessing import Binarizer, StandardScaler, OneHotEncoder
from sklearn.impute import SimpleImputer

column_names = ['CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX', 'PTRATIO', 'B', 'LSTAT', 'MEDV']

dff = pd.read_csv('housing.csv',delimiter=r"\s+", names=column_names)

dff.drop('MEDV',axis=1,inplace=True)

 
#String
x = '0.00632,18.0,2.31,0,0.538,6.575,65.2,4.09,1,296.0,15.3,396.9,4.98'

#DataFrame
y= dff.head(1)

#Array
z = np.array([0.00632,18.0,2.31,0,0.538,6.575,65.2,4.09,1,296.0,15.3,396.9,4.98])

print(predictor.predict(x))**strong text**

,这是错误消息:

enter image description here

这是Cloud Watch上的内容

enter image description here

1 个答案:

答案 0 :(得分:0)

您的SageMaker端点在cloudwatch日志的屏幕截图中提出了ValueError

ValueError: Found array with 0 sample(s)...

您似乎已部署的模型期望输入的形状不同,如Found array with 0 sample(s) (shape=(0, 40)) while a minimum of 1 is required中所述。

sagemaker端点声称您传递的numpy输入值的“形状”为(0, 13),最有可能期望的是(1, 13)。从客户端脚本看来,您似乎正在传递形状为(13,)的数组,并且最终在SageMaker容器中将其解释为(0, 13)

您可以尝试在输入中添加另一个尺寸以在客户端脚本中形成输入形状(1, 13)吗?

z = np.array([[0.00632,18.0,2.31,0,0.538,6.575,65.2,4.09,1,296.0,15.3,396.9,4.98]])

PS:我正在开发一个更快便宜易于使用的平台,用于部署sklearn https://modelzoo.dev中的模型。您可能很适合我们的私人Beta版计划-与contact@modelzoo.dev取得联系,我可以帮助您进行设置。