              if tgt_dim == masks.shape[1]:
                  add_masks = masks
              else:
                  add_masks = np.array([cv2.resize(mask, (tgt_dim, tgt_dim))
                                        for mask in masks])[..., None]
              targets[idx] = np.concatenate((tgt, add_masks), axis=-1)
          return targets
  
      def generate_preview(self, do_preview):
          """ Generate the preview images.
 
</s> remove         masks = targets[-1]
        for idx, tgt in enumerate(targets[:-1]):
 </s> add         if not self._model.config["penalized_mask_loss"] and additional_masks is None:
            logger.trace("No masks to compile. Returning targets")
            return targets

        if not self._model.config["penalized_mask_loss"] and additional_masks is not None:
            masks = additional_masks
        elif additional_masks is not None:
            masks = np.concatenate((masks, additional_masks), axis=-1)

        for idx, tgt in enumerate(targets): </s> remove         logger.trace("masks shape: %s", masks.shape)
        batch = np.concatenate((batch, masks), axis=-1)
 </s> add         Returns
        -------
        :class:`numpy.ndarray`
            The batch with masks applied to the final channels
        """
        logger.trace("Input batch shape: %s, side: %s", batch.shape, side)
        size = batch.shape[1]
        for key in ("masks", "eyes", "mouths"):
            item = self._masks[key]
            if item is None and key != "masks":
                continue
            if item is None and key == "masks":
                logger.trace("Creating dummy masks. side: %s", side)
                masks = np.ones_like(batch[..., :1], dtype=batch.dtype)
            else:
                logger.trace("Obtaining masks for batch. (key: %s side: %s)", key, side)
                masks = np.array([self._get_mask(item[side][filename], size)
                                  for filename, face in zip(filenames, batch)], dtype=batch.dtype)
                masks = self._resize_masks(size, masks)

            logger.trace("masks: (key: %s, shape: %s)", key, masks.shape)
            batch = np.concatenate((batch, masks), axis=-1) </s> remove             self._masks[side] = batch["masks"][0]
 </s> add             self._masks[side] = batch["masks"] </s> remove class PenalizedLoss(tf.keras.losses.Loss):
    """ Penalized Loss function.

    Applies the given loss function just to the masked area of the image.

    Parameters
    ----------
    loss_func: function
        The actual loss function to use
    mask_prop: float, optional
        The amount of mask propagation. Default: `1.0`
    """
    def __init__(self, loss_func, mask_prop=1.0):
        super().__init__(name="penalized_loss")
        self._loss_func = compile_utils.LossesContainer(loss_func)
        self._mask_prop = mask_prop

    def call(self, y_true, y_pred):
        """ Apply the loss function to the masked area of the image.

        Parameters
        ----------
        y_true: tensor or variable
            The ground truth value. This should contain the mask in the 4th channel that will be
            split off for penalizing.
        y_pred: tensor or variable
            The predicted value

        Returns
        -------
        tensor
            The Loss value
        """
        mask = self._prepare_mask(K.expand_dims(y_true[..., -1], axis=-1))
        y_true = y_true[..., :-1]
        n_true = K.concatenate([y_true[:, :, :, i:i+1] * mask for i in range(3)], axis=-1)
        n_pred = K.concatenate([y_pred[:, :, :, i:i+1] * mask for i in range(3)], axis=-1)
        return self._loss_func(n_true, n_pred)

    def _prepare_mask(self, mask):
        """ Prepare the masks for calculating loss

        Parameters
        ----------
        mask: :class:`numpy.ndarray`
            The masks for the current batch

        Returns
        -------
        tensor
            The prepared mask for applying to loss
        """
        mask_as_k_inv_prop = 1 - self._mask_prop
        mask = (mask * self._mask_prop) + mask_as_k_inv_prop
        return mask


 </s> add 
                                      for mask in masks])
                if add_masks.ndim == 3:
                    add_masks = add_masks[..., None]
              if tgt_dim == masks.shape[1]:
                  add_masks = masks
              else:
                  add_masks = np.array([cv2.resize(mask, (tgt_dim, tgt_dim))
                                      for mask in masks])
                if add_masks.ndim == 3:
                    add_masks = add_masks[..., None]
              targets[idx] = np.concatenate((tgt, add_masks), axis=-1)
          return targets
  
      def generate_preview(self, do_preview):
          """ Generate the preview images.
keep keep keep keep replace keep keep keep keep keep
 Add Mouth and Eye Priority to Loss options (#1054)

* Priority Training for Mouth and Eyes - Tensorflow

* Use chosen loss function for area multipliers

* loss multipliers for AMD

* Fix mask multipliers for plaid and roll PenalizedMaskLoss into LossWrapper

* losses_tf: roll PenalizedMaskLoss into LossWrapper 
plugins/train/trainer/_base.py