pbaylies / stylegan-encoder

StyleGAN Encoder - converts real images to latent space
Other
740 stars 182 forks source link

Error while running encode_images.py #41

Closed B-Yassine closed 4 years ago

B-Yassine commented 4 years ago

I am getting this error while trying to load the drive file to google colab and i can't find a solution! Is it because i am limited and the file is too big? Is there any solution?

Downloading https://drive.google.com/uc?id=1MEGjdvVpUsu1jB4zrXZN7Y4kBBOzizDQ ............ failed Traceback (most recent call last): File "encode_images.py", line 241, in <module> main() File "encode_images.py", line 115, in main with dnnlib.util.open_url(args.model_url, cache_dir=config.cache_dir) as f: File "/content/stylegan-encoder/dnnlib/util.py", line 381, in open_url raise IOError("Google Drive quota exceeded") OSError: Google Drive quota exceeded

pbaylies commented 4 years ago

This is a known issue with Google Drive quotas; as a workaround, you can try to go into that Google Drive, share the file to your own account, and then make a copy there and download that URL. Also note that when you do download it, you'll have it stored locally in a cache directory if you need it later.

B-Yassine commented 4 years ago

Thank you for your response. That's exactely what i did and it worked!. However, i am getting this error now:

File "encode_images.py", line 116, in main generator_network, discriminator_network, Gs_network = pickle.load(f) _pickle.UnpicklingError: invalid load key, '<'.

pbaylies commented 4 years ago

I've seen this issue before; make sure you're using Python 3, that your file downloaded properly, and if that doesn't work, then try using encoding='latin1' when you load the pickled file:

pickle.load(f, encoding='latin1')
B-Yassine commented 4 years ago

I tried what you suggested but it doesn't work. I am getting the same error.

File "encode_images.py", line 116, in main generator_network, discriminator_network, Gs_network = pickle.load(f, encoding='latin1') _pickle.UnpicklingError: invalid load key, '<'.

pbaylies commented 4 years ago

Then make sure the file is correct; good luck!

B-Yassine commented 4 years ago

I solved it, but i am struggling with that one now :|

Exception ignored in: <bound method tqdm.__del__ of yassine2_01: loss 103.8618; lr 0.0051: 12% 12/100 [00:17<01:06, 1.33it/s]> Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/tqdm/_tqdm.py", line 931, in __del__ self.close() File "/usr/local/lib/python3.6/dist-packages/tqdm/_tqdm.py", line 1133, in close self._decr_instances(self) File "/usr/local/lib/python3.6/dist-packages/tqdm/_tqdm.py", line 496, in _decr_instances cls.monitor.exit() File "/usr/local/lib/python3.6/dist-packages/tqdm/_monitor.py", line 52, in exit self.join() File "/usr/lib/python3.6/threading.py", line 1053, in join raise RuntimeError("cannot join current thread") RuntimeError: cannot join current thread

It is a big problem when you don't have enough ressources.

B-Yassine commented 4 years ago

Thank you so much i resolved it. The problem was in the tqdm version pre-installed in google colab. I had to downgrade to tqdm==4.24.0

!pip install --force tqdm==4.24.0

pbaylies commented 4 years ago

Oh interesting, I never would have guessed that; glad you figured it out!

jkyndir commented 4 years ago

I tried what you suggested but it doesn't work. I am getting the same error.

File "encode_images.py", line 116, in main generator_network, discriminator_network, Gs_network = pickle.load(f, encoding='latin1') _pickle.UnpicklingError: invalid load key, '<'.

Hi there. I'm having the same problem with the "invalid load key" in the google colab. Could you enlighten me with how you solved that problem ? Much thx.

jkyndir commented 4 years ago

Never mind. I figured it out. I used the shareable link, not the download url to the file. THX.

sathish-rajendran commented 4 years ago

can you please elaborate how you solved it?

HenrySaba commented 4 years ago

Hi, I used the shareable link to the file and I'm still facing this issue:

Traceback (most recent call last): File "encode_images.py", line 247, in <module> main() File "encode_images.py", line 122, in main generator_network, discriminator_network, Gs_network = pickle.load(f) _pickle.UnpicklingError: invalid load key, '<'.

Some elaboration on a solution would be highly appreciated. I'm on Python 3.6.9

HenrySaba commented 4 years ago

Fixed it! Instead of using the link as such:

https://drive.google.com/file/d/{file_id}

You should use the link in the following format:

https://drive.google.com/uc?id={file_id}

Zeltserj commented 4 years ago

