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

error while inference with pretrained faces model #60

Closed williamxiongwei closed 3 years ago

williamxiongwei commented 3 years ago

Hi, Would you like to help solve the error while calling inference.py with pretrained faces model. By the way, everything goes well while calling inference.py with pretrained cars model. Error is listed as follows(cmd: python scripts/inference.py --images_dir=images/from/faces --save_dir=images/to e4e_ffhq_encode.pt): raceback (most recent call last): File "scripts/inference.py", line 137, in main(args) File "scripts/inference.py", line 24, in main net, opts = setup_model(args.ckpt, device) File "/root/miniconda3/envs/e4e_env/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 15, in decorate_context return func(*args, *kwargs) File "scripts/inference.py", line 109, in generateinversions imgs, = g([latent_codes[i].unsqueeze(0)], input_is_latent=True, randomize_noise=False, return_latents=True) File "/root/miniconda3/envs/e4e_env/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(input, **kwargs) File "./models/stylegan2/model.py", line 530, in forward out = conv2(out, latent[:, i + 1], noise=noise2) IndexError: index 16 is out of bounds for dimension 1 with size 16

I appreciate your help. Thanks indeed!

omertov commented 3 years ago

Hi @williamxiongwei! Is it possible that the save_dir already contains a latents.pt file containing latent codes of the cars domain? i.e. of shape (16,512)? If it is the case, it is possible that the latent codes are loaded from there and not inferred from the input images directory, therefore resulting in missing style vectors for the 1024 resolution FFHQ model, so i will advise trying to save the results to an empty directory.

Best, Omer

williamxiongwei commented 3 years ago

Hi @williamxiongwei! Is it possible that the save_dir already contains a latents.pt file containing latent codes of the cars domain? i.e. of shape (16,512)? If it is the case, it is possible that the latent codes are loaded from there and not inferred from the input images directory, therefore resulting in missing style vectors for the 1024 resolution FFHQ model, so i will advise trying to save the results to an empty directory.

Best, Omer

Great job. This does correct the error! Thanks a lot.

omertov commented 3 years ago

Awsome!