  
      def generate_preview(self, do_preview):
          """ Generate the preview if a preview iteration """
          if not do_preview:
              self.samples = None
              self.target = None
              return
          logger.debug("Generating preview")
          if self.preview_feed is None:
              self.set_preview_feed()
          batch = next(self.preview_feed)
 
</s> remove         """ Generate the preview if a preview iteration """
 </s> add         """ Generate the preview images.

        Parameters
        ----------
        do_preview: bool
            Whether the previews should be generated. ``True`` if they should ``False`` if they
            should not be generated, in which case currently stored previews should be deleted.
        """ </s> remove         if self.preview_feed is None:
            self.set_preview_feed()
        batch = next(self.preview_feed)
        self.samples = batch["samples"]
        self.target = [batch["targets"][self.model.largest_face_index]]
        if self.use_mask:
            self.target += [batch["masks"]]

    def set_preview_feed(self):
        """ Set the preview dictionary """
        logger.debug("Setting preview feed: (side: '%s')", self.side)
        preview_images = self.config.get("preview_images", 14)
 </s> add         batch = next(self._preview_feed)
        self._samples = batch["samples"]
        self._target = batch["targets"][self._model.largest_face_index]
        self._masks = batch["masks"][0]

    def _set_preview_feed(self):
        """ Set the preview feed for this batcher.

        Creates a generator from :class:`lib.training_data.TrainingDataGenerator` specifically
        for previews for the batcher.
        """
        logger.debug("Setting preview feed: (side: '%s')", self._side)
        preview_images = self._config.get("preview_images", 14) </s> remove     def get_next(self, do_preview):
        """ Return the next batch from the generator
            Items should come out as: (warped, target [, mask]) """
        batch = next(self.feed)
        if self.use_mask:
            batch = [[batch["feed"], batch["masks"]], batch["targets"] + [batch["masks"]]]
        else:
            batch = [batch["feed"], batch["targets"]]
        self.generate_preview(do_preview)
        return batch
 </s> add     def _get_next(self):
        """ Return the next batch from the :class:`lib.training_data.TrainingDataGenerator` for
        this batcher ready for feeding into the model.

        Returns
        -------
        model_inputs: list
            A list of :class:`numpy.ndarray` for feeding into the model
        model_targets: list
            A list of :class:`numpy.ndarray` for comparing the output of the model
        """
        logger.trace("Generating targets")
        batch = next(self._feed)
        targets_use_mask = self._model.training_opts["learn_mask"]
        model_inputs = batch["feed"] + batch["masks"] if self._use_mask else batch["feed"]
        model_targets = batch["targets"] + batch["masks"] if targets_use_mask else batch["targets"]
        return model_inputs, model_targets </s> remove         logger.debug("Compiling samples: (side: '%s', samples: %s)", self.side, num_images)
        images = images if images is not None else self.target
        retval = [samples[0:num_images]] if samples is not None else [self.samples[0:num_images]]
        if self.use_mask:
            retval.extend(tgt[0:num_images] for tgt in images)
        else:
            retval.extend(images[0:num_images])
 </s> add         logger.debug("Compiling samples: (side: '%s', samples: %s)", self._side, num_images)
        images = images if images is not None else self._target
        masks = masks if masks is not None else self._masks
        samples = samples if samples is not None else self._samples
        retval = [samples[0:num_images], images[0:num_images], masks[0:num_images]] </s> remove         """ Display preview data """
 </s> add         """ Compile a preview image.

        Returns
        -------
        :class:`numpy.ndarry`
            A compiled preview image ready for display or saving
        """
            self._samples = None
            self._target = None
            self._masks = None
  
      def generate_preview(self, do_preview):
          """ Generate the preview if a preview iteration """
          if not do_preview:
            self._samples = None
            self._target = None
            self._masks = None
            self._samples = None
            self._target = None
            self._masks = None
              return
          logger.debug("Generating preview")
          if self.preview_feed is None:
              self.set_preview_feed()
          batch = next(self.preview_feed)
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. 
plugins/train/trainer/_base.py