§
    ’©ºjU  ã                   ó8  — 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
 d dlmZ d dlmZmZmZ d dlmZ d d	lmZ d
ededeeef         fd„Z	 	 	 	 	 	 	 	 d.d
edededeeee         f         deeee         f         deeeeeef         f                  dededededeeeeef         f         fd„Z	 d/deded          defd!„Z	 	 	 	 	 	 	 	 	 d0d
edededeeee         f         deeee         f         ded          deeeeeef         f                  dededededeeeeef         f         fd"„Z	 	 	 	 	 	 	 d1d
edededeeee         f         deeee         f         deeeeeef         f                  deded#eed$                  deeef         fd%„Z	 	 	 	 	 	 	 	 d2d
edededeeee         f         deeee         f         deeeeeef         f                  deded'eeeeeeef         eed(f         f         d#eed$                  defd)„Z	 d/d*eded          defd+„Z	 	 	 	 	 	 	 	 	 d3d
edededeeee         f         deeee         f         ded          deeeeeef         f                  deded'eed(f         d#eed$                  defd-„Z dS )4é    )ÚSequence)ÚListÚOptionalÚUnionN)ÚTensor)Ú
functional)ÚLiteral)Ú_gaussian_kernel_2dÚ_gaussian_kernel_3dÚ_reflection_pad_3d)Ú_check_same_shape©ÚreduceÚpredsÚtargetÚreturnc                 óê   — | j         |j         k    r|                     | j         ¦  «        }t          | |¦  «         t          | j        ¦  «        dvr t          d| j        › d|j        › d�¦  «        ‚| |fS )zªUpdate and returns variables required to compute Structural Similarity Index Measure.

    Args:
        preds: Predicted tensor
        target: Ground truth tensor

    )é   é   zMExpected `preds` and `target` to have BxCxHxW or BxCxDxHxW shape. Got preds: z and target: ú.)ÚdtypeÚtor   ÚlenÚshapeÚ
ValueError)r   r   s     úr/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/image/ssim.pyÚ_ssim_check_inputsr      s—   € ð „{�f”lÒ"Ð"Ø—’˜5œ;Ñ'Ô'ˆÝ�e˜VÑ$Ô$Ð$Ý
ˆ5Œ;ÑÔ˜vÐ%Ð%ÝðEØ œ;ðEð EØ5;´\ðEð Eð Eñ
ô 
ð 	
ð �&ˆ=Ðó    Tç      ø?é   ç{®Gáz„?ç¸…ëQ¸ž?FÚgaussian_kernelÚsigmaÚkernel_sizeÚ
data_rangeÚk1Úk2Úreturn_full_imageÚreturn_contrast_sensitivityc
                 óÄ  — | j         dk    }
t          |t          ¦  «        s|
rd|gz  nd|gz  }t          |t          ¦  «        s|
rd|gz  nd|gz  }t          |¦  «        t          |j        ¦  «        dz
  k    r4t          dt          |¦  «        › dt          |j        ¦  «        › �¦  «        ‚t          |¦  «        dvrt          dt          |¦  «        › �¦  «        ‚t          |¦  «        t          |j        ¦  «        dz
  k    r4t          dt          |¦  «        › dt          |j        ¦  «        › �¦  «        ‚t          |¦  «        dvrt          dt          |¦  «        › �¦  «        ‚|r|	rt          d¦  «        ‚t          d	„ |D ¦   «         ¦  «        rt          d
|› d�¦  «        ‚t          d„ |D ¦   «         ¦  «        rt          d|› d�¦  «        ‚|€_t          |                      ¦   «         |                      ¦   «         z
  |                     ¦   «         |                     ¦   «         z
  ¦  «        }nlt          |t          ¦  «        rWt          j        | |d         |d         ¬¦  «        } t          j        ||d         |d         ¬¦  «        }|d         |d         z
  }t          ||z  d¦  «        }t          ||z  d¦  «        }| j        }|                      d¦  «        }| j        }d„ |D ¦   «         }|r|d         dz
  dz  }|d         dz
  dz  }n|d         dz
  dz  }|d         dz
  dz  }|
