小编lmo*_*e42的帖子

尝试序列化成功生成的 SageMaker 模型时,是什么导致 unpickling 堆栈下溢?

我目前正在致力于在 Amazon Sagemaker 中建立管道。为此,我设置了一个 xgboost-estimator 并在我的数据集上对其进行了训练。训练作业按预期运行,新训练的模型将保存到指定的输出存储桶中。后来我想重新导入模型,这是通过从输出存储桶中获取 model.tar.gz、提取模型并通过 pickle 序列化二进制文件来完成的。

# download the model artifact from AWS S3
!aws s3 cp s3://my-bucket/output/sagemaker-xgboost-2021-09-06-12-19-41-306/output/model.tar.gz .

# opens the downloaded model artifact and loads it as 'model' variable
model_path = "model.tar.gz"
with tarfile.open(model_path) as tar:
    tar.extractall(path=".")

model = pkl.load(open("xgboost-model", "rb"))
Run Code Online (Sandbox Code Playgroud)

每当我尝试调整它时,我都会收到一个 unpickling 堆栈下溢:

---------------------------------------------------------------------------
UnpicklingError                           Traceback (most recent call last)
<ipython-input-9-b88a7424f790> in <module>
     10     tar.extractall(path=".")
     11 
---> 12 model = pkl.load(open("xgboost-model", "rb"))
     13 

UnpicklingError: unpickling stack underflow
Run Code Online (Sandbox Code Playgroud)

到目前为止,我重新训练了模型,看看错误是否发生在不同的模型文件中,并且确实发生了。我还下载了 model.tar.gz 并通过gunzip 对其进行了验证。当正确提取二进制文件 xgboost-model 时,我无法对其进行 pickle。我在 …

pickle python-3.x amazon-sagemaker

7
推荐指数
2
解决办法
4657
查看次数

标签 统计

amazon-sagemaker ×1

pickle ×1

python-3.x ×1