尝试将我的 CNN 模型保存在 Pickle 文件中,但收到类型错误:无法腌制 _thread._local 对象



尝试过2 methods两者都给出相同的错误,请帮助我将其保存为泡菜文件,以便我以后可以使用该模型。

我希望用模型创建service.exe,请提出一种最佳方法,因为我对数据科学比较陌生

result = classifier.predict(kyc_test_image)
kyc_training_set.class_indices
if result[0][0] == 1:
prediction = 'pan'
else:
prediction = 'driv'
kyc_model = classifier
import pickle
modelname = 'cnn_kyc'
outfile = open(modelname,'wb')
pickle.dump(kyc_model,outfile)
outfile.close()

TypeError                                 Traceback (most recent call last)
<ipython-input-35-865fb4ce2e0b> in <module>
----> 1 pickle.dump(kyc_model,outfile)
2 outfile.close()
TypeError: can't pickle _thread._local objects

第二种方法

from sklearn.externals import joblib
joblib.dump(kyc_model, 'cnn_kyc.pkl')
cnn_from_joblib = joblib.load('cnn_kyc.pkl') 
cnn_from_joblib.predict(kyc_test_image)
import joblib        # to save models
# For Saving
python
path_name = "../../../"    # some path

model_name = 'model_name.sav' # I think saving it to sav format maybe will help y

joblib.dump(model, path_name + model_name)
# For Loading
joblib.load(path_name + model_name)

相关内容

  • 没有找到相关文章

最新更新