lib.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)

Dataclass to hold the optional processing plugins

Parameters:
  • color (ColorAdjust | None) – The selected color processing plugin. Default: None

  • mask (MaskAdjust | None) – The selected mask processing plugin. Default: None

  • seamless (SeamlessAdjust | None) – The selected mask processing plugin. Default: None

  • sharpening (ScalingAdjust | None) – The selected mask processing plugin. Default: None

class lib.convert.Converter(output_size: int, coverage_ratio: float, centering: CenteringType, draw_transparent: bool, pre_encode: Callable | None, arguments: Namespace, config_file: str | None = None)

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 (CenteringType) – 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 (Callable | None) – 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 (Namespace) – The arguments that were passed to the convert process as generated from Faceswap’s command line arguments

  • config_file (str | None) – Optional location of custom configuration ini file. If None then use the default config location. Default: None

property cli_arguments: Namespace

The command line arguments passed to the convert process

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 from scripts.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’s plugins.convert.writer plugins.

reinitialize() None

Reinitialize this Converter.

Called as part of the preview tool. Resets all adjustments then loads the plugins as specified in the current config.

Return type:

None

Classes

Adjustments([color, mask, seamless, sharpening])

Dataclass to hold the optional processing plugins

Converter(output_size, coverage_ratio, ...)

The converter is responsible for swapping the original face(s) in a frame with the output of a trained Faceswap model.