PyTorch-StudioGAN icon indicating copy to clipboard operation
PyTorch-StudioGAN copied to clipboard

problem with loading pretrained styegan2 model

Open Byronliang8 opened this issue 3 years ago • 4 comments

When I load with the pretrained stylegan2 model, it will show the errors : Error(s) in loading state_dict for Generator: Missing key(s) in state_dict: "mapping.fc2.weight", "mapping.fc2.bias", "mapping.fc3.weight", "mapping.fc3.bias", "mapping.fc4.weight", "mapping.fc4.bias", "mapping.fc5.weight", "mapping.fc5.bias", "mapping.fc6.weight", "mapping.fc6.bias", "mapping.fc7.weight", "mapping.fc7.bias". Unexpected key(s) in state_dict: "mapping.embed.weight", "mapping.embed.bias". size mismatch for mapping.fc0.weight: copying a param with shape torch.Size([512, 1024]) from checkpoint, the shape in current model is torch.Size([512, 512]).

and the code to load is from training.networks import Generator model=Generator(z_dim=512, c_dim=0, w_dim=512, img_resolution=32, img_channels=3).cuda()

checkpoint_path=('StyleGAN2-pretrain-cifar/model=G_ema-best-weights-step=970000.pth') inmodel=torch.load(checkpoint_path) print(inmodel) #model.load(inmodel) model.load_state_dict(inmodel['state_dict'], strict=True) model.eval() model.cuda() G=model

I want to know what the problem with it

Thanks

Byronliang8 avatar Jun 01 '22 10:06 Byronliang8

Hi does this problem still exist?!

alex4727 avatar Jul 27 '22 07:07 alex4727

Sorry, I didn't solve this question.

Byronliang8 avatar Jul 27 '22 09:07 Byronliang8

I have double checked the code and weight with latest settings and didn't face any problem. It seems like you have used checkpoint for StyleGAN2-ADA. Did you choose the proper config (src/configs/CIFAR10/StyleGAN2-ADA.yaml)?

alex4727 avatar Jul 30 '22 06:07 alex4727

Thanks for your help; I will try it.

Byronliang8 avatar Jul 30 '22 13:07 Byronliang8