§
    ’©ºjn  ã                   óv   — d dl 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
 d dlmZ  G d„ d	e
¦  «        ZdS )
é    )ÚAnyÚListN)ÚTensor)ÚLiteral)Ú_vif_per_channel)ÚMetric)Údim_zero_catc            	       ó�   ‡ — e Zd ZU dZdZdZdZee         e	d<   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ˆ xZS )ÚVisualInformationFidelityu<  Compute Pixel Based Visual Information Fidelity (VIF_).

    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)`` with H,W â‰¥ 41
    - ``target`` (:class:`~torch.Tensor`): Ground truth values of shape ``(N,C,H,W)`` with H,W â‰¥ 41

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

    - ``vif-p`` (:class:`~torch.Tensor`):
        - If ``reduction='mean'`` (default), returns a Tensor mean VIF score.
        - If ``reduction='none'``, returns a tensor of shape ``(N,)`` with VIF values per sample.

    Args:
        sigma_n_sq: variance of the visual noise
        reduction: The reduction method for aggregating scores.

            - ``'mean'``: return the average VIF across the batch.
            - ``'none'``: return a VIF score for each sample in the batch.

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

    Example:
        >>> from torch import randn
        >>> from torchmetrics.image import VisualInformationFidelity
        >>> preds = randn([32, 3, 41, 41], generator=torch.Generator().manual_seed(42))
        >>> target = randn([32, 3, 41, 41], generator=torch.Generator().manual_seed(43))
        >>> vif_mean = VisualInformationFidelity(reduction='mean')
        >>> vif_mean(preds, target)
        tensor(0.0032)
        >>> vif_none = VisualInformationFidelity(reduction='none')
        >>> vif_none(preds, target)
        tensor([0.0040, 0.0049, 0.0017, 0.0039, 0.0041, 0.0043, 0.0030, 0.0028, 0.0012,
                0.0067, 0.0010, 0.0014, 0.0030, 0.0048, 0.0050, 0.0038, 0.0037, 0.0025,
                0.0041, 0.0019, 0.0007, 0.0034, 0.0037, 0.0016, 0.0026, 0.0021, 0.0038,
                0.0033, 0.0031, 0.0020, 0.0036, 0.0057])

    TFÚ	vif_scoreÚtotalç       @ÚmeanÚ
sigma_n_sqÚ	reduction©r   ÚnoneÚkwargsÚreturnNc                 ó  •—  t          ¦   «         j        di |¤Ž t          |t          t          f¦  «        r|dk     rt          d|› �¦  «        ‚|dvrt          d|› �¦  «        ‚|| _        || _        |                      dg d ¬¦  «         d S )Nr   zIArgument `sigma_n_sq` is expected to be a positive float or int, but got r   z7Argument `reduction` must be 'mean' or 'none', but got r   )ÚdefaultÚdist_reduce_fx© )	ÚsuperÚ__init__Ú
isinstanceÚfloatÚintÚ
ValueErrorr   r   Ú	add_state)Úselfr   r   r   Ú	__class__s       €úf/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/image/vif.pyr   z"VisualInformationFidelity.__init__H   s§   ø€ Ø�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"å˜*¥u­c lÑ3Ô3ð 	w°zÀA²~°~ÝÐuÐisÐuÐuÑvÔvÐvàÐ,Ð,Ð,ÝÐbÐW`ÐbÐbÑcÔcÐcà$ˆŒØ"ˆŒØ�Š�{¨B¸tˆÑDÔDÐDÐDÐDó    ÚpredsÚtargetc                 ó&  ‡ ‡‡— ‰                      d¦  «        }ˆˆ ˆfd„t          |¦  «        D ¦   «         }|dk    r't          j        t          j        |¦  «        d¦  «        nt          j        |¦  «        }‰ j                             |¦  «         dS )z*Update state with predictions and targets.é   c                 ó|   •— g | ]8}t          ‰d d …|d d …d d …f         ‰d d …|d d …d d …f         ‰j        ¦  «        ‘Œ9S )N)r   r   )Ú.0Úir%   r!   r&   s     €€€r#   ú
<listcomp>z4VisualInformationFidelity.update.<locals>.<listcomp>X   sg   ø€ ð 
ð 
ð 
ØYZÕ˜U 1 1 1 a¨¨¨¨A¨A¨A :Ô.°°q°q°q¸!¸Q¸Q¸QÀÀÀ°zÔ0BÀDÄOÑTÔTð
ð 
ð 
r$   r   N)ÚsizeÚrangeÚtorchr   ÚstackÚcatr   Úappend)r!   r%   r&   ÚchannelsÚvif_per_channels   ```  r#   Úupdatez VisualInformationFidelity.updateU   s¥   øøø€ à—:’:˜a‘=”=ˆð
ð 
ð 
ð 
ð 
ð 
Ý^cÐdlÑ^mÔ^mð
ñ 
ô 
ˆð JRÐTUÊÈ�%œ*¥U¤[°Ñ%AÔ%AÀ1ÑEÔEÐEÕ[`Ô[dÐetÑ[uÔ[uˆØŒ×Ò˜oÑ.Ô.Ð.Ð.Ð.r$   c                 ól   — t          | j        ¦  «        }| j        dk    r|                     ¦   «         S |S )zCompute VIF over state.r   )r	   r   r   r   )r!   r   s     r#   Úcomputez!VisualInformationFidelity.compute^   s4   € å  ¤Ñ0Ô0ˆ	ØŒ>˜VÒ#Ð#Ø—>’>Ñ#Ô#Ð#ØÐr$   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_differentiableÚhigher_is_betterÚfull_state_updater   r   Ú__annotations__r   r   r   r   r5   r7   Ú__classcell__)r"   s   @r#   r   r      sî   ø€ € € € € € ð%ð %ðN ÐØÐØÐà�FŒ|ÐÐÑØ€M€M�MðEð E 5ð E¸7À>Ô;Rð EÐgjð EÐosð Eð Eð Eð Eð Eð Eð/˜Fð /¨Fð /°tð /ð /ð /ð /ð˜ð ð ð ð ð ð ð ð r$   r   )Útypingr   r   r/   r   Útyping_extensionsr   Ú!torchmetrics.functional.image.vifr   Útorchmetrics.metricr   Útorchmetrics.utilities.datar	   r   r   r$   r#   ú<module>rF      sÀ   ðð Ð Ð Ð Ð Ð Ð Ð à €€€Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à >Ð >Ð >Ð >Ð >Ð >Ø &Ð &Ð &Ð &Ð &Ð &Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4ðJð Jð Jð Jð J ñ Jô Jð Jð Jð Jr$   