rH|d         dz
  dz  }t!          | |||¦  «        } t!          ||||¦  «        }|rt#          |||||¦  «        }nKt%          j        | ||||fd¬¦  «        } t%          j        |||||fd¬¦  «        }|rt)          |||||¦  «        }|sFt          j        |dg|¢R ||¬¦  «        t          j        t          j        |||¬¦  «        ¦  «        z  }t          j        | || | z  ||z  | |z  f¦  «        }|
rt%          j        |||¬¦  «        nt%          j        |||¬¦  «        }|                     | j        d         ¦  «        }|d                              d¦  «        }|d                              d¦  «        }|d         |d         z  }t          j        |d         |z
  d¬¦  «        }t          j        |d         |z
  d¬¦  «        }|d         |z
  }d|                     |¦  «        z  |z   }||z                        |¦  «        |z   }d|z  |z   |z  ||z   |z   |z  z  } |	r–||z  }!|
r|!d|| …|| …|| …f         }!n|!d|| …|| …f         }!|                      | j        d         d¦  «                             d¦  «        |!                     |!j        d         d¦  «                             d¦  «        fS |r6|                      | j        d         d¦  «                             d¦  «        | fS |                      | j        d         d¦  «                             d¦  «        S )a%  Compute Structural Similarity Index Measure.

    Args:
        preds: estimated image
        target: ground truth image
        gaussian_kernel: If true (default), a gaussian kernel is used, if false a uniform kernel is used
        sigma: Standard deviation of the gaussian kernel, anisotropic kernels are possible.
            Ignored if a uniform kernel is used
        kernel_size: the size of the uniform kernel, anisotropic kernels are possible.
            Ignored if a Gaussian kernel is used
        data_range: Range of the image. If ``None``, it is determined from the image (max - min)
        k1: Parameter of SSIM.
        k2: Parameter of SSIM.
        return_full_image: If true, the full ``ssim`` image is returned as a second argument.
            Mutually exclusive with ``return_contrast_sensitivity``
        return_contrast_sensitivity: If true, the contrast term is returned as a second argument.
            The luminance term can be obtained with luminance=ssim/contrast
            Mutually exclusive with ``return_full_image``

    r   é   é   z`kernel_size` has dimension zD, but expected to be two less that target dimensionality, which is: )r-   r,   zMExpected `kernel_size` dimension to be 2 or 3. `kernel_size` dimensionality: zWArguments `return_full_image` and `return_contrast_sensitivity` are mutually exclusive.c              3   ó4   K  — | ]}|d z  dk    p|dk    V — ŒdS )r-   r   N© )Ú.0Úxs     r   ú	<genexpr>z_ssim_update.<locals>.<genexpr>k   s3   è è € Ð
5Ð
5 Aˆ1ˆq‰5�AŠ:Ð˜˜ašÐ
5Ð
5Ð
5Ð
5Ð
5Ð
5r   z8Expected `kernel_size` to have odd positive number. Got r   c              3   ó"   K  — | ]
}|d k    V — ŒdS )r   Nr/   )r0   Úys     r   r2   z_ssim_update.<locals>.<genexpr>n   s&   è è € Ð
!Ð
!�aˆ1�Š6Ð
!Ð
!Ð
!Ð
!Ð
!Ð
!r   z.Expected `sigma` to have positive number. Got Nr   é   )ÚminÚmaxc                 óD   — g | ]}t          d |z  dz   ¦  «        dz  dz   ‘ŒS )g      @g      à?r-   r5   )Úint)r0   Úss     r   ú
<listcomp>z _ssim_update.<locals>.<listcomp>~   s2   € ÐCÐCÐC¸�˜S 1™W s™]Ñ+Ô+¨aÑ/°!Ñ3ÐCÐCÐCr   Úreflect)Úmode)r   Údevice)Úgroupsg        )r6   r   .éÿÿÿÿ)ÚndimÚ
isinstancer   r   r   r   Úanyr7   r6   ÚtupleÚtorchÚclampÚpowr>   Úsizer   r   r   ÚFÚpadr
   ÚonesÚprodÚtensorÚcatÚconv3dÚconv2dÚsplitr   ÚreshapeÚmean)"r   r   r#   r$   r%   r&   r'   r(   r)   r*   Úis_3dÚc1Úc2r>   Úchannelr   Úgauss_kernel_sizeÚpad_hÚpad_wÚpad_dÚkernelÚ
