【发布时间】: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