-
Notifications
You must be signed in to change notification settings - Fork 158
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
Switch to PyTorch #18
base: main
Are you sure you want to change the base?
Conversation
Hi @NotNANtoN, thanks for this work ! I wanted to try to implement it myself but I saw you did it first :) Which script did you use to convert the pre-trained TF models to PyTorch ? This one looks promising but that's maybe the one you used: https://github.com/rosinality/stylegan2-pytorch#convert-weight-from-official-checkpoints |
Hi @julienbeisel! I used https://github.com/NVlabs/stylegan2-ada-pytorch/blob/main/legacy.py. We could try out to use the rosinality weight conversion for the wikiart weights (or all weights where the legacy.py loading does not work). |
@@ -19,7 +19,7 @@ | |||
"License :: OSI Approved :: MIT License", | |||
"Operating System :: OS Independent", | |||
], | |||
install_requires=['tensorflow==1.15', | |||
install_requires=['torch', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
click
should be added in the dependencies
It is used by dnnlib: https://github.com/NVlabs/stylegan2-ada-pytorch/blob/main/legacy.py#L9
@@ -82,14 +96,49 @@ def __init__(self, | |||
self.num_possible_classes = num_possible_classes | |||
self.style_exists = False | |||
|
|||
# some stylegan models cannot be converted to pytorch (wikiart) | |||
self.use_tf = style in ("wikiart",) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using 'abstract photos' and it was not working as well.
Error:
Loading networks from abstract photos.pkl...
Traceback (most recent call last):
File "script.py", line 6, in <module>
L.hallucinate(file_name="song.mp4")
File "/Users/julienbeisel/Documents/git repos/dev/lucid-sonic-dreams/lucidsonicdreams/main.py", line 702, in hallucinate
self.stylegan_init()
File "/Users/julienbeisel/Documents/git repos/dev/lucid-sonic-dreams/lucidsonicdreams/main.py", line 182, in stylegan_init
self.Gs = self.legacy.load_network_pkl(f)['G_ema'].to(device) # type: ignore
File "stylegan2/legacy.py", line 26, in load_network_pkl
G = convert_tf_generator(tf_G)
File "stylegan2/legacy.py", line 111, in convert_tf_generator
raise ValueError('TensorFlow pickle version too low')
ValueError: TensorFlow pickle version too low
I am going to try to convert it differently since other models seem to work.
Ok thanks! I will try to work on it :) I forked the repo to try to make it work on my laptop. I will make some comments if I think some parts can be improved, I can also make a branch and do a PR later if you want! |
@@ -82,14 +96,49 @@ def __init__(self, | |||
self.num_possible_classes = num_possible_classes | |||
self.style_exists = False | |||
|
|||
# some stylegan models cannot be converted to pytorch (wikiart) | |||
self.use_tf = style in ("wikiart",) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a nice way to handle the cases where TF is compatible and not torch would be to:
1 - Define a variable engine
in the LucidSonicDream
object
2 - Create a compatibility dictionary (example : compatibility_dict = {'tf' : ['model_1','model_2'], 'torch' : ['model2']}
)
3 - Raise an error if the model chosen when the LucidSonicDream
object is created is not compatible with the engine (tf or torch)
Thanks for you feedback! Please do a PR on this PR ;) It would be best to just convert all TF models to Torch, but I'm not sure if this is easily doable for conditional GANs. |
Alright I will submit a PR once it's done and I'll try to convert the models. I will also try to fix the comments on the PR. |
@NotNANtoN I spent some time working on it and I really couldn't figure out how to convert these models for PyTorch (nothing is working). I guess the only way to make it work would be to re-train them but it's a lot of work... |
@julienbeisel I assume it's simply not possible with some models unless we know their exact architecture. Maybe you can just make a PR with your changes and then we'll just use PyTorch wherever possible and for some models TF? At least this is working and some pytorch is better than none imo. Have you tried the batch_size argument? When I tried it it just slowed things down, which I don't really understand. But I'll look into it |
…he running of batches
…p by another 20-40% by moving PIL-related stuff past the generation process.
Major update: increased speed massively by a factor of 5-7. The generation for a 90 seconds long piece of music now takes 4.30 minutes for 60fps, whereas this was at over 20 minutes for 43 fps before. |
the objective of this branch is to allow stylegan TF models work with pytorch? I already have model generated with stylegan2-ada-pytorch. Is there a readymade solution for that use case? |
@MoemaMike The objective is to completely switch to PyTorch. All pytorch models trained using the NVIDIA-pytorch repositories work with this branch. There are some TF models that cannot be converted to pytorch atm, in these cases the library just loads them as tensorflow. Maybe @mikaelalafriz can review and/or merge this branch soonish. |
ok, thanks, looking forward to trying it out on Colab |
unfortunately,my progress sometimes have been killed |
and Setting up PyTorch plugin "upfirdn2d_plugin"... Failed warning |
Your progress has been killed because your RAM is full. Either get more RAM or some immediate saves need to be made in the code. As for the plugin: either get compatible cuda drivers with your pytorch version of nvcc "nvidia-cuda-toolkit" or you can add a "return False" in approxiamtely line 27 in the file upfird2nd.py in stylegan2/torch_utils/ops to disable the initialization of the pluging. |
Can't get this going on wildlife or my own pytorch trained models
|
This happens when the batch_size are set to 1 (error in line 600, main.py). Try increasing the batch size. |
I also ran into the same issue, I can confirm increasing the batch size resolves it. |
I've tried everything that possibly could and for the past five days I haven't been able to get this to work at all (both the original lucidsonicdreams and @NotNANtoN 's clmr_clip branch) on It works well on I've followed this link step-by-step: https://developer.nvidia.com/blog/accelerating-tensorflow-on-a100-gpus/ I've also tried |
Frustrating. I currently have a working setup on my RTX 3090 running on Ubuntu 20.04.02. Here is some info about my environment, maybe it can point you in the right direction. Python 3.7 PyTorch: Nvidia: |
Long shot but figured Id sare - having trouble using LSD with a custom class-conditioned pkl trained via the pytorch variation of stylegan2.
|
Isn't wikiart fundamentally a VQGAN model? That's trained with pytorch out of the box. |
How to use it please? I go into NotNANtoN 's repo and see the introdunction is yet |
There are many issues raised here because of the use of tensorflow and I also struggle to get it to work. Hence I switched from using the TF StyleGAN repo to using https://github.com/NVlabs/stylegan2-ada-pytorch. This should make the usage of this repo much easier. It works quite nicely in my tests and it might be faster (the NVIDIA people claim the pytorch version is faster, I did not benchmark it).
The only issue I see is that the wikiart model is not compatible with the PyTorch repo - at least it throws an error when trying to convert it from TF to torch. I "solved" this by just defaulting back to the TF repo when using wikiart. This is not beautiful, but it should work. Unfortunately, I cannot test this as I am too stupid to set up TF properly with my GPU. So, if anyone can test if wikiart still works in this PR with TF or knows how to convert it to torch that would be great.