input_listÚoutputsÚoutput_listÚ
mu_pred_sqÚmu_target_sqÚmu_pred_targetÚsigma_pred_sqÚsigma_target_sqÚsigma_pred_targetÚupperÚlowerÚssim_idx_full_imageÚcontrast_sensitivitys"                                     r   Ú_ssim_updaterj   .   sF  € ð@ ŒJ˜!ŠO€Eå�k¥8Ñ,Ô,ð HØ+0ÐG�a˜;˜-Ñ'Ð'°a¸;¸-Ñ6GˆÝ�e�XÑ&Ô&ð 6Ø$Ð5��U�G‘�¨!¨u¨g©+ˆå
ˆ;ÑÔ�3˜vœ|Ñ,Ô,¨qÑ0Ò0Ð0Ýð.­3¨{Ñ+;Ô+;ð .ð .Ý˜fœlÑ+Ô+ð.ð .ñ
ô 
ð 	
õ ˆ;ÑÔ˜vÐ%Ð%ÝØnÕ\_Ð`kÑ\lÔ\lÐnÐnñ
ô 
ð 	
õ ˆ5�z„z•S˜œÑ&Ô&¨Ñ*Ò*Ð*Ýð.­3¨{Ñ+;Ô+;ð .ð .Ý˜fœlÑ+Ô+ð.ð .ñ
ô 
ð 	
õ ˆ5�z„z˜ÐÐÝØnÕ\_Ð`kÑ\lÔ\lÐnÐnñ
ô 
ð 	
ð ð tÐ8ð tÝÐrÑsÔsÐså
Ð
5Ð
5¨Ð
5Ñ
5Ô
5Ñ5Ô5ð dÝÐbÐT_ÐbÐbÐbÑcÔcÐcå
Ð
!Ð
!˜5Ð
!Ñ
!Ô
!Ñ!Ô!ð TÝÐRÈ%ÐRÐRÐRÑSÔSÐSàÐÝ˜Ÿš™œ u§y¢y¡{¤{Ñ2°F·J²J±L´LÀ6Ç:Â:Á<Ä<Ñ4OÑPÔPˆ
ˆ
Ý	�J¥Ñ	&Ô	&ð 3Ý”˜E z°!¤}¸*ÀQ¼-ÐHÑHÔHˆÝ”˜V¨°A¬¸JÀq¼MÐJÑJÔJˆØ ”] Z°¤]Ñ2ˆ
å	ˆR�*‰_˜aÑ	 Ô	 €BÝ	ˆR�*‰_˜aÑ	 Ô	 €BØŒ\€Fà�jŠj˜‰mŒm€GØŒK€EØCÐC¸UÐCÑCÔCÐàð *Ø" 1Ô%¨Ñ)¨aÑ/ˆØ" 1Ô%¨Ñ)¨aÑ/ˆˆà˜Q” !Ñ#¨Ñ)ˆØ˜Q” !Ñ#¨Ñ)ˆàð 
[Ø˜Q” !Ñ#¨Ñ)ˆÝ" 5¨%°¸Ñ>Ô>ˆÝ# F¨E°5¸%Ñ@Ô@ˆØð 	[Ý(¨Ð2CÀUÈEÐSYÑZÔZˆFøå”�e˜e U¨E°5Ð9À	ÐJÑJÔJˆÝ”�v  u¨e°UÐ;À)ÐLÑLÔLˆØð 	[Ý(¨Ð2CÀUÈEÐSYÑZÔZˆFàð 
Ý”˜W aÐ6¨+Ð6Ð6¸eÈFÐSÑSÔSÕV[ÔV`ÝŒL˜¨E¸&ÐAÑAÔAñW
ô W
ñ 
ˆõ ”˜E 6¨5°5©=¸&À6¹/È5ÐSYÉ>ÐZÑ[Ô[€Jà>CÐu�aŒh�z 6°'Ð:Ñ:Ô:Ð:ÍÌÐR\Ð^dÐmtÐIuÑIuÔIu€Gà—-’- ¤¨A¤Ñ/Ô/€Kà˜Q”×#Ò# AÑ&Ô&€JØ˜q”>×%Ò% aÑ(Ô(€LØ  ”^ k°!¤nÑ4€Nõ ”K ¨A¤°Ñ ;ÀÐEÑEÔE€MÝ”k +¨a¤.°<Ñ"?ÀSÐIÑIÔI€OØ# Aœ¨Ñ7ÐàÐ!×$Ò$ UÑ+Ô+Ñ+¨bÑ0€EØ˜_Ñ,×0Ò0°Ñ7Ô7¸"Ñ<€Eà Ñ.°Ñ3°uÑ<À*È|ÑB[Ð^`ÑB`ÐdiÑAiÑjÐà"ð 	Ø$ u™}ÐØð 	YØ#7¸¸UÀEÀ6¸\È5ÐRWÐQWÈ<ÐY^Ð`eÐ_eÐYeÐ8eÔ#fÐ Ð à#7¸¸UÀEÀ6¸\È5ÐRWÐQWÈ<Ð8WÔ#XÐ à"×*Ò*Ð+>Ô+DÀQÔ+GÈÑLÔL×QÒQÐRTÑUÔUÐWk×WsÒWsØ Ô& qÔ)¨2ñX
ô X
ç
Š$ˆr‰(Œ(ðð 	ð ð kØ"×*Ò*Ð+>Ô+DÀQÔ+GÈÑLÔL×QÒQÐRTÑUÔUÐWjÐjÐjà×&Ò&Ð':Ô'@ÀÔ'CÀRÑHÔH×MÒMÈbÑQÔQÐQr   Úelementwise_meanÚsimilaritiesÚ	reduction)rk   ÚsumÚnoneNc                 ó"   — t          | |¦  «        S )aÂ  Apply the specified reduction to pre-computed structural similarity.

    Args:
        similarities: per image similarities for a batch of images.
        reduction: a method to reduce metric score over individual batch scores

                - ``'elementwise_mean'``: takes the mean
                - ``'sum'``: takes the sum
                - ``'none'`` or ``None``: no reduction will be applied

    Returns:
        The reduced SSIM score

    r   )rl   rm   s     r   Ú_ssim_computerq   ½   s   € õ$ �, 	Ñ*Ô*Ð*r   c                 óÔ   — t          | |¦  «        \  } }t          | ||||||||	|
