【问题标题】:Save a pipeline Logistic Regression model保存管道逻辑回归模型
【发布时间】:2021-07-22 00:14:57
【问题描述】:
lrmodel=logreg_pipeline.fit(X_train_resh,y_train_resh)
lrmodel.write().overwrite().save("E:/strokestuff/strokelrpred")
lrmodel.save("E:/strokestuff/strokelrpred")

lrmodel 是一个管道,我想保存它,我的目的是保存这个模型,然后加载它以部署到 Flutter 中。我已经尝试了所有解决方案,有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: flutter machine-learning pipeline


    【解决方案1】:

    您可以使用joblib 将您的模型保存在.joblib 文件中:

    import joblib
    
    pipe_clf_params = {}
    filename = 'E:/strokestuff/strokelrpred/strokelrpred.joblib'
    
    pipe_clf_params['pipeline'] = lrmodel
    joblib.dump(pipe_clf_params, filename)
    

    【讨论】:

    • 对不起,我不知道如何接受它,我现在已经这样做了。当我加载保存的模型以将其转换为 tflite 模型时,它说,保存的模型文件不存在
    • 像这样加载该文件:pipeline = joblib.load(filename)。请使用与我的回答中提到的相同的filename。
    • import tensorflow as tf import os # Convert the model #mypath ='E:/strokestuff/strokelr/strokelr.pb' converter = tf.lite.TFLiteConverter.from_saved_model(filename) tflite_model = converter.convert() # Save the model. with open('stroke_lr.tflite', 'wb') as f: f.write(tflite_model) 我必须加载并将其转换为 tflite,但这不会发生。我收到操作系统错误 -OSError: SavedModel 文件不存在于:E:/strokestuff/strokelr/strokelrpred.pb\{saved_model.pbtxt|saved_model.pb}
    猜你喜欢
    • 1970-01-01
    • 2018-05-20
    • 2020-12-22
    • 1970-01-01
    • 2018-01-26
    • 2019-06-01
    • 2017-07-21
    • 2019-01-06
    • 2021-04-28
    相关资源
    最近更新 更多