§
    ’©ºj]  ã                   ó    — d dl mZmZmZmZmZ d dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZmZ esdgZesd	dgZ G d
„ d	e¦  «        ZdS )é    )ÚAnyÚLiteralÚOptionalÚSequenceÚUnionN)ÚTensor)Ú_dists_update)ÚMetric)Ú_MATPLOTLIB_AVAILABLEÚ_TORCHVISION_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEz+DeepImageStructureAndTextureSimilarity.plotÚ&DeepImageStructureAndTextureSimilarityc                   ó  ‡ — e Zd ZU dZeed<   eed<   dZeed<   dZeed<   dZ	eed<   d	Z
eed
<   dde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 )r   aß  Calculates Deep Image Structure and Texture Similarity (DISTS) score.

    The metric is a full-reference image quality assessment (IQA) model that combines sensitivity to structural
    distortions (e.g., artifacts due to noise, blur, or compression) with a tolerance of texture resampling
    (exchanging the content of a texture region with a new sample of the same texture). The metric is based on
    a convolutional neural network (CNN) that transforms the reference and distorted images to a new representation.
    Within this representation, a set of measurements are developed that are sufficient to capture the appearance
    of a variety of different visual distortions.

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

    - ``preds`` (:class:`~torch.Tensor`): tensor with images of shape ``(N, 3, H, W)``
    - ``target`` (:class:`~torch.Tensor`): tensor with images of shape ``(N, 3, H, W)``

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

    - ``lpips`` (:class:`~torch.Tensor`): returns float scalar tensor with average LPIPS value over samples

    Args:
        reduction: specifies the reduction to apply to the output.
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError:
            If `reduction` is not one of ["mean", "sum"]

    Example:
        >>> from torch import rand
        >>> from torchmetrics.image.dists import DeepImageStructureAndTextureSimilarity
        >>> metric = DeepImageStructureAndTextureSimilarity()
        >>> preds = rand(10, 3, 100, 100)
        >>> target = rand(10, 3, 100, 100)
        >>> metric(preds, target)
        tensor(0.1882, grad_fn=<CloneBackward0>)

    ÚscoreÚtotalTÚis_differentiableFÚhigher_is_betterÚfull_state_updateç        Úplot_lower_boundÚmeanÚ	reduction©r   ÚsumÚkwargsÚreturnNc                 ó&  •—  t          ¦   «         j        d	i |¤Ž d}||vrt          d|› d|› �¦  «        ‚|| _        |                      dt          j        d¦  «        d¬¦  «         |                      dt          j        d¦  «        d¬¦  «         d S )
Nr   z+Argument `reduction` expected to be one of z	 but got r   r   r   )ÚdefaultÚdist_reduce_fxr   © )ÚsuperÚ__init__Ú
ValueErrorr   Ú	add_stateÚtorchÚtensor)Úselfr   r   Úallowed_reductionsÚ	__class__s       €úh/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/image/dists.pyr#   z/DeepImageStructureAndTextureSimilarity.__init__M   s¤   ø€ Ø�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ø,ÐØÐ.Ð.Ð.ÝÐsÐK]ÐsÐsÐhqÐsÐsÑtÔtÐtØ"ˆŒØ�Š�w­¬°SÑ(9Ô(9È%ˆÑPÔPÐPØ�Š�w­¬°SÑ(9Ô(9È%ˆÑPÔPÐPÐPÐPó    ÚpredsÚtargetc                 ó    — t          ||¦  «        }| xj        |                     ¦   «         z  c_        | xj        |j        d         z  c_        dS )zUpdate the metric state.r   N)r	   r   r   r   Úshape)r(   r-   r.   Úscoress       r+   Úupdatez-DeepImageStructureAndTextureSimilarity.updateV   sC   € å˜u fÑ-Ô-ˆØˆ
Œ
�f—j’j‘l”lÑ"ˆ
Œ
Øˆ
Œ
�e”k !”nÑ$ˆ
Œ
ˆ
ˆ
r,   c                 óD   — | j         dk    r| j        | j        z  n| j        S )zComputes the DISTS score.r   )r   r   r   )r(   s    r+   Úcomputez.DeepImageStructureAndTextureSimilarity.compute\   s$   € à*.¬.¸FÒ*BÐ*BˆtŒz˜DœJÑ&Ð&ÈÌ
ÐRr,   Ú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.dists import DeepImageStructureAndTextureSimilarity
            >>> metric = DeepImageStructureAndTextureSimilarity()
            >>> metric.update(torch.rand(10, 3, 100, 100), torch.rand(10, 3, 100, 100))
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

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

        )Ú_plot)r(   r5   r6   s      r+   Úplotz+DeepImageStructureAndTextureSimilarity.plot`   s   € ðP �zŠz˜#˜rÑ"Ô"Ð"r,   )r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   Úboolr   r   r   Úfloatr   r   r   r#   r2   r4   r   r   r   r   r9   Ú__classcell__)r*   s   @r+   r   r      sm  ø€ € € € € € ð#ð #ðJ €M€M�MØ€M€M�Mà"Ð�tÐ"Ð"Ñ"Ø"Ð�dÐ"Ð"Ñ"Ø#Ð�tÐ#Ð#Ñ#Ø!Ð�eÐ!Ð!Ñ!ðQð Q (¨7°=Ô+AÔ"Bð QÐWZð QÐ_cð Qð Qð Qð Qð Qð Qð%˜Fð %¨Fð %°tð %ð %ð %ð %ðS˜ð Sð Sð Sð Sð
 _cð(#ð (#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð(#ØIQÐRZÔI[ð(#à	ð(#ð (#ð (#ð (#ð (#ð (#ð (#ð (#r,   )Útypingr   r   r   r   r   r&   r   Ú#torchmetrics.functional.image.distsr	   Útorchmetrics.metricr
   Útorchmetrics.utilities.importsr   r   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r!   r,   r+   ú<module>rH      s  ðð ;Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :à €€€Ø Ð Ð Ð Ð Ð à =Ð =Ð =Ð =Ð =Ð =Ø &Ð &Ð &Ð &Ð &Ð &Ø XÐ XÐ XÐ XÐ XÐ XÐ XÐ XØ @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð GØEÐFÐàð qØ@ÐBoÐpÐði#ð i#ð i#ð i#ð i#¨Vñ i#ô i#ð i#ð i#ð i#r,   