¦
  «
        }t          |t          ¦  «        r|\  }}t	          ||¦  «        |fS |}t	          ||¦  «        S )aµ  Compute Structural Similarity Index Measure.

    Args:
        preds: estimated image
        target: ground truth image
        gaussian_kernel: If true (default), a gaussian kernel is used, if false a uniform kernel is used
        sigma: Standard deviation of the gaussian kernel, anisotropic kernels are possible.
            Ignored if a uniform kernel is used
        kernel_size: the size of the uniform kernel, anisotropic kernels are possible.
            Ignored if a Gaussian kernel is used
        reduction: a method to reduce metric score over labels.

            - ``'elementwise_mean'``: takes the mean
            - ``'sum'``: takes the sum
            - ``'none'`` or ``None``: no reduction will be applied

        data_range:
            the range of the data. If None, it is determined from the data (max - min). If a tuple is provided then
            the range is calculated as the difference and input is clamped between the values.
        k1: Parameter of SSIM.
        k2: Parameter of SSIM.
        return_full_image: If true, the full ``ssim`` image is returned as a second argument.
            Mutually exclusive with ``return_contrast_sensitivity``
        return_contrast_sensitivity: If true, the constant term is returned as a second argument.
            The luminance term can be obtained with luminance=ssim/contrast
            Mutually exclusive with ``return_full_image``

    Return:
        Tensor with SSIM score

    Raises:
        TypeError:
            If ``preds`` and ``target`` don't have the same data type.
        ValueError:
            If ``preds`` and ``target`` don't have ``BxCxHxW shape``.
        ValueError:
            If the length of ``kernel_size`` or ``sigma`` is not ``2``.
        ValueError:
            If one of the elements of ``kernel_size`` is not an ``odd positive number``.
        ValueError:
            If one of the elements of ``sigma`` is not a ``positive number``.

    Example:
        >>> from torchmetrics.functional.image import structural_similarity_index_measure
        >>> preds = torch.rand([3, 3, 256, 256])
        >>> target = preds * 0.75
        >>> structural_similarity_index_measure(preds, target)
        tensor(0.9219)

    )r   rj   rB   rD   rq   )r   r   r#   r$   r%   rm   r&   r'   r(   r)   r*   Úsimilarity_packÚ
