  #!/usr/bin/env python3
  
  
  """ Base Trainer Class for Faceswap
  
      Trainers should be inherited from this class.
  
      A training_opts dictionary can be set in the corresponding model.
      Accepted values:
          alignments:         dict containing paths to alignments files for keys 'a' and 'b'
          preview_scaling:    How much to scale the preview out by
          training_size:      Size of the training images
          coverage_ratio:     Ratio of face to be cropped out for training
          mask_type:          Type of mask to use. See lib.model.masks for valid mask names.
                              Set to None for not used
          no_logs:            Disable tensorboard logging
          snapshot_interval:  Interval for saving model snapshots
          warp_to_landmarks:  Use random_warp_landmarks instead of random_warp
          augment_color:      Perform random shifting of L*a*b* colors
          no_flip:            Don't perform a random flip on the image
          pingpong:           Train each side seperately per save iteration rather than together
  """
  
  import logging
  import os
  import time
 
</s> remove     """ Display samples for preview and timelapse """
 </s> add     """ Compile samples for display for preview and time-lapse

    Parameters
    ----------
    model: plugin from :mod:`plugins.train.model`
        The selected model that will be running this trainer
    use_mask: bool
        ``True`` if a mask should be displayed otherwise ``False``
    coverage_ratio: float
        Ratio of face to be cropped out of the training image.
    scaling: float, optional
        The amount to scale the final preview image by. Default: `1.0`

    Attributes
    ----------
    images: dict
        The :class:`numpy.ndarray` training images for generating previews on each side. The
        dictionary should contain 2 keys ("a" and "b") with the values being the training images
        for generating samples corresponding to each side.
    """ </s> remove         self.model.reset_pingpong()
 </s> add         self._model.reset_pingpong()


class TrainingAlignments():
    """ Obtain Landmarks and required mask from alignments file.

    Parameters
    ----------
    training_opts: dict
        The dictionary of model training options (see module doc-string for information about
        contents)
    image_list: dict
        The file paths for the images to be trained on for each side. The dictionary should contain
        2 keys ("a" and "b") with the values being a list of full paths corresponding to each side.
    """
    def __init__(self, training_opts, image_list):
        logger.debug("Initializing %s: (training_opts: '%s', image counts: %s)",
                     self.__class__.__name__, training_opts,
                     {k: len(v) for k, v in image_list.items()})
        self._training_opts = training_opts
        self._hashes = self._get_image_hashes(image_list)
        self._detected_faces = self._load_alignments()
        self._check_all_faces()
        logger.debug("Initialized %s", self.__class__.__name__) </s> remove     """ Base Trainer """
 </s> add     """ Trainer plugin base Object.

    All Trainer plugins must inherit from this class.

    Parameters
    ----------
    model: plugin from :mod:`plugins.train.model`
        The model that will be running this trainer
    images: dict
        The file paths for the images to be trained on for each side. The dictionary should contain
        2 keys ("a" and "b") with the values being a list of full paths corresponding to each side.
    batch_size: int
        The requested batch size for iteration to be trained through the model.
    configfile: str
        The path to a custom configuration file. If ``None`` is passed then configuration is loaded
        from the default :file:`.config.train.ini` file.
    """
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
  #!/usr/bin/env python3
  
  
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
This class heavily references the :attr:`plugins.train.model._base.ModelBase.training_opts`
``dict``. The following keys are expected from this ``dict``:

    * **alignments** (`dict`, `optional`) - If training with a mask or the warp to landmarks \
    command line option is selected then this is required, otherwise it can be ``None``. The \
    dictionary should contain 2 keys ("a" and "b") with the values being the path to the \
    alignments file for the corresponding side.

    * **preview_scaling** (`int`) - How much to scale displayed preview image by.

    * **training_size** ('int') - Size of the training images in pixels.

    * **coverage_ratio** ('float') - Ratio of face to be cropped out of the training image.

    * **mask_type** ('str') - The type of mask to select from the alignments file.

    * **mask_blur_kernel** ('int') - The size of the kernel to use for gaussian blurring the mask.

    * **mask_threshold** ('int') - The threshold for min/maxing mask to 0/100.

    * **learn_mask** ('bool') - Whether the mask should be trained in the model.

    * **penalized_mask_loss** ('bool') - Whether the mask should be penalized from loss.

    * **no_logs** ('bool') - Whether Tensorboard logging should be disabled.

    * **snapshot_interval** ('int') - How many iterations between model snapshot saves.

    * **warp_to_landmarks** ('bool') - Whether to use random_warp_landmarks instead of random_warp.

    * **augment_color** ('bool') - Whether to use color augmentation.

    * **no_flip** ('bool') - Whether to turn off random horizontal flipping.

    * **pingpong** ('bool') - Train each side separately per save iteration rather than together.
  """
  
  import logging
  import os
  import time
keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Smart Masks - Training Implementation (#914)

* Smart Masks - Training

- Reinstate smart mask training code
- Reinstate mask_type back to model.config
- change 'replicate_input_mask to 'learn_mask'
- Add learn mask option
- Add mask loading from alignments to plugins.train.trainer
- Add mask_blur and mask threshold options
- _base.py - Pass mask options through training_opts dict
- plugins.train.model - check for mask_type not None for learn_mask and penalized_mask_loss
- Limit alignments loading to just those faces that appear in the training folder
- Raise error if not all training images have an alignment, and alignment file is required
- lib.training_data - Mask generation code
- lib.faces_detect - cv2 dimension stripping bugfix
- Remove cv2 linting code

* Update mask helptext in cli.py

* Fix Warp to Landmarks
Remove SHA1 hashing from training data

* Update mask training config

* Capture missing masks at training init

* lib.image.read_image_batch - Return filenames with batch for ordering

* scripts.train - Documentation

* plugins.train.trainer - documentation

* Ensure backward compatibility.
Fix convert for new predicted masks

* Update removed masks to components for legacy models. 
plugins/train/trainer/_base.py