How havish-coder/talking_heads works
1. This repository is a single-purpose video generation pipeline for audio-driven half-body human animation. It is not a service or app; the core architecture is split into preprocessing, model definition, training, and inference.
2. The top-level boundary is between raw media inputs and training-ready artifacts. Raw videos, audio, reference images, and pose sequences are transformed into intermediate files that the training code consumes from disk, rather than recomputing expensive encoders on every step.
3. The Preprocessing/ folder is the ingestion and feature-extraction layer. Its scripts suggest separate passes for:
- video encoding / latent preparation,
- audio embedding extraction,
- reference image encoding,
- DWPose keypoint preprocessing,
- renaming / dataset organization.
This is the stage that turns heterogeneous media into consistent clip-aligned assets.
4. The main data products of preprocessing are likely the same ones described in the README: VAE latents, audio embeddings, and pose arrays. These become the stable interface between preprocessing and training, which is important for GPU memory control and reproducibility.
5. The Src/Models/ folder contains the model-side architecture. talking_heads_dit.py is the central generator wrapper, and audio_encoder.py likely handles projection or adaptation of audio features into the DiT hidden space. This is where the project adapts CogVideoX-style components into a talking-head-specific diffusion model.
6. The generator architecture is a DiT-based video diffusion model rather than a UNet pipeline. The README indicates the reference image is injected by token prepending instead of a dedicated ReferenceNet, and audio is passed through an embedding projection into the transformer conditioning path. That means the model boundary is a unified transformer over video tokens plus conditioning tokens.
7. The Src/training/ folder is the learning subsystem. dataset.py is the loader for aligned video/audio/pose samples and precomputed features, loss.py defines the diffusion objective, and train.py is the training entrypoint. config.yaml is the main control plane for batch size, resolution, frame count, checkpoints, and optimization settings.
8. Training is designed around frozen heavy backbones and lightweight trainable adapters. The README makes clear that the VAE, Wav2Vec2, and main CogVideoX backbone are kept fixed, while smaller projection/adapter layers are trained. Architecturally, that means the optimization boundary is narrow and memory-efficient.
9. The Src/inference.py module is the runtime generation path. It should load pretrained weights plus a fine-tuned checkpoint, accept a reference image, audio, and pose conditioning, run the denoising process, and decode the generated latent sequence back into a video file.
10. The repo has a clear offline preprocessing → training → inference flow. Training depends on precomputed artifacts on disk, while inference depends on a trained checkpoint plus the same conditioning inputs. That separation is one of the most important diagram boundaries.
11. External dependencies materially shape the architecture: CogVideoX pretrained weights provide the backbone, Wav2Vec2 provides audio embeddings, DWPose provides hand/body pose inputs, and ffmpeg is used for audio extraction from video. These are not incidental tools; they define the modality pipeline.
12. The repository also reflects a single-GPU / low-VRAM constraint. The architecture intentionally avoids a second full reference network and avoids recomputing encoders during training. For an architecture diagram, that constraint explains why preprocessing artifacts exist and why the model uses lighter identity-conditioning strategies.
Main entry points: talking_heads_dit.py Talking DiT · dataset.py Dataset · train.py Train loop · encode_vid.py Video encode
Components 17
Preprocessing
Offline ingestion and feature extraction
- Video encode · Prepares video clips and latent-ready samples from raw media
Preprocessing/encode_vid.py - Audio embed · Extracts or prepares audio features for downstream conditioning
Preprocessing/Audioencoder.py - Ref image · Encodes reference images into reusable conditioning assets
Preprocessing/Enocde_refernce_image.py - Pose prep · Runs DWPose keypoint preprocessing and sequence alignment
Preprocessing/preprocessing_dwpose.py - Dataset org · Renames and organizes clips into training-ready layout
Preprocessing/rename.py
Models
Transformer generator and conditioning modules
- Audio encoder · Projects audio features into the model hidden space
Src/Models/audio_encoder.py - Talking DiT · Main diffusion transformer for audio-driven talking-head synthesis
Src/Models/talking_heads_dit.py
Training
Dataset, loss, and optimization entrypoint
- Dataset · Loads aligned clips, precomputed latents, audio, and pose arrays
Src/training/dataset.py - Loss · Defines the diffusion training objective
Src/training/loss.py - Config · Central training settings for batch size, resolution, frames, and checkpoints
Src/training/config.yaml - Train loop · Training entrypoint that ties data, model, loss, and checkpointing together
Src/training/train.py
Inference
Checkpoint-driven video synthesis
- Inference · Loads a checkpoint and generates video from reference image, audio, and pose
Src/inference.py
External
Frozen backbones and third-party modality tools
- VAE latents · Precomputed video latent representation stored on disk
- Wav2Vec2 · External audio encoder backbone kept frozen during training
- CogVideoX · Pretrained diffusion backbone adapted for talking-head generation
- DWPose · External body and hand keypoint extractor used in preprocessing
- ffmpeg · Used to extract audio and support media conversion
Connections 20
- Video encode → VAE latents: writes · Produces reusable latent video artifacts
- Audio embed → Wav2Vec2: uses · Relies on audio backbone for embeddings
- Ref image → Talking DiT: conditions · Provides reference-image identity tokens
- Pose prep → DWPose: uses · Depends on pose extractor for keypoints
- Dataset org → Dataset: organizes · Shapes files into training-friendly structure
- Video encode → Dataset: feeds · Supplies precomputed video latents
- Audio embed → Dataset: feeds · Supplies audio embeddings
- Pose prep → Dataset: feeds · Supplies pose arrays
- Config → Train loop: configures · Controls the optimization run
- Dataset → Train loop: batches · Provides aligned training samples
- Talking DiT → Train loop: optimized by · Main trainable generator module
- Loss → Train loop: supervises · Computes diffusion objective during training
- CogVideoX → Talking DiT: backbone · Frozen pretrained core adapted by the model
- Audio encoder → Talking DiT: conditions · Maps audio features into transformer space
- Wav2Vec2 → Audio encoder: features · Supplies frozen audio embeddings
- VAE latents → Inference: decodes · Latents are turned back into video frames
- Talking DiT → Inference: runs · Denoising generator used at inference time
- ffmpeg → Audio embed: extracts · Supports audio extraction from source video
- ffmpeg → Video encode: converts · Supports media conversion during preprocessing
- CogVideoX → Inference: loads · Pretrained weights combined with fine-tuned checkpoint