o
    Ðôj¸  ã                   @   s`   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„ deƒZdS )	é    )ÚAnyÚOptionalN)ÚTensorÚtensor)Ú_scc_per_channel_compute)Ú_scc_update)ÚMetricc                	       sz   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d„Zdededdfdd„Zdefdd„Z‡  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                    sl   t ƒ jdi |¤Ž |d u rtg d¢g d¢g d¢gƒ}|| _|| _| jdtdƒdd� | jdtdƒ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__r   úi/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torchmetrics/image/scc.pyr   ;   s   z&SpatialCorrelationCoefficient.__init__ÚpredsÚtargetc              	      s~   t ˆˆˆjˆjƒ\‰‰‰ ‡ ‡‡‡fdd„tˆ d¡ƒD ƒ}ˆ jt tjtj	|dd�g d¢d�¡7  _ˆ j
ˆ d¡7  _
dS )z*Update state with predictions and targets.c              
      sX   g | ](}t ˆd d …|d d …d d …f  d¡ˆd d …|d d …d d …f  d¡ˆ ˆjƒ‘qS )Né   )Ú_scc_computeÚ	unsqueezer   )Ú.0Úi©r   r   r   r    r   r   Ú
<listcomp>J   s    Jÿÿz8SpatialCorrelationCoefficient.update.<locals>.<listcomp>r!   )Údim)r!   é   é   r   N)r   r   r   ÚrangeÚsizer
   Útorchr   ÚmeanÚcatr   )r   r   r    Zscc_per_channelr   r&   r   ÚupdateG   s   þ,z$SpatialCorrelationCoefficient.updatec                 C   s   | j | j S )zICompute the VIF score based on inputs passed in to ``update`` previously.)r
   r   )r   r   r   r   ÚcomputeQ   s   z%SpatialCorrelationCoefficient.compute)Nr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_differentiableÚhigher_is_betterÚfull_state_updater   Ú__annotations__r   Úintr   r   r0   r1   Ú__classcell__r   r   r   r   r	      s   
 $
r	   )Útypingr   r   r-   r   r   Ú!torchmetrics.functional.image.sccr   r"   r   Útorchmetrics.metricr   r	   r   r   r   r   Ú<module>   s   