def save_model(model, file=None):
"""
Save the model to file with cPickle
This function is used by the training function to save the model.
Parameters
----------
model : :class:`yadll.model.Model`
model to be saved in file
file : `string`
file name
"""
if file is None:
if model.file is None:
logger.error('No file name. Model not saved.')
return
else:
d_file = model.file
else:
d_file = file
try:
with open(d_file, 'wb') as f:
pickle.dump(model, f, pickle.HIGHEST_PROTOCOL)
except RuntimeError:
sys.setrecursionlimit(5000)
with open(d_file, 'wb') as f:
pickle.dump(model, f, pickle.HIGHEST_PROTOCOL)
评论列表
文章目录