Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_pickle.UnpicklingError: invalid load key, 'x'

Tags:

python

pickle

I have this pickle file, which I'm trying to unpickle using the following Python script:

import _pickle as pickle

pickle_file = open('bof.pkl', 'rb')
data = pickle.load(pickle_file)

When I run the program, I get the following error:

Traceback (most recent call last):
  File "unpickle.py", line 4, in <module>
    data = pickle.load(pickle_file)
_pickle.UnpicklingError: invalid load key, 'x'.

How can I solve this issue, as I couldn't find a way to do that.

like image 416
Simplicity Avatar asked Jun 30 '17 15:06

Simplicity


People also ask

How do you load data on pickle?

Python Pickle load To retrieve pickled data, the steps are quite simple. You have to use pickle. load() function to do that. The primary argument of pickle load function is the file object that you get by opening the file in read-binary (rb) mode.

What is UnPickling error in Python?

Pickling error - _pickle. UnpicklingError: invalid load key, '<'. This kind of error comes when Weights are complete or some problem with the Weights/ Pickle file because of which UnPickling of weights giving Error.

How do I Unpickle a pickle file?

As we said earlier, the load() method can be used to unpickle the pickled Python object. You have to first open the pickled file using rb (read-binary) permission and pass the opened file to the load() method, as shown below. The load() method unpickles the data and returns the actual object.


1 Answers

I found that the program was using from sklearn.externals import joblib, and thus saved the pickle file as follows:

joblib.dump(....)

I was thus able to load the pickle content as follows:

clf = joblib.load('pickle_file.pkl')
like image 169
Simplicity Avatar answered Oct 12 '22 10:10

Simplicity