convert module

Converter for Faceswap

class lib.convert.Converter(output_size, coverage_ratio, centering, draw_transparent, pre_encode, arguments, configfile=None)

Bases: object

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

  • 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 arguments
  • configfile (str, optional) – Optional location of custom configuration ini file. If None then use the default config location. Default: None

The command line arguments passed to the convert process

process(in_queue, out_queue)

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.

  • in_queue (queue.Queue) – The output from scripts.convert.Predictor. Contains detected faces from the Faceswap model as well as the frame to be patched.
  • out_queue (queue.Queue) – The queue to place patched frames into for writing by one of Faceswap’s plugins.convert.writer plugins.

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-loaded lib.config.FaceswapConfig. used over any configuration on disk.