      def predict(self, feed_faces, batch_size=None):
          """ Perform inference on the feed """
          logger.trace("Predicting: Batchsize: %s", len(feed_faces))
          feed = [feed_faces]
          if self.has_predicted_mask:
              feed.append(np.repeat(self.input_mask, feed_faces.shape[0], axis=0))
          logger.trace("Input shape(s): %s", [item.shape for item in feed])
  
          predicted = self.predictor(feed, batch_size=batch_size)
          predicted = predicted if isinstance(predicted, list) else [predicted]
 
</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         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_predictions(self, feed_a, feed_b):
        """ Return the sample predictions from the model """
 </s> add     def _get_predictions(self, feed_a, feed_b):
        """ Feed the samples to the model and return predictions

        Parameters
        ----------
        feed_a: list
            List of :class:`numpy.ndarray` of feed images for the "a" side
        feed_a: list
            List of :class:`numpy.ndarray` of feed images for the "b" side

        Returns
        list:
            List of :class:`numpy.ndarray` of predictions received from the model
        """ </s> remove     def _get_landmarks(self, filenames, batch, side):
 </s> add     def _apply_mask(self, filenames, batch, side):
        """ Applies the mask to the 4th channel of the image. If masks are not being used
        applies a dummy all ones mask """
        logger.trace("Input batch shape: %s, side: %s", batch.shape, side)
        if self._masks is None:
            logger.trace("Creating dummy masks. side: %s", side)
            masks = np.ones_like(batch[..., :1], dtype=batch.dtype)
        else:
            logger.trace("Obtaining masks for batch. side: %s", side)
            masks = np.array([self._masks[side][filename].mask
                              for filename, face in zip(filenames, batch)], dtype=batch.dtype)
            masks = self._resize_masks(batch.shape[1], masks)

        logger.trace("masks shape: %s", masks.shape)
        batch = np.concatenate((batch, masks), axis=-1)
        logger.trace("Output batch shape: %s, side: %s", batch.shape, side)
        return batch

    @staticmethod
    def _resize_masks(target_size, masks):
        """ Resize the masks to the target size """
        logger.trace("target size: %s, masks shape: %s", target_size, masks.shape)
        mask_size = masks.shape[1]
        if target_size == mask_size:
            logger.trace("Mask and targets the same size. Not resizing")
            return masks
        interpolator = cv2.INTER_CUBIC if mask_size < target_size else cv2.INTER_AREA
        masks = np.array([cv2.resize(mask,
                                     (target_size, target_size),
                                     interpolation=interpolator)[..., None]
                          for mask in masks])
        logger.trace("Resized masks: %s", masks.shape)
        return masks

    def _get_landmarks(self, filenames, side): </s> remove         if self.args.write_image or self.args.redirect_gui or self.args.preview:
            display_func = self.show
 </s> add         if self._args.write_image or self._args.redirect_gui or self._args.preview:
            display_func = self._show
        if self.model.feed_mask:
      def predict(self, feed_faces, batch_size=None):
          """ Perform inference on the feed """
          logger.trace("Predicting: Batchsize: %s", len(feed_faces))
          feed = [feed_faces]
        if self.model.feed_mask:
              feed.append(np.repeat(self.input_mask, feed_faces.shape[0], axis=0))
          logger.trace("Input shape(s): %s", [item.shape for item in feed])
  
          predicted = self.predictor(feed, batch_size=batch_size)
          predicted = predicted if isinstance(predicted, list) else [predicted]
keep keep keep keep 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/convert.py