style_transformer_encoder
A transformer encoder that turns an image into StyleGAN W+ codes by letting style queries attend to CNN features.
Diffusion and generative · 157 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
At a glance
- Parameters
- 194.6K
- Operations
- 157
- Framework
- PyTorch
- Recurrent
- No
- Published
- 2022
- Cited by
- 2 (as of 5 October 2026)
- Authors
- Xueqi Hu, Qiusheng Huang, Zhengyi Shi and others
- Checked
- Passed: the trace was replayed operation by operation and matched the model's own output for this input.
Files
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
Details
- Stable ID
- m12160
- Graph hash
- 5b05cd7a18599cb7292bf7c13f56c3e3b9729b7c3127bae3d8b375086bbc2c13
- Skeleton hash
- 6041b6e6a8eea013492b50ebf8e9683338f1a9721ad09107a2e7106fd130e4ce
- Architecture hash
- 29a4116908c2e313ad603598f27f101bf327fddf465df4ae9fa911fc5bd04e4a
- Diagram SHA-256
- 6096a542cd16bd696a7bb51511ef57d9939d9306e9c67fdeabc3f277acda660c
- TorchLens version
- 2.36.0
- Renderer
- graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
- Check
- Forward pass replayed in PyTorch
How this diagram was made
menagerie.classics.style_transformer_encoder:build_style_transformer_encoder: build({}) What it is
The Style Transformer is an encoder for GAN inversion: it turns a real image into the latent codes a pretrained StyleGAN needs to reconstruct and then edit it. The problem it addresses is that existing GAN inversion methods fail to provide latent codes for reliable reconstruction and flexible editing at the same time. It works in W+ space, where each image is represented by 18 different codes of 512 dimensions each.
A CNN encoder provides multi-scale image features that serve as keys and values. The style codes to be determined for the different generator layers are treated as queries. The query tokens start as learnable parameters and are mapped into W+ space before any attention happens. Then multi-stage alternating self- and cross-attention update the queries so that the generator can invert the input. The same block structure is applied three times, drawing on image features F1 to F3 in turn. Self-attention among the queries is there to regularize them, so the final codes handed to the generator are tightly linked.
Rather than random query initialization, the pretrained StyleGAN MLP first maps each learnable code zn to a starting style query in W space. During training, the StyleGAN backbone G, including its affine layer A, is kept strictly fixed. The training objectives are the same as pSp's. No adversarial loss is used during training. The paper splits editing into label-based, where only a target label is given, and reference-based, where another image supplies the desired style. For label-based editing, a pretrained non-linear latent classifier determines the editing direction. For inversion quality the method is compared against pSp and e4e.
Key idea. A multi-stage style transformer in W+ space whose style queries are gradually updated from multi-scale image features through self- and cross-attention.
- Style Transformer
- style transformer encoder
- GAN inversion
- StyleGAN inversion
- W+ latent
- image editing
- pSp
- e4e
- latent code encoder
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
Cite the paper
@misc{hu2022styletransformerimageinversion,
title={Style Transformer for Image Inversion and Editing},
author={Xueqi Hu and Qiusheng Huang and Zhengyi Shi and Siyuan Li and Changxin Gao and Li Sun and Qingli Li},
year={2022},
eprint={2203.07932},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2203.07932},
}