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

Questions about generate_latents_and_attribute_scores.py #41

Closed NoctisZ closed 2 years ago

NoctisZ commented 2 years ago

Great work and thank you so much for sharing the code! I got a couple of questions regarding the generate_latents_and_attribute_scores.py which I'm using to generate training data for new boundaries:

Would you kindly let me know if I'm missing something here? I would really appreciate it!

woctezuma commented 2 years ago

From the README:

An npy file will be saved every save_interval samples.

In generate_latents_and_attribute_scores.py:

https://github.com/yuval-alaluf/stylegan3-editing/blob/e2a63fc7f072c4f8b8a7ba1dac8c7f87a8eb1647/editing/interfacegan/generate_latents_and_attribute_scores.py#L30-L31

https://github.com/yuval-alaluf/stylegan3-editing/blob/e2a63fc7f072c4f8b8a7ba1dac8c7f87a8eb1647/editing/interfacegan/generate_latents_and_attribute_scores.py#L62-L64

https://github.com/yuval-alaluf/stylegan3-editing/blob/e2a63fc7f072c4f8b8a7ba1dac8c7f87a8eb1647/editing/interfacegan/generate_latents_and_attribute_scores.py#L90-L94

From your post:

  • will only save a npy file at every (save_interval+ 1) step since seed_idx starts from 0.

No, it will save every save_interval, though it is true that it will always save the first seed, indexed by seed_idx=0, unless the check seed>0 helps with.

NoctisZ commented 2 years ago

I see your point, so basically with if seed_idx % save_interval == 0 and seed > 0, the first seed, indexed by seed_idx=0, will always be saved, and then starting from the second seed, we'll save them every save_interval step.

I tried with n_images set to 5 and save_interval set to 2, and found that data in _id0 folder contains 3 faces since the first seed is saved together with the next two, and the data in _id1 folder contains 2 faces. However, if n_images is set to 4 and save_interval is 2, I can only get one folder (ie. _id0) that contains 3 faces and lost data for the 4th face. I guess I just need to be careful with this hyperparameter setting then.

woctezuma commented 2 years ago

Hmmm... Thinking a bit more about it...

In practice, seed and seed_idx are the same here, so I have trouble understanding why there is this call to enumerate(). đŸ¤”

As you mentioned, you get batches of images of length save_interval, except for the first batch which has an additional image corresponding to seed_idx=0. For n_images=5 and save_interval=2, you get a first batch of 3 images, and a second batch of 2 images. For n_images=4 and save_interval=2, you get a first batch of 3 images, and the second batch never reaches 2 images, so it is not saved.

In the scenario that this is actually a bug, then maybe one could replace this line:

https://github.com/yuval-alaluf/stylegan3-editing/blob/e2a63fc7f072c4f8b8a7ba1dac8c7f87a8eb1647/editing/interfacegan/generate_latents_and_attribute_scores.py#L64

with:

for seed_idx, seed in enumerate(range(n_images), start=1):

This way, the following line:

https://github.com/yuval-alaluf/stylegan3-editing/blob/e2a63fc7f072c4f8b8a7ba1dac8c7f87a8eb1647/editing/interfacegan/generate_latents_and_attribute_scores.py#L90

could be simplified to:

if seed_idx % save_interval == 0:

You would get batches of images of length save_interval. For n_images=5 and save_interval=2, you would get a first batch of 2 images, and a second batch of 2 images, while the third batch would never be completed. For n_images=4 and save_interval=2, you would get a first batch of 2 images, and a second batch of 2 images.

The save_interval parameter would:

NoctisZ commented 2 years ago

Yes totally agree. Thanks for the response!