我使用dill
将ML模型保存到文件中。
当我使用python -m unittest
运行测试时,它可以工作。但是,如果我尝试使用python setup.py test
运行测试,则会在尝试保存模型的原始文件中出现错误TypeError: can't pickle PyCapsule objects
。
我在setup.py中用于测试的设置:test_suite='tests',tests_require=['pytest']
错误:
File "/Users/anna/anaconda3/lib/python3.6/site-packages/dill/_dill.py", line 1055, in save_builtin_method
pickler.save_reduce(_get_attr, (module, obj.__name__), obj=obj)
File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 610, in save_reduce
save(args)
File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 476, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 736, in save_tuple
save(element)
File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 476, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/anna/anaconda3/lib/python3.6/site-packages/dill/_dill.py", line 1260, in save_module
state=_main_dict)
File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 634, in save_reduce
save(state)
File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 476, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/anna/anaconda3/lib/python3.6/site-packages/dill/_dill.py", line 893, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 821, in save_dict
self._batch_setitems(obj.items())
File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 847, in _batch_setitems
save(v)
File "/Users/anna/anaconda3/lib/python3.6/pickle.py", line 496, in save
rv = reduce(self.proto)
TypeError: can't pickle PyCapsule objects
您能帮我知道为什么它不起作用吗?
最佳答案
我是dill
的作者。这是dill
的已知未解决问题。请参阅:https://github.com/uqfoundation/dill/issues/106。本质上,PyCapsule
对象的序列化功能尚未在dill
中注册。