$ show deepfakes/faceswap
FaceSwap is a deep learning face-swapping application that provides a complete pipeline for extracting faces from images/video, training autoencoder models, and converting (swapping) faces in new media. It features a modular plugin architecture for detectors, aligners, maskers, identity extractors, training models, and converters, supporting multiple GPU backends (NVIDIA, AMD, Apple Silicon, CPU). The application includes both a command-line interface and a full tkinter-based GUI for managing projects, editing alignments manually, previewing conversions, and analyzing training progress. It also provides auxiliary tools for sorting faces, generating masks, manipulating alignments, and processing video via ffmpeg. The codebase is heavily research-oriented with custom loss functions (LPIPS, LDR-FLIP, GMSD, etc.), custom neural network layers (PixelShuffler, AdaIN), and advanced training features (learning rate finder, mixed precision, distributed training). While primarily an application, it contains significant data/research components in its model architectures and loss implementations.
The LLM identified 6 files worth highlighting for reuse:
Provides a clean, extensible serializer hierarchy (JSON, pickle, YAML, NPY, compressed) with a common interface. Self-contained with no internal dependencies, making it directly reusable in any Python project requiring multiple serialization formats.
Implements thread-safe background generators (FSThread, MultiThread, BackgroundGenerator) with proper error propagation and shutdown handling. The BackgroundGenerator pattern is particularly reusable for IO-bound data loading pipelines.
Defines ConfigItem, ConfigSection, and GlobalSection dataclasses for typed configuration values with validation, default values, and ini serialization. This pattern is reusable for any application needing a structured, validated configuration system.
Implements a batching iterator pipeline with FIFO queues, overflow handling, and FLUSH/SHUTDOWN signals. The ExtractIterator base class and its subclasses (InputIterator, InboundIterator, etc.) provide a reusable pattern for multi-stage data processing pipelines.
Contains custom Keras 3 layers (PixelShuffler, ReflectionPadding2D, ScalarOp, etc.) that are registered as custom objects. These layers are self-contained and can be extracted for use in other Keras models requiring sub-pixel convolutions or reflection padding.
Defines an abstract base class for GPU statistics with methods for getting card most free, system info, and VRAM usage. Implementations exist for NVIDIA, AMD, Apple Silicon, and CPU. This abstraction is reusable for any application needing cross-platform GPU monitoring.