Solution to UnicodeDecodeError when using pickle

Recently, I want to initialize the pytorch model with the parameters of the caffe model. The idea is to convert the caffe model into a dict first, and then match it with the parameters of pytorch. The pickle.load() function needs to be used in this process, but the following encoding error is encountered when using it: UnicodeDecodeError: 'ascii' codec can't decode byte 0x8b in position 6: ordinal not in range(128). Set the encoding in the pickle.load() function to 'iso-8859-1' to solve the problem,

import pickle as pkl


weights = "xxx.pkl"
pkl.load(weights, encoding="iso-8859-1")

Guess you like

Origin blog.csdn.net/qq_38964360/article/details/132114720