convert package

The Convert Package handles the various plugins available for performing conversion in Faceswap

mask package

mask._base module

Base class for Faceswap mask Plugins

class plugins.convert.mask._base.Adjustment(mask_type, output_size, configfile=None, config=None)

Bases: object

Parent class for Mask Adjustment Plugins.

All mask plugins must inherit from this class.

Parameters:
  • mask_type (str) – The type of mask that this plugin is being used for
  • output_size (int) – The size, in pixels, of the output from the Faceswap model.
  • configfile (str, Optional) – Optional location of custom configuration ini file. If None then use the default config location. Default: None
  • config (lib.config.FaceswapConfig, Optional) – Optional pre-loaded lib.config.FaceswapConfig. If passed, then this will be used over any configuration on disk. If None then it is ignored. Default: None
config

The configuration dictionary for this plugin.

Type:dict
mask_type

The type of mask that this plugin is being used for.

Type:str
dummy

(output_size, output_size, 3)

Type:numpy.ndarray
Type:A dummy mask of all zeros of the shape
process(*args, **kwargs)

Override for specific mask adjustment plugin processes.

Input parameters will vary from plugin to plugin.

Should return a numpy.ndarray mask with the plugin’s actions applied

run(*args, **kwargs)

Perform selected adjustment on face

skip

True if the blur type config attribute is None otherwise False

Type:bool

mask.box_blend module

Plugin to blend the edges of the face box that comes out of the Faceswap Model into the final frame.

class plugins.convert.mask.box_blend.Mask(output_size, **kwargs)

Bases: plugins.convert.mask._base.Adjustment

Manipulations to perform on the edges of the box that is received from the Faceswap model.

As the size of the box coming out of the model is identical for every face, the mask to be applied is just calculated once (at launch).

Parameters:
  • output_size (int) – The size of the output from the Faceswap model.
  • **kwargs (dict, optional) – See the parent _base for additional keyword arguments.
process(new_face)

Apply the box mask to the swapped face.

Parameters:new_face (numpy.ndarray) – The swapped face that has been output from the Faceswap model
Returns:The input face is returned with the box mask added to the alpha channel if a blur type has been specified in the plugin configuration. If this configuration is set to None then the input face is returned with no mask applied.
Return type:numpy.ndarray

mask.mask_blend module

Plugin to blend the edges of the face between the swap and the original face.

class plugins.convert.mask.mask_blend.Mask(mask_type, output_size, coverage_ratio, **kwargs)

Bases: plugins.convert.mask._base.Adjustment

Manipulations to perform to the mask that is to be applied to the output of the Faceswap model.

Parameters:
  • mask_type (str) – The mask type to use for this plugin
  • output_size (int) – The size of the output from the Faceswap model.
  • coverage_ratio (float) – The coverage ratio that the Faceswap model was trained at.
  • **kwargs (dict, optional) – See the parent _base for additional keyword arguments.
process(detected_face, sub_crop_offset, predicted_mask=None)

Obtain the requested mask type and perform any defined mask manipulations.

Parameters:
  • detected_face (lib.align.DetectedFace) – The DetectedFace object as returned from scripts.convert.Predictor.
  • sub_crop_offset (numpy.ndarray, optional) – The (x, y) offset to crop the mask from the center point.
  • predicted_mask (numpy.ndarray, optional) – The predicted mask as output from the Faceswap Model, if the model was trained with a mask, otherwise None. Default: None.
Returns:

  • mask (numpy.ndarray) – The mask with all requested manipulations applied
  • raw_mask (numpy.ndarray) – The mask with no erosion/dilation applied