String to StyleGAN Latent
Paste a face back into existence
- STYLEGAN_LATENT
This is the receiving end of StyleGANLatentToString. Paste in the encoded latent string and you get an actual STYLEGAN_LATENT back, ready to feed a sampler or a direction node. It's the least glamorous node in the pack and the one that quietly makes StyleGAN faces shareable in a way the rest of ComfyUI can't: a face that fits in a text field.
Why you'd want that
Three situations, all of which come up:
- You found the face. You tweaked a seed, applied a GANSpace component at strength 2.4 with a coarse mask, and it's the best thing you've made all week. A seed number doesn't reproduce it. The string does - exactly, float for float.
- You're handing a workflow to someone else. The PNG metadata route works, but it needs an image file to travel with the workflow. A string lives inside the graph. Same workflow, same face, no "where's the input folder" conversation.
- You're scripting ComfyUI. A latent you can put in JSON is a latent you can key a database on, log, or generate from code.
How the mechanism works
The input, stylegan_latent_string, is a multiline STRING - the base64 arm of the pack's serialization: numpy array → np.save → zlib compress → base64. Decoding is the reverse, and the resulting tensor is moved straight onto your compute device, so it's ready to use without a .to() in between.
Two behaviours worth knowing, both from the source: leading and trailing whitespace is stripped before decoding, and standard base64 decoding ignores embedded line breaks - so a string that's been wrapped by a widget or a text editor still works. What it does not survive is real corruption. Drop a character, paste half of it, let a formatter mangle it, and you get an exception rather than a wrong-but-plausible face.
The output is one STYLEGAN_LATENT, which goes into ApplyStyleGANDirection, StyleGANDirectionSweep, BlendStyleGANLatents, or StyleGANSampler. From the sampler it's a normal image; the pack's latent registry means saving it straight off the sampler still embeds metadata, so the string round trip can end up as a PNG again if you want.
The thing the string does not contain is the checkpoint. Unlike the PNG route, there's no stylegan_model_file chunk riding along. So a pasted latent against the wrong model doesn't error - it renders something, and that something is nonsense. It's worth pasting the model name into a note node next to the string, because future-you will not remember.
The workflow pairing
The obvious loop: GenerateStyleGANLatent → ApplyStyleGANDirection → StyleGANLatentToString → copy → paste into StringToStyleGANLatent → StyleGANSampler. That's a saved face with the whole edit baked in. It also works as a debugging trick - dump the string before and after a direction node, compare the two, and you instantly know whether that edit did anything at all, which beats squinting at near-identical images.
Install
Manager → search ComfyUI-StyleGan (publisher dflfd), or:
cd ComfyUI/custom_nodes
git clone https://github.com/dfl/ComfyUI-StyleGan
Restart, models in ComfyUI/models/stylegan/. This node needs no model, no compiled kernels, nothing beyond what the pack already installs - its pip list is just numpy, ninja, safetensors, packaging. That makes it one of the nodes you can use while your CUDA toolchain build is still failing. Rendering is the part that needs CUDA Toolkit, ninja and MSVC/GCC, plus that 30–60s first-run plugin compile.
Where people get burned
- Malformed paste. Base64 errors look cryptic but they always mean the same thing: the string isn't intact. Re-copy from the source.
- A latent from a different checkpoint. Silent nonsense output. There is no compatibility check anywhere in this path.
- Assuming it's compressed cleverly. It's zlib over raw float32 - a few tens of KB of base64 per latent. Don't try to put hundreds of these in a CSV and expect a small file.
- Copying the string out of a rendered preview instead of the node widget. The UI truncates long values in some views. Use the widget's own text, or a text-file node.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| stylegan_latent_string | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STYLEGAN_LATENT | STYLEGAN_LATENT | — |