similarityÚimages                 r   Ú#structural_similarity_index_measurerv   Ò   s�   € õ~ ' u¨fÑ5Ô5�M€Eˆ6Ý"ØØØØØØØ
Ø
ØØ#ñô €Oõ �/¥5Ñ)Ô)ð ;Ø+Ñˆ
�EÝ˜Z¨Ñ3Ô3°UÐ:Ð:à €JÝ˜ YÑ/Ô/Ð/r   Ú	normalize©ÚreluÚsimplec	                 óœ   — t          | |||||||d¬¦	  «	        \  }	}
|dk    r(t          j        |	¦  «        }	t          j        |
¦  «        }
|	|
fS )NT)r*   ry   )rj   rE   ry   )r   r   r#   r$   r%   r&   r'   r(   rw   Úsimri   s              r   Ú_get_normalized_sim_and_csr}   '  sp   € õ !-ØØØØØØØ
Ø
Ø$(ð
!ñ 
!ô 
!Ñ€CÐ	ð �FÒÐÝŒj˜‰oŒoˆÝ$œzÐ*>Ñ?Ô?ÐØÐ$Ð$Ð$r   ©gÇº¸�ð¦?g×4ï8EGÒ?g÷äa¡Ö4Ó?g¼?Î?g9EGrùÁ?Úbetas.c
                 ó(  — g }
| j         dk    }t          |t          ¦  «        s|rd|gz  nd|gz  }t          |t          ¦  «        s|rd|gz  nd|gz  }|                      ¦   «         d         dt	          |¦  «        z  k     s.|                      ¦   «         d         dt	          |¦  «        z  k     r3t          dt	          |¦  «        › ddt	          |¦  «        z  › d�¦  «        ‚t          d	t	          |¦  «        d	z
  ¦  «        dz  }|                      ¦   «         d         |z  |d
         d	z
  k    r8t          dt	          |¦  «        › d|d
         › d|d
         d	z
  |z  › d�¦  «        ‚|                      ¦   «         d         |z  |d	         d	z
  k    r8t          dt	          |¦  «        › d|d	         › d|d	         d	z
  |z  › d�¦  «        ‚t          t	          |¦  «        ¦  «        D ]¼}t          | ||||||||	¬¦	  «	        \  }}|
 	                    |¦  «         t	          |¦  «        dk    r+t          j        | d¦  «        } t          j        |d¦  «        }Œpt	          |¦  «        dk    r+t          j        | d¦  «        } t          j        |d¦  «        }Œ®t          d¦  «        ‚||
d<   t          j        |
¦  «        }|	dk    r|d	z   dz  }t          j        ||j        ¬¦  «                             dd	¦  «        }||z  }t          j        |d
¬¦  «        S )a±  Compute Multi-Scale Structural Similarity Index Measure.

    Adapted from: https://github.com/jorge-pessoa/pytorch-msssim/blob/master/pytorch_msssim/__init__.py.

    Args:
        preds: estimated image
        target: ground truth image
        gaussian_kernel: If true, a gaussian kernel is used, if false a uniform kernel is used
        sigma: Standard deviation of the gaussian kernel
        kernel_size: size of the gaussian kernel
        reduction: a method to reduce metric score over labels.

            - ``'elementwise_mean'``: takes the mean
            - ``'sum'``: takes the sum
            - ``'none'`` or ``None``: no reduction will be applied

        data_range: Range of the image. If ``None``, it is determined from the image (max - min)
        k1: Parameter of structural similarity index measure.
        k2: Parameter of structural similarity index measure.
        betas: Exponent parameters for individual similarities and contrastive sensitives returned by different image
            resolutions.
        normalize: When MultiScaleSSIM loss is used for training, it is desirable to use normalizes to improve the
            training stability. This `normalize` argument is out of scope of the original implementation [1], and it is
            adapted from https://github.com/jorge-pessoa/pytorch-msssim instead.

    Raises:
        ValueError:
            If the image height or width is smaller then ``2 ** len(betas)``.
        ValueError:
            If the image height is smaller than ``(kernel_size[0] - 1) * max(1, (len(betas) - 1)) ** 2``.
        ValueError:
            If the image width is smaller than ``(kernel_size[0] - 1) * max(1, (len(betas) - 1)) ** 2``.

    r   r,   r-   r@   éþÿÿÿz)For a given number of `betas` parameters zH, the image height and width dimensions must be larger than or equal to r   r5   r   z and kernel size z', the image height must be larger than z&, the image width must be larger than )rw   )r-   r-   )r-   r-   r-   z(length of kernel_size is neither 2 nor 3rz   )r>   )Úaxis)rA   rB   r   rH   r   r   r7   Úranger}   ÚappendrI   Ú
