a
    þdÔ  ã                   @   sP   d dl Z d dlmZ d dlmZ e je jee jdœdd„ZG dd„ dejƒZ	dS )é    N)ÚinputÚtargetÚmax_valÚreturnc                 C   s   dt  | ||¡ S )aH  Function that computes the PSNR loss.

    The loss is computed as follows:

     .. math::

        \text{loss} = -\text{psnr(x, y)}

    See :meth:`~kornia.losses.psnr` for details abut PSNR.

    Args:
        input: the input image with shape :math:`(*)`.
        labels : the labels image with shape :math:`(*)`.
        max_val: The maximum value in the input tensor.

    Return:
        the computed loss as a scalar.

    Examples:
        >>> ones = torch.ones(1)
        >>> psnr_loss(ones, 1.2 * ones, 2.) # 10 * log(4/((1.2-1)**2)) / log(10)
        tensor(-20.0000)
    g      ð¿)ÚmetricsZpsnr)r   r   r   © r   ú[/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/kornia/losses/psnr.pyÚ	psnr_loss   s    r	   c                       s@   e Zd ZdZeddœ‡ fdd„Zejejejdœdd„Z‡  Z	S )	ÚPSNRLossaƒ  Create a criterion that calculates the PSNR loss.

    The loss is computed as follows:

     .. math::

        \text{loss} = -\text{psnr(x, y)}

    See :meth:`~kornia.losses.psnr` for details abut PSNR.

    Args:
        max_val: The maximum value in the input tensor.

    Shape:
        - Input: arbitrary dimensional tensor :math:`(*)`.
        - Target: arbitrary dimensional tensor :math:`(*)` same shape as input.
        - Output: a scalar.

    Examples:
        >>> ones = torch.ones(1)
        >>> criterion = PSNRLoss(2.)
        >>> criterion(ones, 1.2 * ones) # 10 * log(4/((1.2-1)**2)) / log(10)
        tensor(-20.0000)
    N)r   r   c                    s   t ƒ  ¡  || _d S ©N)ÚsuperÚ__init__r   )Úselfr   ©Ú	__class__r   r   r   =   s    
zPSNRLoss.__init__)r   r   r   c                 C   s   t ||| jƒS r   )r	   r   )r   r   r   r   r   r   ÚforwardA   s    zPSNRLoss.forward)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úfloatr   ÚtorchÚTensorr   Ú__classcell__r   r   r   r   r
   #   s   r
   )
r   Ztorch.nnÚnnZkornia.metricsr   r   r   r	   ÚModuler
   r   r   r   r   Ú<module>   s   