简体   繁体   English

在AWS EC2实例中加载泡菜包

[英]Loading a pickle package in AWS EC2 instance

I have saved one of my models in local using pickle (windows Python 3.6), I needed that model to run on an EC2 Linux instance (using Python 2.7) to make predictions. 我已经使用pickle(Windows Python 3.6)在本地保存了一个模型,我需要该模型在EC2 Linux实例上运行(使用Python 2.7)进行预测。 I had transferred the saved model from my laptop to EC2 instance using Filezilla, now when I am trying to load the model using the following code: 现在,当我尝试使用以下代码加载模型时,我已经使用Filezilla将保存的模型从笔记本电脑转移到EC2实例:

filename = 'Customer_segmentation_model_xgb_final.sav'
loaded_model = pickle.load(open(filename,'rb'))

It gives the following error: 它给出以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/pickle.py", line 1384, in load
    return Unpickler(file).load()
  File "/usr/lib64/python2.7/pickle.py", line 864, in load
    dispatch[key](self)
  File "/usr/lib64/python2.7/pickle.py", line 892, in load_proto
    raise ValueError, "unsupported pickle protocol: %d" % proto
ValueError: unsupported pickle protocol: 3

Someone please suggest what I am doing wrong and what needs to be done. 有人建议我做错了什么,需要做什么。

It looks like a compatibility problem, I would suggest to install the same version of Python on your server (python 3.6) since the pickle module is part of the Python standard library: 似乎有兼容性问题,我建议您在服务器上安装相同版本的Python(Python 3.6),因为pickle模块是Python标准库的一部分:

sudo apt-get install python3.6

You could also force a lower protocol when you dump initially ( EDIT : like proposed in the comments): 您也可以在最初转储时强制使用较低的协议( 编辑 :如注释中建议的那样):

pickle.dump(model, file, protocol=2)

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM