§
    ’©ºjÛ  ã                   ó¢   — 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 dl
mZmZ d dlmZmZ d dlmZmZ esdd	gZnesd	gZ G d
„ de	¦  «        ZdS )é    )ÚSequence)ÚAnyÚOptionalÚUnion)ÚTensor)ÚIntersectionOverUnion)Ú_giou_computeÚ_giou_update)Ú_MATPLOTLIB_AVAILABLEÚ_TORCHVISION_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEÚ GeneralizedIntersectionOverUnionz%GeneralizedIntersectionOverUnion.plotc                   ó:  ‡ — e Zd ZU dZdZeed<   dZee         ed<   dZ	eed<   dZ
eed<   d	Zeed
<   	 	 	 	 ddedee         dedededdfˆ fd„Zedededefd„¦   «         Zedededefd„¦   «         Z	 ddeeeee         f                  dee         defd„Zˆ xZS )r   a¢  Compute Generalized Intersection Over Union (`GIoU`_).

    As input to ``forward`` and ``update`` the metric accepts the following input:

    - ``preds`` (:class:`~List`): A list consisting of dictionaries each containing the key-values
      (each dictionary corresponds to a single image). Parameters that should be provided per dict:

        - ``boxes`` (:class:`~torch.Tensor`): float tensor of shape ``(num_boxes, 4)`` containing ``num_boxes``
          detection boxes of the format specified in the constructor.
          By default, this method expects ``(xmin, ymin, xmax, ymax)`` in absolute image coordinates.
        - ``labels`` (:class:`~torch.Tensor`): integer tensor of shape ``(num_boxes)`` containing 0-indexed detection
          classes for the boxes.

    - ``target`` (:class:`~List`): A list consisting of dictionaries each containing the key-values
      (each dictionary corresponds to a single image). Parameters that should be provided per dict:

        - ``boxes`` (:class:`~torch.Tensor`): float tensor of shape ``(num_boxes, 4)`` containing ``num_boxes`` ground
          truth boxes of the format specified in the constructor.
          By default, this method expects ``(xmin, ymin, xmax, ymax)`` in absolute image coordinates.
        - ``labels`` (:class:`~torch.Tensor`): integer tensor of shape ``(num_boxes)`` containing 0-indexed ground truth
          classes for the boxes.

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

    - ``giou_dict``: A dictionary containing the following key-values:

        - giou: (:class:`~torch.Tensor`) with overall giou value over all classes and samples.
        - giou/cl_{cl}: (:class:`~torch.Tensor`), if argument ``class metrics=True``

    Args:
        box_format:
            Input format of given boxes. Supported formats are ``[`xyxy`, `xywh`, `cxcywh`]``.
        iou_thresholds:
            Optional IoU thresholds for evaluation. If set to `None` the threshold is ignored.
        class_metrics:
            Option to enable per-class metrics for IoU. Has a performance impact.
        respect_labels:
            Ignore values from boxes that do not have the same label as the ground truth box. Else will compute Iou
            between all pairs of boxes.
        kwargs:
            Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Example:
        >>> import torch
        >>> from torchmetrics.detection import GeneralizedIntersectionOverUnion
        >>> preds = [
        ...    {
        ...        "boxes": torch.tensor([[296.55, 93.96, 314.97, 152.79], [298.55, 98.96, 314.97, 151.79]]),
        ...        "scores": torch.tensor([0.236, 0.56]),
        ...        "labels": torch.tensor([4, 5]),
        ...    }
        ... ]
        >>> target = [
        ...    {
        ...        "boxes": torch.tensor([[300.00, 100.00, 315.00, 150.00]]),
        ...        "labels": torch.tensor([5]),
        ...    }
        ... ]
        >>> metric = GeneralizedIntersectionOverUnion()
        >>> metric(preds, target)
        {'giou': tensor(0.8613)}

    Raises:
        ModuleNotFoundError:
            If torchvision is not installed with version 0.8.0 or newer.

    FÚis_differentiableTÚhigher_is_betterÚfull_state_updateÚgiouÚ	_iou_typeg      ð¿Ú_invalid_valÚxyxyNÚ