avg_pool2dÚ
avg_pool3drE   ÚstackrM   r>   ÚviewrL   )r   r   r#   r$   r%   r&   r'   r(   r   rw   Úmcs_listrT   Ú
_betas_divÚ_r|   ri   Ú	mcs_stackÚmcs_weighteds                     r   Ú_multiscale_ssim_updaterŽ   C  sˆ  € ðh  €HàŒJ˜!ŠO€Eå�k¥8Ñ,Ô,ð HØ+0ÐG�a˜;˜-Ñ'Ð'°a¸;¸-Ñ6GˆÝ�e�XÑ&Ô&ð 6Ø$Ð5��U�G‘�¨!¨u¨g©+ˆà‡z‚z�|„|�BÔ˜!�s 5™zœz™/Ò)Ð)¨U¯ZªZ©\¬\¸"Ô-=ÀÅSÈÁZÄZÁÒ-OÐ-OÝð;½¸E¹
¼
ð ;ð ;Ø()­S°©Z¬Z©ð;ð ;ð ;ñ
ô 
ð 	
õ
 �Q�˜U™œ a™Ñ)Ô)¨QÑ.€JØ‡z‚z�|„|�BÔ˜:Ñ%¨°Q¬¸!Ñ);Ò;Ð;ÝðZ½¸E¹
¼
ð Zð ZÐU`ÐabÔUcð Zð ZØ6AÀ!´nÀqÑ6HÈJÑ5VðZð Zð Zñ
ô 
ð 	
ð ‡z‚z�|„|�BÔ˜:Ñ%¨°Q¬¸!Ñ);Ò;Ð;ÝðY½¸E¹
¼
ð Yð YÐU`ÐabÔUcð Yð YØ5@À´^ÀaÑ5GÈ:Ñ4UðYð Yð Yñ
ô 
ð 	
õ
 •3�u‘:”:ÑÔð Ið IˆÝ$>Ø�6˜?¨E°;À
