尝试过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)