          logger.info("  Starting")
          if is_preview:
              logger.info("  Using live preview")
          logger.info("  Press '%s' to save and quit",
                      "Terminate" if self.args.redirect_gui else "ENTER")
          if not self.args.redirect_gui:
              logger.info("  Press 'S' to save model weights immediately")
          logger.info("===================================================")
  
          keypress = KBHit(is_gui=self.args.redirect_gui)
          err = False
 
</s> remove         keypress = KBHit(is_gui=self.args.redirect_gui)
 </s> add         keypress = KBHit(is_gui=self._args.redirect_gui) </s> remove     def monitor(self, thread):
        """ Monitor the console, and generate + monitor preview if requested """
        is_preview = self.args.preview
 </s> add     def _monitor(self, thread):
        """ Monitor the background :func:`_training` thread for key presses and errors.

        Returns
        -------
        bool
            ``True`` if there has been an error in the background thread otherwise ``False``
        """
        is_preview = self._args.preview </s> remove         prior = "dssim_loss"
        new = "loss_function"
        if prior not in self.config:
            return False
        self.config[new] = "ssim" if self.config[prior] else "mae"
        del self.config[prior]
        logger.info("Updated config from older dssim format. New config loss function: %s",
                    self.config[new])
        return True
 </s> add         logger.debug("Checking for legacy state file update")
        priors = ["dssim_loss", "penalized_mask_loss", "mask_type"]
        new_items = ["loss_function", "learn_mask", "mask_type"]
        updated = False
        for old, new in zip(priors, new_items):
            if old not in self.config:
                logger.debug("Legacy item '%s' not in config. Skipping update", old)
                continue

            # dssim_loss > loss_function
            if old == "dssim_loss":
                self.config[new] = "ssim" if self.config[old] else "mae"
                del self.config[old]
                updated = True
                logger.info("Updated config from legacy dssim format. New config loss "
                            "function: '%s'", self.config[new])
                continue

            # Add learn mask option and set to True if model has "penalized_mask_loss" specified
            if old == "penalized_mask_loss" and new not in self.config:
                self.config[new] = self.config["penalized_mask_loss"]
                updated = True
                logger.info("Added new 'learn_mask' config item for this model. Value set to: %s",
                            self.config[new])
                continue

            # Replace removed masks with most similar equivalent
            if old == "mask_type" and self.config[old] in ("facehull", "dfl_full"):
                old_mask = self.config[old]
                self.config[new] = "components"
                updated = True
                logger.info("Updated 'mask_type' from '%s' to '%s' for this model",
                            old_mask, self.config[new])

        logger.debug("State file updated for legacy config: %s", updated)
        return updated </s> remove     def run_training_cycle(self, model, trainer):
        """ Perform the training cycle """
 </s> add     def _run_training_cycle(self, model, trainer):
        """ Perform the training cycle.

        Handles the background training, updating previews/time-lapse on each save interval,
        and saving the model.

        Parameters
        ----------
        model: :file:`plugins.train.model` plugin
            The requested model plugin
        trainer: :file:`plugins.train.trainer` plugin
            The requested model trainer plugin
        """ </s> remove                     with self.lock:
                        for name, image in self.preview_buffer.items():
 </s> add                     with self._lock:
                        for name, image in self._preview_buffer.items():
                    "Terminate" if self._args.redirect_gui else "ENTER")
        if not self._args.redirect_gui:
          logger.info("  Starting")
          if is_preview:
              logger.info("  Using live preview")
          logger.info("  Press '%s' to save and quit",
                    "Terminate" if self._args.redirect_gui else "ENTER")
        if not self._args.redirect_gui:
                    "Terminate" if self._args.redirect_gui else "ENTER")
        if not self._args.redirect_gui:
              logger.info("  Press 'S' to save model weights immediately")
          logger.info("===================================================")
  
          keypress = KBHit(is_gui=self.args.redirect_gui)
          err = False
keep keep keep keep 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. 
scripts/train.py