omertov / encoder4editing

Official implementation of "Designing an Encoder for StyleGAN Image Manipulation" (SIGGRAPH 2021) https://arxiv.org/abs/2102.02766
MIT License
945 stars 154 forks source link

error when loading the pretrained Encoder4Editing ffhq encoder #56

Closed ArashVahabpour closed 3 years ago

ArashVahabpour commented 3 years ago

Hello, Thanks for providing the code. When I use the pre-trained ffhq encoder, I stumble upon the following error

RuntimeError: Error(s) in loading state_dict for Encoder4Editing:
    Unexpected key(s) in state_dict: "styles.16.convs.0.weight", "styles.16.convs.0.bias", "styles.16.convs.2.weight", "styles.16.convs.2.bias", "styles.16.convs.4.weight", "styles.16.convs.4.bias", "styles.16.convs.6.weight", "styles.16.convs.6.bias", "styles.16.convs.8.weight", "styles.16.convs.8.bias", "styles.16.convs.10.weight", "styles.16.convs.10.bias", "styles.16.linear.weight", "styles.16.linear.bias", "styles.17.convs.0.weight", "styles.17.convs.0.bias", "styles.17.convs.2.weight", "styles.17.convs.2.bias", "styles.17.convs.4.weight", "styles.17.convs.4.bias", "styles.17.convs.6.weight", "styles.17.convs.6.bias", "styles.17.convs.8.weight", "styles.17.convs.8.bias", "styles.17.convs.10.weight", "styles.17.convs.10.bias", "styles.17.linear.weight", "styles.17.linear.bias". 

Can you please let me know if you know how to resolve this issue? Thanks!

omertov commented 3 years ago

Hi @ArashVahabpour! This is caused by a wrong opts.stylegan_size value in the following line: https://github.com/omertov/encoder4editing/blob/1f27dfc64b1f5567aea5b67018804e7daf961ef6/models/encoders/psp_encoders.py#L146 (according to the exception it seems like it is set to 512 while it should be 1024)

Perhaps the 1024 value in the checkpoint is being overriden by the script you are running, can you elaborate which script it is? (On a previous commit we fixed a bug in which if your dataset type contained the string 'car' it would override the stylegan_size value to 512, perhaps pulling the latest code will help)

Best, Omer