eladrich / pixel2style2pixel

Official Implementation for "Encoding in Style: a StyleGAN Encoder for Image-to-Image Translation" (CVPR 2021) presenting the pixel2style2pixel (pSp) framework
https://eladrich.github.io/pixel2style2pixel/
MIT License
3.19k stars 570 forks source link

How to get W+ space for the encoded images ? #15

Closed lil-km closed 3 years ago

lil-km commented 3 years ago

I tried running inference on a set of images for encoding in the FFHQ latent space, it gave me a set of projected images. But no .npy file associated with it for W+ space as cited in the paper to do further image maniputations.

Is it possible to get the W+ space vectors ?

eladrich commented 3 years ago

Hi @7khalil, please see the explanation in issue #11

lil-km commented 3 years ago

Hi @eladrich, I followed the modification that needs to make in https://github.com/eladrich/pixel2style2pixel/blob/master/models/psp.py#L66 by setting return_latents=True. But when I tried to make inference, I got this error :

Loading pSp from checkpoint: ./experiment/ckpt/psp_ffhq_encode.pt Loading dataset for ffhq_encode 0% 0/1 [00:00<?, ?it/s] Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2680, in fromarray mode, rawmode = _fromarray_typemap[typekey] KeyError: ((1, 1, 1, 256), '|u1')

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "scripts/inference.py", line 136, in run() File "scripts/inference.py", line 82, in run result = tensor2im(result_batch[i]) File "./utils/common.py", line 23, in tensor2im return Image.fromarray(var.astype('uint8')) File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2682, in fromarray raise TypeError("Cannot handle this data type: %s, %s" % typekey) TypeError: Cannot handle this data type: (1, 1, 1, 256), |u1

is there another modification that needs to be done in the code, to retrive W+ ?

yuval-alaluf commented 3 years ago

Hi @7khalil , It's a bit hard to tell what the issue is without looking at the modification you made. Any chance you can send a snippet of the modification(s) you made in inference.py?
In the meantime, please verify that result_batch[i] is the correct shape (probably something like (3, 256, 256)).

eladrich commented 3 years ago

Closing due to inactivity