§
    ’©ºj¸  ã                   ón   — d dl mZmZ d dlZd dlmZ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ÚOptionalN)ÚTensorÚtensor)Ú_scc_per_channel_compute)Ú_scc_update)ÚMetricc            	       ó„   ‡ — e Zd ZU dZdZdZdZeed<   eed<   dde	e         d	e
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 )ÚSpatialCorrelationCoefficienta  Compute Spatial Correlation Coefficient (SCC_).

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

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

    - ``scc`` (:class:`~torch.Tensor`): Tensor with scc score

    Args:
        hp_filter: High-pass filter tensor. default: tensor([[-1,-1,-1],[-1,8,-1],[-1,-1,-1]]).
        window_size: Local window size integer. default: 8.
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Example:
        >>> from torch import randn
        >>> from torchmetrics.image import SpatialCorrelationCoefficient as SCC
        >>> preds = randn([32, 3, 64, 64])
        >>> target = randn([32, 3, 64, 64])
        >>> scc = SCC()
        >>> scc(preds, target)
        tensor(0.0023)

    TFÚ	scc_scoreÚtotalNé   Úhigh_pass_filterÚwindow_sizeÚkwargsÚreturnc                 ó  •—  t          ¦   «         j        di |¤Ž |€t          g d¢g d¢g d¢g¦  «        }|| _        || _        |                      dt          d¦  «        d¬¦  «         |                      dt          d¦  «        d¬¦  «         d S )	N)éÿÿÿÿr   r   )r   r   r   r   g        Úsum)ÚdefaultÚdist_reduce_fxr   © )ÚsuperÚ__init__r   Ú	hp_filterÚwsÚ	add_state)Úselfr   r   r   Ú	__class__s       €úf/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/image/scc.pyr   z&SpatialCorrelationCoefficient.__init__;   s—   ø€ Ø�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"àÐ#Ý% | | |°[°[°[À,À,À,Ð&OÑPÔPÐà)ˆŒØˆŒà�Š�{­F°3©K¬KÈˆÑNÔNÐNØ�Š�w­¨s©¬ÀEˆÑJÔJÐJÐJÐJó    ÚpredsÚtargetc           
      óŽ  ‡ ‡‡‡— t          ‰‰‰ j        ‰ j        ¦  «        \  ŠŠŠˆˆˆ ˆfd„t          ‰                     d¦  «        ¦  «        D ¦   «         }‰ xj        t          j        t          j        t          j	        |d¬¦  «        g d¢¬¦  «        ¦  «        z  c_        ‰ xj
        ‰                     d¦  «        z  c_
        dS )z*Update state with predictions and targets.c                 óÊ   •— g | ]_}t          ‰d d …|d d …d d …f                              d¦  «        ‰d d …|d d …d d …f                              d¦  «        ‰‰j        ¦  «        ‘Œ`S )Né   )Ú_scc_computeÚ	unsqueezer   )Ú.0Úir   r"   r   r#   s     €€€€r    ú
<listcomp>z8SpatialCorrelationCoefficient.update.<locals>.<listcomp>J   s‹   ø€ ð 
ð 
ð 
àõ ˜˜q˜q˜q ! Q Q Q¨¨¨˜zÔ*×4Ò4°QÑ7Ô7¸ÀÀÀÀ1ÀaÀaÀaÈÈÈÀ
Ô9K×9UÒ9UÐVWÑ9XÔ9XÐZcÐeiÔelÑmÔmð
ð 
ð 
r!   r&   )Údim)r&   é   é   r   N)r   r   r   ÚrangeÚsizer   Útorchr   ÚmeanÚcatr   )r   r"   r#   Úscc_per_channelr   s   ``` @r    Úupdatez$SpatialCorrelationCoefficient.updateG   sÌ   øøøø€ å#.¨u°f¸d¼nÈdÌgÑ#VÔ#VÑ ˆˆv�yð
ð 
ð 
ð 
ð 
ð 
ð 
å˜5Ÿ:š: a™=œ=Ñ)Ô)ð
ñ 
ô 
ˆð 	ˆŒ�%œ)¥E¤J­u¬y¸ÈaÐ/PÑ/PÔ/PÐV_ÐV_ÐV_Ð$`Ñ$`Ô$`ÑaÔaÑaˆŒØˆ
Œ
�e—j’j ‘m”mÑ#ˆ
Œ
ˆ
ˆ
r!   c                 ó    — | j         | j        z  S )zICompute the VIF score based on inputs passed in to ``update`` previously.)r   r   )r   s    r    Úcomputez%SpatialCorrelationCoefficient.computeQ   s   € àŒ~ ¤
Ñ*Ð*r!   )Nr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_differentiableÚhigher_is_betterÚfull_state_updater   Ú__annotations__r   Úintr   r   r5   r7   Ú__classcell__)r   s   @r    r   r      sé   ø€ € € € € € ðð ð6 ÐØÐØÐàÐÐÑØ€M€M�Mð
Kð 
K¨°&Ô)9ð 
KÈsð 
KÐbeð 
KÐjnð 
Kð 
Kð 
Kð 
Kð 
Kð 
Kð$˜Fð $¨Fð $°tð $ð $ð $ð $ð+˜ð +ð +ð +ð +ð +ð +ð +ð +r!   r   )Útypingr   r   r1   r   r   Ú!torchmetrics.functional.image.sccr   r'   r   Útorchmetrics.metricr	   r   r   r!   r    ú<module>rE      sª   ðð !Ð  Ð  Ð  Ð  Ð  Ð  Ð  à €€€Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à VÐ VÐ VÐ VÐ VÐ VØ 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø &Ð &Ð &Ð &Ð &Ð &ð;+ð ;+ð ;+ð ;+ð ;+ Fñ ;+ô ;+ð ;+ð ;+ð ;+r!   