  
  # <<< START: from Dfaker >>> #
  def PenalizedLoss(mask, loss_func,  # pylint: disable=invalid-name
                    mask_prop=1.0, mask_scaling=1.0, preprocessing_func=None):
      """ Plaidml + tf Penalized loss function
          mask_scaling: For multi-decoder output the target mask will likely be at
                        full size scaling, so this is the scaling factor to reduce
                        the mask by.
          preprocessing_func: The preprocessing function to use. Should take a Keras Input
                              as it's only input
      """
  
      def scale_mask(mask, scaling):
          """ Scale the input mask to be the same size as the input face """
          if scaling != 1.0:
 
</s> remove 
    def scale_mask(mask, scaling):
        """ Scale the input mask to be the same size as the input face """
 </s> add     def _scale_mask(mask, scaling):
        """ Scale the input mask to be the same size as the input face

        Parameters
        ----------
        mask: input tensor
            The mask for the current image
        scaling: float
            The amount to scale the input mask by

        Returns
        -------
        tensor
            The resized input mask
        """ </s> remove     """ A wrapper for mask loss that can perform pre-processing on the input
        prior to calling the loss function
        loss_func: The loss function to use
        preprocessing_func: The preprocessing function to use. Should take a Keras Input
        as it's only argument """

 </s> add     """ A wrapper for mask loss that can perform pre-processing on the input prior to calling the
    loss function.

    Parameters
    ----------
    loss_func: class or function
        The actual loss function to use
    preprocessing_func: function
        The pre-processing function to use. Should take a Keras Input as it's only argument
    """ </s> remove     """
    generalized function used to return a large variety of mathematical loss functions
    primary benefit is smooth, differentiable version of L1 loss

    Barron, J. A More General Robust Loss Function
    https://arxiv.org/pdf/1701.03077.pdf
    Parameters:
        alpha: penalty factor. larger number give larger weight to large deviations
        beta: scale factor used to adjust to the input scale (i.e. inputs of mean 1e-4 or 256 )
    Return:
        a loss value from the results of function(y_pred - y_true)
    Example:
        a=1.0, x>>c , c=1.0/255.0 will give a smoothly differentiable version of L1 / MAE loss
        a=1.999999 (lim as a->2), beta=1.0/255.0 will give L2 / RMSE loss
 </s> add     """ Generalized function used to return a large variety of mathematical loss functions.

    The primary benefit is a smooth, differentiable version of L1 loss.

    Parameters
    ----------
    y_true: tensor or variable
        The ground truth value
    y_pred: tensor or variable
        The predicted value
    alpha: float, optional
        Penalty factor. Larger number give larger weight to large deviations. Default: `1.0`
    beta: float, optional
        Scale factor used to adjust to the input scale (i.e. inputs of mean `1e-4` or `256`).
        Default: `1.0/255.0`

    Returns
    -------
    tensor
        The loss value from the results of function(y_pred - y_true)

    References
    ----------
    Barron, J. A More General Robust Loss Function - https://arxiv.org/pdf/1701.03077.pdf

    Example
    -------
    >>> a=1.0, x>>c , c=1.0/255.0  # will give a smoothly differentiable version of L1 / MAE loss
    >>> a=1.999999 (limit as a->2), beta=1.0/255.0 # will give L2 / RMSE loss </s> remove     """ PixelShuffler layer for Keras
       by t-ae: https://gist.github.com/t-ae/6e1016cc188104d123676ccef3264981 """
    # pylint: disable=C0103
 </s> add     """ PixelShuffler layer for Keras.

    This layer requires a Convolution2D prior to it, having output filters computed according to
    the formula :math:`filters = k * (scale_factor * scale_factor)` where `k` is a user defined
    number of filters (generally larger than 32) and `scale_factor` is the up-scaling factor
    (generally 2).

    This layer performs the depth to space operation on the convolution filters, and returns a
    tensor with the size as defined below.

    Notes
    -----
    In practice, it is useful to have a second convolution layer after the
    :class:`PixelShuffler` layer to speed up the learning process. However, if you are stacking
    multiple :class:`PixelShuffler` blocks, it may increase the number of parameters greatly,
    so the Convolution layer after :class:`PixelShuffler` layer can be removed.

    Example
    -------
    >>> # A standard sub-pixel up-scaling block
    >>> x = Convolution2D(256, 3, 3, padding="same", activation="relu")(...)
    >>> u = PixelShuffler(size=(2, 2))(x)
    [Optional]
    >>> x = Convolution2D(256, 3, 3, padding="same", activation="relu")(u)

    Parameters
    ----------
    size: tuple, optional
        The (`h`, `w`) scaling factor for up-scaling. Default: `(2, 2)`
    data_format: ["channels_first", "channels_last", ``None``], optional
        The data format for the input. Default: ``None``
    kwargs: dict
        The standard Keras Layer keyword arguments (if any)

    References
    ----------
    https://gist.github.com/t-ae/6e1016cc188104d123676ccef3264981
    """ </s> remove     def inner_loss(y_true, y_pred):
        # Branching because tensorflows broadcasting is wonky and
        # plaidmls concatenate is implemented ineficient.
 </s> add     def _inner_loss(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
        y_pred: tensor or variable
            The predicted value

        Returns
        -------
        tensor
            The Loss value

        Notes
        -----
        Branching because TensorFlow's broadcasting is wonky and plaidML's concatenate is
        implemented inefficiently.
        """
    """ Plaidml and Tensorflow Penalized Loss function.

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

    Parameters
    ----------
    mask: input tensor
        The mask for the current image
    loss_func: function
        The actual loss function to use
    mask_prop: float, optional
        The amount of mask propagation. Default: `1.0`
    mask_scaling: float, optional
        For multi-decoder output the target mask will likely be at full size scaling, so this is
        the scaling factor to reduce the mask by. Default: `1.0`
    preprocessing_func: function, optional
        If preprocessing is required on the input mask, then this should be the function to use.
        The function should take a Keras Input as it's only argument. Set to ``None`` if no
        preprocessing is to be performed. Default: ``None``
  
  # <<< START: from Dfaker >>> #
  def PenalizedLoss(mask, loss_func,  # pylint: disable=invalid-name
                    mask_prop=1.0, mask_scaling=1.0, preprocessing_func=None):
    """ Plaidml and Tensorflow Penalized Loss function.

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

    Parameters
    ----------
    mask: input tensor
        The mask for the current image
    loss_func: function
        The actual loss function to use
    mask_prop: float, optional
        The amount of mask propagation. Default: `1.0`
    mask_scaling: float, optional
        For multi-decoder output the target mask will likely be at full size scaling, so this is
        the scaling factor to reduce the mask by. Default: `1.0`
    preprocessing_func: function, optional
        If preprocessing is required on the input mask, then this should be the function to use.
        The function should take a Keras Input as it's only argument. Set to ``None`` if no
        preprocessing is to be performed. Default: ``None``
    """ Plaidml and Tensorflow Penalized Loss function.

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

    Parameters
    ----------
    mask: input tensor
        The mask for the current image
    loss_func: function
        The actual loss function to use
    mask_prop: float, optional
        The amount of mask propagation. Default: `1.0`
    mask_scaling: float, optional
        For multi-decoder output the target mask will likely be at full size scaling, so this is
        the scaling factor to reduce the mask by. Default: `1.0`
    preprocessing_func: function, optional
        If preprocessing is required on the input mask, then this should be the function to use.
        The function should take a Keras Input as it's only argument. Set to ``None`` if no
        preprocessing is to be performed. Default: ``None``
    """ Plaidml and Tensorflow Penalized Loss function.

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

    Parameters
    ----------
    mask: input tensor
        The mask for the current image
    loss_func: function
        The actual loss function to use
    mask_prop: float, optional
        The amount of mask propagation. Default: `1.0`
    mask_scaling: float, optional
        For multi-decoder output the target mask will likely be at full size scaling, so this is
        the scaling factor to reduce the mask by. Default: `1.0`
    preprocessing_func: function, optional
        If preprocessing is required on the input mask, then this should be the function to use.
        The function should take a Keras Input as it's only argument. Set to ``None`` if no
        preprocessing is to be performed. Default: ``None``
    """ Plaidml and Tensorflow Penalized Loss function.

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

    Parameters
    ----------
    mask: input tensor
        The mask for the current image
    loss_func: function
        The actual loss function to use
    mask_prop: float, optional
        The amount of mask propagation. Default: `1.0`
    mask_scaling: float, optional
        For multi-decoder output the target mask will likely be at full size scaling, so this is
        the scaling factor to reduce the mask by. Default: `1.0`
    preprocessing_func: function, optional
        If preprocessing is required on the input mask, then this should be the function to use.
        The function should take a Keras Input as it's only argument. Set to ``None`` if no
        preprocessing is to be performed. Default: ``None``
    """ Plaidml and Tensorflow Penalized Loss function.

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

    Parameters
    ----------
    mask: input tensor
        The mask for the current image
    loss_func: function
        The actual loss function to use
    mask_prop: float, optional
        The amount of mask propagation. Default: `1.0`
    mask_scaling: float, optional
        For multi-decoder output the target mask will likely be at full size scaling, so this is
        the scaling factor to reduce the mask by. Default: `1.0`
    preprocessing_func: function, optional
        If preprocessing is required on the input mask, then this should be the function to use.
        The function should take a Keras Input as it's only argument. Set to ``None`` if no
        preprocessing is to be performed. Default: ``None``
    """ Plaidml and Tensorflow Penalized Loss function.

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

    Parameters
    ----------
    mask: input tensor
        The mask for the current image
    loss_func: function
        The actual loss function to use
    mask_prop: float, optional
        The amount of mask propagation. Default: `1.0`
    mask_scaling: float, optional
        For multi-decoder output the target mask will likely be at full size scaling, so this is
        the scaling factor to reduce the mask by. Default: `1.0`
    preprocessing_func: function, optional
        If preprocessing is required on the input mask, then this should be the function to use.
        The function should take a Keras Input as it's only argument. Set to ``None`` if no
        preprocessing is to be performed. Default: ``None``
      """
  
      def scale_mask(mask, scaling):
          """ Scale the input mask to be the same size as the input face """
          if scaling != 1.0:
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
 Simple backend unit tests (#1020)

* Add simple backend tests for lib.model
* Document lib.model
* Fix GMSD Loss for AMD
* Remove obsolete code from lib.model 
lib/model/losses.py