§
    ’©ºjv  ã                   ó¸   — d dl mZ d dlmZmZmZmZ d dl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)ÚLiteral)Ú"_spectral_distortion_index_computeÚ!_spectral_distortion_index_update)ÚMetric)Úrank_zero_warn)Údim_zero_cat)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEzSpectralDistortionIndex.plotc            	       ó$  ‡ — 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<   	 dd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 )ÚSpectralDistortionIndexag  Compute Spectral Distortion Index (SpectralDistortionIndex_) also now as D_lambda.

    The metric is used to compare the spectral distortion between two images.

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

    - ``preds`` (:class:`~torch.Tensor`): Low resolution multispectral image of shape ``(N,C,H,W)``
    - ``target``(:class:`~torch.Tensor`): High resolution fused image of shape ``(N,C,H,W)``

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

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

    Args:
        p: Large spectral differences
        reduction: a method to reduce metric score over labels.

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

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

    Example:
        >>> from torch import rand
        >>> from torchmetrics.image import SpectralDistortionIndex
        >>> preds = rand([16, 3, 16, 16])
        >>> target = rand([16, 3, 16, 16])
        >>> sdi = SpectralDistortionIndex()
        >>> sdi(preds, target)
        tensor(0.0234)

    TÚhigher_is_betterÚis_differentiableFÚfull_state_updateg        Úplot_lower_boundg      ð?Úplot_upper_boundÚpredsÚtargeté   Úelementwise_meanÚpÚ	reduction©r   ÚsumÚnoneÚkwargsÚreturnNc                 óf  •—  t          ¦   «         j        di |¤Ž t          d¦  «         t          |t          ¦  «        r|dk    rt          d|› d�¦  «        ‚|| _        d}||vrt          d|› d|› �¦  «        ‚|| _        |                      dg d	¬
¦  «         |                      dg d	¬
¦  «         d S )Nz�Metric `SpectralDistortionIndex` will save all targets and predictions in buffer. For large datasets this may lead to large memory footprint.r   z.Expected `p` to be a positive integer. Got p: ú.r   z(Expected argument `reduction` be one of z	 but got r   Úcat)ÚdefaultÚdist_reduce_fxr   © )	ÚsuperÚ__init__r   Ú
isinstanceÚintÚ
ValueErrorr   r   Ú	add_state)Úselfr   r   r"   Úallowed_reductionsÚ	__class__s        €úk/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/image/d_lambda.pyr+   z SpectralDistortionIndex.__init__L   sç   ø€ ð 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ýð*ñ	
ô 	
ð 	
õ ˜!�SÑ!Ô!ð 	T Q¨!¢V VÝÐRÈaÐRÐRÐRÑSÔSÐSØˆŒØ@ÐØÐ.Ð.Ð.ÝÐpÐHZÐpÐpÐenÐpÐpÑqÔqÐqØ"ˆŒØ�Š�w¨¸5ˆÑAÔAÐAØ�Š�x¨¸EˆÑBÔBÐBÐBÐBó    c                 ó”   — t          ||¦  «        \  }}| j                             |¦  «         | j                             |¦  «         dS )z#Update state with preds and target.N)r   r   Úappendr   ©r0   r   r   s      r3   ÚupdatezSpectralDistortionIndex.update`   sG   € å9¸%ÀÑHÔH‰ˆˆvØŒ
×Ò˜%Ñ Ô Ð ØŒ×Ò˜6Ñ"Ô"Ð"Ð"Ð"r4   c                 óŠ   — t          | j        ¦  «        }t          | j        ¦  «        }t          ||| j        | j        ¦  «        S )z.Compute and returns spectral distortion index.)r   r   r   r
   r   r   r7   s      r3   ÚcomputezSpectralDistortionIndex.computef   s8   € å˜TœZÑ(Ô(ˆÝ˜dœkÑ*Ô*ˆÝ1°%¸ÀÄÈÌÑXÔXÐXr4   Ú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
            >>> from torch import rand
            >>> from torchmetrics.image import SpectralDistortionIndex
            >>> preds = rand([16, 3, 16, 16])
            >>> target = rand([16, 3, 16, 16])
            >>> metric = SpectralDistortionIndex()
            >>> metric.update(preds, target)
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

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

        )Ú_plot)r0   r;   r<   s      r3   ÚplotzSpectralDistortionIndex.plotl   s   € ðX �zŠz˜#˜rÑ"Ô"Ð"r4   )r   r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   Úfloatr   r   r   r-   r	   r   r+   r8   r:   r   r   r   r   r   r?   Ú__classcell__)r2   s   @r3   r   r      s™  ø€ € € € € € ð!ð !ðF "Ð�dÐ!Ð!Ñ!Ø"Ð�tÐ"Ð"Ñ"Ø#Ð�tÐ#Ð#Ñ#Ø!Ð�eÐ!Ð!Ñ!Ø!Ð�eÐ!Ð!Ñ!à�Œ<ÐÐÑØ�ŒLÐÐÑð SeðCð CØðCØ%,Ð-NÔ%OðCØpsðCà	ðCð Cð Cð Cð Cð Cð(#˜Fð #¨Fð #°tð #ð #ð #ð #ðY˜ð Yð Yð Yð Yð _cð,#ð ,#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð,#ØIQÐRZÔI[ð,#à	ð,#ð ,#ð ,#ð ,#ð ,#ð ,#ð ,#ð ,#r4   r   N)Úcollections.abcr   Útypingr   r   r   r   Útorchr   Útyping_extensionsr	   Ú&torchmetrics.functional.image.d_lambdar
   r   Útorchmetrics.metricr   Útorchmetrics.utilitiesr   Útorchmetrics.utilities.datar   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r)   r4   r3   ú<module>rS      s(  ðð %Ð $Ð $Ð $Ð $Ð $Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -à Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à xÐ xÐ xÐ xÐ xÐ xÐ xÐ xØ &Ð &Ð &Ð &Ð &Ð &Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð 8Ø6Ð7Ððy#ð y#ð y#ð y#ð y#˜fñ y#ô y#ð y#ð y#ð y#r4   