Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: can't pickle weakref objects #13

Closed
zzw-zwzhang opened this issue Aug 3, 2021 · 6 comments
Closed

TypeError: can't pickle weakref objects #13

zzw-zwzhang opened this issue Aug 3, 2021 · 6 comments

Comments

@zzw-zwzhang
Copy link

I fixed it by adding .state_dict():
torch.save(ema.state_dict(), os.path.join(opt.output_dir, now + 'ema.pth'))
torch.save(ema2.state_dict(), os.path.join(opt.output_dir, now + 'ema2.pth'))

@tomguluson92
Copy link

ME TOO! This problem still exists though changed to DP from the original DDP!

-> torch.save(ema, os.path.join(opt.output_dir, now + 'ema.pth'))
(Pdb) n
TypeError: cannot pickle 'weakref' object

@xvdp
Copy link

xvdp commented Aug 4, 2021

change that line adding .state_dict(), same w all other lines where modules are saved
e.g. torch.save(ema.state_dict(), ...

@marcoamonteiro
Copy link
Owner

This may be related to different library versions since it works on our machines. Thanks for posting a solution for others who run into this issue.

@resnant
Copy link

resnant commented Sep 10, 2021

This saved me. Thanks!

@zzhuolun
Copy link

zzhuolun commented Mar 8, 2022

change that line adding .state_dict(), same w all other lines where modules are saved e.g. torch.save(ema.state_dict(), ...

Thanks!

And in case someone else meets error while updating ema parameters at ema.update(generator_ddp.parameters()), e.g.

ValueError: dictionary update sequence element #0 has length 256; 2 is required

don't forget to change the ema loading method to:

ema = ExponentialMovingAverage(generator.parameters(), decay=0.999)
ema.load_state_dict(torch.load(os.path.join(opt.load_dir, "ema.pth"), map_location=device))

@ifti1394
Copy link

ifti1394 commented Aug 5, 2022

1 pickle.dump(model,open('model_70_version_01.pkl','wb'))

Error is showing : cannot pickle 'weakref' object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants