[英]Why do I get unpickling error for persistent sklearn model?
I have a trained decision tree model which I created in a google research notebook, and pickled like this:我在谷歌研究笔记本中创建了一个训练有素的决策树模型,并像这样腌制:
pickle.dump(tree, open(tree_15.sav, 'wb'))
We have an online analysis project built from docker, creating the same environment that I used to create the model.我们有一个从 docker 构建的在线分析项目,创建的环境与我用来创建模型的环境相同。 (And some other packages for other functionality.) I want to import my model in that other project, with the following line:
(以及其他一些用于其他功能的包。)我想在其他项目中导入我的模型,使用以下行:
predictive_model = pickle.load(open(self.sav_path, 'rb'), fix_imports=True, encoding='latin1')
But I get:但我得到:
_pickle.UnpicklingError: invalid load key, '\xef'.
Funny thing is, I can not reproduce the same bug locally.有趣的是,我无法在本地重现相同的错误。 I use a windows desktop (so I have problems with building from docker locally), but I use the same version of every package, the .sav file is not corrupted - hash checks out -, etc. It runs quite fine locally every time.
我使用 Windows 桌面(所以我在本地从 docker 构建时遇到问题),但我使用每个包的相同版本,.sav 文件没有损坏 - 哈希检查 - 等等。它每次都在本地运行得很好。 The previous version of the same model ran online as well.
同一模型的先前版本也在网上运行。 I'm quite lost here to be honest.
老实说,我在这里很迷茫。
Often, gzip
's open()
doesn't have the issues that the built-in open()
has, so why not try the following:通常,
gzip
的open()
没有内置open()
问题,所以为什么不尝试以下操作:
import gzip, pickle
with gzip.open(self.sav_path, 'rb') as f:
predictive_model = pickle.load(f, fix_imports=True, encoding='latin1')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.