How neuralchen/simswap works
Main Components
a. Data Layer
• Raw face datasets (e.g., VGGFace2-224, VGGFace2-HQ) stored locally or on cloud drives
• Pretrained weight artifacts (arcface_checkpoint.tar, SimSwap checkpoints)
b. Preprocessing Layer
• insightface_func: face detection & cropping (single & multi)
• parsing_model: face‐parsing network (resnet-based segmentation)
• util modules (alignment, resizing, normalization)
c. Core Modeling Layer
• Feature extractor: ArcFace model (arcface_models.py)
• Generator: fs_networks*.py variants (224, 512, fix)
• Projected Discriminator: pg_modules/projected_discriminator.py
• Loss & projection heads: projectionhead.py, base_model.py
d. Orchestration Layer
• options/…: command‐line argument parsing for train.py & predict.py
• train.py & predict.py: entry points for training and inference
• Notebook interfaces: train.ipynb, MultiSpecific.ipynb, SimSwap colab.ipynb
e. Post-processing & Visualization
• util/video_swap*.py, util/add_watermark.py, util/html.py, util/visualizer.py
• Output directory: frames/videos, HTML gallery
f. Deployment/Integration
• cog.yaml: deployment spec for Replicate/Docker
• download-weights.sh: bootstrap script
• docs/guidance: user docs & sample webpage
Relationships & Data Flows
• Data Layer → Preprocessing: videos/images are fed to face detector → cropped faces → aligned & parsed
• Preprocessing → Core Modeling (Training): batches of aligned, parsed faces → generator + discriminator → backprop → model artifacts
• Preprocessing → Core Modeling (Inference): feed source & target crops into generator → produce swapped face
• Core Modeling (Inference) → Post-processing: blend swapped face back into original frame → add watermark or mask → write out video/images
• Orchestration layer (CLI/notebooks) invokes pipelines in correct sequence, passing in options and I/O paths
Architectural Patterns & Design Principles
• Modular separation by function: “insightface_func,” “parsing_model,” “models,” “pg_modules,” “util”
• ML pipeline pattern: clearly defined stages (preprocess → model → postprocess)
• Config-driven CLI: options/*.py supply hyperparameters and file paths
• Extensibility: multiple network variants can be plugged via config.py and BaseModel
Technologies & Frameworks
• Python ≥3.6
• PyTorch ≥1.5; TorchVision
• NumPy, OpenCV, Pillow, moviepy, imageio
• insightface library for detection & recognition
• timm (0.5.4) for backbone nets
• Docker/Replicate (via cog.yaml) for containerized inference
Must-Haves
• Callouts for external dependencies (Google Drive links, Docker, Colab notebooks)