Load StyleGAN Directions
Pinning a good edit so you can find it next month
- STYLEGAN_DIRECTIONS
Discovering a direction is the fun part. Remembering which component on which seed produced that one good jawline edit is not. This node is the boring-but-necessary half of the workflow: it loads a saved bundle of StyleGAN directions off disk, so your edit stops being "rerun PCA and hope the ordering didn't shift".
It pairs with the pack's standalone scripts. discover_directions.py writes each component as its own named tensor in one .safetensors file (component_00, component_01, …) plus metadata recording the discovery order, so loading it back is exact rather than reconstructive:
python discover_directions.py model.safetensors --method sefa
By default that lands in ComfyUI/models/stylegan_directions/ - a sibling of models/stylegan/, deliberately not the same folder, so model checkpoints and direction bundles never show up mixed in one file picker.
What you set
stylegan_directions_file is a dropdown populated from ComfyUI/models/stylegan_directions/*.safetensors only. The pack registers that folder with a .safetensors-only extension list, so a .pkl or a stray .json won't appear, and a bundle dropped anywhere else won't either.
direction_name is optional and does two quite different things:
- Blank → you get the whole bundle back as a stacked tensor, in the order the file's metadata says (
component_order), falling back to sorted key order. That's what you want forStyleGANDirectionSweep-style exploration, where you're pokingcomponent_indexto see what exists. - Filled in (e.g.
component_03) → you get that one direction, wrapped as a single-element batch. Useful once you've identified the keeper, because then everyApplyStyleGANDirectiondownstream hascomponent_index = 0and nothing to misclick.
Output is one STYLEGAN_DIRECTIONS, wired into ApplyStyleGANDirection or StyleGANDirectionSweep. Once it's a file, this is deterministic: same bundle, same edit, next month, different machine.
Where the files come from
The in-graph discovery nodes (DiscoverGANSpaceDirections, DiscoverSeFaDirections) don't write anything - they hand back an in-memory bundle that dies with the session. So you have two options for permanence:
- Keep the discovery node in the graph. Re-running costs seconds for SeFa and a handful for GANSpace, and the result is reproducible for a given seed.
- Export offline with
discover_directions.pyand load the file here. This is the option that survives checkpoint swaps, model-folder reorganisation, and someone else opening your workflow. The script even renders a preview grid if you pass--sweep 0,1,2 --sweep-out sweep.png, so you can identify components before you ever open ComfyUI. Note--sweeprenders images, so it needs the compiled StyleGAN ops working; discovery itself doesn't.
Install
ComfyUI 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/, directions in ComfyUI/models/stylegan_directions/ (create it if the node's dropdown is empty - the folder is created lazily by the pack's scripts, not guaranteed to exist on a fresh clone). The pack's four pip deps are trivial; the actual pain is the runtime-compiled CUDA extensions needing CUDA Toolkit, ninja and MSVC/GCC, with a 30–60s plugin build the first time you render.
Because the offline script imports the pack directly, run it with the same Python environment ComfyUI uses if you can - it needs torch and safetensors at minimum, and it resolves dnnlib/torch_utils from the pack folder itself.
Where people get burned
- The file isn't in the dropdown. It's not in
models/stylegan_directions/. The picker does not browse anywhere else. direction_nametypo. You get aValueErrorthat also lists every key actually in the file, which is the friendliest failure in this whole pack. Read it instead of guessing again.- Mismatched checkpoint. A direction bundle carries its method, component count and
w_dim- but not which model it came from. Load a SeFa bundle from model A against model B and the node happily hands it over; the edits just come out as garbage or mush. Name your files with the model in them; the script's default filename already does. - A direction that felt strong yesterday feels flat today. Different PCA run means different ordering and sign. Once you've found a keeper, export it. That's the entire reason this node exists.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| stylegan_directions_file | COMBO | 0 options: | |
| direction_nameopt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STYLEGAN_DIRECTIONS | STYLEGAN_DIRECTIONS | — |