# xingangpan/draggan architecture

> Architecture diagram of the GitHub repository xingangpan/draggan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xingangpan/draggan
- Repository: https://github.com/xingangpan/draggan

## Overview

DragGAN is an interactive point-based editor for images generated by pretrained StyleGAN models. The main workflow is to choose a model and seed, generate an image, set source/target points and a mask, then iteratively render the edited result. The repository also provides a Gradio interface, latent/model controls, and adjacent StyleGAN-Human tools including PTI inversion and InsetGAN composition. Links follow the README and shown excerpts/SOURCE INDEX references; unsampled capabilities are included where documented, but their internal wiring is not assumed.

Main entry points: [`visualizer_drag.py`](https://github.com/xingangpan/draggan/blob/main/visualizer_drag.py) (Desktop GUI), [`viz/renderer.py`](https://github.com/xingangpan/draggan/blob/main/viz/renderer.py) (Render engine), [`training/networks_stylegan2.py`](https://github.com/xingangpan/draggan/blob/main/training/networks_stylegan2.py) (StyleGAN2 generator), [`visualizer_drag_gradio.py`](https://github.com/xingangpan/draggan/blob/main/visualizer_drag_gradio.py) (Gradio demo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Editing interfaces"]
  node_desktop["Desktop GUI<br/>[visualizer_drag.py]"]
  node_gradio["Gradio demo"]
  node_drag["Point controls<br/>[drag_widget.py]"]
  node_latent["Latent controls<br/>[latent_widget.py]"]
  node_pickle["Model selection<br/>[pickle_widget.py]"]
  node_capture["Capture controls<br/>[capture_widget.py]"]
end

subgraph group_render["Generation and editing"]
  node_renderer["Render engine<br/>[renderer.py]"]
end

subgraph group_models["GAN models"]
  node_sg2["StyleGAN2 generator"]
  node_sg3["StyleGAN3 generator"]
  node_human_gen["Human generator<br/>[networks.py]"]
  node_legacy["Checkpoint loading<br/>[legacy.py]"]
  node_training["GAN training<br/>[training_loop.py]"]
  node_weights[("Pretrained weights")]
end

subgraph group_human["Human-image tools"]
  node_human_edit["Human editing<br/>[edit.py]"]
  node_pti["PTI inversion<br/>[run_pti.py]"]
  node_inset["Face-body composition<br/>[insetgan.py]"]
end

subgraph group_runtime["Runtime support"]
  node_ops["GAN tensor ops<br/>[upfirdn2d.py]"]
end

node_user(("Editor"))

node_user -->|"opens"| node_desktop
node_user -->|"opens"| node_gradio
node_desktop -->|"updates controls"| node_drag
node_desktop -->|"hosts controls"| node_latent
node_desktop -->|"hosts controls"| node_pickle
node_desktop -->|"hosts controls"| node_capture
node_desktop -->|"renders via"| node_renderer
node_gradio -->|"uses renderer"| node_renderer
node_drag -->|"sets edit args"| node_desktop
node_renderer -->|"loads checkpoint"| node_legacy
node_renderer -->|"selects generator"| node_sg2
node_renderer -->|"selects generator"| node_sg3
node_renderer -->|"selects generator"| node_human_gen
node_sg2 -->|"uses resampling"| node_ops
node_legacy -->|"reconstructs network"| node_sg2
node_user -.->|"inverts image"| node_pti
node_pti -->|"loads latent and weights"| node_desktop
node_user -.->|"runs human edits"| node_human_edit
node_user -.->|"runs composition"| node_inset
node_user -.->|"trains models"| node_training
node_weights -.->|"provides checkpoint"| node_renderer

click node_desktop "https://github.com/xingangpan/draggan/blob/main/visualizer_drag.py"
click node_gradio "https://github.com/xingangpan/draggan/blob/main/visualizer_drag_gradio.py"
click node_drag "https://github.com/xingangpan/draggan/blob/main/viz/drag_widget.py"
click node_latent "https://github.com/xingangpan/draggan/blob/main/viz/latent_widget.py"
click node_pickle "https://github.com/xingangpan/draggan/blob/main/viz/pickle_widget.py"
click node_capture "https://github.com/xingangpan/draggan/blob/main/viz/capture_widget.py"
click node_renderer "https://github.com/xingangpan/draggan/blob/main/viz/renderer.py"
click node_sg2 "https://github.com/xingangpan/draggan/blob/main/training/networks_stylegan2.py"
click node_sg3 "https://github.com/xingangpan/draggan/blob/main/training/networks_stylegan3.py"
click node_human_gen "https://github.com/xingangpan/draggan/blob/main/stylegan_human/training_scripts/sg2/training/networks.py"
click node_legacy "https://github.com/xingangpan/draggan/blob/main/legacy.py"
click node_ops "https://github.com/xingangpan/draggan/blob/main/torch_utils/ops/upfirdn2d.py"
click node_human_edit "https://github.com/xingangpan/draggan/blob/main/stylegan_human/edit.py"
click node_pti "https://github.com/xingangpan/draggan/blob/main/stylegan_human/run_pti.py"
click node_inset "https://github.com/xingangpan/draggan/blob/main/stylegan_human/insetgan.py"
click node_training "https://github.com/xingangpan/draggan/blob/main/training/training_loop.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_desktop,node_gradio,node_drag,node_latent,node_pickle,node_capture toneBlue
class node_renderer toneAmber
class node_sg2,node_sg3,node_human_gen,node_legacy,node_training,node_weights toneMint
class node_human_edit,node_pti,node_inset toneRose
class node_ops,node_user toneIndigo
```

## Components

### Editing interfaces

- [Desktop GUI](https://github.com/xingangpan/draggan/blob/main/visualizer_drag.py): `visualizer_drag.py`
- [Gradio demo](https://github.com/xingangpan/draggan/blob/main/visualizer_drag_gradio.py): `visualizer_drag_gradio.py`
- [Point controls](https://github.com/xingangpan/draggan/blob/main/viz/drag_widget.py): `viz/drag_widget.py`
- [Latent controls](https://github.com/xingangpan/draggan/blob/main/viz/latent_widget.py): `viz/latent_widget.py`
- [Model selection](https://github.com/xingangpan/draggan/blob/main/viz/pickle_widget.py): `viz/pickle_widget.py`
- [Capture controls](https://github.com/xingangpan/draggan/blob/main/viz/capture_widget.py): `viz/capture_widget.py`

### Generation and editing

- [Render engine](https://github.com/xingangpan/draggan/blob/main/viz/renderer.py): `viz/renderer.py`

### GAN models

- [StyleGAN2 generator](https://github.com/xingangpan/draggan/blob/main/training/networks_stylegan2.py): `training/networks_stylegan2.py`
- [StyleGAN3 generator](https://github.com/xingangpan/draggan/blob/main/training/networks_stylegan3.py): `training/networks_stylegan3.py`
- [Human generator](https://github.com/xingangpan/draggan/blob/main/stylegan_human/training_scripts/sg2/training/networks.py): `stylegan_human/training_scripts/sg2/training/networks.py`
- [Checkpoint loading](https://github.com/xingangpan/draggan/blob/main/legacy.py): `legacy.py`
- [GAN training](https://github.com/xingangpan/draggan/blob/main/training/training_loop.py): `training/training_loop.py`
- **Pretrained weights**

### Human-image tools

- [Human editing](https://github.com/xingangpan/draggan/blob/main/stylegan_human/edit.py): `stylegan_human/edit.py`
- [PTI inversion](https://github.com/xingangpan/draggan/blob/main/stylegan_human/run_pti.py): `stylegan_human/run_pti.py`
- [Face-body composition](https://github.com/xingangpan/draggan/blob/main/stylegan_human/insetgan.py): `stylegan_human/insetgan.py`

### Runtime support

- [GAN tensor ops](https://github.com/xingangpan/draggan/blob/main/torch_utils/ops/upfirdn2d.py): `torch_utils/ops/upfirdn2d.py`

### Other components

- **Editor**

## Connections

- Editor → Desktop GUI: opens
- Editor → Gradio demo: opens
- Desktop GUI → Point controls: updates controls (evidence: `visualizer_drag.py`)
- Desktop GUI → Latent controls: hosts controls (evidence: `visualizer_drag.py`)
- Desktop GUI → Model selection: hosts controls (evidence: `visualizer_drag.py`)
- Desktop GUI → Capture controls: hosts controls (evidence: `visualizer_drag.py`)
- Desktop GUI → Render engine: renders via (evidence: `visualizer_drag.py`)
- Gradio demo → Render engine: uses renderer (evidence: `visualizer_drag_gradio.py`)
- Point controls → Desktop GUI: sets edit args (evidence: `viz/drag_widget.py`)
- Render engine → Checkpoint loading: loads checkpoint (evidence: `viz/renderer.py`)
- Render engine → StyleGAN2 generator: selects generator (evidence: `viz/renderer.py`)
- Render engine → StyleGAN3 generator: selects generator (evidence: `viz/renderer.py`)
- Render engine → Human generator: selects generator (evidence: `viz/renderer.py`)
- StyleGAN2 generator → GAN tensor ops: uses resampling (evidence: `training/networks_stylegan2.py`)
- Checkpoint loading → StyleGAN2 generator: reconstructs network (evidence: `legacy.py`)
- Editor → PTI inversion: inverts image
- PTI inversion → Desktop GUI: loads latent and weights
- Editor → Human editing: runs human edits
- Editor → Face-body composition: runs composition (evidence: `stylegan_human/insetgan.py`)
- Editor → GAN training: trains models
- Pretrained weights → Render engine: provides checkpoint
