【问题标题】:AWS SageMaker 'invoke_endpoint' returns output of definition of functions, not codeAWS SageMaker \'invoke_endpoint\' 返回函数定义的输出,而不是代码
【发布时间】:2023-01-26 21:22:10
【问题描述】:

我最近开始使用 AWS SageMaker,有一些我不明白的地方。

在 SageMaker 中,我部署了一个端点,我想测试它。我了解到我必须使用 invoke_endpoint 函数。 当我部署端点时,端点中有一个名为 MyFile.py 的文件,其结构如下:

[importing libraries]


[definition of some functions]


if __name__ == '__main__':
    [block of code that does some operations and invokes functions]


[definition of other functions]

当我使用以下代码时:

import boto3
import sagemaker

[...]

sagemaker_runtime = boto3.client('runtime.sagemaker')

response = sagemaker_runtime.invoke_endpoint(
    EndpointName='MyEndPoint',
    ContentType='MyContentType',
    Body=MyBody
)

我看到 response 对象包含最后一个代码块中定义的函数的输出,在以 if __name__ == '__main__': 开头的块之后。

但是,鉴于在最后一段代码中没有调用函数的代码,这怎么可能呢?此外,这是否意味着 invoke_endpoint 函数将 __name__ 变量设置为 __main__ 以外的其他变量?

【问题讨论】:

    标签: python amazon-web-services runtime amazon-sagemaker endpoint


    【解决方案1】:

    找到了答案。 我正在使用 SKLearn 来创建我的端点,SKLearn 端点会自动按顺序触发一系列函数,如下所示:https://sagemaker.readthedocs.io/en/stable/frameworks/sklearn/using_sklearn.html#sagemaker-scikit-learn-model-server

    【讨论】:

      猜你喜欢
      • 2014-09-03
      • 1970-01-01
      • 2021-09-11
      • 2018-08-10
      • 2018-05-08
      • 2021-12-21
      • 2020-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多