Hi, I've tried everything on this post and searched the internet, yet nothing woks. When I run encode_images.py with the default URL it throws a quota exceeded error. when I put a different URL (for say the copy I made for myself) I get the pickling error:

Traceback (most recent call last):
  File "encode_images.py", line 241, in <module>
    main()
  File "encode_images.py", line 116, in main
    generator_network, discriminator_network, Gs_network = pickle.load(f, encoding='latin1')
_pickle.UnpicklingError: invalid load key, '<'.

If anyone solved this or has a link to a working pretrained model I'd highly appreciate it

YanaHrytsenko commented 4 years ago

I have same issue.

Ani1211999 commented 4 years ago

I have same issue but my laptop doesn't have GPU any way I can perform it on colab only.I am using only 3 images for my purpose.

Ani1211999 commented 4 years ago

but still it is giving

utaccn commented 3 years ago

Hi, I've tried everything on this post and searched the internet, yet nothing woks. When I run encode_images.py with the default URL it throws a quota exceeded error. when I put a different URL (for say the copy I made for myself) I get the pickling error:

Traceback (most recent call last):
  File "encode_images.py", line 241, in <module>
    main()
  File "encode_images.py", line 116, in main
    generator_network, discriminator_network, Gs_network = pickle.load(f, encoding='latin1')
_pickle.UnpicklingError: invalid load key, '<'.

If anyone solved this or has a link to a working pretrained model I'd highly appreciate it

I have the same issue

nhorton04 commented 3 years ago

Has anyone figured this out? I somehow got this all to work a while ago but I forget what I did, and have reinstalled my OS since then. Very frustrating issue. I am in the exact same position as @utaccn

utaccn commented 3 years ago

I gave up and I did use stylegan2 @nhorton04

serarmani commented 3 years ago

Has anyone figured this out? I somehow got this all to work a while ago but I forget what I did, and have reinstalled my OS since then. Very frustrating issue. I am in the exact same position as @utaccn

Once you have a link it looks like this: https://drive.google.com/file/d/1wTczzzzzzzzzzzzzzzzzzzzzzycaBq8Or/view?usp=sharing there are 3 changes that you should do before being able to share that file: 1- change the pickle.load(f) to pickle.load(f, encoding='latin1') 2- change the shareable link to: https://drive.google.com/uc?id=1wTczzzzzzzzzzzzzzzzcaBq8Or pay attention we modify 2 parts: a) uc?id= && b)delete the last part 3- make sure your link is changed to be shared with anyone from your google drive settings good luck

serarmani commented 3 years ago

I have same issue but my laptop doesn't have GPU any way I can perform it on colab only.I am using only 3 images for my purpose.

here is what you need to do: 1- download the pickle file manually (from the link that the error already shows) 2- upload it to your google drive 3- change the sharing option from only you to anyone with the link. 4- generate and copy the sharing link from of uploaded file from your google drive 5- in the link change the file/d/ part to uc?id= 6- delete the ending part (/view?usp=sharing) 7- from file tab of your colab notebook, find and click on encode_images.py 8- on the right side of your browser the code will open. find the parsers sections 9- find the line which gives the default url to load the pickle file: parser.add_argument('--model_url', default= 10- change the url to what we created in the previous steps. thats it.

agountis commented 3 years ago

I have same issue but my laptop doesn't have GPU any way I can perform it on colab only.I am using only 3 images for my purpose.

here is what you need to do: 1- download the pickle file manually (from the link that the error already shows) 2- upload it to your google drive 3- change the sharing option from only you to anyone with the link. 4- generate and copy the sharing link from of uploaded file from your google drive 5- in the link change the file/d/ part to uc?id= 6- delete the ending part (/view?usp=sharing) 7- from file tab of your colab notebook, find and click on encode_images.py 8- on the right side of your browser the code will open. find the parsers sections 9- find the line which gives the default url to load the pickle file: parser.add_argument('--model_url', default= 10- change the url to what we created in the previous steps. thats it.

@serarmani This worked really well. However, I'd make this suggestion: Instead of modifying the encode_images.py file, use the command line flag instead. Modify (from the fast version): !python encode_images.py --optimizer=lbfgs --face_mask=True --iterations=6 --use_lpips_loss=0 --use_discriminator_loss=0 --output_video=True aligned_images/ generated_images/ latent_representations/

to be: !python encode_images.py --model_url=ADD_LINK_HERE --optimizer=lbfgs --face_mask=True --iterations=6 --use_lpips_loss=0 --use_discriminator_loss=0 --output_video=True aligned_images/ generated_images/ latent_representations/

Obviously, change ADD_LINK_HERE to be the google drive link you created in the previous step. No quotes needed.