ÈBÐPRÐ^gð%
ñ %
ô %
Ñ!ˆÐ!ð 	�ŠÐ,Ñ-Ô-Ð-åˆ{ÑÔ˜qÒ Ð Ý”L ¨Ñ/Ô/ˆEÝ”\ &¨&Ñ1Ô1ˆFˆFÝ�ÑÔ Ò"Ð"Ý”L ¨	Ñ2Ô2ˆEÝ”\ &¨)Ñ4Ô4ˆFˆFåÐGÑHÔHÐHà€HˆR�LÝ”˜HÑ%Ô%€Ià�HÒÐØ ‘] aÑ'ˆ	åŒL˜ yÔ'7Ð8Ñ8Ô8×=Ò=¸bÀ!ÑDÔD€EØ˜eÑ#€LÝŒ:�l¨Ð+Ñ+Ô+Ð+r   Úmcs_per_imagec                 ó"   — t          | |¦  «        S )aæ  Apply the specified reduction to pre-computed multi-scale structural similarity.

    Args:
        mcs_per_image: per image similarities for a batch of images.
        reduction: a method to reduce metric score over individual batch scores

                - ``'elementwise_mean'``: takes the mean
                - ``'sum'``: takes the sum
                - ``'none'`` or ``None``: no reduction will be applied

    Returns:
        The reduced multi-scale structural similarity

    r   )r�   rm   s     r   Ú_multiscale_ssim_computer‘   ¬  s   € õ$ �- Ñ+Ô+Ð+r   ry   c                 ód  — t          |	t          ¦  «        st          d¦  «        ‚t          |	t          ¦  «        r(t          d„ |	D ¦   «         ¦  «        st          d¦  «        ‚|
r|
dvrt          d¦  «        ‚t	          | |¦  «        \  } }t          | ||||||||	|
¦
  «
        }t          ||¦  «        S )ae
  Compute `MultiScaleSSIM`_, Multi-scale Structural Similarity Index Measure.

    This metric is a generalization of Structural Similarity Index Measure by incorporating image details at different
    resolution scores.

    Args:
        preds: Predictions from model of shape ``[N, C, H, W]``
        target: Ground truth values of shape ``[N, C, H, W]``
        gaussian_kernel: If true, a gaussian kernel is used, if false a uniform kernel is used
        sigma: Standard deviation of the gaussian kernel
        kernel_size: size of the gaussian kernel
        reduction: a method to reduce metric score over labels.

            - ``'elementwise_mean'``: takes the mean
            - ``'sum'``: takes the sum
            - ``'none'`` or ``None``: no reduction will be applied

        data_range:
            the range of the data. If None, it is determined from the data (max - min). If a tuple is provided then
            the range is calculated as the difference and input is clamped between the values.
        k1: Parameter of structural similarity index measure.
        k2: Parameter of structural similarity index measure.
        betas: Exponent parameters for individual similarities and contrastive sensitivities returned by different image
            resolutions.
        normalize: When MultiScaleSSIM loss is used for training, it is desirable to use normalizes to improve the
            training stability. This `normalize` argument is out of scope of the original implementation [1], and it is
            adapted from https://github.com/jorge-pessoa/pytorch-msssim instead.

    Return:
        Tensor with Multi-Scale SSIM score

    Raises:
        TypeError:
            If ``preds`` and ``target`` don't have the same data type.
        ValueError:
            If ``preds`` and ``target`` don't have ``BxCxHxW shape``.
        ValueError:
            If the length of ``kernel_size`` or ``sigma`` is not ``2``.
        ValueError:
            If one of the elements of ``kernel_size`` is not an ``odd positive number``.
        ValueError:
            If one of the elements of ``sigma`` is not a ``positive number``.

    Example:
        >>> from torch import rand
        >>> from torchmetrics.functional.image import multiscale_structural_similarity_index_measure
        >>> preds = rand([3, 3, 256, 256])
        >>> target = preds * 0.75
        >>> multiscale_structural_similarity_index_measure(preds, target, data_range=1.0)
        tensor(0.9628)

    References:
        [1] Multi-Scale Structural Similarity For Image Quality Assessment by Zhou Wang, Eero P. Simoncelli and Alan C.
        Bovik `MultiScaleSSIM`_

    z3Argument `betas` is expected to be of a type tuple.c              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S )N)rB   Úfloat)r0   Úbetas     r   r2   zAmultiscale_structural_similarity_index_measure.<locals>.<genexpr>  s,   è è € Ð+VÐ+VÈ­J°t½UÑ,CÔ,CÐ+VÐ+VÐ+VÐ+VÐ+VÐ+Vr   z5Argument `betas` is expected to be a tuple of floats.rx   zNArgument `normalize` to be expected either `None` or one of 'relu' or 'simple')rB   rD   r   Úallr   rŽ   r‘   )r   r   r#   r$   r%   rm   r&   r'   r(   r   rw   r�   s               r   Ú.multiscale_structural_similarity_index_measurer—   Á  s×   € õJ �e�UÑ#Ô#ð PÝÐNÑOÔOÐOÝ�%�ÑÔð R­Ð+VÐ+VÐPUÐ+VÑ+VÔ+VÑ(VÔ(Vð RÝÐPÑQÔQÐQØð k�YÐ&8Ð8Ð8ÝÐiÑjÔjÐjå& u¨fÑ5Ô5�M€Eˆ6Ý+Øˆv�¨¨{¸JÈÈBÐPUÐW`ñô €Mõ $ M°9Ñ=Ô=Ð=r   )Tr   r    Nr!   r"   FF)rk   )	Tr   r    rk   Nr!   r"   FF)Tr   r    Nr!   r"   N)Tr   r    Nr!   r"   r~   N)	Tr   r    rk   Nr!   r"   r~   ry   )!Úcollections.abcr   Útypingr   r   r   rE   r   Útorch.nnr   rI   Útyping_extensionsr	   Ú#torchmetrics.functional.image.utilsr
   r   r   Útorchmetrics.utilities.checksr   Ú"torchmetrics.utilities.distributedr   rD   r   Úboolr”   r9   rj   rq   rv   r}   rŽ   r‘   r—   r/   r   r   ú<module>r       sz  ðð %Ð $Ð $Ð $Ð $Ð $Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (à €€€Ø Ð Ð Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $Ø %Ð %Ð %Ð %Ð %Ð %à lÐ lÐ lÐ lÐ lÐ lÐ lÐ lÐ lÐ lØ ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5ð˜fð ¨fð ¸¸vÀv¸~Ô9Nð ð ð ð ð, !Ø+.Ø-/Ø>BØØØ#Ø(-ðLRð LRØðLRàðLRð ðLRð �˜ œÐ'Ô(ð	LRð
 �s˜H SœMÐ)Ô*ðLRð ˜˜u e¨E°5¨LÔ&9Ð9Ô:Ô;ðLRð 	ðLRð 	ðLRð ðLRð "&ðLRð ˆ6�5˜ ˜Ô(Ð(Ô)ðLRð LRð LRð LRðb CUð+ð +Øð+àÐ>Ô?ð+ð ð+ð +ð +ð +ð0 !Ø+.Ø-/ØBTØ>BØØØ#Ø(-ðR0ð R0ØðR0àðR0ð ðR0ð �˜ œÐ'Ô(ð	R0ð
 �s˜H SœMÐ)Ô*ðR0ð Ð>Ô?ðR0ð ˜˜u e¨E°5¨LÔ&9Ð9Ô:Ô;ðR0ð 	ðR0ð 	ðR0ð ðR0ð "&ðR0ð ˆ6�5˜ ˜Ô(Ð(Ô)ðR0ð R0ð R0ð R0ðp !Ø+.Ø-/Ø>BØØØ59ð%ð %Øð%àð%ð ð%ð �˜ œÐ'Ô(ð	%ð
 �s˜H SœMÐ)Ô*ð%ð ˜˜u e¨E°5¨LÔ&9Ð9Ô:Ô;ð%ð 	ð%ð 	ð%ð ˜Ð 0Ô1Ô2ð%ð ˆ6�6ˆ>Ôð%ð %ð %ð %ð> !Ø+.Ø-/Ø>BØØðQð 6:ð!f,ð f,Øðf,àðf,ð ðf,ð �˜ œÐ'Ô(ð	f,ð
 �s˜H SœMÐ)Ô*ðf,ð ˜˜u e¨E°5¨LÔ&9Ð9Ô:Ô;ðf,ð 	ðf,ð 	ðf,ð ��u˜e U¨E°5Ð8Ô9¸5ÀÈÀÔ;LÐLÔMðf,ð  ˜Ð 0Ô1Ô2ð!f,ð" ð#f,ð f,ð f,ð f,ðV CUð,ð ,Øð,àÐ>Ô?ð,ð ð,ð ,ð ,ð ,ð0 !Ø+.Ø-/ØBTØ>BØØØGØ5;ðP>ð P>ØðP>àðP>ð ðP>ð �˜ œÐ'Ô(ð	P>ð
 �s˜H SœMÐ)Ô*ðP>ð Ð>Ô?ðP>ð ˜˜u e¨E°5¨LÔ&9Ð9Ô:Ô;ðP>ð 	ðP>ð 	ðP>ð �˜�ÔðP>ð ˜Ð 0Ô1Ô2ðP>ð ðP>ð P>ð P>ð P>ð P>ð P>r   