【问题标题】:Run A Prediction On Pre-Created Model/Endpoint对预先创建的模型/端点运行预测
【发布时间】:2019-08-14 19:55:38
【问题描述】:

我通过 Sagemaker Jupyter 笔记本实例中的单独脚本创建了一个端点。我正在尝试在另一个脚本中访问该端点并对其进行推理。

我不知道我可以运行什么来专门拉取端点并将其分配给变量。

过去我部署了一个链接到 RCF 的端点,如下所示:

#This creates an endpoint
rcf_inference = rcf.deploy(
    initial_instance_count=1,
    instance_type='ml.m4.xlarge',
)
print('Endpoint name: {}'.format(rcf_inference.endpoint))

我在另一个脚本中使用了 rcf_inference 变量来运行推理,我想在这里遵循相同的路线,但无法重新部署 rcf。

#This grabs the data we want to test from an s3
s3=boto3.client('s3')
obj=s3.get_object(Bucket=bucket,Key=testingDataKey)


prediction_data = pandas.read_csv(io.BytesIO(obj['Body'].read()))
prediction_data_numpy=np.array(prediction_data)

#This line runs the test data and stores it in results. 
#I do not have a rcf_inference variable, so I can't run it this way though.
#results = rcf_inference.predict(prediction_data_numpy)

predictor = RealTimePredictor(endpoint=endpoint, accept=CONTENT_TYPE_CSV)
results=predictor.predict(prediction_data_numpy.tobytes())

必须有某种方法来调用我的端点并将其分配给这个变量,对吧?我的目标是获取这个变量并对其进行推断,就像我在其他脚本中所做的那样。当我通过当前方法运行它时,我得到“无法评估提供的有效负载”。

【问题讨论】:

    标签: python jupyter endpoint amazon-sagemaker inference


    【解决方案1】:

    您使用 RealTimePredictor 的方法是正确的。只要您在同一区域并使用正确的端点名称,那么一切都应该按预期工作。

    我假设 RCF 代表 RandomCutForest,它是 SageMaker Python SDK 中支持的算法。在这种情况下,很可能在部署该算法时提供的预测器类在默认序列化/反序列化方面可能具有不同的配置。请使用该类或复制相同的配置:https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/amazon/randomcutforest.py#L152

    【讨论】:

      【解决方案2】:

      如果我错了,请纠正我,但听起来您正在寻找“DescribeEndpoint”API 调用。

      以下内容可能是您正在寻找的内容:

      sagemaker.Session().sagemaker_client.describe_endpoint(EndpointName=endpoint_name)
      

      查看 sagemaker-python-sdk 存储库中的以下代码 sn-p 以获取工作示例:https://github.com/aws/sagemaker-python-sdk/blob/db6c55ec4a21dbd59e264e2ab9fc1e8494aa781f/tests/integ/test_mxnet_train.py#L131

      如果有帮助,请告诉我!

      【讨论】:

        猜你喜欢
        • 2022-11-12
        • 2020-01-11
        • 2018-06-12
        • 1970-01-01
        • 2016-10-06
        • 2015-11-13
        • 1970-01-01
        • 2020-12-08
        • 1970-01-01
        相关资源
        最近更新 更多