pkl to pt conversion
vedantdere opened this issue · 10 comments
How to convert pkl file to pt ?
stylegan3-editing/models/stylegan3/legacy.py
Lines 300 to 301 in e2a63fc
The function does not support StyleGAN3 checkpoints, I believe.
stylegan3-editing/models/stylegan3/legacy.py
Lines 303 to 304 in e2a63fc
How did you create the weights .PT Files For StyleGan3?
https://github.com/yuval-alaluf/stylegan3-editing#stylegan3-encoder
testing rosinality pkl to pt
I believe this is what you guys want:
path = "/path/to/your/sg3.pkl"
with open(path, "rb") as f:
decoder = pickle.load(f)['G_ema'].cuda()
state_dict = decoder.state_dict()
torch.save(state_dict, "/path/to/your/sg3.pt")
Let me know if this works as I haven't tested it out yet
@hotnikq , I'm not sure I follow here.
Please open a new issue if you are having a problem running something. And please provide a clear, detailed summary of what you're trying to run.
@hotnikq , you're saying the code I posted above did not work for you on the stylegan3-r-ffhqu-256x256.pkl
file?
How did you create the weights .PT Files For StyleGan3?
I have answered the question above and provided the code that we used to convert pkl
files to pt
files. I am really not sure why you are still trying to use the legacy.py
file after it was noted above that this file is not relevant for SG3 models.
And @hotnikq , it is quite difficult to follow these threads with so many comments. Please try to limit your comments when possible to make it easier for myself and others to follow these threads.
I believe this is what you guys want:
path = "/path/to/your/sg3.pkl" with open(path, "rb") as f: decoder = pickle.load(f)['G_ema'].cuda() state_dict = decoder.state_dict() torch.save(state_dict, "/path/to/your/sg3.pt")Let me know if this works as I haven't tested it out yet
Testing now !
import pickle
from enum import Enum
from pathlib import Path
from typing import Optional
import torch
checkpoint_path = "pretrained_models/stylegan3-r-ffhqu-256x256.pkl"
print(f"Loading StyleGAN3 generator from path: {checkpoint_path}")
with open(checkpoint_path, "rb") as f:
decoder = pickle.load(f)['G_ema'].cuda()
print('Done!')
state_dict = decoder.state_dict()
torch.save(state_dict, "pretrained_models/stylegan3-r-ffhqu-256x256.pt")
print('Done!')
This code works just fine the topic ends here!
now i need to adapt the generator model to math the checkpoint
RuntimeError: Error(s) in loading state_dict for Generator:
size mismatch for synthesis.L3_52_1024.up_filter: copying a param with shape torch.Size([24]) from checkpoint, the shape in current model is torch.Size([12]).
I am happy to see that the code I gave you above works fine and that we can now close this issue.
If you have an issue that is unrelated to this, please open a new issue with a concise yet clear explanation of the problem you are facing