PluginLoader

class plugins.plugin_loader.PluginLoader

Bases: object

Retrieve, or get information on, Faceswap plugins

Return a specific plugin, list available plugins, or get the default plugin for a task.

Example

>>> from plugins.plugin_loader import PluginLoader
>>> align_plugins = PluginLoader.get_available_extractors('align')
>>> aligner = PluginLoader.get_aligner('cv2-dnn')

Attributes Summary

extract_plugins

Methods Summary

get_available_convert_plugins(convert_category)

Return a list of available converter plugins in the given category

get_available_extractors(extractor_type[, ...])

Return a list of available extractors of the given type

get_available_models()

Return a list of available training models

get_converter(category, name[, disable_logging])

Return requested converter plugin

get_default_model()

Return the default training model plugin name

get_extractor(plugin_type, name)

Return requested extractor plugin

get_model(name[, disable_logging])

Return requested training model plugin

get_trainer(name[, disable_logging])

Return requested training trainer plugin

Attributes Documentation

extract_plugins = {'align': ['plugins.extract.align.cv2_dnn.CV2DNNAlign', 'plugins.extract.align.fan.FAN', 'plugins.extract.align.hrnet.HRNet'], 'detect': ['plugins.extract.detect.cv2_dnn.CV2DNNDetect', 'plugins.extract.detect.mtcnn.MTCNN', 'plugins.extract.detect.retinaface.RetinaFace', 'plugins.extract.detect.s3fd.S3FD'], 'identity': ['plugins.extract.identity.t_face.TFace', 'plugins.extract.identity.vggface2.VGGFace2'], 'mask': ['plugins.extract.mask.bisenet_fp.BiSeNetFP', 'plugins.extract.mask.custom.Custom', 'plugins.extract.mask.unet_dfl.UNetDFL', 'plugins.extract.mask.vgg_clear.VGGClear', 'plugins.extract.mask.vgg_obstructed.VGGObstructed']}

Methods Documentation

static get_available_convert_plugins(convert_category: str, add_none: bool = True) list[str]

Return a list of available converter plugins in the given category

Parameters:
  • convert_category (str) – The category of converter plugin to return the plugins for

  • add_none (bool) – Append “none” to the list of returned plugins. Default: True

Return type:

A list of the available converter plugin names in the given category

classmethod get_available_extractors(extractor_type: Literal['align', 'detect', 'identity', 'mask'], add_none: bool = False, extend_plugin: bool = False) list[str]

Return a list of available extractors of the given type

Parameters:
  • extractor_type (Literal['align', 'detect', 'identity', 'mask']) – The type of extractor to return the plugins for

  • add_none (bool) – Append “none” to the list of returned plugins. Default: False

  • extend_plugin (bool) – Some plugins have configuration options that mean that multiple ‘pseudo-plugins’ can be generated based on their settings. An example of this is the bisenet-fp mask which, whilst selected as ‘bisenet-fp’ can be stored as ‘bisenet-fp-face’ and ‘bisenet-fp-head’ depending on whether hair has been included in the mask or not. True will generate each pseudo-plugin, False will generate the original plugin name. Default: False

Return type:

A list of the available extractor plugin names for the given type

static get_available_models() list[str]

Return a list of available training models

Return type:

A list of the available training model plugin names

static get_converter(category: str, name: str, disable_logging: bool = False) Callable

Return requested converter plugin

Converters work slightly differently to other faceswap plugins. They are created to do a specific task (e.g. color adjustment, mask blending etc.), so multiple plugins will be loaded in the convert phase, rather than just one plugin for the other phases.

Parameters:
  • name (str) – The name of the requested converter plugin

  • disable_logging (bool) – Whether to disable the INFO log message that the plugin is being imported. Default: False

  • category (str)

Return type:

A converter sub plugin

static get_default_model() str

Return the default training model plugin name

Return type:

The default faceswap training model

classmethod get_extractor(plugin_type: T.Literal['align', 'detect', 'identity', 'mask'], name: str) ExtractPlugin

