tools.mask package
tools.mask.cli Module
Command Line Arguments for tools
- class tools.mask.cli.MaskArgs(subparser: _SubParsersAction | None, command: str, description: str = 'default')
Class to parse the command line arguments for Mask tool
- Parameters:
subparser (_SubParsersAction | None)
command (str)
description (str)
- static get_argument_list()
Returns the argument list for the current command.
The argument list should be a list of dictionaries pertaining to each option for a command. This function should be overridden with the actual argument list for each command’s argument list.
See existing parsers for examples.
- Returns:
The list of command line options for the given command
- Return type:
list
- static get_info()
Return command information
Classes
|
Class to parse the command line arguments for Mask tool |
Class Inheritance Diagram

tools.mask.loader Module
Handles loading of faces/frames from source locations and pairing with alignments information
- class tools.mask.loader.Loader(location: str, is_faces: bool)
Loader for reading source data from disk, and yielding the output paired with alignment information
- Parameters:
location (str) – Full path to the source files location
is_faces (bool) –
Trueif the source is a folder of faceswap extracted faces
- add_alignments(alignments_object: Alignments | None) None
Add the loaded alignments to
_alignmentsfor content matching- Parameters:
alignments_object (Alignments | None) – The alignments file object or
Noneif not provided- Return type:
None
- property file_list: list[str]
Full file list of source files to be loaded
- property is_video: bool
Trueif the source is a video file otherwiseFalse
- load() Generator[FrameFaces, None, None]
Load content from source and pair with corresponding alignment data
- Yields:
The extract media object for the processed face
- Return type:
Generator[FrameFaces, None, None]
- property location: str
Full path to the source folder/video file location
- property skip_count: int
The number of faces/frames that have been skipped due to no match in alignments file
Classes
|
Loader for reading source data from disk, and yielding the output paired with alignment information |
tools.mask.mask Module
Tool to generate masks and previews of masks for existing alignments file
- class tools.mask.mask.Mask(arguments: Namespace)
This tool is part of the Faceswap Tools suite and should be called from
python tools.py maskcommand.Faceswap Masks tool. Generate masks from existing alignments files, and output masks for preview.
Wrapper for the mask process to run in either batch mode or single use mode
- Parameters:
arguments (Namespace) – The
argparsearguments as passed in fromtools.py
- process() None
The entry point for triggering the Extraction Process.
Should only be called from
lib.cli.launcher.ScriptExecutor- Return type:
None
Classes
|
This tool is part of the Faceswap Tools suite and should be called from |
tools.mask.mask_generate Module
Handles the generation of masks from faceswap for updating into an alignments file
- class tools.mask.mask_generate.MaskGenerator(mask_type: str, update_all: bool, input_is_faces: bool, loader: loader.Loader, alignments: align.alignments.Alignments | None, input_location: str, config_file: str | None)
Uses faceswap’s extract pipeline to generate masks and update them into the alignments file and/or extracted face PNG Headers
- Parameters:
mask_type (str) – The mask type to generate
update_all (bool) –
Trueto update all faces,Falseto only update faces missing masksinput_is_faces (bool) –
Trueif the input are faceswap extracted faces otherwiseFalseloader (loader.Loader) – The loader for loading source images/video from disk
config_file (str | None) – Full path to a custom config file to load.
Nonefor default configalignments (align.alignments.Alignments | None)
input_location (str)
- process() T.Generator[FrameFaces, None, None]
Process the output from the extractor pipeline
- Yields:
The FrameFaces object with updated masks
- Return type:
T.Generator[FrameFaces, None, None]
Classes
|
Uses faceswap's extract pipeline to generate masks and update them into the alignments file and/or extracted face PNG Headers |
tools.mask.mask_import Module
Import mask processing for faceswap’s mask tool
- class tools.mask.mask_import.Import(import_path: str, centering: CenteringType, storage_size: int, input_is_faces: bool, loader: loader.Loader, alignments: align.alignments.Alignments | None, input_location: str, mask_type: str)
Import masks from disk into an Alignments file
- Parameters:
import_path (str) – The path to the input images
centering (CenteringType) – The centering to store the mask at
storage_size (int) – The size to store the mask at
input_is_faces (bool) –
Trueif the input is aligned faces otherwiseFalseloader (loader.Loader) – The source file loader object
alignments (align.alignments.Alignments | None) – The alignments file object for the faces, if provided
mask_type (str) – The mask type to update to
input_location (str)
- import_mask(media: FrameFaces) None
Import the mask for the given Extract Media object
- Parameters:
media (FrameFaces) – The extract media object containing the face(s) to import the mask for
- Return type:
None
- property skip_count: int
Number of masks that were skipped as they do not exist for given faces
- property update_count: int
Number of masks that were skipped as they do not exist for given faces
Classes
|
Import masks from disk into an Alignments file |
tools.mask.mask_output Module
Output processing for faceswap’s mask tool
- class tools.mask.mask_output.Output(arguments: Namespace, alignments: align.alignments.Alignments | None, file_list: list[str])
Handles outputting of masks for preview/editing to disk
- Parameters:
arguments (Namespace) – The command line arguments that the mask tool was called with
alignments (align.alignments.Alignments | None) – The alignments file object (or
Noneif not provided and input is faces)file_list (list[str]) – Full file list for the loader. Used for extracting alignments from faces
- close() None
Shut down the image saver if it is open
- Return type:
None
- save(frame: str, idx: int, detected_face: DetectedFace, frame_dims: tuple[int, int] | None = None) None
Build the mask preview image and save
- Parameters:
frame (str) – The frame name in the alignments file
idx (int) – The index of the face for this frame in the alignments file
detected_face (DetectedFace) – A detected_face object for a face
frame_dims (tuple[int, int] | None) – The size of the original frame, if input is faces otherwise
None. Default:None
- Return type:
None
- property should_save: bool
Trueif mask images should be output otherwiseFalse
Classes
|
Handles outputting of masks for preview/editing to disk |