Torch:类型错误:无法腌制“WeakMethod”对象

问题描述 投票:0回答:1

我想使用

torch.save()
保存权重。

我也遇到了这个问题

--------------------------------------------------
TypeError: cannot pickle 'WeakMethod' object
-------------------------------------------
Traceback (most recent call last):
  File "./train.py", line 163, in <module>
    trainer.train()
  File "/home/jsw/4DenoiseNet/networks/train/tasks/semantic/../../tasks/semantic/modules/trainer.py", line 283, in train
    torch.save(state, self.log + "/FourDenoiseNet" + "")
  File "/home/jsw/anaconda3/envs/cvpr/lib/python3.8/site-packages/torch/serialization.py", line 441, in save
    _save(obj, opened_zipfile, pickle_module, pickle_protocol)
  File "/home/jsw/anaconda3/envs/cvpr/lib/python3.8/site-packages/torch/serialization.py", line 653, in _save
    pickler.dump(obj)
TypeError: cannot pickle 'WeakMethod' object

我像这样更改了变量:

state = None  # this makes code working but save None  
self.log = None  # it is not working to run code
python pickle torch
1个回答
0
投票

我的错误信息

回溯(最近一次调用最后一次): 文件“./train.py”,第 163 行,位于 训练师.train() 文件“/home/jsw/4DenoiseNet/networks/train/tasks/semantic/../../tasks/semantic/modules/trainer.py”,第 283 行,训练中 torch.save(状态, self.log + "/FourDenoiseNet" + "") 文件“/home/jsw/anaconda3/envs/cvpr/lib/python3.8/site-packages/torch/serialization.py”,第 441 行,保存 _save(obj,打开的zip文件,pickle_模块,pickle_协议) 文件“/home/jsw/anaconda3/envs/cvpr/lib/python3.8/site-packages/torch/serialization.py”,第 653 行,在 _save 中 pickler.dump(obj) 类型错误:无法腌制“WeakMethod”对象

© www.soinside.com 2019 - 2024. All rights reserved.