§
    ’©ºj5  ã                   ó˜   — d dl mZ d dlmZmZmZ d dl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mZ esd	gZ G d
„ de¦  «        ZdS )é    )ÚSequence)ÚAnyÚOptionalÚUnionN)ÚTensor)Ú_rmse_sw_computeÚ_rmse_sw_update)ÚMetric)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEz+RootMeanSquaredErrorUsingSlidingWindow.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<   eed	<   d
Zee         ed<   eed<   	 ddedeeef         dd
fˆ fd„Zdededd
fd„Zdee         fd„Z	 ddeeeee         f                  dee         defd„Zˆ xZS )Ú&RootMeanSquaredErrorUsingSlidingWindowa@  Computes Root Mean Squared Error (RMSE) using sliding window.

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

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

    - ``rmse_sw`` (:class:`~torch.Tensor`): returns float scalar tensor with average RMSE-SW value over sample

    Args:
        window_size: Sliding window used for rmse calculation
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Example:
        >>> from torch import rand
        >>> from torchmetrics.image import RootMeanSquaredErrorUsingSlidingWindow
        >>> preds = rand(4, 3, 16, 16)
        >>> target = rand(4, 3, 16, 16)
        >>> rmse_sw = RootMeanSquaredErrorUsingSlidingWindow()
        >>> rmse_sw(preds, target)
        tensor(0.4158)

    Raises:
        ValueError: If ``window_size`` is not a positive integer.

    FÚhigher_is_betterTÚis_differentiableÚfull_state_updateç        Úplot_lower_boundÚrmse_val_sumNÚrmse_mapÚtotal_imagesé   Úwindow_sizeÚkwargsÚreturnc                 ón  •—  t          ¦   «         j        di |¤Ž t          |t          ¦  «        rt          |t          ¦  «        r|dk     rt	          d¦  «        ‚|| _        |                      dt          j        d¦  «        d¬¦  «         |                      dt          j        d¦  «        d¬¦  «         d S )	Né   z<Argument `window_size` is expected to be a positive integer.r   r   Úsum)ÚdefaultÚdist_reduce_fxr   © )	ÚsuperÚ__init__Ú
isinstanceÚintÚ
ValueErrorr   Ú	add_stateÚtorchÚtensor)Úselfr   r   Ú	__class__s      €új/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/image/rmse_sw.pyr#   z/RootMeanSquaredErrorUsingSlidingWindow.__init__E   s¶   ø€ ð
 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ý˜+¥sÑ+Ô+ð 	]µ
¸;ÍÑ0LÔ0Lð 	]ÐQ\Ð_`ÒQ`ÐQ`ÝÐ[Ñ\Ô\Ð\Ø&ˆÔà�Š�~­u¬|¸CÑ/@Ô/@ÐQVˆÑWÔWÐWØ�Š�~­u¬|¸CÑ/@Ô/@ÐQVˆÑWÔWÐWÐWÐWó    ÚpredsÚtargetc                 óô   — | j         €5|j        dd…         }t          j        ||j        |j        ¬¦  «        | _         t          ||| j        | j        | j         | j	        ¦  «        \  | _        | _         | _	        dS )z*Update state with predictions and targets.Nr   )ÚdtypeÚdevice)
r   Úshaper(   Úzerosr1   r2   r	   r   r   r   )r*   r.   r/   Ú
_img_shapes       r,   Úupdatez-RootMeanSquaredErrorUsingSlidingWindow.updateR   sr   € àŒ=Ð Øœ a b bÔ)ˆJÝ!œK¨
¸&¼,ÈvÌ}Ð]Ñ]Ô]ˆDŒMå>MØ�6˜4Ô+¨TÔ->ÀÄÈtÔO`ñ?
ô ?
Ñ;ˆÔ˜4œ=¨$Ô*;Ð*;Ð*;r-   c                 ó^   — | j         €J ‚t          | j        | j         | j        ¦  «        \  }}|S )zWCompute Root Mean Squared Error (using sliding window) and potentially return RMSE map.)r   r   r   r   )r*   ÚrmseÚ_s      r,   Úcomputez.RootMeanSquaredErrorUsingSlidingWindow.compute\   s2   € àŒ}Ð(Ð(Ð(Ý" 4Ô#4°d´mÀTÔEVÑWÔW‰ˆˆaØˆr-   Ú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 import RootMeanSquaredErrorUsingSlidingWindow
            >>> metric = RootMeanSquaredErrorUsingSlidingWindow()
            >>> metric.update(torch.rand(4, 3, 16, 16), torch.rand(4, 3, 16, 16))
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

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

        )Ú_plot)r*   r;   r<   s      r,   Úplotz+RootMeanSquaredErrorUsingSlidingWindow.plotb   s   € ðP �zŠz˜#˜rÑ"Ô"Ð"r-   )r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   Úfloatr   r   r   r%   ÚdictÚstrr   r#   r6   r:   r   r   r   r   r?   Ú__classcell__)r+   s   @r,   r   r      s�  ø€ € € € € € ðð ð: #Ð�dÐ"Ð"Ñ"Ø"Ð�tÐ"Ð"Ñ"Ø#Ð�tÐ#Ð#Ñ#Ø!Ð�eÐ!Ð!Ñ!àÐÐÑØ!%€Hˆh�vÔÐ%Ð%Ñ%ØÐÐÑð ðXð XàðXð �s˜C�x”.ðXð 
ð	Xð Xð Xð Xð Xð Xð
˜Fð 
¨Fð 
°tð 
ð 
ð 
ð 
ð˜ &Ô)ð ð ð ð ð _cð(#ð (#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð(#ØIQÐRZÔI[ð(#à	ð(#ð (#ð (#ð (#ð (#ð (#ð (#ð (#r-   r   )Úcollections.abcr   Útypingr   r   r   r(   r   Ú%torchmetrics.functional.image.rmse_swr   r	   Útorchmetrics.metricr
   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r!   r-   r,   ú<module>rQ      sö   ðð %Ð $Ð $Ð $Ð $Ð $Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à €€€Ø Ð Ð Ð Ð Ð à SÐ SÐ SÐ SÐ SÐ SÐ SÐ SØ &Ð &Ð &Ð &Ð &Ð &Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð GØEÐFÐðl#ð l#ð l#ð l#ð l#¨Vñ l#ô l#ð l#ð l#ð l#r-   