StyleGAN Latent to String
Flatten a face into copy-pasteable text
- stylegan_latent
- STRING
Small node, real use case. A StyleGAN latent is a float tensor, and ComfyUI's usual ways of moving tensors around are all awkward: the PNG metadata trick needs a file, a seed needs the whole generation history, and a wire only reaches as far as the graph does. This node turns the latent into a plain string - copy it into a note, paste it into a workflow someone else will run, drop it in a JSON payload, and the face comes back exactly.
It's the lossless, portable, no-attachments form of a StyleGAN face. One input, one output, no widgets.
What the string actually is
Not a nice JSON array of floats, if that's what you were hoping - that would be enormous. It's the latent as a numpy array, saved to a BytesIO with np.save, zlib-compressed, then base64-encoded. Same encoding the pack uses for the PNG metadata chunk, which is why strings from this node and latents read out of saved images are interchangeable.
Practical consequences:
- It's long. One latent is
num_ws × w_dimfloat32 - for a typical 16×512 StyleGAN2 that's ~32KB of raw floats, and compressed random floats don't compress much. Expect a wall of a few tens of thousands of base64 characters. Fine for a text file, a clipboard, or a node's multiline widget; not something you'll eyeball or diff. - It's lossless for float32. Round-trip through the sibling node gives you bit-identical values, not a rounded approximation.
- It carries no model information. Compare with the PNG route, where the pack also writes
stylegan_model_file. A bare string is just numbers. If you're archiving faces, name your files or keep a note - nothing in the latent tells you which checkpoint it belongs to, and a latent from the wrong checkpoint renders as garbage rather than raising an error.
Wiring it
Input is a STYLEGAN_LATENT - from GenerateStyleGANLatent, ApplyStyleGANDirection, LoadStyleGANLatentImg, anywhere. Output is a plain STRING, which in ComfyUI means it goes into anything with a string socket: a text-file writer, a "show text" display node, a note, or an API payload if you're driving ComfyUI programmatically.
The one that surprises people pleasantly is the display node. Wire it into a text preview, run the graph, copy the wall of characters out of the UI, and you've got a face in your clipboard. Paste it into StringToStyleGANLatent on a completely different machine with the same checkpoint and you have the same face. No seed, no direction bundle, no dependency on whether your PCA run reorders components next month.
It's also a decent debugging instrument. Dump the string at two points in a chain of ApplyStyleGANDirection nodes and compare - if they're identical, your edit did nothing, which is the fastest way to catch a wrong strength scale or a hopeless mask.
Install
Nothing special - it ships in the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/dfl/ComfyUI-StyleGan
or via ComfyUI Manager, search ComfyUI-StyleGan (publisher dflfd). Restart, put a checkpoint in ComfyUI/models/stylegan/. This is one of the nodes that needs no GPU work at all - no compiled kernels, and it doesn't even load a model. It'll function on an install where StyleGANSampler still can't build its plugins, so it's handy for extracting latents from images while you sort your toolchain out.
Where people get burned
- String gets truncated or hand-edited. Base64 is unforgiving: one dropped character and decoding fails, usually with a fairly unhelpful error. Copy the whole thing or don't bother.
- Newlines mid-string. The decoder strips surrounding whitespace and standard base64 decoders discard embedded line breaks, so ordinary widget wrapping is fine - but a text editor that "helpfully" reformats or wraps with other characters isn't.
- Wrong checkpoint. The most common real failure, and it's silent. A latent is only meaningful relative to the model that made it.
- Expecting it to be readable. If you were after "the seed and the direction strengths", this isn't that. It's the end result, in bulk, with the reasoning stripped out.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| stylegan_latent | STYLEGAN_LATENT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |