§
    ’©ºj0  ã                   óö   — d dl mZ d dlZd dlmZ esdgZ	 ddej        dej        dee         ded	ej        f
d
„Zddej        de	d	ej        fd„Z
	 	 	 ddej        dej        dee         dede	d	ej        fd„ZdS )é    )ÚOptionalN)Ú_TORCHVISION_AVAILABLEÚ complete_intersection_over_unionÚpredsÚtargetÚiou_thresholdÚreplacement_valÚreturnc                 ó`  — | j         dk    s| j        d         dk    rt          d| j        › �¦  «        ‚|j         dk    s|j        d         dk    rt          d|j        › �¦  «        ‚ddlm} |                      ¦   «         dk    r=t          j        |j        d         |j        d         |j        t          j	        ¬¦  «        S |                     ¦   «         dk    r=t          j        | j        d         | j        d         | j        t          j	        ¬¦  «        S  || |¦  «        }|�	||||k     <   |S )	Né   éÿÿÿÿé   z-Expected preds to be of shape (N, 4) but got z.Expected target to be of shape (N, 4) but got r   )Úcomplete_box_iou)ÚdeviceÚdtype)
ÚndimÚshapeÚ
ValueErrorÚtorchvision.opsr   ÚnumelÚtorchÚzerosr   Úfloat32)r   r   r   r	   r   Úious         úv/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/detection/ciou.pyÚ_ciou_updater      s)  € ð „z�Q‚€˜%œ+ bœ/¨QÒ.Ð.ÝÐVÈÌÐVÐVÑWÔWÐWØ„{�aÒÐ˜6œ<¨Ô+¨qÒ0Ð0ÝÐXÈ&Ì,ÐXÐXÑYÔYÐYà0Ð0Ð0Ð0Ð0Ð0à‡{‚{�}„}˜ÒÐÝŒ{˜6œ<¨œ?¨F¬L¸¬OÀFÄMÕY^ÔYfÐgÑgÔgÐgØ‡|‚|�~„~˜ÒÐÝŒ{˜5œ; qœ>¨5¬;°q¬>À%Ä,ÕV[ÔVcÐdÑdÔdÐdà
Ð
˜5 &Ñ
)Ô
)€CØÐ Ø#2ˆˆC�-ÒÑ Ø€Jó    Tr   Ú	aggregatec                 ó¼   — |s| S |                       ¦   «         dk    r&|                      ¦   «                              ¦   «         nt          j        d| j        ¬¦  «        S )Nr   g        )r   )r   ÚdiagÚmeanr   Útensorr   )r   r   s     r   Ú_ciou_computer#   -   sM   € Øð Øˆ
Ø #§	¢	¡¤¨a¢ ˆ3�8Š8‰:Œ:�?Š?ÑÔÐµU´\À#ÈcÌjÐ5YÑ5YÔ5YÐYr   c                 óŽ   — t           st          dt          j        › d�¦  «        ‚t	          | |||¦  «        }t          ||¦  «        S )aY	  Compute Complete Intersection over Union (`CIOU`_) between two sets of boxes.

    Both sets of boxes are expected to be in (x1, y1, x2, y2) format with 0 <= x1 < x2 and 0 <= y1 < y2.

    Args:
        preds:
            The input tensor containing the predicted bounding boxes.
        target:
            The tensor containing the ground truth.
        iou_threshold:
            Optional IoU thresholds for evaluation. If set to `None` the threshold is ignored.
        replacement_val:
            Value to replace values under the threshold with.
        aggregate:
            Return the average value instead of the full matrix of values

    Example::
        By default iou is aggregated across all box pairs e.g. mean along the diagonal of the IoU matrix:

        >>> import torch
        >>> from torchmetrics.functional.detection import complete_intersection_over_union
        >>> preds = torch.tensor(
        ...     [
        ...         [296.55, 93.96, 314.97, 152.79],
        ...         [328.94, 97.05, 342.49, 122.98],
        ...         [356.62, 95.47, 372.33, 147.55],
        ...     ]
        ... )
        >>> target = torch.tensor(
        ...     [
        ...         [300.00, 100.00, 315.00, 150.00],
        ...         [330.00, 100.00, 350.00, 125.00],
        ...         [350.00, 100.00, 375.00, 150.00],
        ...     ]
        ... )
        >>> complete_intersection_over_union(preds, target)
        tensor(0.5790)

    Example::
        By setting `aggregate=False` the IoU score per prediction and target boxes is returned:

        >>> import torch
        >>> from torchmetrics.functional.detection import complete_intersection_over_union
        >>> preds = torch.tensor(
        ...     [
        ...         [296.55, 93.96, 314.97, 152.79],
        ...         [328.94, 97.05, 342.49, 122.98],
        ...         [356.62, 95.47, 372.33, 147.55],
        ...     ]
        ... )
        >>> target = torch.tensor(
        ...     [
        ...         [300.00, 100.00, 315.00, 150.00],
        ...         [330.00, 100.00, 350.00, 125.00],
        ...         [350.00, 100.00, 375.00, 150.00],
        ...     ]
        ... )
        >>> complete_intersection_over_union(preds, target, aggregate=False)
        tensor([[ 0.6883, -0.2072, -0.3352],
                [-0.2217,  0.4881, -0.1913],
                [-0.3971, -0.1543,  0.5606]])

    ú`zf` requires that `torchvision` is installed. Please install with `pip install torchmetrics[detection]`.)r   ÚModuleNotFoundErrorr   Ú__name__r   r#   )r   r   r   r	   r   r   s         r   r   r   3   sb   € õL "ð 
Ý!ðJÕ0Ô9ð Jð Jð Jñ
ô 
ð 	
õ �u˜f m°_Ñ
EÔ
E€CÝ˜˜iÑ(Ô(Ð(r   )r   )T)Nr   T)Útypingr   r   Útorchmetrics.utilities.importsr   Ú__doctest_skip__ÚTensorÚfloatr   Úboolr#   r   © r   r   ú<module>r/      sN  ðð Ð Ð Ð Ð Ð à €€€à AÐ AÐ AÐ AÐ AÐ Aàð <Ø:Ð;Ðð ijðð ØŒ<ðØ!&¤ðØ>FÀu¼oðØ`eðà
„\ðð ð ð ð*Zð Z�u”|ð Z°ð ZÀÄð Zð Zð Zð Zð &*ØØðL)ð L)ØŒ<ðL)àŒLðL)ð ˜E”?ðL)ð ð	L)ð
 ðL)ð „\ðL)ð L)ð L)ð L)ð L)ð L)r   