model.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:yadll 作者: pchavanne 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号