StyleAlign icon indicating copy to clipboard operation
StyleAlign copied to clipboard

how to get the npy file of w_plus?

Open snow1929 opened this issue 2 years ago • 14 comments

how to get the npy file of w_plus?

snow1929 avatar Sep 18 '22 07:09 snow1929

We use e4e encoder to invert real images into w+ space. We provide pretrained e4e models for FFHQ512, FFHQ512_dog, FFHQ512_dog_cat in here.

Please clone the e4e repo and download the pretrained models, and run

python scripts/inference.py \
--images_dir=/path/to/images/directory \
--save_dir=/path/to/saving/directory \
path/to/checkpoint.pt 

in e4e folder. The w_plus latent codes will be in the save_dir. Then you just need to save the torch file to npy file.

betterze avatar Sep 18 '22 07:09 betterze

@betterze Thanks you for explaining the code of model. As I try to run the code There is an error happened. But I have no idea how to fix it. Would you please give me some suggestion for dealing it ?

python3 projector_z.py --outdir=./example/dog/  --target=./example/dog/ --network=./checkpoint/ffhq512_dog.pkl

image

snow1929 avatar Sep 27 '22 06:09 snow1929

I run the sample code on colab And the error of tensor is happend Is there anything wrong? image

snow1929 avatar Sep 28 '22 04:09 snow1929

@snow1929 which tensorflow version you are using? I use 1.14

betterze avatar Sep 28 '22 06:09 betterze

I use tensorflow 1.15 image I try to change the version of tensorflow and run it again. thank you

snow1929 avatar Sep 28 '22 06:09 snow1929

I run the sample code on colab And the error of tensor is happend Is there anything wrong? image

This error is related to the environment (gcc). Pls install the environment following stylegan2-ada.

betterze avatar Sep 28 '22 07:09 betterze

Hi @betterze , I have already check the source of image. All of the image is 512x512. Thus, I have no idea how to fix this trouble.

image

Traceback (most recent call last):
  File "Compare.py", line 89, in <module>
    main()
  File "Compare.py", line 79, in main
    out=np.concatenate([imgs,invert,target],axis=1)
  File "<__array_function__ internals>", line 6, in concatenate
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 2, the array at index 0 has size 512 and the array at index 2 has size 256

snow1929 avatar Oct 01 '22 08:10 snow1929

Would you mind printing the shape of [imgs,invert,target] separately?

betterze avatar Oct 01 '22 08:10 betterze

name = ['flickr_dog_000043.jpg', 'flickr_dog_000045.jpg', 'flickr_dog_000054.jpg', 'flickr_dog_000059.jpg']
imgs_shape= (512, 512, 3)
invert_shape= (512, 512, 3)
target_shape= (256, 256, 3)

image

snow1929 avatar Oct 01 '22 10:10 snow1929

The target images are in shape (256,256), rather than (512, 512). So it causes the error.

betterze avatar Oct 01 '22 11:10 betterze

Which target model (target_pkl) you are using?

betterze avatar Oct 01 '22 11:10 betterze

I choose the model of "stylegan2-ffhq512_dog_cat-config-f.pkl" as target_pkl!! image

snow1929 avatar Oct 01 '22 12:10 snow1929

The images in the target_path are in (256, 256), could you doublecheck this. Go to the folder and check the image size.

Remove all images in the target_path, and rerun

python I2I.py --network $target_pkl \
  	      --source_path $source_path \
  	      --target_path $target_path	


python Compare.py --source_img_path $source_img_path \
  	      --source_path $source_path \
  	      --target_path $target_path \
  	      --save_path $compare_html 

betterze avatar Oct 01 '22 12:10 betterze

@betterze If I want to use e4e encoder to invert real images into w+ space with my own dataset.

how to get "checkpoint.pt"

I have to finished the prtrained model by [e4e encoder]? Or, can I invert the stylegan-ada prtrained model to pt filetype? how to do it?

snow1929 avatar Nov 09 '22 06:11 snow1929