# mandeep15686/faceswap architecture

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

- Interactive diagram: https://gitdiagram.com/mandeep15686/faceswap
- Repository: https://github.com/mandeep15686/faceswap

## Overview

FaceSwap Pipeline v2 converts a target video and multi-angle source identity photos into a swapped video. The documented frame workflow decodes, detects and tracks faces, gates low-quality frames, then applies geometry, smoothing, alignment, identity, swap, parsing, occlusion handling, enhancement, color transfer, blending, and encoding. `main.py` is the orchestration entry point; `pipeline/base.py` provides the shared frame context and stage contract. The README documents the stage order and temporal feedback; sampled excerpts do not show the complete frame loop, so those links rely on that documentation.

Main entry points: [`pipeline/stage08_dreamid.py`](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage08_dreamid.py) (DreamID swapper), [`pipeline/stage13_blending.py`](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage13_blending.py) (Seamless blender), [`main.py`](https://github.com/mandeep15686/faceswap/blob/main/main.py) (Pipeline runner), [`pipeline/stage09_parsing.py`](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage09_parsing.py) (Face parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Orchestration and context"]
  node_main["Pipeline runner<br/>[main.py]"]
  node_frame_context["Frame context<br/>[base.py]"]
end

subgraph group_tracking["Face tracking"]
  node_decoder["Video decoder<br/>[stage01_decoder.py]"]
  node_detector["Face detector"]
  node_tracker["Face tracker<br/>[stage03_tracker.py]"]
  node_quality_gate["Quality gate<br/>[quality_gate.py]"]
  node_geometry["3D geometry"]
  node_smoother["Landmark smoother"]
  node_aligner["Face alignment"]
end

subgraph group_identity["Identity and synthesis"]
  node_identity_embed["Identity embedding"]
  node_dreamid["DreamID swapper<br/>[stage08_dreamid.py]"]
end

subgraph group_compositing["Compositing and output"]
  node_parser["Face parser<br/>[stage09_parsing.py]"]
  node_occlusion["Occlusion detector"]
  node_enhancer["Face enhancer"]
  node_color_transfer["Color transfer"]
  node_blender["Seamless blender"]
  node_encoder["Video encoder<br/>[stage14_encoder.py]"]
end

node_user(("User"))

node_user -->|"runs with inputs"| node_main
node_main -->|"builds source identity"| node_identity_embed
node_decoder -->|"provides frames"| node_detector
node_detector -->|"provides detections"| node_tracker
node_tracker -->|"provides track history"| node_quality_gate
node_quality_gate -->|"gates frames"| node_geometry
node_geometry -->|"provides landmarks"| node_smoother
node_smoother -->|"provides landmarks"| node_aligner
node_aligner -->|"provides aligned face"| node_identity_embed
node_identity_embed -->|"provides identity"| node_dreamid
node_dreamid -->|"provides swapped face"| node_parser
node_parser -->|"provides face regions"| node_occlusion
node_occlusion -->|"provides occlusion mask"| node_enhancer
node_enhancer -->|"provides enhanced face"| node_color_transfer
node_color_transfer -->|"provides corrected face"| node_blender
node_parser -->|"provides parse mask"| node_blender
node_occlusion -->|"provides blend mask"| node_blender
node_blender -->|"provides composited frames"| node_encoder
node_dreamid -->|"feeds previous frame"| node_dreamid
node_main -.->|"coordinates frame stages"| node_frame_context

click node_main "https://github.com/mandeep15686/faceswap/blob/main/main.py"
click node_frame_context "https://github.com/mandeep15686/faceswap/blob/main/pipeline/base.py"
click node_decoder "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage01_decoder.py"
click node_detector "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage02_detector.py"
click node_tracker "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage03_tracker.py"
click node_quality_gate "https://github.com/mandeep15686/faceswap/blob/main/pipeline/quality_gate.py"
click node_geometry "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage04_geometry.py"
click node_smoother "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage05_smoother.py"
click node_aligner "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage06_alignment.py"
click node_identity_embed "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage07_identity.py"
click node_dreamid "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage08_dreamid.py"
click node_parser "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage09_parsing.py"
click node_occlusion "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage10_occlusion.py"
click node_enhancer "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage11_enhancement.py"
click node_color_transfer "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage12_color_transfer.py"
click node_blender "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage13_blending.py"
click node_encoder "https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage14_encoder.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_main,node_frame_context,node_user toneBlue
class node_decoder,node_detector,node_tracker,node_quality_gate,node_geometry,node_smoother,node_aligner toneAmber
class node_identity_embed,node_dreamid toneMint
class node_parser,node_occlusion,node_enhancer,node_color_transfer,node_blender,node_encoder toneRose
```

## Components

### Orchestration and context

- [Pipeline runner](https://github.com/mandeep15686/faceswap/blob/main/main.py): `main.py`
- [Frame context](https://github.com/mandeep15686/faceswap/blob/main/pipeline/base.py): `pipeline/base.py`

### Face tracking

- [Video decoder](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage01_decoder.py): `pipeline/stage01_decoder.py`
- [Face detector](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage02_detector.py): `pipeline/stage02_detector.py`
- [Face tracker](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage03_tracker.py): `pipeline/stage03_tracker.py`
- [Quality gate](https://github.com/mandeep15686/faceswap/blob/main/pipeline/quality_gate.py): `pipeline/quality_gate.py`
- [3D geometry](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage04_geometry.py): `pipeline/stage04_geometry.py`
- [Landmark smoother](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage05_smoother.py): `pipeline/stage05_smoother.py`
- [Face alignment](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage06_alignment.py): `pipeline/stage06_alignment.py`

### Identity and synthesis

- [Identity embedding](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage07_identity.py): `pipeline/stage07_identity.py`
- [DreamID swapper](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage08_dreamid.py): `pipeline/stage08_dreamid.py`

### Compositing and output

- [Face parser](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage09_parsing.py): `pipeline/stage09_parsing.py`
- [Occlusion detector](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage10_occlusion.py): `pipeline/stage10_occlusion.py`
- [Face enhancer](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage11_enhancement.py): `pipeline/stage11_enhancement.py`
- [Color transfer](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage12_color_transfer.py): `pipeline/stage12_color_transfer.py`
- [Seamless blender](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage13_blending.py): `pipeline/stage13_blending.py`
- [Video encoder](https://github.com/mandeep15686/faceswap/blob/main/pipeline/stage14_encoder.py): `pipeline/stage14_encoder.py`

### Other components

- **User**

## Connections

- User → Pipeline runner: runs with inputs (evidence: `README.md`)
- Pipeline runner → Identity embedding: builds source identity (evidence: `main.py`)
- Video decoder → Face detector: provides frames (evidence: `README.md`)
- Face detector → Face tracker: provides detections (evidence: `README.md`)
- Face tracker → Quality gate: provides track history (evidence: `README.md`)
- Quality gate → 3D geometry: gates frames (evidence: `README.md`)
- 3D geometry → Landmark smoother: provides landmarks (evidence: `README.md`)
- Landmark smoother → Face alignment: provides landmarks (evidence: `README.md`)
- Face alignment → Identity embedding: provides aligned face (evidence: `README.md`)
- Identity embedding → DreamID swapper: provides identity (evidence: `pipeline/stage08_dreamid.py`)
- DreamID swapper → Face parser: provides swapped face (evidence: `README.md`)
- Face parser → Occlusion detector: provides face regions (evidence: `README.md`)
- Occlusion detector → Face enhancer: provides occlusion mask (evidence: `README.md`)
- Face enhancer → Color transfer: provides enhanced face (evidence: `README.md`)
- Color transfer → Seamless blender: provides corrected face (evidence: `README.md`)
- Face parser → Seamless blender: provides parse mask (evidence: `README.md`)
- Occlusion detector → Seamless blender: provides blend mask (evidence: `README.md`)
- Seamless blender → Video encoder: provides composited frames (evidence: `README.md`)
- DreamID swapper → DreamID swapper: feeds previous frame (evidence: `README.md`)
- Pipeline runner → Frame context: coordinates frame stages
