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.
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.
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.
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.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With