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

Inference with sample size >1 fails #83

Open VisionaryMind opened 2 years ago

VisionaryMind commented 2 years ago

This would appear to be a repeat of #60, however, deleting the output directly (or clearing it) does not fix the problem. If option --n_sample is set to any number higher than 1, the following error arises:

Traceback (most recent call last): File "scripts/inference.py", line 133, in main(args) File "scripts/inference.py", line 37, in main generate_inversions(args, generator, latent_codes, is_cars=is_cars) File "/home/visionarymind/anaconda3/envs/e4e_env/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 26, in decorate_context return func(*args, **kwargs) File "scripts/inference.py", line 105, in generateinversions imgs, = g([latent_codes[i].unsqueeze(0)], input_is_latent=True, randomize_noise=False, return_latents=True) IndexError: index 1 is out of bounds for dimension 0 with size 1

Deleting the output directory or ensuring there is no pre-existing latents.pt file does not fix the problem. Do you have any idea what the issue could be?

omertov commented 2 years ago

Hi @VisionaryMind, Sorry for the long response time, haven't had the time to maintain this repo for a while.

In case this is still relevant, I wonder if the images directory you point to contains only a single image, in which case there is only one latent code (index 0) and when you specify n_samples > 1 it fails to find the second latent code (index 1) since there is no such code.

I commited a change relevant to the above, let me know if the problem still persist.

Best, Omer