  
          * **masks** (`dict`, `optional`). Required if :attr:`penalized_mask_loss` or \
          :attr:`learn_mask` is ``True``. Returning dictionary has a key of **side** (`str`) the \
          value of which is a `dict` of {**filename** (`str`): :class:`lib.faces_detect.Mask`}.
      config: dict
          The configuration `dict` generated from :file:`config.train.ini` containing the trainer \
          plugin configuration options.
      """
      def __init__(self, model_input_size, model_output_shapes, coverage_ratio, augment_color,
                   no_flip, warp_to_landmarks, alignments, config):
 
</s> remove         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)
 </s> add         applies a dummy all ones mask.

        If the configuration options `eye_multiplier` and/or `mouth_multiplier` are greater than 1
        then these masks are applied to the final channels of the batch respectively.

        Parameters
        ----------
        filenames: list
            The list of filenames that correspond to this batch
        batch: :class:`numpy.ndarray`
            The batch of faces that have been loaded from disk
        side: str
            '"a"' or '"b"' the side that is being processed </s> remove class PenalizedLoss():  # pylint:disable=too-few-public-methods
    """ 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):
        self._loss_func = 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 = y_true * mask
        n_pred = y_pred * mask
        if isinstance(self._loss_func, DSSIMObjective):
            # Extract Image Patches in SSIM requires that y_pred be of a known shape, so
            # specifically reshape the tensor.
            n_pred = K.reshape(n_pred, K.int_shape(y_pred))
        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  </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 
        * **masks_eye** (`dict`, `optional`). Required if config option "eye_multiplier" is \
        a value greater than 1. Returning dictionary has a key of **side** (`str`) the \
        value of which is a `dict` of {**filename** (`str`): :class:`bytes`} which is a zipped \
        eye mask.

        * **masks_mouth** (`dict`, `optional`). Required if config option "mouth_multiplier" is \
        a value greater than 1. Returning dictionary has a key of **side** (`str`) the \
        value of which is a `dict` of {**filename** (`str`): :class:`bytes`} which is a zipped \
        mouth mask.

  
          * **masks** (`dict`, `optional`). Required if :attr:`penalized_mask_loss` or \
          :attr:`learn_mask` is ``True``. Returning dictionary has a key of **side** (`str`) the \
          value of which is a `dict` of {**filename** (`str`): :class:`lib.faces_detect.Mask`}.
        * **masks_eye** (`dict`, `optional`). Required if config option "eye_multiplier" is \
        a value greater than 1. Returning dictionary has a key of **side** (`str`) the \
        value of which is a `dict` of {**filename** (`str`): :class:`bytes`} which is a zipped \
        eye mask.

        * **masks_mouth** (`dict`, `optional`). Required if config option "mouth_multiplier" is \
        a value greater than 1. Returning dictionary has a key of **side** (`str`) the \
        value of which is a `dict` of {**filename** (`str`): :class:`bytes`} which is a zipped \
        mouth mask.

      config: dict
          The configuration `dict` generated from :file:`config.train.ini` containing the trainer \
          plugin configuration options.
      """
      def __init__(self, model_input_size, model_output_shapes, coverage_ratio, augment_color,
                   no_flip, warp_to_landmarks, alignments, config):
keep keep keep add keep 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 
lib/training_data.py