Mask

class plugins.convert.mask.mask_blend.Mask(mask_type: str, output_size: int, coverage_ratio: float, config_file: str | None = None)

Bases: object

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.

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

Methods Summary

run(detected_face, source_offset, ...[, ...])

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

Methods Documentation

run(detected_face: DetectedFace, source_offset: ndarray, target_offset: ndarray, centering: Literal['legacy', 'face', 'head'], landmarks_mask: LandmarksMask | None = None, predicted_mask: ndarray | None = None) tuple[ndarray, ndarray]

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

Parameters:
  • detected_face (lib.align.detected_face.DetectedFace) – The DetectedFace object as returned from scripts.convert.Predictor.

  • source_offset (numpy.ndarray) – The (x, y) offset for the mask at its stored centering

  • target_offset (numpy.ndarray) – The (x, y) offset for the mask at the requested target centering

  • centering ([“legacy”, “face”, “head”]) – The centering to obtain the mask for

  • landmarks_mask (lib.align.aligned_mask.LandmarksMask | None, optional) – The landmarks mask object, if requested or None. Default: None

  • predicted_mask (numpy.ndarray | None, 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

Return type:

tuple[ndarray, ndarray]

run(detected_face: DetectedFace, source_offset: ndarray, target_offset: ndarray, centering: Literal['legacy', 'face', 'head'], landmarks_mask: LandmarksMask | None = None, predicted_mask: ndarray | None = None) tuple[ndarray, ndarray]

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

Parameters:
  • detected_face (lib.align.detected_face.DetectedFace) – The DetectedFace object as returned from scripts.convert.Predictor.

  • source_offset (numpy.ndarray) – The (x, y) offset for the mask at its stored centering

  • target_offset (numpy.ndarray) – The (x, y) offset for the mask at the requested target centering

  • centering ([“legacy”, “face”, “head”]) – The centering to obtain the mask for

  • landmarks_mask (lib.align.aligned_mask.LandmarksMask | None, optional) – The landmarks mask object, if requested or None. Default: None

  • predicted_mask (numpy.ndarray | None, 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

Return type:

tuple[ndarray, ndarray]