Nodes/ComfyUI-StyleGan/Batch Average StyleGAN Latents
ComfyUI Node

Batch Average StyleGAN Latents

The average-face node

By spacepxl·Created 2 years ago·Updated 2 years ago· 21
Batch Average StyleGAN Latents
  • stylegan_latent
  • STYLEGAN_LATENT

Batch Average StyleGAN Latents does one thing, and it's the one thing the "average face" meme is made of: take a batch of latents, average them, and return a single latent that renders as the statistical center of the group. Feed it 64 random faces and you get The Default Person - smooth, generic, vaguely unsettling, instantly recognizable. It's a small node, but it's the anchor for a whole class of latent-space tricks.

What it does under the hood

The math is almost embarrassingly short: torch.mean across the batch dimension to get the average w, then a normalization pass that subtracts the mean and divides by the standard deviation of that averaged vector. The normalization is the subtle part - a raw mean of w codes can drift off-distribution, and the re-centering keeps the result sitting in the region of latent space the generator knows how to render. The output is one STYLEGAN_LATENT with the same width as every input row, so it drops into the sampler or the blend node without any adaptation.

Input is a single stylegan_latent (a batch of 2+ vectors; a batch of one is just that one, normalized). Output is STYLEGAN_LATENT.

Why you'd actually reach for it

Averaging is rarely the destination - it's the baseline. The classic trick is subtracting it. Since the average latent represents "generic face," the vector from average to a specific face represents that face's distinctiveness. Push a face away from the average and you exaggerate whatever makes it recognizable; blend toward the average and you neutralize it. Run it through Blend StyleGAN Latents and you've got a slider from "this specific person" to "statistically normal person," which is a genuinely useful editing lever.

It also works as a cheap denoiser of sorts: average several latents of the same concept to collapse the random variation and keep the structure. StyleGAN inversion research leans on exactly this - the projector in this pack computes a w_avg over 10,000 samples to seed its optimization - so you're using the same trick the literature uses, just in the workflow instead of the training loop.

Caveats

Don't expect a clean "average" of content. The mean of two faces isn't their blended features in the way slerp gives you - it's a statistical center, and it can land on generic mush or occasionally something that looks like neither input. That's expected; this node is the benchmark, not the morph. And it stays within the pack's StyleGAN/extra category for a reason - it's only useful once you're already juggling batches of latents. If that's you, it's a three-second node that unlocks some of the pack's most interesting experiments.

CategoryStyleGAN/extra

Inputs (1)

NameTypeDefaultDescription
stylegan_latentSTYLEGAN_LATENT

Outputs (1)

NameTypeDescription
STYLEGAN_LATENTSTYLEGAN_LATENT