# zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis architecture

> Architecture diagram of the GitHub repository zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis
- Repository: https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis

## Overview

This repository implements one-shot, free-view neural talking-head synthesis. The principal user workflow supplies a source face image and a driving video, then demo.py estimates facial motion and head pose, animates the source, and writes a result video; optional free-view angles modify the pose. A separate training workflow loads video-frame pairs, augments them, and optimizes the synthesis models. The README documents cropping guidance and face-restoration post-processing. Some subsystem links are based on README statements or SOURCE INDEX references because the relevant source was not excerpted.

Main entry points: [`demo.py`](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/demo.py) (Demo runner), [`train.py`](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/train.py) (Training loop), [`modules/util.py`](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/util.py) (Network blocks), [`modules/generator.py`](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/generator.py) (Occlusion-aware generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference and preparation"]
  node_crop["Crop guidance<br/>[crop-video.py]"]
  node_demo["Demo runner<br/>[demo.py]"]
  node_animate["Frame animation<br/>[animate.py]"]
end

subgraph group_networks["Synthesis networks"]
  node_keypoints["Keypoint detector"]
  node_headpose["Head pose estimator<br/>[hopenet.py]"]
  node_generator["Occlusion-aware generator<br/>[generator.py]"]
  node_motion["Dense motion<br/>[dense_motion.py]"]
  node_model["Training loss models<br/>[model.py]"]
  node_network_utils["Network blocks<br/>[util.py]"]
end

subgraph group_training["Training"]
  node_train_entry["Training entry<br/>[run.py]"]
  node_trainer["Training loop<br/>[train.py]"]
  node_dataset["Video-pair dataset<br/>[frames_dataset.py]"]
  node_augmentation["Clip augmentation<br/>[augmentation.py]"]
  node_logger["Training logger<br/>[logger.py]"]
end

subgraph group_parallel["Parallel primitives"]
  node_sync_batchnorm["Synchronized batch norm<br/>[batchnorm.py]"]
  node_sync_comm["Replica communication<br/>[comm.py]"]
  node_replication["Parallel replication<br/>[replicate.py]"]
end

node_user(("User"))
node_source["Source image"]
node_driving["Driving video"]
node_result["Result video"]
node_restoration["Face restoration"]

node_user -->|"runs"| node_demo
node_user -->|"requests crop"| node_crop
node_source -->|"provides image"| node_demo
node_driving -->|"provides video"| node_demo
node_crop -->|"guides cropping"| node_driving
node_demo -->|"estimates landmarks"| node_keypoints
node_demo -->|"estimates pose"| node_headpose
node_demo -->|"animates source"| node_generator
node_demo -->|"calls animation"| node_animate
node_animate -.->|"writes video"| node_result
node_result -.->|"can post-process"| node_restoration
node_generator -->|"uses"| node_motion
node_generator -->|"uses blocks"| node_network_utils
node_motion -->|"uses blocks"| node_network_utils
node_keypoints -->|"uses blocks"| node_network_utils
node_train_entry -->|"starts training"| node_trainer
node_train_entry -->|"configures dataset"| node_dataset
node_trainer -->|"loads batches"| node_dataset
node_dataset -->|"applies transforms"| node_augmentation
node_trainer -->|"computes losses"| node_model
node_trainer -->|"logs training"| node_logger
node_model -->|"uses estimator"| node_headpose
node_network_utils -->|"uses normalization"| node_sync_batchnorm
node_sync_batchnorm -->|"exchanges statistics"| node_sync_comm
node_replication -.->|"registers replicas"| node_sync_batchnorm

click node_crop "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/crop-video.py"
click node_demo "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/demo.py"
click node_animate "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/animate.py"
click node_keypoints "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/keypoint_detector.py"
click node_headpose "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/hopenet.py"
click node_generator "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/generator.py"
click node_motion "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/dense_motion.py"
click node_model "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/model.py"
click node_network_utils "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/util.py"
click node_train_entry "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/run.py"
click node_trainer "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/train.py"
click node_dataset "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/frames_dataset.py"
click node_augmentation "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/augmentation.py"
click node_logger "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/logger.py"
click node_sync_batchnorm "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/sync_batchnorm/batchnorm.py"
click node_sync_comm "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/sync_batchnorm/comm.py"
click node_replication "https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/sync_batchnorm/replicate.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_crop,node_demo,node_animate,node_user toneBlue
class node_keypoints,node_headpose,node_generator,node_motion,node_model,node_network_utils toneAmber
class node_train_entry,node_trainer,node_dataset,node_augmentation,node_logger toneMint
class node_sync_batchnorm,node_sync_comm,node_replication toneRose
class node_source,node_driving,node_result,node_restoration toneIndigo
```

## Components

### Inference and preparation

- [Crop guidance](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/crop-video.py): `crop-video.py`
- [Demo runner](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/demo.py): `demo.py`
- [Frame animation](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/animate.py): `animate.py`

### Synthesis networks

- [Keypoint detector](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/keypoint_detector.py): `modules/keypoint_detector.py`
- [Head pose estimator](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/hopenet.py): `modules/hopenet.py`
- [Occlusion-aware generator](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/generator.py): `modules/generator.py`
- [Dense motion](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/dense_motion.py): `modules/dense_motion.py`
- [Training loss models](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/model.py): `modules/model.py`
- [Network blocks](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/modules/util.py): `modules/util.py`

### Training

- [Training entry](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/run.py): `run.py`
- [Training loop](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/train.py): `train.py`
- [Video-pair dataset](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/frames_dataset.py): `frames_dataset.py`
- [Clip augmentation](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/augmentation.py): `augmentation.py`
- [Training logger](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/logger.py): `logger.py`

### Parallel primitives

- [Synchronized batch norm](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/sync_batchnorm/batchnorm.py): `sync_batchnorm/batchnorm.py`
- [Replica communication](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/sync_batchnorm/comm.py): `sync_batchnorm/comm.py`
- [Parallel replication](https://github.com/zhanglonghao1992/one-shot_free-view_neural_talking_head_synthesis/blob/main/sync_batchnorm/replicate.py): `sync_batchnorm/replicate.py`

### Other components

- **User**
- **Source image**
- **Driving video**
- **Result video**
- **Face restoration**

## Connections

- User → Demo runner: runs (evidence: `README.md`)
- User → Crop guidance: requests crop (evidence: `README.md`)
- Source image → Demo runner: provides image (evidence: `README.md`)
- Driving video → Demo runner: provides video (evidence: `README.md`)
- Crop guidance → Driving video: guides cropping (evidence: `README.md`)
- Demo runner → Keypoint detector: estimates landmarks (evidence: `demo.py`)
- Demo runner → Head pose estimator: estimates pose (evidence: `demo.py`)
- Demo runner → Occlusion-aware generator: animates source (evidence: `demo.py`)
- Demo runner → Frame animation: calls animation (evidence: `demo.py`)
- Frame animation → Result video: writes video
- Result video → Face restoration: can post-process (evidence: `README.md`)
- Occlusion-aware generator → Dense motion: uses (evidence: `modules/generator.py`)
- Occlusion-aware generator → Network blocks: uses blocks (evidence: `modules/generator.py`)
- Dense motion → Network blocks: uses blocks (evidence: `modules/dense_motion.py`)
- Keypoint detector → Network blocks: uses blocks (evidence: `modules/keypoint_detector.py`)
- Training entry → Training loop: starts training (evidence: `run.py`)
- Training entry → Video-pair dataset: configures dataset (evidence: `run.py`)
- Training loop → Video-pair dataset: loads batches (evidence: `train.py`)
- Video-pair dataset → Clip augmentation: applies transforms (evidence: `frames_dataset.py`)
- Training loop → Training loss models: computes losses (evidence: `train.py`)
- Training loop → Training logger: logs training (evidence: `train.py`)
- Training loss models → Head pose estimator: uses estimator (evidence: `modules/model.py`)
- Network blocks → Synchronized batch norm: uses normalization (evidence: `modules/util.py`)
- Synchronized batch norm → Replica communication: exchanges statistics (evidence: `sync_batchnorm/batchnorm.py`)
- Parallel replication → Synchronized batch norm: registers replicas
