o
    €o™iV	  ã                   @  sL   d dl mZ d dlZd dlmZ d dlmZ ddd„ZG dd„ dejƒZdS )é    )ÚannotationsN)Únn)ÚmetricsÚimageútorch.TensorÚtargetÚmax_valÚfloatÚreturnc                 C  s   dt  | ||¡ S )a:  Compute 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:
        image: the input image with shape :math:`(*)`.
        target : the labels image with shape :math:`(*)`.
        max_val: The maximum value in the image 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      ð¿)r   Úpsnr)r   r   r   © r   úF/home/ubuntu/.local/lib/python3.10/site-packages/kornia/losses/psnr.pyÚ	psnr_loss   s   r   c                      s,   e Zd ZdZd‡ fdd„Z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 image tensor.

    Shape:
        - Image: arbitrary dimensional tensor :math:`(*)`.
        - Target: arbitrary dimensional tensor :math:`(*)` same shape as image.
        - 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)

    r   r	   r
   ÚNonec                   s   t ƒ  ¡  || _d S ©N)ÚsuperÚ__init__r   )Úselfr   ©Ú	__class__r   r   r   Q   s   

zPSNRLoss.__init__r   r   r   c                 C  s   t ||| jƒS r   )r   r   )r   r   r   r   r   r   ÚforwardU   s   zPSNRLoss.forward)r   r	   r
   r   )r   r   r   r   r
   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__classcell__r   r   r   r   r   6   s    r   )r   r   r   r   r   r	   r
   r   )	Ú
__future__r   Útorchr   Úkorniar   r   ÚModuler   r   r   r   r   Ú<module>   s   
