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

any way to get the visualizer to support importing stylegan3-nada .pkl files? #9

Closed
nicolai256 opened this issue Apr 9, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@nicolai256
Copy link

nicolai256 commented Apr 9, 2022

(https://github.com/rinongal/StyleGAN-nada/blob/StyleGAN3-NADA/stylegan3_nada.ipynb)
i'm making some tweaks to my stylegan3 network with this but it seems like i'm not able to import it to the visualizer
any way to get the visualizer to support these?
the generating of images in this repo is a little whacky but it's such a good tweak to stylegan, would be great if it worked :)
there is a fix for converting stylegan2-nada files to stylegan2 but not for 3 yet :/

https://github.com/eps696/stylegan2ada (this is the one for stylegan2 that converts the .pt files to .pkl files again)

@PDillis PDillis added the enhancement New feature or request label Apr 9, 2022
@PDillis
Copy link
Owner

PDillis commented Apr 9, 2022

Can you share more details on how the NADA models are saved? What about the conversion of SGAN2-NADA to SGAN2, can you share this fix or link? Might give it a go, but I have a lot of other things to do first on this repo, so if you leave here a better documentation of the problem, perhaps there's someone that might be able to fix it.

@nicolai256
Copy link
Author

stylegan3-nada saving model (the maker of the code states that the generated pkl works with stylegan3)
rinongal/StyleGAN-nada#42 (comment)
stylegan3-nada official colab
https://colab.research.google.com/github/rinongal/stylegan-nada/blob/StyleGAN3-NADA/stylegan3_nada.ipynb
**stylegan3-nada customized colab (this is the one i use to load custom stylegans) **
https://colab.research.google.com/drive/1aVgDTl5iZMD785PStLZsykP1aiymyrk4?usp=sharing
the model i generated with stylegan-nada and the original model
https://drive.google.com/drive/folders/1UR5Ap7BvlW10dzL6VaI6zRgpazuHrnHa?usp=sharing
stylegan3-nada official jupyter notebook
https://github.com/rinongal/StyleGAN-nada/blob/StyleGAN3-NADA/stylegan3_nada.ipynb
stylegan2-nada to stylegan2 fix repo (Rosinality or StyleGAN2-NADA.pt to Nvidia SG2-ada-pytorch.pkl (conversion is all the way on the bottom of readme)
https://github.com/eps696/stylegan2ada

the thing is the stylegan3-nada can also export .pkl checkpoint files but they're only 86mb when the original pkl file is 287mb
it can export .pt files and those are 230mb so that's closer to the original,
i tried running it in the visualizer but it doesn't work, i also tried running it in the stylegan3 code and it gave this error
stylegan3 error =

Loading networks from "/content/drive/MyDrive/000150.pkl"...
Traceback (most recent call last):
  File "/content/drive/MyDrive/WIP/stylegan3/gen_images.py", line 143, in <module>
    generate_images() # pylint: disable=no-value-for-parameter
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/content/drive/MyDrive/WIP/stylegan3/gen_images.py", line 108, in generate_images
    G = legacy.load_network_pkl(f)['G_ema'].to(device) # type: ignore
  File "/content/drive/MyDrive/WIP/stylegan3/legacy.py", line 40, in load_network_pkl
    assert isinstance(data['G'], torch.nn.Module)
KeyError: 'G'

@nicolai256
Copy link
Author

nicolai256 commented Apr 12, 2022

i got it working, i changed stylegan-fun/viz/renderer.py
line 20 import pickle
line 158 with dnnlib.util.open_url(pkl, verbose=False) as f:
data = pickle.load(f)
both types work now, default one and stylegan3-nada

@PDillis
Copy link
Owner

PDillis commented Apr 12, 2022

It works beautifully! I might say that there's some test needed to be done, and the change you propose should actually be done inside dnnlib.util.open_url, so as to use it in any other part of the repo, but so far I was able to open your model in Windows 10 :)

image

PDillis added a commit that referenced this issue Apr 23, 2022
@PDillis
Copy link
Owner

PDillis commented Apr 23, 2022

All code should work with your converted StyleGAN-NADA models (4765f95). Check this is the case and reopen this if something breaks. Thanks!

@PDillis PDillis closed this as completed Apr 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants