convert module
Converter for Faceswap
- class lib.convert.Adjustments(color: ColorAdjust | None = None, mask: MaskAdjust | None = None, seamless: SeamlessAdjust | None = None, sharpening: ScalingAdjust | None = None)
Bases:
object
Dataclass to hold the optional processing plugins
- Parameters:
color (
Adjustment
, Optional) – The selected color processing plugin. Default: Nonemask (
Mask
, Optional) – The selected mask processing plugin. Default: Noneseamless (
Color
, Optional) – The selected mask processing plugin. Default: Nonesharpening (
Adjustment
, Optional) – The selected mask processing plugin. Default: None
- color: ColorAdjust | None = None
- mask: MaskAdjust | None = None
- seamless: SeamlessAdjust | None = None
- sharpening: ScalingAdjust | None = None
- class lib.convert.Converter(output_size: int, coverage_ratio: float, centering: CenteringType, draw_transparent: bool, pre_encode: Callable | None, arguments: Namespace, configfile: str | None = None)
Bases:
object
The converter is responsible for swapping the original face(s) in a frame with the output of a trained Faceswap model.
- Parameters:
output_size (int) – The size of the face, in pixels, that is output from the Faceswap model
coverage_ratio (float) – The ratio of the training image that was used for training the Faceswap model
centering (str) – The extracted face centering that the model was trained on (“face” or “legacy”)
draw_transparent (bool) – Whether the final output should be drawn onto a transparent layer rather than the original frame. Only available with certain writer plugins.
pre_encode (python function) – Some writer plugins support the pre-encoding of images prior to saving out. As patching is done in multiple threads, but writing is done in a single thread, it can speed up the process to do any pre-encoding as part of the converter process.
arguments (
argparse.Namespace
) – The arguments that were passed to the convert process as generated from Faceswap’s command line argumentsconfigfile (str, optional) – Optional location of custom configuration
ini
file. IfNone
then use the default config location. Default:None
- property cli_arguments: Namespace
The command line arguments passed to the convert process
- Type:
argparse.Namespace
- process(in_queue: EventQueue, out_queue: EventQueue)
Main convert process.
Takes items from the in queue, runs the relevant adjustments, patches faces to final frame and outputs patched frame to the out queue.
- Parameters:
in_queue (
EventQueue
) – The output fromscripts.convert.Predictor
. Contains detected faces from the Faceswap model as well as the frame to be patched.out_queue (
EventQueue
) – The queue to place patched frames into for writing by one of Faceswap’splugins.convert.writer
plugins.
- reinitialize(config: FaceswapConfig) None
Reinitialize this
Converter
.Called as part of the
preview
tool. Resets all adjustments then loads the plugins as specified in the given config.- Parameters:
config (
lib.config.FaceswapConfig
) – Pre-loadedlib.config.FaceswapConfig
. used over any configuration on disk.