joblib.dump() 报错

来源:10-8 基于新数据的迁移学习实战

慕函数4411803

2021-05-22


TypeError Traceback (most recent call last)
in
3 import joblib
4
----> 5 joblib.dump(model1, “model1.m”)
6

G:\anaconda3\envs\imooc_ai\lib\site-packages\joblib\numpy_pickle.py in dump(value, filename, compress, protocol, cache_size)
478 elif is_filename:
479 with open(filename, ‘wb’) as f:
–> 480 NumpyPickler(f, protocol=protocol).dump(value)
481 else:
482 NumpyPickler(filename, protocol=protocol).dump(value)

G:\anaconda3\envs\imooc_ai\lib\pickle.py in dump(self, obj)
485 if self.proto >= 4:
486 self.framer.start_framing()
–> 487 self.save(obj)
488 self.write(STOP)
489 self.framer.end_framing()

G:\anaconda3\envs\imooc_ai\lib\site-packages\joblib\numpy_pickle.py in save(self, obj)
280 return
281
–> 282 return Pickler.save(self, obj)
283
284

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save(self, obj, save_persistent_id)
601
602 # Save the reduce() output and finally memoize the object
–> 603 self.save_reduce(obj=obj, *rv)
604
605 def persistent_id(self, obj):

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save_reduce(self, func, args, state, listitems, dictitems, state_setter, obj)
715 if state is not None:
716 if state_setter is None:
–> 717 save(state)
718 write(BUILD)
719 else:

G:\anaconda3\envs\imooc_ai\lib\site-packages\joblib\numpy_pickle.py in save(self, obj)
280 return
281
–> 282 return Pickler.save(self, obj)
283
284

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save(self, obj, save_persistent_id)
558 f = self.dispatch.get(t)
559 if f is not None:
–> 560 f(self, obj) # Call unbound method with explicit self
561 return
562

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save_dict(self, obj)
969
970 self.memoize(obj)
–> 971 self._batch_setitems(obj.items())
972
973 dispatch[dict] = save_dict

G:\anaconda3\envs\imooc_ai\lib\pickle.py in _batch_setitems(self, items)
995 for k, v in tmp:
996 save(k)
–> 997 save(v)
998 write(SETITEMS)
999 elif n:

G:\anaconda3\envs\imooc_ai\lib\site-packages\joblib\numpy_pickle.py in save(self, obj)
280 return
281
–> 282 return Pickler.save(self, obj)
283
284

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save(self, obj, save_persistent_id)
601
602 # Save the reduce() output and finally memoize the object
–> 603 self.save_reduce(obj=obj, *rv)
604
605 def persistent_id(self, obj):

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save_reduce(self, func, args, state, listitems, dictitems, state_setter, obj)
715 if state is not None:
716 if state_setter is None:
–> 717 save(state)
718 write(BUILD)
719 else:

G:\anaconda3\envs\imooc_ai\lib\site-packages\joblib\numpy_pickle.py in save(self, obj)
280 return
281
–> 282 return Pickler.save(self, obj)
283
284

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save(self, obj, save_persistent_id)
558 f = self.dispatch.get(t)
559 if f is not None:
–> 560 f(self, obj) # Call unbound method with explicit self
561 return
562

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save_dict(self, obj)
969
970 self.memoize(obj)
–> 971 self._batch_setitems(obj.items())
972
973 dispatch[dict] = save_dict

G:\anaconda3\envs\imooc_ai\lib\pickle.py in _batch_setitems(self, items)
995 for k, v in tmp:
996 save(k)
–> 997 save(v)
998 write(SETITEMS)
999 elif n:

G:\anaconda3\envs\imooc_ai\lib\site-packages\joblib\numpy_pickle.py in save(self, obj)
280 return
281
–> 282 return Pickler.save(self, obj)
283
284

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save(self, obj, save_persistent_id)
558 f = self.dispatch.get(t)
559 if f is not None:
–> 560 f(self, obj) # Call unbound method with explicit self
561 return
562

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save_dict(self, obj)
969
970 self.memoize(obj)
–> 971 self._batch_setitems(obj.items())
972
973 dispatch[dict] = save_dict

G:\anaconda3\envs\imooc_ai\lib\pickle.py in _batch_setitems(self, items)
994 write(MARK)
995 for k, v in tmp:
–> 996 save(k)
997 save(v)
998 write(SETITEMS)

G:\anaconda3\envs\imooc_ai\lib\site-packages\joblib\numpy_pickle.py in save(self, obj)
280 return
281
–> 282 return Pickler.save(self, obj)
283
284

G:\anaconda3\envs\imooc_ai\lib\pickle.py in save(self, obj, save_persistent_id)
576 reduce = getattr(obj, “reduce_ex”, None)
577 if reduce is not None:
–> 578 rv = reduce(self.proto)
579 else:
580 reduce = getattr(obj, “reduce”, None)

TypeError: cannot pickle ‘weakref’ object

用的sklearn 版本高于0.23
直接import joblib
想问新版本有没有办法解决?

写回答

1回答

flare_zhao

2021-05-24

最好版本一致,新版本的话,可以查询一下,应该有替换方法

0
2
flare_zhao
回复
慕函数4411803
版本问题其实这次解决了,以后跟新版本也会有新的问题,所以最高效的方法还是保持版本一致。印象中高版本sklearn只是joblib的引用方式不同,网上搜索对应版本sklearn模型保存,应该有新的保存方法的
2021-05-25
共2条回复

Python3入门人工智能 掌握机器学习+深度学习

人工智能基础全方位讲解,构建完整人工智能知识体系,带你入门AI

1952 学习 · 596 问题

查看课程