yuval-alaluf / stylegan3-editing

Official Implementation of "Third Time's the Charm? Image and Video Editing with StyleGAN3" (AIM ECCVW 2022) https://arxiv.org/abs/2201.13433
https://yuval-alaluf.github.io/stylegan3-editing/
MIT License
660 stars 72 forks source link

Latents from latents.npy file #34

Closed uselessai closed 2 years ago

uselessai commented 2 years ago

Hi! I am trying to use the latent vectors (I need to do some interpolations) from the "latents.npy" file in the stylegan3 pkl model and it does not work, I have tried with several latent vectors and always got the same imagen. I trained the model with Market-1501 dataset.

This is the image I got from the inference when the latents.npy is created. inference

And this is the imagen when I use latents.npy siempreigual

This is my code, I have modified the gen_images.py from stylegan3 github project.

    x = np.load("/content/latents.npy", allow_pickle=True)
    for i in x.flat:
        print(i.keys())
        latent_numpy = i["1_1003_00002.jpg"][4] # get latents from image 1_1003_00002.jpg

    latent_tensor =  torch.from_numpy(latent_numpy).to(device)

    # this is from the Stylegan3 github, file  gen_images.py
    img = G(latent_tensor, label, truncation_psi=truncation_psi, noise_mode=noise_mode)
    img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
    PIL.Image.fromarray(img[0].cpu().numpy(), "RGB").save(f"{outdir}/seed{seed:04d}.png") 

I do not know if I am missing something. Thanks in advance.

yuval-alaluf commented 2 years ago

Perhaps the reason for the difference is the parameters you used when calling G? Maybe you used a different truncation_psi when running inference and when generating the images in the code snippet you provided above?

uselessai commented 2 years ago

Thanks for the response.

I used the same truncation_psi, equal to 1, but I also had tried with different truncation_psi and always got the same image with small differences finishing at truncation_psi = 0 showing the average image.

This example is what is showing with different truncation_psi values, from truncation_psi [0, 1] psi_truncationtest

I also had tried with different latents vectors from differents images and always got the same with aslile

I am using google colab to test this code with the pt model. https://colab.research.google.com/drive/1vPF7zz8Rsc6D8_TBUFDRxsslHagebmr9?usp=sharing

yuval-alaluf commented 2 years ago

Are these latents that were obtained with inversion? Did you make sure that your code works correctly on randomly generated latents?