yuval-alaluf / restyle-encoder

Official Implementation for "ReStyle: A Residual-Based StyleGAN Encoder via Iterative Refinement" (ICCV 2021) https://arxiv.org/abs/2104.02699
https://yuval-alaluf.github.io/restyle-encoder/
MIT License
1.03k stars 155 forks source link

Restyle doesnt work anymore after running StyleGAN Nada #31

Closed xXLeoXxOne closed 3 years ago

xXLeoXxOne commented 3 years ago

After getting restyle to work, I had much fun using it for a few months.

Then I heard about StyleGAN Nada and wanted to try it out... so I downloaded the repo and tried it out... first time running it worked but after that it didnt anymore... I did not install anything new and there arent any error messages.

The problem is that both restyle and nada (which depends on restyle) dont work anymore because they are stuck loading both the pSp and the e4e encoder inside the models folder. After a bit of research I found out that they are stuck loading the StyleGan2 Generator which is stuck at importing the FusedLeakyReLU, fused_leaky_relu and upfirdn2d. It doesnt crash/throw any errors and seems to load forever.

I am pretty frustrated right now because I cant use restyle anymore...

Does anyone know why this happens and how I can fix it?

yuval-alaluf commented 3 years ago

I think I have actually come across this issue myself. What I believe is happening is an issue with the compilation of the CUDA extensions and ninja. For some reason, sometimes the files become locked and the script becomes stuck forever. I believe the following issue my help you solve your issue: https://github.com/eladrich/pixel2style2pixel/issues/80#issuecomment-778637066 If not let me know and I will be happy to try and help you understand the source of the issue

xXLeoXxOne commented 3 years ago

I dont have a torch_extensions folder... My .cache folder contained some torch stuff but deleting it didnt change anything.

Thats my Traceback:

Traceback (most recent call last): File "toonify_ffhq.py", line 16, in from models.psp import pSp File "C:\Users\msk4x\Documents\Projekte\restyle-encoder-main\models\psp.py", line 8, in from models.stylegan2.model import Generator File "C:\Users\msk4x\Documents\Projekte\restyle-encoder-main\models\stylegan2\model.py", line 7, in from models.stylegan2.op import FusedLeakyReLU File "C:\Users\msk4x\Documents\Projekte\restyle-encoder-main\models\stylegan2\op__init__.py", line 1, in from .fused_act import FusedLeakyReLU, fused_leaky_relu File "C:\Users\msk4x\Documents\Projekte\restyle-encoder-main\models\stylegan2\op\fused_act.py", line 13, in os.path.join(module_path, 'fused_bias_act_kernel.cu'), File "C:\Users\msk4x\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\utils\cpp_extension.py", line 1091, in load keep_intermediates=keep_intermediates) File "C:\Users\msk4x\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\utils\cpp_extension.py", line 1306, in _jit_compile baton.wait() File "C:\Users\msk4x\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\utils\file_baton.py", line 42, in wait time.sleep(self.wait_seconds) KeyboardInterrupt

yuval-alaluf commented 3 years ago

Notice that the stack trace points to the exact same issue in the link I provided. The torch extensions folder should be stored somewhere so it is surprising you are unable to find it by following the steps I provided there. Anyway, can you try running the following to find the files:

find / -name "fused"

Also, you can run your script in debug and dive into the load function that loads these extensions. From there you can see the path to the extensions and go to delete the lock file: https://github.com/yuval-alaluf/restyle-encoder/blob/cb2010a6fc18af2d370e8886ebd3b38408406c9e/models/stylegan2/op/fused_act.py#L9-L16

xXLeoXxOne commented 3 years ago

Works!!! Thank you so much I am so happy right now :) Windows Search somehow didnt find the folder and your command didnt work but with a bit of research I found another command and found the folder inside AppData/Local

xXLeoXxOne commented 3 years ago

Will try StyleGAN Nada again later but if it stops working I now know the fix :)

yuval-alaluf commented 3 years ago

Ah. Didn't know you were working on windows which explains why the command didn't work. I'm happy to see you were able to solve the issue 😄