StyleGAN2 weird mapping behavior


I have a question regarding the official StyleGAN2 implementation.
Instead of mapping directly from the input vector z to an output image, I wanted to also get the intermediate latent vector w. But I noticed that doing the pass through the neural network in two steps leads to a different output image.

Here is a basic code snippet that showcases what I did:

Gs_kwargs = dnnlib.EasyDict()
Gs_kwargs.output_transform = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)
Gs_kwargs.randomize_noise = False
Gs_kwargs.minibatch_size = 1

image_1 =, None, **Gs_kwargs)[0]
image_2 =, None), **Gs_kwargs)[0]

The network GS is the “stylegan2-ffhq-config-f” network.
I feel like I am missing something obvious, since it does not make any sense that performing both operations individually leads to a different output than performing them at once. The images have some common traits but are far more different than could be explained by different noise inputs that are somehow not deactivated.

Thank you for your help!

I found the error myself:
If one uses the standard method to map from z to the final image in one step, there seems to be a truncation parameter that is automatically set and moves the latent w toward the mean w, here denoted w_avg, (which is a latent code for the “standard” face) in the following way:

w_new = w_avg + (w - w_avg) * truncation_psi

with truncation_psi < 1.
It then uses the new w_new for further computation in the synthesis network.
This method is mentioned in the StyleGAN paper as well, but it is stated nowhere that this is generally applied even if you dont actually set this parameter, neither in the paper nor in any documentation of the code I found. This is definetely not a good way to design and document code…

If one does not want this behavior, one way is to set “Gs_kwargs.truncation_psi = 1” for the network kwargs.
Another way to get the same output for both ways is to apply the truncation manually to the two-step procedure to get the same result.

Hi @Marc14,

This forum talks more about issues and updates related to TensorRT. We recommend you post your query on a related platform if you need further assistance.

Thank you.