Nodes/ComfyUI-StyleGan/StyleGAN Latent From Batch
ComfyUI Node

StyleGAN Latent From Batch

Pull one latent out of a batch

By spacepxl·Created 2 years ago·Updated 2 years ago· 21
StyleGAN Latent From Batch
  • stylegan_latent
  • STYLEGAN_LATENT
index0

Sometimes you don't want the whole batch - you want one latent from it, and on your terms. StyleGAN Latent From Batch is the pack's index node: feed it a STYLEGAN_LATENT holding several vectors plus an index, and it returns a single-vector latent. That's the entire job, and it's genuinely useful in two specific spots.

How it works

The stylegan_latent input is a batch - [N, num_layers, 512] - and index (default 0, min 0) picks row N. The node then detach().clone()s that row so the output is an independent latent, not a view into the batch you might later mutate. One forgiving detail: it clamps out-of-range indices to the last element instead of erroring, so index = 999 on a batch of 8 quietly returns row 7 rather than exploding. That's friendly, but it can mask bugs - check your index if the output looks like the wrong image.

Output is a single STYLEGAN_LATENT, same width as the batch rows, ready for the sampler, the blend node, or the average node.

The two places you'll actually use it

  1. After inversion. StyleGAN Inversion outputs training_latents - the latent at every optimization step. This node is how you harvest a specific frame: index = 250 gets you the latent at step 250, which renders as a rough-but-recognizable reconstruction far faster than re-running the full 1000 steps. And if you feed a chain of increasing indices to the sampler, you've built the inversion-progress animation without touching any other node.

  2. After batched generation. Generate StyleGAN Latent with batch_size = 64 hands you 64 faces in one tensor. This node lets you pluck face #17 to inspect or edit in isolation while leaving the rest of the batch untouched - handy when you want to cherry-pick winners from a grid without regenerating.

When to skip it

If you only ever render whole batches - say, a 64-face contact sheet straight through the sampler - you don't need this node at all. It exists for the moments you want one row of a multi-row latent, and those moments are almost always downstream of the inversion node. Thin as it is, it's the difference between "I generated 1000 latents" and "I can actually reach any one of them," and for latent-space work that's a real capability, not paperwork.

CategoryStyleGAN/extra

Inputs (2)

NameTypeDefaultDescription
stylegan_latentSTYLEGAN_LATENT
indexINT0

Outputs (1)

NameTypeDescription
STYLEGAN_LATENTSTYLEGAN_LATENT