我有一个应用程序,我正在加载非常大的 python 对象——它们是序列化的 scikit-learn 分类器及其相关的词汇表。
分类器足够大(大约 1-100 MB),将它们加载到内存中是一项非常重要的任务。实际读取速度很快,但 unpickling 需要很长时间,对于 4MB 分类器来说大约需要 10 秒。
有没有比 cPickle.dumps/cPickle.loads 更快的方法来序列化/反序列化对象?
附加信息:
分类器是 10 个元素的一对一随机森林的实例。分类器在大约 1000 个样本、大约 500 个特征和 52 个可能的标签上进行了训练。该min_density
参数设置为 0。
cPickle.load 的 cProfile 输出:
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 300.168 300.168 <ipython-input-4-9b8a128f290d>:1(loader)
1 0.899 0.899 301.067 301.067 <string>:1(<module>)
51380 288.151 0.006 288.151 0.006 __init__.py:93(__RandomState_ctor)
51380 0.059 0.000 0.404 0.000 fromnumeric.py:1774(amax)
1 11.613 11.613 300.168 300.168 {cPickle.load}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
51380 0.344 0.000 0.344 0.000 {method 'max' of 'numpy.ndarray' objects}
1 0.000 0.000 0.000 0.000 {open}
我正在 github.com/scikit-learn 上打开一个关于此的问题。