请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

joblib.dump() 报错


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
想问新版本有没有办法解决?

正在回答 回答被采纳积分+3

1回答

flare_zhao 2021-05-24 10:53:53

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

0 回复 有任何疑惑可以回复我~
  • 提问者 慕函数4411803 #1
    自己试了一些,发现都不成功,所以才想问一下,老师有没有建议?
    尝试用pickle 方法存储也是一样的 error
    回复 有任何疑惑可以回复我~ 2021-05-24 11:13:35
  • flare_zhao 回复 提问者 慕函数4411803 #2
    版本问题其实这次解决了,以后跟新版本也会有新的问题,所以最高效的方法还是保持版本一致。印象中高版本sklearn只是joblib的引用方式不同,网上搜索对应版本sklearn模型保存,应该有新的保存方法的
    回复 有任何疑惑可以回复我~ 2021-05-25 15:29:26
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信