尝试使用joblib / pickle加载.pkl或.sav文件时出现内存错误

时间:2020-08-06 13:42:37

标签: python memory scikit-learn pickle joblib

我已经训练了线性SVC模型。我试图通过.sav文件或.pkl文件正常保存它。这样做时,我发现训练后的模型的大小为450 mb。加载使我出现了内存错误。然后我尝试压缩文件,然后保存并加载。

import joblib
filename = 'linear_svc.pkl'
joblib.dump(classifier, filename,compress=True) 

loaded_model = joblib.load('linear_svc.pkl')

压缩后文件变为30mb,但仍然出现内存错误。关于如何解决此问题的任何想法。附加追溯以供参考

Traceback (most recent call last):

  File "<ipython-input-3-896775683223>", line 1, in <module>
    loaded_model = joblib.load('linear_svc.pkl')

  File "C:\Users\km\Anaconda3\lib\site-packages\joblib\numpy_pickle.py", line 585, in load
    obj = _unpickle(fobj, filename, mmap_mode)

  File "C:\Users\km\Anaconda3\lib\site-packages\joblib\numpy_pickle.py", line 504, in _unpickle
    obj = unpickler.load()

  File "C:\Users\km\Anaconda3\lib\pickle.py", line 1085, in load
    dispatch[key[0]](self)

  File "C:\Users\km\Anaconda3\lib\site-packages\joblib\numpy_pickle.py", line 342, in load_build
    self.stack.append(array_wrapper.read(self))

  File "C:\Users\km\Anaconda3\lib\site-packages\joblib\numpy_pickle.py", line 187, in read
    array = self.read_array(unpickler)

  File "C:\Users\km\Anaconda3\lib\site-packages\joblib\numpy_pickle.py", line 133, in read_array
    array = unpickler.np.empty(count, dtype=self.dtype)

MemoryError

0 个答案:

没有答案