Return requested extractor plugin

Parameters:
  • type – The type of extractor plugin to obtain

  • name (str) – The name of the requested extractor plugin

  • plugin_type (T.Literal['align', 'detect', 'identity', 'mask'])

Return type:

An extraction plugin

Raises:

ValueError – If an invalid plugin type or plugin name is selected

static get_model(name: str, disable_logging: bool = False) type[ModelBase]

Return requested training model plugin

Parameters:
  • name (str) – The name of the requested training model plugin

  • disable_logging (bool) – Whether to disable the INFO log message that the plugin is being imported. Default: False

Return type:

A training model plugin

static get_trainer(name: str, disable_logging: bool = False) type[TrainerBase]

Return requested training trainer plugin

Parameters:
  • name (str) – The name of the requested training trainer plugin

  • disable_logging (bool) – Whether to disable the INFO log message that the plugin is being imported. Default: False

Return type:

A training trainer plugin

static get_available_convert_plugins(convert_category: str, add_none: bool = True) list[str]

Return a list of available converter plugins in the given category

Parameters:
  • convert_category (str) – The category of converter plugin to return the plugins for

  • add_none (bool) – Append “none” to the list of returned plugins. Default: True

Return type:

A list of the available converter plugin names in the given category

classmethod get_available_extractors(extractor_type: Literal['align', 'detect', 'identity', 'mask'], add_none: bool = False, extend_plugin: bool = False) list[str]

Return a list of available extractors of the given type

Parameters:
  • extractor_type (Literal['align', 'detect', 'identity', 'mask']) – The type of extractor to return the plugins for

  • add_none (bool) – Append “none” to the list of returned plugins. Default: False

  • extend_plugin (bool) – Some plugins have configuration options that mean that multiple ‘pseudo-plugins’ can be generated based on their settings. An example of this is the bisenet-fp mask which, whilst selected as ‘bisenet-fp’ can be stored as ‘bisenet-fp-face’ and ‘bisenet-fp-head’ depending on whether hair has been included in the mask or not. True will generate each pseudo-plugin, False will generate the original plugin name. Default: False

Return type:

A list of the available extractor plugin names for the given type

static get_available_models() list[str]

Return a list of available training models

Return type:

A list of the available training model plugin names

static get_converter(category: str, name: str, disable_logging: bool = False) Callable

Return requested converter plugin

Converters work slightly differently to other faceswap plugins. They are created to do a specific task (e.g. color adjustment, mask blending etc.), so multiple plugins will be loaded in the convert phase, rather than just one plugin for the other phases.

Parameters:
  • name (str) – The name of the requested converter plugin

  • disable_logging (bool) – Whether to disable the INFO log message that the plugin is being imported. Default: False

  • category (str)

Return type:

A converter sub plugin

static get_default_model() str

Return the default training model plugin name

Return type:

The default faceswap training model

classmethod get_extractor(plugin_type: T.Literal['align', 'detect', 'identity', 'mask'], name: str) ExtractPlugin

Return requested extractor plugin

Parameters:
  • type – The type of extractor plugin to obtain

  • name (str) – The name of the requested extractor plugin

  • plugin_type (T.Literal['align', 'detect', 'identity', 'mask'])

Return type:

An extraction plugin

Raises:

ValueError – If an invalid plugin type or plugin name is selected

static get_model(name: str, disable_logging: bool = False) type[ModelBase]

Return requested training model plugin

Parameters:
  • name (str) – The name of the requested training model plugin

  • disable_logging (bool) – Whether to disable the INFO log message that the plugin is being imported. Default: False

Return type:

A training model plugin

static get_trainer(name: str, disable_logging: bool = False) type[TrainerBase]

Return requested training trainer plugin

Parameters:
  • name (str) – The name of the requested training trainer plugin

  • disable_logging (bool) – Whether to disable the INFO log message that the plugin is being imported. Default: False

Return type:

A training trainer plugin