FaceSwap Re-Feed and Re-Align Options in Face Extraction: Complete Guide
The re-feed option averages multiple alignment passes with jittered bounding boxes to stabilize landmarks, while the re-align option performs a second alignment pass on initially aligned faces to improve accuracy on extreme angles.
The re-feed and re-align options in FaceSwap's face extraction pipeline provide advanced control over landmark stability and accuracy. These optional processing passes, implemented in the deepfakes/faceswap repository, allow users to refine face alignment beyond the standard single-pass detection. Both options trade extraction speed for improved landmark quality, making them essential tools for high-quality deepfake production or challenging source material.
How Re-Feed Stabilizes Landmark Detection
The re-feed option (-R or --re-feed) implements a jitter-reduction technique during the alignment phase. When enabled, the extractor performs the initial face detection, then artificially nudges the detected bounding box slightly and runs the alignment algorithm again. This process repeats for the specified number of iterations, with all resulting landmark sets being averaged together to produce the final output.
Use this option when processing high-quality swaps or long video sequences where landmark stability is critical. The averaging process smooths out tiny positional jitters that can cause temporal flickering in the final output. However, each re-feed iteration runs the aligner again, making extraction proportionally slower—for example, -R 3 requires approximately three times the normal alignment processing time.
How Re-Align Handles Extreme Angles
The re-align option (-a or --re-align) addresses a different problem: faces captured at sharp angles or extreme side profiles. After the initial alignment produces a roughly aligned face, this option feeds that cropped and aligned face back through the aligner for a second pass. This reprocessing helps the landmark detection network cope with perspectives greater than 45 degrees, often producing a cleaner, more accurate landmark set on difficult poses.
Enable re-align when working with very rotated faces or side profiles where the first alignment pass might miss subtle facial features. Like re-feed, this option adds another full alignment pass to the pipeline, increasing total extraction time accordingly. The two options can be combined for maximum accuracy on challenging datasets.
Implementation in the FaceSwap Codebase
The re-feed and re-align functionality spans three critical components in the FaceSwap architecture:
CLI Arguments Definition
The command-line interface declares both flags in lib/cli/args_extract_convert.py. The re-feed argument and its help text occupy lines 9-22, while the re-align flag appears at lines 25-31. These definitions handle the -R/--re-feed and -a/--re-align user inputs that control the pipeline behavior.
Configuration Defaults
Default values and GUI-accessible settings reside in plugins/extract/extract_config.py at lines 15-22. This file defines the realign_refeeds and filter_realign configuration items, allowing users to set persistent defaults via the .ini configuration file rather than passing arguments every session.
Processing Engine Logic
The actual orchestration happens in plugins/extract/align/_base/processing.py, specifically within the ReAlign helper class at lines 44-53. This class determines whether re-feed iterations should undergo re-alignment and implements filtering logic to skip unnecessary processing on low-quality detections. According to the FaceSwap source code, this module coordinates the second-pass alignment workflow that makes both features possible.
Practical Usage Examples
Run extraction with re-feed to reduce jitter in high-quality video sources:
# Standard extraction without extra processing
faceswap -i ./videos/source.mp4 -o ./extracted -s s3fd
# Re-feed 3 times for maximum landmark stability
faceswap -i ./videos/source.mp4 -o ./extracted -s s3fd -R 3
# Combine re-feed (2 passes) with re-align for extreme angles
faceswap -i ./videos/source.mp4 -o ./extracted -s s3fd -R 2 -a
For programmatic control in Python scripts calling the FaceSwap library directly:
from faceswap import FaceswapExtractor
extractor = FaceswapExtractor(
input_dir="videos/source",
output_dir="extracted",
detector="s3fd",
re_feed=2, # Re-feed twice for jitter reduction
re_align=True, # Enable second alignment pass
)
extractor.run()
Summary
- Re-feed (
-R) averages multiple alignment passes with jittered bounding boxes to stabilize landmarks, ideal for temporal consistency in video sequences. - Re-align (
-a) performs a second alignment pass on initially cropped faces to improve accuracy on extreme angles and side profiles. - Both options are defined in
lib/cli/args_extract_convert.py, configured viaplugins/extract/extract_config.py, and executed by theReAlignclass inplugins/extract/align/_base/processing.py. - Enabling either option increases extraction time proportionally to the number of additional passes required.
- These features can be combined for maximum accuracy when processing challenging source material with rotation or instability issues.
Frequently Asked Questions
What is the difference between re-feed and re-align?
Re-feed introduces controlled jitter to the bounding box and averages the results across multiple alignment passes to reduce positional instability. Re-align takes the initially aligned face crop and runs it through the aligner a second time to correct errors on extreme angles. Re-feed addresses temporal consistency, while re-align addresses geometric accuracy on difficult poses.
How much slower is extraction with re-feed enabled?
Extraction time scales linearly with the re-feed count. Setting -R 3 runs the aligner three times on each face, making the alignment phase approximately three times slower than the default single pass. The total pipeline slowdown depends on how much time your specific aligner model requires per face.
Should I use both re-feed and re-align together?
Yes, for maximum accuracy on challenging source material. Combining -R 2 (or higher) with -a first stabilizes the landmark positions through averaging, then performs a final alignment pass on the stabilized crop. This combination is particularly effective for side-profile faces in high-quality swap projects where extraction time is less critical than output accuracy.
Where are the re-feed and re-align settings stored?
Default configuration values reside in plugins/extract/extract_config.py at lines 15-22, which defines the realign_refeeds and filter_realign parameters used by the GUI and configuration files. CLI arguments override these defaults temporarily for individual extraction jobs.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →