§
    ’©ºj»  ã                   ó¼   — d dl mZ d dlmZmZmZmZ d dlmZm	Z	 d dl
mZ d dlmZmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ esdgZ G d„ de¦  «        ZdS )é    )ÚSequence)ÚAnyÚListÚOptionalÚUnion)ÚTensorÚtensor)ÚLiteral)Ú_uqi_computeÚ_uqi_update)ÚMetric)Úrank_zero_warn)Údim_zero_cat)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEzUniversalImageQualityIndex.plotc                   óX  ‡ — e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	e
ed<   d	Ze
ed
<   ee         ed<   ee         ed<   eed<   eed<   	 	 	 ddee         dee
         ded         deddf
ˆ fd„Zdededdfd„Zdefd„Z	 d deeeee         f                  dee         defd„Zˆ xZS )!ÚUniversalImageQualityIndexa…  Compute Universal Image Quality Index (UniversalImageQualityIndex_).

    As input to ``forward`` and ``update`` the metric accepts the following input

    - ``preds`` (:class:`~torch.Tensor`): Predictions from model of shape ``(N,C,H,W)``
    - ``target`` (:class:`~torch.Tensor`): Ground truth values of shape ``(N,C,H,W)``

    As output of `forward` and `compute` the metric returns the following output

    - ``uiqi`` (:class:`~torch.Tensor`): if ``reduction!='none'`` returns float scalar tensor with average UIQI value
      over sample else returns tensor of shape ``(N,)`` with UIQI values per sample

    Args:
        kernel_size: size of the gaussian kernel
        sigma: Standard deviation of the gaussian kernel
        reduction: a method to reduce metric score over labels.

            - ``'elementwise_mean'``: takes the mean (default)
            - ``'sum'``: takes the sum
            - ``'none'`` or ``None``: no reduction will be applied

        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Return:
        Tensor with UniversalImageQualityIndex score

    Example:
        >>> import torch
        >>> from torchmetrics.image import UniversalImageQualityIndex
        >>> preds = torch.rand([16, 1, 16, 16])
        >>> target = preds * 0.75
        >>> uqi = UniversalImageQualityIndex()
        >>> uqi(preds, target)
        tensor(0.9216)

    TÚis_differentiableÚhigher_is_betterFÚfull_state_updateç        Úplot_lower_boundg      ð?Úplot_upper_boundÚpredsÚtargetÚsum_uqiÚnumel©é   r    ©ç      ø?r"   Úelementwise_meanÚkernel_sizeÚsigmaÚ	reduction©r#   ÚsumÚnoneNÚkwargsÚreturnNc                 ó¶  •—  t          ¦   «         j        di |¤Ž |dvrt          d|› d�¦  «        ‚|�|dk    r@t          d¦  «         |                      dg d¬¦  «         |                      d	g d¬¦  «         nJ|                      d
t          d¦  «        d¬¦  «         |                      dt          d¦  «        d¬¦  «         || _        || _        || _        d S )Nr'   zThe `reduction` zI is not valid. Valid options are `elementwise_mean`, `sum`, `none`, None.r)   zÇMetric `UniversalImageQualityIndex` will save all targets and predictions in the buffer when using`reduction=None` or `reduction='none'. For large datasets, this may lead to a large memory footprint.r   Úcat)ÚdefaultÚdist_reduce_fxr   r   r   r(   )r/   r   r   © )	ÚsuperÚ__init__Ú
ValueErrorr   Ú	add_stater	   r$   r%   r&   )Úselfr$   r%   r&   r*   Ú	__class__s        €úf/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/image/uqi.pyr2   z#UniversalImageQualityIndex.__init__P   s  ø€ ð 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"ØÐEÐEÐEÝØw 9ÐwÐwÐwñô ð ð Ð 	¨VÒ 3Ð 3Ýðxñô ð ð �NŠN˜7¨B¸uˆNÑEÔEÐEØ�NŠN˜8¨RÀˆNÑFÔFÐFÐFà�NŠN˜9¥f¨S¡k¤kÀ%ˆNÑHÔHÐHØ�NŠN˜7¥F¨1¡I¤I¸eˆNÑDÔDÐDØ&ˆÔØˆŒ
Ø"ˆŒˆˆó    c                 óÌ  — t          ||¦  «        \  }}| j        �| j        dk    r6| j                             |¦  «         | j                             |¦  «         dS t          ||| j        | j        d¬¦  «        }| xj        |z  c_        |j	        }| xj
        |d         |d         z  |d         | j        d         z
  dz   z  |d         | j        d         z
  dz   z  z  c_
        dS )	z*Update state with predictions and targets.Nr)   r(   )r&   r   é   é   é   )r   r&   r   Úappendr   r   r$   r%   r   Úshaper   )r5   r   r   Ú	uqi_scoreÚpss        r7   Úupdatez!UniversalImageQualityIndex.updatej   sê   € å# E¨6Ñ2Ô2‰ˆˆvØŒ>Ð! T¤^°vÒ%=Ð%=ØŒJ×Ò˜eÑ$Ô$Ð$ØŒK×Ò˜vÑ&Ô&Ð&Ð&Ð&å$ U¨F°DÔ4DÀdÄjÐ\aÐbÑbÔbˆIØˆLŒL˜IÑ%ˆLŒLØ”ˆBØˆJŒJ˜"˜Qœ% " Q¤%™-¨2¨a¬5°4Ô3CÀAÔ3FÑ+FÈÑ+JÑKÈrÐRSÌuÐW[ÔWgÐhiÔWjÑOjÐmnÑOnÑoÑoˆJŒJˆJˆJr8   c                 óü   — | j         dk    s| j         €Jt          | j        ¦  «        }t          | j        ¦  «        }t	          ||| j        | j        | j         ¦  «        S | j         dk    r| j        | j        z  n| j        S )z&Compute explained variance over state.r)   Nr#   )	r&   r   r   r   r   r$   r%   r   r   )r5   r   r   s      r7   Úcomputez"UniversalImageQualityIndex.computev   sv   € àŒ>˜VÒ#Ð# t¤~Ð'=Ý  ¤Ñ,Ô,ˆEÝ! $¤+Ñ.Ô.ˆFÝ  v¨tÔ/?ÀÄÈTÌ^Ñ\Ô\Ð\Ø,0¬NÐ>PÒ,PÐ,PˆtŒ|˜dœjÑ(Ð(ÐVZÔVbÐbr8   ÚvalÚaxc                 ó.   — |                       ||¦  «        S )a¼  Plot a single or multiple values from the metric.

        Args:
            val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.
                If no value is provided, will automatically call `metric.compute` and plot that result.
            ax: An matplotlib axis object. If provided will add plot to that axis

        Returns:
            Figure and Axes object

        Raises:
            ModuleNotFoundError:
                If `matplotlib` is not installed

        .. plot::
            :scale: 75

            >>> # Example plotting a single value
            >>> import torch
            >>> from torchmetrics.image import UniversalImageQualityIndex
            >>> preds = torch.rand([16, 1, 16, 16])
            >>> target = preds * 0.75
            >>> metric = UniversalImageQualityIndex()
            >>> metric.update(preds, target)
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> import torch
            >>> from torchmetrics.image import UniversalImageQualityIndex
            >>> preds = torch.rand([16, 1, 16, 16])
            >>> target = preds * 0.75
            >>> metric = UniversalImageQualityIndex()
            >>> values = [ ]
            >>> for _ in range(10):
            ...     values.append(metric(preds, target))
            >>> fig_, ax_ = metric.plot(values)

        )Ú_plot)r5   rD   rE   s      r7   ÚplotzUniversalImageQualityIndex.plot~   s   € ðX �zŠz˜#˜rÑ"Ô"Ð"r8   )r   r!   r#   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   Úfloatr   r   r   r   Úintr
   r   r2   rA   rC   r   r   r   r   rH   Ú__classcell__)r6   s   @r7   r   r      sÃ  ø€ € € € € € ð#ð #ðJ #Ð�tÐ"Ð"Ñ"Ø!Ð�dÐ!Ð!Ñ!Ø#Ð�tÐ#Ð#Ñ#Ø!Ð�eÐ!Ð!Ñ!Ø!Ð�eÐ!Ð!Ñ!à�Œ<ÐÐÑØ�ŒLÐÐÑØ€O€O�OØ€M€M�Mð &.Ø!+ØFXð	#ð #à˜c”]ð#ð ˜Œð#ð ÐBÔCð	#ð
 ð#ð 
ð#ð #ð #ð #ð #ð #ð4
p˜Fð 
p¨Fð 
p°tð 
pð 
pð 
pð 
pðc˜ð cð cð cð cð _cð,#ð ,#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð,#ØIQÐRZÔI[ð,#à	ð,#ð ,#ð ,#ð ,#ð ,#ð ,#ð ,#ð ,#r8   r   N)Úcollections.abcr   Útypingr   r   r   r   Útorchr   r	   Útyping_extensionsr
   Ú!torchmetrics.functional.image.uqir   r   Útorchmetrics.metricr   Útorchmetrics.utilitiesr   Útorchmetrics.utilities.datar   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r0   r8   r7   ú<module>r]      s.  ðð %Ð $Ð $Ð $Ð $Ð $Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -à  Ð  Ð  Ð  Ð  Ð  Ð  Ð  Ø %Ð %Ð %Ð %Ð %Ð %à GÐ GÐ GÐ GÐ GÐ GÐ GÐ GØ &Ð &Ð &Ð &Ð &Ð &Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð ;Ø9Ð:ÐðK#ð K#ð K#ð K#ð K# ñ K#ô K#ð K#ð K#ð K#r8   