FastAI V2:来自 learn.export() 的 TabularLearner export.pkl 非常大
FastAI V2: TabularLearner export.pkl from learn.export() is Very Large
我不确定这是否是有意为之,但 learn.export()
中的 export.pkl
大约为 471 MB,这在某些应用程序的部署中有点过高。
来自 SaveModelCallback
的模型本身只有 131 KB
,我只想使用 Learner
来应用相同的 transforms/processing(标准化,FillMissing , 分类).
这么大有什么原因吗?我也确认了
learn.xb
=
(None, )
learn.yb
=
(None, )
原文Post:https://forums.fast.ai/t/tabularlearner-export-pkl-from-learn-export-is-very-large/81251/2
必须pip install wwf
看到https://walkwithfastai.com/tab.export
from wwf.tab.export import *
我们在Learner中手动保存模型
torch.save(learn.model, f'{model_dir}/2_{REF}_LEARNER_MODEL.pt')
我们也导出表格对象
to.export(f'{model_dir}/3_{REF}_TABULAR_OBJECT.pkl')
我们加载表格对象
to_new = load_pandas(f'{model_dir}/3_{REF}_TABULAR_OBJECT.pkl')
to_new = to_new.train.new(df[:20])
to_new.process()
- 我们加载模型
model_2 = torch.load(f'{model_dir}/2_{REF}_LEARNER_MODEL.pt')
learn_new = TabularLearner(dls_new, model)
- 我们进行推理
row, clas, probs = learn_new.predict(df.iloc[0])
row.show()
probs
节省可观:
- 模型:135 kb
- 表格对象:6 kb
对比
- learn.export() 417 mb
我不确定这是否是有意为之,但 learn.export()
中的 export.pkl
大约为 471 MB,这在某些应用程序的部署中有点过高。
来自 SaveModelCallback
的模型本身只有 131 KB
,我只想使用 Learner
来应用相同的 transforms/processing(标准化,FillMissing , 分类).
这么大有什么原因吗?我也确认了
learn.xb
=
(None, )
learn.yb
=
(None, )
原文Post:https://forums.fast.ai/t/tabularlearner-export-pkl-from-learn-export-is-very-large/81251/2
必须pip install wwf
看到https://walkwithfastai.com/tab.export
from wwf.tab.export import *
我们在Learner中手动保存模型
torch.save(learn.model, f'{model_dir}/2_{REF}_LEARNER_MODEL.pt')
我们也导出表格对象
to.export(f'{model_dir}/3_{REF}_TABULAR_OBJECT.pkl')
我们加载表格对象
to_new = load_pandas(f'{model_dir}/3_{REF}_TABULAR_OBJECT.pkl')
to_new = to_new.train.new(df[:20])
to_new.process()
- 我们加载模型
model_2 = torch.load(f'{model_dir}/2_{REF}_LEARNER_MODEL.pt')
learn_new = TabularLearner(dls_new, model)
- 我们进行推理
row, clas, probs = learn_new.predict(df.iloc[0])
row.show()
probs
节省可观:
- 模型:135 kb
- 表格对象:6 kb
对比
- learn.export() 417 mb