box_formatÚiou_thresholdÚclass_metricsÚrespect_labelsÚkwargsÚreturnc                 óB   •—  t          ¦   «         j        ||||fi |¤Ž d S ©N)ÚsuperÚ__init__)Úselfr   r   r   r   r   Ú	__class__s         €úk/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/detection/giou.pyr!   z)GeneralizedIntersectionOverUnion.__init__j   s1   ø€ ð 	�‰ŒÔ˜ ]°MÀ>Ð\Ð\ÐU[Ð\Ð\Ð\Ð\Ð\ó    Úargsc                  ó   — t          | i |¤ŽS r   )r
   ©r&   r   s     r$   Ú_iou_update_fnz/GeneralizedIntersectionOverUnion._iou_update_fnt   s   € å˜TÐ, VÐ,Ð,Ð,r%   c                  ó   — t          | i |¤ŽS r   )r	   r(   s     r$   Ú_iou_compute_fnz0GeneralizedIntersectionOverUnion._iou_compute_fnx   s   € å˜dÐ- fÐ-Ð-Ð-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 object and Axes object

        Raises:
            ModuleNotFoundError:
                If `matplotlib` is not installed

        .. plot::
            :scale: 75

            >>> # Example plotting single value
            >>> import torch
            >>> from torchmetrics.detection import GeneralizedIntersectionOverUnion
            >>> preds = [
            ...    {
            ...        "boxes": torch.tensor([[296.55, 93.96, 314.97, 152.79], [298.55, 98.96, 314.97, 151.79]]),
            ...        "scores": torch.tensor([0.236, 0.56]),
            ...        "labels": torch.tensor([4, 5]),
            ...    }
            ... ]
            >>> target = [
            ...    {
            ...        "boxes": torch.tensor([[300.00, 100.00, 315.00, 150.00]]),
            ...        "labels": torch.tensor([5]),
            ...    }
            ... ]
            >>> metric = GeneralizedIntersectionOverUnion()
            >>> metric.update(preds, target)
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> import torch
            >>> from torchmetrics.detection import GeneralizedIntersectionOverUnion
            >>> preds = [
            ...    {
            ...        "boxes": torch.tensor([[296.55, 93.96, 314.97, 152.79], [298.55, 98.96, 314.97, 151.79]]),
            ...        "scores": torch.tensor([0.236, 0.56]),
            ...        "labels": torch.tensor([4, 5]),
            ...    }
            ... ]
            >>> target = lambda : [
            ...    {
            ...        "boxes": torch.tensor([[300.00, 100.00, 335.00, 150.00]]) + torch.randint(-10, 10, (1, 4)),
            ...        "labels": torch.tensor([5]),
            ...    }
            ... ]
            >>> metric = GeneralizedIntersectionOverUnion()
            >>> vals = []
            >>> for _ in range(20):
            ...     vals.append(metric(preds, target()))
            >>> fig_, ax_ = metric.plot(vals)

        )Ú_plot)r"   r,   r-   s      r$   Úplotz%GeneralizedIntersectionOverUnion.plot|   s   € ðD �zŠz˜#˜rÑ"Ô"Ð"r%   )r   NFT)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   r   Ústrr   Úfloatr   r!   Ústaticmethodr   r)   r+   r   r   r   r   r0   Ú__classcell__)r#   s   @r$   r   r      sË  ø€ € € € € € ðBð BðH $Ð�tÐ#Ð#Ñ#Ø'+Ð�h˜t”nÐ+Ð+Ñ+Ø"Ð�tÐ"Ð"Ñ"à€IˆsÐÐÑØ€L�%ÐÐÑð !Ø)-Ø#Ø#ð]ð ]àð]ð   ”ð]ð ð	]ð
 ð]ð ð]ð 
ð]ð ]ð ]ð ]ð ]ð ]ð ð-˜cð -¨Sð -°Vð -ð -ð -ñ „\ð-ð ð.˜sð .¨cð .°fð .ð .ð .ñ „\ð.ð _cðB#ð B#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ðB#ØIQÐRZÔI[ðB#à	ðB#ð B#ð B#ð B#ð B#ð B#ð B#ð B#r%   N)Úcollections.abcr   Útypingr   r   r   Útorchr   Útorchmetrics.detection.iour   Ú&torchmetrics.functional.detection.giour	   r
   Útorchmetrics.utilities.importsr   r   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   © r%   r$   ú<module>rD      s  ðð %Ð $Ð $Ð $Ð $Ð $Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à Ð Ð Ð Ð Ð à <Ð <Ð <Ð <Ð <Ð <Ø NÐ NÐ NÐ NÐ NÐ NÐ NÐ NØ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XØ @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð AØ:Ð<cÐdÐÐØ	ð AØ?Ð@Ðð`#ð `#ð `#ð `#ð `#Ð'<ñ `#ô `#ð `#ð `#ð `#r%   