          self.state.config["subpixel_upscaling"] = False
          self.state.config["reflect_padding"] = False
          self.state.config["mask_type"] = None
          self.state.config["lowmem"] = False
          self.encoder_dim = 1024
  
          if set_lowmem:
              logger.debug("Setting encoder_dim and lowmem flag for legacy lowmem model")
 
</s> remove         self.args = arguments
        self.timelapse = self.set_timelapse()
        self.images = self.get_images()
        self.stop = False
        self.save_now = False
        self.preview_buffer = dict()
        self.lock = Lock()

        self.trainer_name = self.args.trainer
 </s> add         self._args = arguments
        self._timelapse = self._set_timelapse()
        self._images = self._get_images()
        self._stop = False
        self._save_now = False
        self._preview_buffer = dict()
        self._lock = Lock()

        self.trainer_name = self._args.trainer </s> remove                 self.save_now = False
 </s> add                 self._save_now = False </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(): </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         self.stop = True
 </s> add         self._stop = True
        self.state.config["mask_blur_kernel"] = 3
        self.state.config["mask_threshold"] = 4
        self.state.config["learn_mask"] = False
          self.state.config["subpixel_upscaling"] = False
          self.state.config["reflect_padding"] = False
          self.state.config["mask_type"] = None
        self.state.config["mask_blur_kernel"] = 3
        self.state.config["mask_threshold"] = 4
        self.state.config["learn_mask"] = False
          self.state.config["lowmem"] = False
          self.encoder_dim = 1024
  
          if set_lowmem:
              logger.debug("Setting encoder_dim and lowmem flag for legacy lowmem model")
keep keep add 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/model/_base.py