§
    ­¸j× ã                  óT  — U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
m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mZmZmZmZmZ d d	lmZ d dlZd dl Z d dl!Z!d dl"m#c m$Z% d dl&Z&d d
l'm(Z( d dl)m*Z* d dl+m,Z,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5m6Z6m7Z7 d dl8m9Z9m:Z:m;Z; d dl<m=Z=m>Z>m?Z? d dl@mAZAmBZB d dlCmDZDmEZE d dlFmGZGmHZH d dlImJZJmKZK d dlLmMZM erd dlNmOZOmPZP 	  e!jQ        d¦  «         n# eR$ r Y nw xY w eM¦   «         ZS ed¦  «        ZT ed¦  «        ZUdZd„ZVd[d „ZWd\d#„ZXd$ZYd%d&geY¢ZZ e[d'd(h¦  «        Z\ e]d)„ eYD ¦   «         ¦  «        Z^d*e_d+<   d,Z`d*e_d-<   d.Zad/e_d0<   d1Zbd/e_d2<   d]d:„Zcd^d?„Zdd_dC„Zed`dF„ZfdGdHœdadN„ZgdbdT„Zh G dU„ d%¦  «        ZidcdW„ZjdddY„ZkdS )eé    )ÚannotationsN)Údefaultdict)ÚCallable)ÚcopyÚdeepcopy)Úwraps)ÚPath)ÚTYPE_CHECKINGÚAnyÚConcatenateÚLiteralÚ	ParamSpecÚTypeVarÚcast)Úurlparse)ÚImage)Ú_namespace_from_configs)ÚCOCO_CLASS_NAMESÚCOCO_CLASSES)Údownload_pretrain_weightsÚget_model_cache_dir)ÚModelConfigÚTrainConfig)Úactive_keypoint_countsÚinfer_coco_keypoint_schemaÚinfer_yolo_keypoint_schema)Úannotated_category_idsÚfilter_parent_categoriesÚis_valid_coco_dataset)ÚWebDatasetSplitUnavailableErrorÚ
index_nameÚread_shard_index)ÚREQUIRED_YOLO_YAML_FILESÚis_valid_yolo_dataset)ÚModelContextÚ_build_model_context)Ú_is_launcher_main_processÚis_main_process)Ú_is_bg_first_schemaÚ&precision_cholesky_to_pixel_covariance)Ú
get_logger©Ú
DetectionsÚ	KeyPointsÚhighÚ_PÚ_RÚimageútorch.TensorÚreturnúnp.ndarray[Any, Any]c                ó@  — |                       ddd¦  «        }| j        j        dk    r²| j        t          j        t          j        t          j        fv rˆt          d„ | j	        D ¦   «         ¦  «        rj| 
                    d¦  «                             t          j        ¦  «                             ¦   «                              ¦   «                              d¬¦  «        S |                     ¦   «                              ¦   «         dz                       t"          j        ¦  «        S )	ac  Convert a normalized CHW tensor into the uint8 HWC source-image representation.

    For a CUDA tensor in ``float16``/``float32``/``float64`` with every dimension greater than one, the
    multiply-then-truncate cast runs on-device before the (now ``uint8``) transfer; every other input,
    including CPU tensors and CUDA tensors of another dtype such as ``bfloat16``, keeps the previous
    NumPy-side conversion. NaN pixels convert successfully on both paths, but only the NumPy-side path
    emits an incidental invalid-cast ``RuntimeWarning`` for them; the on-device path does not.

    Args:
        image: Source tensor in channel-first layout.

    Returns:
        The writable, owning NumPy array stored in prediction metadata.

    Examples:
        >>> source = _tensor_to_source_array(torch.zeros(3, 2, 2))
        >>> source.shape
        (2, 2, 3)
    é   é   r   Úcudac              3  ó"   K  — | ]
}|d k    V — ŒdS )r7   N© )Ú.0Úsizes     ú[/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/rfdetr/detr.pyú	<genexpr>z*_tensor_to_source_array.<locals>.<genexpr>U   s&   è è € Ð1Ð1˜T��q’Ð1Ð1Ð1Ð1Ð1Ð1ó    éÿ   ÚK)Úorder)ÚpermuteÚdeviceÚtypeÚdtypeÚtorchÚfloat16Úfloat32Úfloat64ÚallÚshapeÚmulÚtoÚuint8ÚcpuÚnumpyr   ÚastypeÚnp)r2   Úsource_views     r>   Ú_tensor_to_source_arrayrV   =   sã   € ð( —-’-  1 aÑ(Ô(€KàŒÔ˜VÒ#Ð#ØŒK�EœM­5¬=½%¼-ÐHÐHÐHÝÐ1Ð1 U¤[Ð1Ñ1Ô1Ñ1Ô1ð Ið �Š˜sÑ#Ô#×&Ò&¥u¤{Ñ3Ô3×7Ò7Ñ9Ô9×?Ò?ÑAÔA×FÒFÈSÐFÑQÔQÐQØ�OŠOÑÔ×#Ò#Ñ%Ô%¨Ñ+×3Ò3µB´HÑ=Ô=Ð=r@   c                ó„   — | j         dk    r| dd…dd…df         } t          j        |                      d¦  «        ¦  «        S )aâ  Return a zero-copy ``uint8`` CHW *view* of a 2-D/3-D HWC image array.

    This is the layout half of ``torchvision.transforms.functional.to_tensor``; the dtype half is
    :func:`_uint8_chw_to_float`. Splitting them lets :meth:`RFDETR.predict` send the
    1-byte-per-channel storage across the host-to-device boundary and widen it on the accelerator,
    instead of widening it 4x on the host and transferring that.

    Args:
        image: A ``(H, W)`` grayscale or ``(H, W, C)`` HWC ``uint8`` array.

    Returns:
        A ``(C, H, W)`` ``uint8`` tensor sharing *image*'s storage.

    Examples:
        >>> arr = np.zeros((2, 2, 3), dtype=np.uint8)
        >>> _uint8_image_to_chw_view(arr).shape
        torch.Size([3, 2, 2])
    r8   N)r8   r   r7   )ÚndimrH   Ú
from_numpyÚ	transpose)r2   s    r>   Ú_uint8_image_to_chw_viewr[   ^   sD   € ð& „z�Q‚€Ø�a�a�a˜˜˜˜D�jÔ!ˆÝÔ˜EŸOšO¨IÑ6Ô6Ñ7Ô7Ð7r@   ÚchwÚscalec                ó�   — |                       t          j        ¦   «         t          j        ¬¦  «        }|                     |¦  «        S )a{  Widen a ``uint8`` CHW tensor to the default float dtype and scale it into ``[0, 1]``.

    Dtype and layout are converted together and the division is done in place on that fresh float
    allocation, so the pair costs one allocation rather than ``to_tensor``'s three.

    Args:
        chw: ``(C, H, W)`` ``uint8`` tensor, on any device.
        scale: 0-dim tensor holding ``255``, on ``chw``'s device and in the target dtype. It has to
            be a tensor rather than the Python ``int``: CUDA evaluates ``Tensor.div_(255)`` as a
            multiplication by ``255``'s reciprocal, which rounds differently from the host's
            division for just under half of all byte values (126 of 256, 1 ULP). A tensor divisor
            keeps IEEE-754 correctly rounded division on both, so the result does not depend on
            where it was computed.

    Returns:
        A contiguous ``(C, H, W)`` tensor in the current default floating-point dtype, scaled to
        ``[0, 1]``, byte-for-byte identical to ``to_tensor``'s output. For ``C == 1`` the leading
        dimension's own stride may differ from ``to_tensor``'s, which is immaterial: a size-1
        dimension's stride has no memory-layout effect.

    Examples:
        >>> chw = _uint8_image_to_chw_view(np.zeros((2, 2, 3), dtype=np.uint8))
        >>> _uint8_chw_to_float(chw, torch.tensor(255.0)).dtype
        torch.float32
    )rG   Úmemory_format)rO   rH   Úget_default_dtypeÚcontiguous_formatÚdiv_)r\   r]   Úwideneds      r>   Ú_uint8_chw_to_floatrd   v   s7   € ð4 �fŠf�5Ô2Ñ4Ô4ÅEÔD[ˆfÑ\Ô\€GØ�<Š<˜ÑÔÐr@   )Ú
RFDETRBaseÚRFDETRKeypointPreviewÚRFDETRLargeÚRFDETRLargeDeprecatedÚRFDETRMediumÚ
RFDETRNanoÚ	RFDETRSegÚRFDETRSeg2XLargeÚRFDETRSegLargeÚRFDETRSegMediumÚRFDETRSegNanoÚRFDETRSegPreviewÚRFDETRSegSmallÚRFDETRSegXLargeÚRFDETRSmallÚRFDETRr%   rh   rk   c              #  ó,   K  — | ]}|t           v¯|V — Œd S ©N)Ú'_CHECKPOINT_MODEL_NAME_EXCLUDED_SYMBOLS)r<   Úclass_symbols     r>   r?   r?   ©   s6   è è € ð >ð >Ø!¸ÕMtÐ9tÐ9t€LÐ9tÐ9tÐ9tÐ9tð>ð >r@   ztuple[str, ...]Ú$_CHECKPOINT_MODEL_NAME_CLASS_SYMBOLS)ÚRFDETRXLargeÚRFDETR2XLargeÚ)_CHECKPOINT_PLUS_MODEL_NAME_CLASS_SYMBOLS))úkeypoint-previewrf   )zseg-2xlargerl   )zseg-xxlargerl   )z
seg-xlargerr   )z	seg-largerm   )z
seg-mediumrn   )z	seg-smallrq   )zseg-nanoro   )zseg-previewrp   )Úlargerg   )Úmediumri   )Úsmallrs   )Únanorj   )Úbasere   ztuple[tuple[str, str], ...]Ú_CHECKPOINT_MODEL_MAP_ENTRIES))Ú2xlarger{   )Úxxlarger{   )Úxlargerz   Ú"_CHECKPOINT_PLUS_MODEL_MAP_ENTRIESrM   ÚobjectÚ
block_sizeÚintÚ
patch_sizeÚnum_windowsútuple[int, int]c                ó   — 	 t          d| ¦  «        \  }}n)# t          t          f$ r t          d| ›d�¦  «        d‚w xY wd|fd|ffD ]®\  }}t          |t          ¦  «        r+t          d|› dt          |¦  «        j        › d	| ›d
�¦  «        ‚	 t          j        |¦  «         n:# t          $ r- t          d|› dt          |¦  «        j        › d	| ›d
�¦  «        d‚w xY w|dk    rt          d| ›d�¦  «        ‚Œ¯t          j        |¦  «        t          j        |¦  «        }	}||z  dk    s	|	|z  dk    rt          d|› d|› d|› d| ›d�	¦  «        ‚||	fS )uÕ  Validate a user-supplied ``(height, width)`` shape tuple and return normalised plain-int dims.

    Args:
        shape: The raw value supplied by the caller (e.g. from ``export(shape=...)`` or
            ``predict(shape=...)``).  Must be a two-element sequence of positive integers (or integer-compatible types
            accepted by :func:`operator.index`).
        block_size: Required divisor for both dimensions.  Equals ``patch_size * num_windows``.
        patch_size: Backbone patch size â€” used only in error messages.
        num_windows: Number of attention windows â€” used only in error messages.

    Returns:
        A ``(height, width)`` tuple of plain Python :class:`int` values.

    Raises:
        ValueError: If ``shape`` cannot be unpacked as a two-element sequence, if either
            dimension is a bool, float, or other non-integer type, if either dimension is not positive, or if either
            dimension is not divisible by ``block_size``.
    ztuple[Any, Any]zGshape must be a sequence of two positive integers (height, width), got ú.NÚheightÚwidthzshape z must be an integer, got z (shape=z).r   z?shape must contain positive integers for height and width, got z-shape must have both dimensions divisible by ú (patch_size=ú * num_windows=z), got )	r   Ú	TypeErrorÚ
ValueErrorÚ
isinstanceÚboolrF   Ú__name__ÚoperatorÚindex)
rM   r‰   r‹   rŒ   Ú
raw_heightÚ	raw_widthÚdim_nameÚdimr�   r‘   s
             r>   Ú_validate_shape_dimsrŸ   Ä   s
  € ð0yÝ $Ð%6¸Ñ >Ô >Ñˆ
�I�IøÝ•zÐ"ð yð yð yÝÐmÐchÐmÐmÐmÑnÔnÐtxÐxðyøøøà# ZÐ0°7¸IÐ2FÐGð 
kð 
k‰ˆ�#Ý�c�4Ñ Ô ð 	rÝÐp hÐpÐpÍÈcÉÌÔI[ÐpÐpÐejÐpÐpÐpÑqÔqÐqð	ÝŒN˜3ÑÔÐÐøÝð 	ð 	ð 	ÝØc˜ÐcÐc½DÀ¹I¼IÔ<NÐcÐcÐX]ÐcÐcÐcñô àðð	øøøð �!Š8ˆ8ÝÐiÐ_dÐiÐiÐiÑjÔjÐjð õ ”N :Ñ.Ô.µ´¸yÑ0IÔ0IˆE€FØ�
Ñ˜aÒÐ 5¨:Ñ#5¸Ò#:Ð#:ÝðU¸Jð Uð UØ%ðUð UØ6AðUð UØJOðUð Uð Uñ
ô 
ð 	
ð �5ˆ=Ðs   ‚ –&<ÂB"Â"7Cú
int | NoneÚmodel_configÚcallerÚstrc                ó˜  — | €t          |dd¦  «        } nst          | t          ¦  «        st          | t          ¦  «        r| dk    rt	          d| ›�¦  «        ‚t          |dd¦  «        }|�| |k    rt	          |› d| › d|› d�¦  «        ‚t          | t          ¦  «        st          | t          ¦  «        r| dk    rt	          d| ›�¦  «        ‚| S )	u2  Resolve and validate the ``patch_size`` argument for :meth:`RFDETR.export` and :meth:`RFDETR.predict`.

    Args:
        patch_size: Value supplied by the caller, or ``None`` to read from ``model_config``.
        model_config: The model's configuration object.  Must expose ``patch_size`` as a
            positive integer attribute when ``patch_size`` is ``None`` or when a mismatch check is needed.
        caller: Name of the calling method (``"export"`` or ``"predict"``) â€” used in
            error messages to help the caller locate the problem.

    Returns:
        A validated, positive :class:`int` patch size.

    Raises:
        ValueError: If the resolved or provided ``patch_size`` is not a positive integer,
            or if a caller-provided value disagrees with ``model_config.patch_size``.
    Nr‹   é   r   z+patch_size must be a positive integer, got z(patch_size=z5) does not match the instantiated model's patch_size=z`. Patch size is an architectural parameter; omit patch_size to use the model's configured value.)Úgetattrr–   r—   rŠ   r•   )r‹   r¡   r¢   Úmodel_patch_sizes       r>   Ú_resolve_patch_sizer¨   õ   s  € ð" ÐÝ˜\¨<¸Ñ<Ô<ˆ
ˆ
å�j¥$Ñ'Ô'ð 	[­z¸*ÅcÑ/JÔ/Jð 	[ÈjÐ\]ÊoÈoÝÐYÈ:ÐYÐYÑZÔZÐZÝ" <°¸tÑDÔDÐØÐ'¨JÐ:JÒ,JÐ,JÝØð Hð H zð Hð HØ.ðHð Hð Hñô ð õ
 �*�dÑ#Ô#ð W­:°jÅ#Ñ+FÔ+Fð WÈ*ÐXYÊ/È/ÝÐUÀzÐUÐUÑVÔVÐVØÐr@   Ú	model_ctxr   ÚNonec                óL  — t          | dd¦  «        }t          | dd¦  «        }|�|�t          |d¦  «        sdS t          |t          ¦  «        rt	          j        |¦  «        }|j        dk    r=|j        €6t	          j        |j        t          j         	                    ¦   «         ¦  «        }t          |                     ¦   «         d¦  «        }|�T|j        |k    rKt	          j        d¦  «        5  |                     |¦  «        | _        ddd¦  «         dS # 1 swxY w Y   dS dS dS )aò  Move model weights to the target device recorded in *model_ctx*.

    ``_build_model_context`` intentionally keeps the ``nn.Module`` on CPU so that ``RFDETR.__init__`` does not
    initialise CUDA (which would prevent DDP strategies from forking in notebook environments).  This helper performs
    the deferred ``.to(device)`` on first use.

    It is safe to call on duck-typed stand-ins (e.g. ``SimpleNamespace``); the function silently returns when the
    expected attributes are missing.
    rE   NÚmodelÚ
parametersr9   F)r¦   Úhasattrr–   r£   rH   rE   rF   rš   r9   Úcurrent_deviceÚnextr­   Úinference_moderO   r¬   )r©   ÚtargetÚinnerÚfirst_params       r>   Ú_move_model_context_to_devicerµ     s`  € õ �Y ¨$Ñ/Ô/€FÝ�I˜w¨Ñ-Ô-€EØ€~˜˜­g°e¸\Ñ.JÔ.J˜ØˆÝ�&�#ÑÔð &Ý”˜fÑ%Ô%ˆØ„{�fÒÐ ¤Ð!5õ
 ”˜fœk­5¬:×+DÒ+DÑ+FÔ+FÑGÔGˆÝ�u×'Ò'Ñ)Ô)¨4Ñ0Ô0€KØÐ ;Ô#5¸Ò#?Ð#?õ Ô! %Ñ(Ô(ð 	/ð 	/Ø#Ÿhšh vÑ.Ô.ˆIŒOð	/ð 	/ð 	/ñ 	/ô 	/ð 	/ð 	/ð 	/ð 	/ð 	/ð 	/ð 	/øøøð 	/ð 	/ð 	/ð 	/ð 	/ð 	/ð ÐÐ#?Ð#?s   Ã-DÄDÄDÚmethodú"Callable[Concatenate[Any, _P], _R]c                ó^   ‡ — t          ‰ ¦  «        dˆ fd	„¦   «         }t          d
|¦  «        }|S )aÕ  Decorate RF-DETR instance methods that require lazy model device placement.

    The wrapped method receives the same arguments and return value as the original method. Before calling it, the
    decorator moves ``self.model.model`` to ``self.model.device`` if the model context is available and the weights are
    still on a different device. This keeps public inference methods clean while preserving deferred CUDA initialization
    during ``RFDETR.__init__``.
    Úselfr   Úargsú_P.argsÚkwargsú	_P.kwargsr4   r1   c                óX   •— t          t          | dd ¦  «        ¦  «          ‰| g|¢R i |¤ŽS )Nr¬   )rµ   r¦   )r¹   rº   r¼   r¶   s      €r>   Úwrapperz(_ensure_model_on_device.<locals>.wrapperA  s=   ø€ å%¥g¨d°G¸TÑ&BÔ&BÑCÔCÐCØˆv�dÐ,˜TÐ,Ð,Ð, VÐ,Ð,Ð,r@   r·   )r¹   r   rº   r»   r¼   r½   r4   r1   )r   r   )r¶   r¿   Útyped_wrappers   `  r>   Ú_ensure_model_on_devicerÁ   8  sK   ø€ õ ˆ6�]„]ð-ð -ð -ð -ð -ñ „]ð-õ Ð=¸wÑGÔG€MØÐr@   F)Úfor_evalÚdetectorrÂ   r—   r¼   ú0tuple[TrainConfig, str | None, list[int] | None]c               óX  — ddl m} |                     dd¦  «        }t                               |¦  «        \  }}|                     dd¦  «        }|��™t          |t          ¦  «        rt          d¦  «        ‚	 t          j	        |¦  «        }n"# t          $ r}t          d¦  «        |‚d}~ww xY w|dk    rt          d¦  «        ‚| j        j        | j        j        z  }	||	z  dk    r3t          d|› d| j        j        › d	| j        j        › d
|	› d|	› d�¦  «        ‚| j        j        }
| j        j        | j        j        z  }|
|k    r|| j        j        z  }|| j        _        n|
}|| j        _        t!          | d¦  «        rn| j        �gt!          | j        d¦  «        r|| j        _        t%          | j        dd¦  «        }|�.t!          |d¦  «        r||_        t!          |d¦  «        r||_        |rL|                     d¦  «        dk    r3|                     d¦  «        dk    rt(          j        d         j        |d<    | j        di |¤Ž}|j        dk    r<|r:t(          j        d         j        }t2                               d|¦  «         ||_        n{|j        dk    rpt7          | j        ¦  «          || j        | j        |¬¦  «        }|j        |_        |j        |_        t2                               d|j        |j        |j        ¦  «         tA          | ¦  «        j!        | j        _"        |||fS )u   Absorb the special run kwargs and build a :class:`~rfdetr.config.TrainConfig`.

    Shared by :meth:`RFDETR.train` and :meth:`RFDETR.evaluate` so both accept exactly the same keyword arguments.
    Handles the kwargs that are not plain ``TrainConfig`` fields: ``device`` (mapped to PyTorch Lightning
    accelerator/devices), and
    ``resolution`` (a ``ModelConfig`` field applied to ``detector.model_config`` in place, with the positional-encoding
    size and cached inference context kept in sync). Remaining kwargs are forwarded to
    :meth:`RFDETR.get_train_config`; ``batch_size="auto"`` is resolved by auto-batch probing (skipped when
    ``for_eval=True`` â€” see below).
    ``model_config.model_name`` is set to the concrete subclass name.

    Defined at module scope (rather than as a method) so that :meth:`RFDETR.train` / :meth:`RFDETR.evaluate`, which are
    unit-tested by calling the unbound method with a ``MagicMock`` ``self``, still run the real preprocessing: a
    module-level function is not intercepted by the mock, so no per-test monkeypatching of this helper is needed.

    Args:
        detector: The :class:`RFDETR` instance whose ``model_config`` and model context the run targets.
        for_eval: When ``True`` (set by :meth:`RFDETR.evaluate`), ``batch_size="auto"`` is not resolved by probing â€”
            the probe forces train mode and runs a forward+backward pass to size for the *training* memory envelope
            (retained activations and gradients), which both wastes compute on a call that never backprops and
            under-sizes the eval batch relative to what a no-grad forward pass can actually fit. Falls back to
            :attr:`TrainConfig.batch_size`'s default instead.
        **kwargs: Keyword arguments accepted by :meth:`RFDETR.train` / :meth:`RFDETR.evaluate`.

    Returns:
        ``(train_config, accelerator, devices)`` where ``accelerator`` / ``devices`` are PTL trainer kwargs derived
        from the ``device`` kwarg (``None`` when ``device`` was not provided).

    Raises:
        ValueError: If ``resolution`` is not a positive integer or is not divisible by
            ``patch_size * num_windows`` for the model variant.
    r   )Úresolve_auto_batch_configrE   NÚ
resolutionz%resolution must be a positive integerzresolution=z! is not divisible by patch_size (z) * num_windows (z) = z,. Choose a resolution that is a multiple of r�   r¬   rº   Úpositional_encoding_sizeÚ	amp_dtypeÚfp8Ú
batch_sizeÚautozx[auto-batch] batch_size='auto' is a train-only feature; evaluate() uses the default micro-batch (%s) instead of probing.)Úmodel_contextr¡   Útrain_configz][auto-batch] resolved train config: batch_size=%s grad_accum_steps=%s effective_batch_size=%sr;   )#Úrfdetr.training.auto_batchrÆ   Úpoprt   Ú_resolve_trainer_device_kwargsr–   r—   r•   r™   rš   r”   r¡   r‹   rŒ   rÈ   rÇ   r®   r¬   r¦   Úgetr   Úmodel_fieldsÚdefaultÚget_train_configrË   ÚloggerÚinforµ   Úsafe_micro_batchÚrecommended_grad_accum_stepsÚgrad_accum_stepsÚeffective_batch_sizerF   r˜   Ú
model_name)rÃ   rÂ   r¼   rÆ   Ú_deviceÚ_acceleratorÚ_devicesÚ_resolutionÚerrorr‰   Ú_current_peÚ_derived_peÚnew_peÚ
model_argsÚconfigÚdefault_batch_sizeÚ
auto_batchs                    r>   Ú_prepare_run_configré   J  sÌ  € ðJ EÐDÐDÐDÐDÐDð �jŠj˜ 4Ñ(Ô(€GÝ#×BÒBÀ7ÑKÔKÑ€L�(ð
 —*’*˜\¨4Ñ0Ô0€KØÑÝ�k¥4Ñ(Ô(ð 	FÝÐDÑEÔEÐEð	QÝ"œ.¨Ñ5Ô5ˆKˆKøÝð 	Qð 	Qð 	QÝÐDÑEÔEÈ5ÐPøøøøð	Qøøøà˜!ÒÐÝÐDÑEÔEÐEØÔ*Ô5¸Ô8MÔ8YÑYˆ
Ø˜Ñ# qÒ(Ð(ÝðK˜kð Kð KØ'Ô4Ô?ðKð KàÔ)Ô5ðKð Kà;EðKð Kð >HðKð Kð Kñô ð ð Ô+ÔDˆØÔ+Ô6¸(Ô:OÔ:ZÑZˆØ˜+Ò%Ð%à  HÔ$9Ô$DÑDˆFØ=CˆHÔ!Ô:Ð:ð !ˆFØ+6ˆÔÔ(õ �8˜WÑ%Ô%ð 	A¨(¬.Ð*DÝ�x”~ |Ñ4Ô4ð 8Ø,7�”Ô)Ý  ¤°¸Ñ>Ô>ˆJØÐ%Ý˜: |Ñ4Ô4ð 8Ø,7�JÔ)Ý˜:Ð'AÑBÔBð AØ:@�JÔ7Øð N�F—J’J˜{Ñ+Ô+¨uÒ4Ð4¸¿ºÀLÑ9QÔ9QÐU[Ò9[Ð9[õ  +Ô7¸ÔEÔMˆˆ|ÑØ&ˆXÔ&Ð0Ð0¨Ð0Ð0€FØÔ˜FÒ"Ð" xÐ"õ )Ô5°lÔCÔKÐÝ�Šð3àñ	
ô 	
ð 	
ð
 /ˆÔÐØ	Ô	˜fÒ	$Ð	$õ 	& h¤nÑ5Ô5Ð5Ø.Ð.Ø"œ.Ø!Ô.Øð
ñ 
ô 
ˆ
ð
 'Ô7ˆÔØ",Ô"IˆÔÝ�ŠØkØÔØÔ#ØÔ+ñ		
ô 	
ð 	
õ (,¨H¡~¤~Ô'>€HÔÔ$Ø�< Ð)Ð)s   Á8B Â
B,ÂB'Â'B,ræ   r   r   Úclass_namesúlist[str] | Nonec                ó^  — 	 |                       ¦   «         |                      ¦   «         |j        j        ||rt          |¦  «        nddœ}t	          j        |dt          ¬¦  «        }t          j        | j	        d¬¦  «         d}	 t          j        d| j	        d	d
d¬¦  «        5 }|j        }|                     |¦  «         |                     ¦   «          ddd¦  «         n# 1 swxY w Y   t          j        |t          j                             | j	        d¦  «        ¦  «         |�ft          j                             |¦  «        rIt'          j        t*          ¦  «        5  t          j        |¦  «         ddd¦  «         n# 1 swxY w Y   dS dS dS dS # |�et          j                             |¦  «        rGt'          j        t*          ¦  «        5  t          j        |¦  «         ddd¦  «         w # 1 swxY w Y   w w w xY w# t.          $ r& t0                               d| j	        d¬¦  «         Y dS w xY w)uó  Write the run's complete configuration to ``training_config.json`` in the output directory.

    Called twice per run: once before training starts, so a run stopped with Ctrl-C or killed by a crash still
    leaves a record of how it was configured, and once after it finishes, which overwrites the first copy with the
    dataset-resolved class names. Both copies carry the same keys; the start-of-run one may hold ``class_names:
    null`` where the label space could not be read ahead of training.

    The serialized payload goes to a temporary file in the same directory and is moved over the final path with
    :func:`os.replace`, so a kill or a full disk mid-write leaves the previous complete copy in place instead of a
    truncated one â€” the start-of-run write overwrites the finished copy of an earlier run in the same output
    directory. Nothing here can end a training run: every failure, serialization included, is logged and swallowed,
    since this file is provenance rather than part of training.

    Args:
        config: The resolved training configuration.
        model_config: The detector's model configuration, after dataset-derived alignment.
        class_names: Label space to record, or ``None`` when it could not be resolved.

    Examples:
        Writes to ``config.output_dir``, so this is documentation rather than a doctest:

        ```python
        _save_training_config(train_config, model_config, ["cat", "dog"])
        # -> writes output/training_config.json
        ```
    r   )rÎ   r¡   Úmodel_config_typerê   Únum_classesr8   )ÚindentrÔ   T©Úexist_okNÚwFúutf-8z.tmp)ÚdirÚdeleteÚencodingÚsuffixztraining_config.jsonz*Could not save training_config.json to %s.©Úexc_info)Ú
model_dumpÚ	__class__r˜   ÚlenÚjsonÚdumpsr£   ÚosÚmakedirsÚ
output_dirÚtempfileÚNamedTemporaryFileÚnameÚwriteÚflushÚreplaceÚpathÚjoinÚexistsÚ
contextlibÚsuppressÚOSErrorÚremoveÚ	ExceptionrÖ   Úwarning)ræ   r¡   rê   Úcomplete_configÚpayloadÚtmp_pathÚtmp_files          r>   Ú_save_training_configr  Ï  sö  € ð6gà"×-Ò-Ñ/Ô/Ø(×3Ò3Ñ5Ô5Ø!-Ô!7Ô!@Ø&Ø/:ÐA�3˜{Ñ+Ô+Ð+Àð
ð 
ˆõ ”*˜_°QÅÐDÑDÔDˆÝ
Œ�FÔ%°Ð5Ñ5Ô5Ð5ð  $ˆð	(ÝÔ,Ø˜Ô*°5À7ÐSYðñ ô ð !àØ#œ=�Ø—’˜wÑ'Ô'Ð'Ø—’Ñ Ô Ð ð!ð !ð !ñ !ô !ð !ð !ð !ð !ð !ð !øøøð !ð !ð !ð !õ ŒJ�x¥¤§¢¨fÔ.?ÐAWÑ!XÔ!XÑYÔYÐYð Ð#­¬¯ª°xÑ(@Ô(@Ð#ÝÔ(­Ñ1Ô1ð (ð (Ý”I˜hÑ'Ô'Ð'ð(ð (ð (ñ (ô (ð (ð (ð (ð (ð (ð (øøøð (ð (ð (ð (ð (ð (ð $Ð#Ð#Ð#ð(ð (øð Ð#­¬¯ª°xÑ(@Ô(@Ð#ÝÔ(­Ñ1Ô1ð (ð (Ý”I˜hÑ'Ô'Ð'ð(ð (ð (ñ (ô (ð (ð (ð (ð (ð (ð (øøøð (ð (ð (ð (ð (ð $Ð#øøøøõ ð gð gð gÝ�ŠÐCÀVÔEVÐaeˆÑfÔfÐfÐfÐfÐfðgøøøs–   ‚B G< ÂF Â!1CÃF ÃC"Ã"F Ã%C"Ã&;F Ä!:G< ÅE<Å0G< Å<F Æ G< ÆF ÆG< Æ;G9Ç
G+ÇG9Ç+G/Ç/G9Ç2G/Ç3G9Ç9G< Ç<,H,È+H,c                  óÆ  — e Zd ZU dZg d¢Zg d¢ZdZded<   eZ	ded<   e
Zd	ed
<   ded<   ddœd‚d„Zdƒd„Zd„d„Zeddœd…d„¦   «         Zed†d„¦   «         Zd‡d„Zd d!œdˆd%„Zed&d'ej        fdd(d)œd‰d2„¦   «         Zdƒd3„ZedŠd4„¦   «         Z	 	 	 	 	 	 	 	 	 	 	 	 	 d‹ddd&ddddddd9œ	dŒdU„Zed�dX„¦   «         ZedŽd[„¦   «         Zedd\œd�d_„¦   «         Zeddd`œd�db„¦   «         Z d‘dc„Z!ed’de„¦   «         Z"ed’df„¦   «         Z#ed’dg„¦   «         Z$ed“dj„¦   «         Z%d”dm„Z&d•dn„Z'ddœd–dp„Z(ed—dq„¦   «         Z)dƒdr„Z* ej+        ¦   «         e	 	 	 	 d˜d™dz„¦   «         ¦   «         Z,	 	 	 dšd›d€„Z-dœd�„Z.dS )�rt   z´The base RF-DETR class implements the core methods for training RF-DETR models, running inference on the models,
    optimising models, and uploading trained models for deployment.)g
×£p=
ß?gÉv¾Ÿ/Ý?g–C‹lçûÙ?)gZd;ßOÍ?gyé&1¬Ì?gÍÌÌÌÌÌÌ?Nú
str | Noner=   ztype[ModelConfig]Ú_model_config_classztype[TrainConfig]Ú_train_config_classúdict[str, list[dict[str, Any]]]Ú_coco_categories_cacheF©Útrust_checkpointr  r—   r¼   r   r4   rª   c               óî  —  | j         d	i |¤Ž| _        |                      ¦   «          |                      | j        |¬¦  «        | _        t          t          ¦  «        | _        t          | j        ¦  «        | _        t          | j	        ¦  «        | _	        | j        j
        dk    rŽddlm} d„ t          t          | j        j
        ¦  «         || j        ¦  «        ¦  «        D ¦   «         | _        d„ t          t          | j        j
        ¦  «         || j	        ¦  «        ¦  «        D ¦   «         | _	        d| j        _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        dS )
aÁ  Initialize with ModelConfig fields as keyword arguments.

        Passes all remaining kwargs to the variant's ModelConfig. Unknown kwargs raise
        ``pydantic.ValidationError``. See the variant's config class for available
        parameters (e.g. ``RFDETRSmallConfig``).

        Args:
            trust_checkpoint: When ``True``, allow ``pretrain_weights`` to fall back to full
                pickle deserialization (``weights_only=False``) if safe loading fails. Set this
                only when ``pretrain_weights`` points to a checkpoint you explicitly trust (e.g.
                when called internally by :meth:`from_checkpoint`); left ``False`` by default for
                the ordinary construction path, which only ever downloads official Roboflow-hosted
                weights.
            **kwargs: ModelConfig field values (e.g. ``resolution``, ``num_classes``,
                ``pretrain_weights``, ``gradient_checkpointing``).
        r  é   r   )Úcyclec                ó   — g | ]\  }}|‘ŒS r;   r;   ©r<   Ú_Úvals      r>   ú
<listcomp>z#RFDETR.__init__.<locals>.<listcomp>1  s   € ÐjÐjÐj¡& ! S˜#ÐjÐjÐjr@   c                ó   — g | ]\  }}|‘ŒS r;   r;   r"  s      r>   r%  z#RFDETR.__init__.<locals>.<listcomp>2  s   € ÐhÐhÐh¡  C˜ÐhÐhÐhr@   NFr;   )Úget_model_configr¡   Úmaybe_download_pretrain_weightsÚ	get_modelr¬   r   ÚlistÚ	callbacksÚmeansÚstdsÚnum_channelsÚ	itertoolsr   ÚzipÚrangeÚinference_modelÚ_is_optimized_for_inferenceÚ3_has_warned_about_not_being_optimized_for_inferenceÚ_optimized_has_been_compiledÚ_optimized_batch_sizeÚ_optimized_resolutionÚ_optimized_dtypeÚ_optimized_inplaceÚ_has_been_trained)r¹   r  r¼   r   s       r>   Ú__init__zRFDETR.__init__  sj  € ð" 2˜DÔ1Ð;Ð;°FÐ;Ð;ˆÔØ×,Ò,Ñ.Ô.Ð.Ø—^’^ DÔ$5ÐHX�^ÑYÔYˆŒ
Ý>IÍ$Ñ>OÔ>OˆŒå˜$œ*Ñ%Ô%ˆŒ
Ý˜œ‘O”OˆŒ	ð ÔÔ)¨QÒ.Ð.Ø'Ð'Ð'Ð'Ð'Ð'àjÐj­Cµ°dÔ6GÔ6TÑ0UÔ0UÐW\ÐW\Ð]aÔ]gÑWhÔWhÑ,iÔ,iÐjÑjÔjˆDŒJØhÐh­3­u°TÔ5FÔ5SÑ/TÔ/TÐV[ÐV[Ð\`Ô\eÑVfÔVfÑ+gÔ+gÐhÑhÔhˆDŒIà%)ˆŒ
Ô"Ø+0ˆÔ(ØCHˆÔ@Ø,1ˆÔ)Ø15ˆÔ"Ø15ˆÔ"Ø48ˆÔØ"'ˆÔØ!&ˆÔÐÐr@   c                ó¸  — | j         j        €dS t          | j         j        ¦  «        }t          j                             |¦  «        sEt          ¦   «         }t          j        |d¬¦  «         t          j                             ||¦  «        }n3t          j        t          j                             |¦  «        d¬¦  «         || j         _        t          |¦  «         dS )uw  Download pre-trained weights if they are not already downloaded.

        Bare filenames (no directory component, e.g. ``rf-detr-base.pth``) are resolved to the model cache directory â€”
        set the ``RF_HOME`` environment variable to override the location (default: ``~/.roboflow/models``). Resolution
        happens in ``ModelConfig.expand_path`` for explicitly-provided values, and here as a fallback for field defaults
        (which Pydantic does not validate by default).

        Paths that already contain a directory component are used as-is; the parent directory is created if it does not
        yet exist.
        NTrð   )
r¡   Úpretrain_weightsr£   rÿ   r  Údirnamer   r   r	  r   )r¹   r=  Ú	cache_dirs      r>   r(  z&RFDETR.maybe_download_pretrain_weights>  s¿   € ð ÔÔ-Ð5ØˆFÝ˜tÔ0ÔAÑBÔBÐÝŒw�ŠÐ/Ñ0Ô0ð 	Jå+Ñ-Ô-ˆIÝŒK˜	¨DÐ1Ñ1Ô1Ð1Ý!œwŸ|š|¨IÐ7GÑHÔHÐÐåŒK�œŸšÐ(8Ñ9Ô9ÀDÐIÑIÔIÐIØ-=ˆÔÔ*Ý!Ð"2Ñ3Ô3Ð3Ð3Ð3r@   r   c                ó   —  | j         di |¤ŽS )z8Retrieve the configuration parameters used by the model.r;   )r  ©r¹   r¼   s     r>   r'  zRFDETR.get_model_configV  ó   € à'ˆtÔ'Ð1Ð1¨&Ð1Ð1Ð1r@   r  ústr | os.PathLike[str]c               óº  ‡6‡7‡8‡9— ddl mŠ9 d}i Š6g }ddlm} |r`	 ddlmc m} t          D ]}t          ||¦  «        }	|	‰6|<   Œˆ6fd„t          D ¦   «         }d}n!# t          $ r}
|
j        dvr‚ Y d}
~
nd}
~
ww xY wddlm}  |t          |¦  «        |¬	¦  «        }|d
         }ˆ9fd„t          ‰9¦  «        D ¦   «         Š7ˆ7fd„t           D ¦   «         Š8ˆ8fd„t"          D ¦   «         }ˆ8fd„t"          D ¦   «         }ˆ8fd„t"          D ¦   «         }||z   |z   |z   }t%          ‰8¦  «        }|r|                     ‰6¦  «         ‰7                     d¦  «        }|�||d<   |                     d¦  «        }d}t+          |t          ¦  «        r,|                     ¦   «         }|r|                     |¦  «        }nd}t+          |t$          ¦  «        rHt          |                     dd¦  «        ¦  «                             ¦   «                              ¦   «         }nBt          t          |dd¦  «        ¦  «                             ¦   «                              ¦   «         }d}|dv rEt0          j                             t1          j        |¦  «        ¦  «                             ¦   «         }d}|€›|t          v }d|v od|vod|v}|s7|s|r3ddlm} t;          d|›d|›d�|                     d¬¦  «        z   ¦  «        ‚|D ]\  }}||v r|} nŒ|r;|�9t>                                d|t          |dtC          |¦  «        ¦  «        |¦  «         |€tE          d |›d!|›d|›d"�¦  «        ‚t+          |t$          ¦  «        r|                     d#¦  «        }nt          |d#d¦  «        }i }tG          ¦   «         } t          |d$d¦  «        }!i }"t          |!d%d¦  «        }#t+          |#t$          ¦  «        r|#}"n(t          |!d&d¦  «        }$t+          |$t$          ¦  «        r|$}"|                     d'¦  «        }%t+          |%t$          ¦  «        rA|% $                    ¦   «         D ],\  }&}'|&dk    rŒ|"r|&|"v r|'||&<   |  %                    |&¦  «         Œ-|�d#|vr||d#<   |  %                    d#¦  «         |                     d(¦  «        pi }(|(s…d)|v r�d*})i }(|d)          $                    ¦   «         D ]b\  }*}+|* &                    |)¦  «        rH|*tO          |)¦  «        d…         }&|& &                    d+¦  «        r|&tO          d+¦  «        d…         }&|+|(|&<   Œc|(�rfd,|vrÃ|"rd,|"v r½|(                     d-¦  «        },t+          |,tP          j)        ¦  «        rŽ|,j*        d.k    rƒd/„ |, +                    d0¬1¦  «         ,                    ¦   «         D ¦   «         }-|                     d,¦  «        }.|-|.k    rt>           -                    d2|.|-¦  «         |-|d,<   |  %                    d,¦  «         d#|vr›|(                     d3¦  «        }/t+          |/tP          j)        ¦  «        rl|/j*        d.k    ra|/j.        d         d0z
  }0|                     d#¦  «        }1|0|1k    rt>           -                    d4|1|0¦  «         |0|d#<   |  %                    d#¦  «         |                     |¦  «         t          |¦  «        |d<   ||d5<   | tG          |¦  «        z
  }2 |d9i |¤Ž}3d|3_/        |2ryt          |3d'd¦  «        }4t          |4d6d¦  «        }5|5€t          |4d7d¦  «        }5|5�|5 0                    |2¦  «         d#|2v r)d#t          |4d6tG          ¦   «         ¦  «        vs
J d8¦   «         ‚|3S ):uÖ  Load an RF-DETR model from a training checkpoint, automatically inferring the model class.

        The correct subclass is resolved in order of preference:

        1. ``model_name`` key in the checkpoint (written by the PTL training
           stack since v1.7.0).
        2. ``pretrain_weights`` field in the checkpoint's ``args`` entry
           (legacy fallback for older checkpoints).
        3. The **filename** of *path* itself, used as a last resort when
           ``pretrain_weights`` is absent or an unset-like sentinel value
           (empty string, ``"none"``, or ``"null"``).  Starter weights
           published by Roboflow store ``pretrain_weights="none"`` in their
           ``args``; passing the canonical filename (e.g.
           ``rf-detr-small.pth``) lets ``from_checkpoint`` infer the class
           automatically.

        Both legacy ``argparse.Namespace`` checkpoints (produced by ``engine.py``) and dict-style checkpoints (produced
        by the PTL training stack) are supported.

        Args:
            path: Path to a checkpoint file (e.g. ``checkpoint_best_total.pth``).
            trust_checkpoint: When ``True``, fall back to ``weights_only=False``
                (full pickle) if safe deserialization fails.  Only set this for
                checkpoints from fully trusted sources; the default ``False``
                keeps the safe loading path and raises if it cannot succeed.
                Applies to both the initial checkpoint read here and the
                constructor's own reload of the same file via
                :func:`~rfdetr.models.weights.load_pretrain_weights`.
            **kwargs: Additional keyword arguments forwarded to the model
                constructor (e.g. ``accept_platform_model_license=True`` for XLarge / 2XLarge models).

                ``num_classes`` is resolved in this priority order:

                1. Explicit caller kwarg â€” always wins.
                2. Weight inference from ``class_embed.weight`` shape in the checkpoint
                   (``shape[0] - 1``, since the head includes a background class). This
                   overrides a stale ``model_config`` value written before fine-tuning
                   changed the class count.
                3. ``saved_model_config["num_classes"]`` from the checkpoint's
                   ``model_config`` entry â€” may be stale for older checkpoints.
                4. Legacy ``args["num_classes"]`` dict entry.
                5. Constructor default.

                In cases 2â€“5 the field is not recorded as a user-set override, so
                :meth:`train` can still adapt the detection head to the training
                dataset's class count.  Pass an explicit ``num_classes=N`` to pin
                the head and prevent adaptation.

        Returns:
            An instance of the appropriate :class:`RFDETR` subclass loaded from the checkpoint.

        Warning:
            By default this method attempts safe deserialization
            (``weights_only=True``).  Pass ``trust_checkpoint=True`` only for
            checkpoints from fully trusted sources, as it enables full pickle
            deserialization which can execute arbitrary code.

        Raises:
            FileNotFoundError: If *path* does not exist.
            OSError: If *path* exists but cannot be read.
            KeyError: If the checkpoint does not contain an ``"args"`` key.
            ValueError: If the model class cannot be inferred from ``model_name``,
                ``pretrain_weights``, or the checkpoint filename.

        Examples:
            >>> model = RFDETR.from_checkpoint("checkpoint_best_total.pth")  # doctest: +SKIP
            >>> model = RFDETRSmall.from_checkpoint("checkpoint_best_total.pth")  # doctest: +SKIP
        r   NF)Ú_IS_RFDETR_PLUS_AVAILABLEc                ó*   •— g | ]\  }}|‰|         f‘ŒS r;   r;   )r<   r  rx   Ú_plus_symbolss      €r>   r%  z*RFDETR.from_checkpoint.<locals>.<listcomp>¯  s4   ø€ ð !ð !ð !Ù<N¸DÀ,�T˜=¨Ô6Ð7ð!ð !ð !r@   T>   úrfdetr_plus.modelsÚrfdetr_plus©Ú_safe_torch_load©Útrustrº   c                ó~   •— i | ]9}|                      d ¦  «        ¯t          ‰|¦  «        }t          |d|¦  «        |“Œ:S )rt   r˜   )Ú
startswithr¦   )r<   ÚsymbolÚvariant_objÚrfdetr_variantss      €r>   ú
<dictcomp>z*RFDETR.from_checkpoint.<locals>.<dictcomp>¿  s^   ø€ ð ;
ð ;
ð ;
àØ× Ò  Ñ*Ô*ð;
õ !(¨¸Ñ @Ô @�õ �K ¨VÑ4Ô4°kð;
ð ;
ð ;
r@   c                ó"   •— i | ]}|‰|         “ŒS r;   r;   )r<   rx   Ú_variant_name_to_classs     €r>   rS  z*RFDETR.from_checkpoint.<locals>.<dictcomp>Å  s.   ø€ ð 5
ð 5
ð 5
ØCOˆLÐ0°Ô>ð5
ð 5
ð 5
r@   c                óT   •— g | ]$\  }}|                      d ¦  «        ¯|‰|         f‘Œ%S )úseg-©rO  ©r<   r  rx   Ú_variant_symbolss      €r>   r%  z*RFDETR.from_checkpoint.<locals>.<listcomp>Ê  sJ   ø€ ð 4
ð 4
ð 4
á"��lØ�Š˜vÑ&Ô&ð4
ØÐ# LÔ1Ð2ð4
ð 4
ð 4
r@   c                ó2   •— g | ]\  }}d |v ¯	|‰|         f‘ŒS )Úkeypointr;   rY  s      €r>   r%  z*RFDETR.from_checkpoint.<locals>.<listcomp>Ï  s=   ø€ ð 9
ð 9
ð 9
á"��lØ˜TÐ!Ð!ð Ð# LÔ1Ð2à!Ð!Ð!r@   c                ó\   •— g | ](\  }}|                      d ¦  «        sd|v¯|‰|         f‘Œ)S )rW  r\  rX  rY  s      €r>   r%  z*RFDETR.from_checkpoint.<locals>.<listcomp>Ô  sS   ø€ ð 5
ð 5
ð 5
á"��lØ—?’? 6Ñ*Ô*ð5
ð 0:ÀÐ/EÐ/Eð Ð# LÔ1Ð2à/EÐ/EÐ/Er@   rh   rÜ   Ú r=  >   r^  ÚnoneÚnullr†   rW  r}   )Ú_INSTALL_MSGzCheckpoint model_name=z, pretrain_weights=z# requires the rfdetr_plus package. zplatform model downloads©r  zQpretrain_weights unset in checkpoint %r; inferred model class %s from filename %rr˜   z/Could not infer model class from checkpoint at z (model_name=z/). Please instantiate the model class directly.rî   r  rÓ   Ú
__fields__r¡   r¬   Ú
state_dictzmodel.z
_orig_mod.Únum_keypoints_per_classÚ_kp_active_maskr8   c                ó,   — g | ]}t          |¦  «        ‘ŒS r;   ©rŠ   )r<   Úns     r>   r%  z*RFDETR.from_checkpoint.<locals>.<listcomp>d  s   € Ð#QÐ#QÐ#Q¨q¥C¨¡F¤FÐ#QÐ#QÐ#Qr@   r7   )rž   u   from_checkpoint: overriding num_keypoints_per_class %s â†’ %s (inferred from _kp_active_mask; saved model_config may be stale).zclass_embed.weightuv   from_checkpoint: overriding num_classes %s â†’ %s (inferred from class_embed.weight; saved model_config may be stale).r  Úmodel_fields_setÚ__pydantic_fields_set__uÊ   num_classes still in model_fields_set after checkpoint load; Pydantic may return a snapshot rather than the live backing set â€” switch to model_construct(_fields_set=...) for Pydantic v3 compatibility.r;   )1Úrfdetr.variantsÚvariantsÚrfdetr.platformrE  Úrfdetr.platform.modelsÚplatformÚmodelsr|   r¦   r‡   ÚModuleNotFoundErrorr  Úrfdetr.utilities.iorK  r£   rô   ry   rƒ   ÚdictÚupdaterÒ   r–   ÚstripÚlowerrÿ   r  ÚbasenameÚfspathra  ÚImportErrorÚformatrÖ   r×   Úreprr•   ÚsetÚitemsÚaddrO  rü   rH   ÚTensorrX   ÚsumÚtolistÚdebugrM   r:  Údifference_update):Úclsr  r  r¼   Ú_plus_availableÚ_plus_entriesrE  Úplatform_modelsrx   Úplus_objÚexrK  Úckptrº   Ú_seg_mapÚ_keypoint_mapÚ	_base_mapÚ
_model_mapÚ	_name_mapÚ_large_deprecated_clsÚsaved_model_nameÚ	model_clsÚnormalized_nameÚweights_nameÚ_filename_fallbackÚplus_by_model_nameÚplus_by_weights_namera  r  Úklassrî   Úconstructor_kwargsÚcheckpoint_config_keysr  Ú
_mc_fieldsÚ_mc_model_fieldsÚ
_mc_legacyÚsaved_model_configÚkeyÚvalueÚ_ckpt_weightsÚ_pfxÚkÚvÚ_kp_maskÚ_inferred_kpÚ_current_kpÚ
_ce_weightÚ_inferred_ncÚ_current_ncÚcheckpoint_derived_keysr¬   Úloaded_configÚ
fields_setrG  rU  rZ  rR  s:                                                         @@@@r>   Úfrom_checkpointzRFDETR.from_checkpointZ  sã	  øøøø€ ðN 	2Ð1Ð1Ð1Ð1Ð1àˆØ13ˆØ8:ˆØ=Ð=Ð=Ð=Ð=Ð=à$ð 	ðØ@Ð@Ð@Ð@Ð@Ð@Ð@Ð@Ð@å$Mð ;ð ;�LÝ& ¸ÑEÔE�HØ2:�M ,Ñ/Ð/ð!ð !ð !ð !ÝRtð!ñ !ô !�ð #'��øÝ&ð ð ð Ø”7Ð"GÐGÐGØð HÐGÐGÐGÐGøøøøðøøøð 	9Ð8Ð8Ð8Ð8Ð8à/Ð/µ°D±	´	ÐAQÐRÑRÔRˆØ�FŒ|ˆð;
ð ;
ð ;
ð ;
å˜oÑ.Ô.ð;
ñ ;
ô ;
Ðð5
ð 5
ð 5
ð 5
ÝSwð5
ñ 5
ô 5
Ðð
4
ð 4
ð 4
ð 4
å&Cð4
ñ 4
ô 4
ˆð
9
ð 9
ð 9
ð 9
å&Cð9
ñ 9
ô 9
ˆð
5
ð 5
ð 5
ð 5
å&Cð5
ñ 5
ô 5
ˆ	ð
 6>ÀÑ5MÐP]Ñ5]Ð`iÑ5iˆ
õ .2Ð2BÑ-CÔ-Cˆ	àð 	,Ø×Ò˜]Ñ+Ô+Ð+ð !7× :Ò :Ð;RÑ SÔ SÐØ Ð,Ø1FˆIÐ-Ñ.ØŸ8š8 LÑ1Ô1ÐØ)-ˆ	ÝÐ&­Ñ,Ô,ð 	!Ø.×4Ò4Ñ6Ô6ˆOØð ;Ø%ŸMšM¨/Ñ:Ô:�	øà ˆOõ �d�DÑ!Ô!ð 	VÝ˜tŸxšxÐ(:¸BÑ?Ô?Ñ@Ô@×FÒFÑHÔH×NÒNÑPÔPˆLˆLå�w tÐ-?ÀÑDÔDÑEÔE×KÒKÑMÔM×SÒSÑUÔUˆLð #ÐØÐ/Ð/Ð/Ýœ7×+Ò+­B¬I°d©O¬OÑ<Ô<×BÒBÑDÔDˆLØ!%ÐàÐð "1Õ4]Ð!]Ðà˜LÐ(Ðr¨V¸<Ð-GÐrÐL^ÐfrÐLrð !ð #ð Ð(:ð Ð>Rð Ø8Ð8Ð8Ð8Ð8Ð8å!ð-Ð-=ð -ð -ÐT`ð -ð -ð -Ø/;×/BÒ/BÐHbÐ/BÑ/cÔ/cñdñô ð ð
  *ð ð ‘��eØ˜<Ð'Ð'Ø %�IØ�Eð (ð "ð  iÐ&;Ý—’ØgØÝ˜I zµ4¸	±?´?ÑCÔCØ ñ	ô ð ð ÐÝð@À$ð @ð @Ø/ð@ð @ØFRð@ð @ð @ñô ð õ �d�DÑ!Ô!ð 	=Ø&*§h¢h¨}Ñ&=Ô&=ˆKˆKå! $¨°tÑ<Ô<ˆKà-/ÐÝ+.©5¬5Ðõ & iÐ1FÈÑMÔMÐØ%'ˆ
Ý"Ð#6¸ÈÑMÔMÐÝÐ&­Ñ-Ô-ð 	(Ø)ˆJˆJå Ð!4°lÀDÑIÔIˆJÝ˜*¥dÑ+Ô+ð (Ø'�
à!ŸXšX nÑ5Ô5ÐÝÐ(­$Ñ/Ô/ð 	4Ø0×6Ò6Ñ8Ô8ð 4ð 4‘
��UØÐ,Ò,Ð,ØØ!ð 4 S¨JÐ%6Ð%6Ø.3Ð& sÑ+Ø*×.Ò.¨sÑ3Ô3Ð3øàÐ" }¸FÐ'BÐ'BØ0;Ð˜}Ñ-Ø"×&Ò& }Ñ5Ô5Ð5ð )-¯ª°Ñ(9Ô(9Ð(?¸RˆØð 		+ °Ð!5Ð!5ØˆDØˆMØ˜\Ô*×0Ò0Ñ2Ô2ð +ð +‘��1Ø—<’< Ñ%Ô%ð +Ø�C ™IœI˜K˜Kœ.�Cà—~’~ lÑ3Ô3ð 7Ø!¥# lÑ"3Ô"3Ð"5Ð"5Ô6˜Ø)*�M #Ñ&øØñ !	>ð )°Ð6Ð6À
Ð6ÐNgÐkuÐNuÐNuØ(×,Ò,Ð->Ñ?Ô?�Ý˜h­¬Ñ5Ô5ð J¸(¼-È1Ò:LÐ:LØ#QÐ#Q°H·L²LÀQ°LÑ4GÔ4G×4NÒ4NÑ4PÔ4PÐ#QÑ#QÔ#Q�LØ"4×"8Ò"8Ð9RÑ"SÔ"S�KØ# {Ò2Ð2ÝŸšð`à'Ø(ñ	ô ð ð EQÐ&Ð'@ÑAØ*×.Ò.Ð/HÑIÔIÐIð  FÐ*Ð*Ø*×.Ò.Ð/CÑDÔD�
Ý˜j­%¬,Ñ7Ô7ð >¸J¼OÈqÒ<PÐ<PØ#-Ô#3°AÔ#6¸Ñ#:�LØ"4×"8Ò"8¸Ñ"GÔ"G�KØ# {Ò2Ð2ÝŸšðcà'Ø(ñ	ô ð ð 9EÐ& }Ñ5Ø*×.Ò.¨}Ñ=Ô=Ð=à×!Ò! &Ñ)Ô)Ð)õ 25°T±´ÐÐ-Ñ.ð 2BÐÐ-Ñ.ð #9½3¸v¹;¼;Ñ"FÐà�	Ð/Ð/Ð.Ð/Ð/ˆð #'ˆÔà"ð 	Ý# E¨>¸4Ñ@Ô@ˆMõ ! Ð0BÀDÑIÔIˆJØÐ!Ý$ ]Ð4MÈtÑTÔT�
ØÐ%Ø×,Ò,Ð-DÑEÔEÐEð Ð 7Ð7Ð7Ø$­G°MÐCUÕWZÑW\ÔW\Ñ,]Ô,]Ð]Ð]Ð]ð`ñ ^Ô]Ð]ð ˆs   š=A Á
A6Á"
A1Á1A6rE   ú#tuple[str | None, list[int] | None]c                ó¸  — | €dS 	 t          j        | ¦  «        }n3# t          t          t          f$ r}t          d| ›d�¦  «        |‚d}~ww xY w|j        dk    rdS |j        dk    rd|j        �|j        gndfS |j        d	k    rd	|j        �|j        gndfS |j        d
k    rd|j        �|j        gndfS t          j        d|j        ›d�t          d¬¦  «         dS )a`  Map a torch-style device specifier to PTL ``accelerator``/``devices`` kwargs.

        Args:
            device: A device specifier accepted by ``torch.device``.

        Returns:
            ``(accelerator, devices)`` where ``devices`` is ``None`` unless an explicit device index is provided (for
            example ``cuda:1``). ``device.type == "xla"`` maps to ``accelerator="tpu"`` -- PTL's accelerator
            registry has no ``"xla"`` string; ``"tpu"`` is its canonical name for the XLA backend.

        Raises:
            ValueError: If ``device`` is not a valid torch device specifier.
        N)NNz&Invalid device specifier for train(): zE. Expected values like 'cpu', 'cuda', 'cuda:0', or torch.device(...).rQ   )rQ   Nr9   ÚgpuÚmpsÚxlaÚtpuzDevice type zˆ is not explicitly mapped to a PyTorch Lightning accelerator; falling back to PTL auto-detection. Training may use an unexpected device.r8   ©Ú
stacklevel)
rH   rE   r”   r•   ÚRuntimeErrorrF   rš   ÚwarningsÚwarnÚUserWarning)rE   Úresolved_deviceÚexcs      r>   rÑ   z%RFDETR._resolve_trainer_device_kwargs«  s\  € ð ˆ>Ø�:ð	Ý#œl¨6Ñ2Ô2ˆOˆOøÝ�:¥|Ð4ð 	ð 	ð 	ÝðV¸ð Vð Vð Vñô ð ðøøøøð	øøøð Ô 5Ò(Ð(Ø�;ØÔ 6Ò)Ð)Ø°_Ô5JÐ5V˜?Ô0Ð1Ð1Ð\`Ð`Ð`ØÔ 5Ò(Ð(Ø°_Ô5JÐ5V˜?Ô0Ð1Ð1Ð\`Ð`Ð`ØÔ 5Ò(Ð(ð
 °_Ô5JÐ5V˜?Ô0Ð1Ð1Ð\`Ð`Ð`åŒðf˜?Ô/ð fð fð fåØð		
ñ 	
ô 	
ð 	
ð ˆzs   † ›A²AÁAc           	     ó˜  — 	 ddl m}m}m} nD# t          $ r7}|j        r|j                             d¦  «        r‚ t          d¦  «        |‚d}~ww xY wt          | dd¦  «        rt          j
        dt          d	¬
¦  «         t          | fi |¤Ž\  }}}t          |dd¦  «        }	|	r*|                      |¦  «         |                      |	¦  «         t          ¦   «         �rst          |dd¦  «        }
|
�€H|	�rE| j        j        �s8t%          | d¦  «        si | _        	 t(                               |	t(                               | j        |	¦  «        ¬¦  «        }
nH# t.          t0          t2          t4          f$ r(}t6                               d|	|¦  «         d}
Y d}~nd}~ww xY w|
€›t;          |	¦  «        t=          d¦  «        z                       ¦   «         rj	 tA          |	d¦  «         !                    ¦   «         }
nF# t.          t0          t2          t4          f$ r&}t6                               d|	|¦  «         Y d}~nd}~ww xY wtE          || j        |
¦  «         nVt6           #                    dtH          j%         &                    d¦  «        tH          j%         &                    d¦  «        ¦  «          || j        |¦  «        } || j        |¦  «        }|j'        rÒt          ¦   «         rÄ	 ddl(m)} | *                    d¦  «         t;          |j+        ¦  «        dz  } || ,                    ¦   «         |d¬¦  «         -                    ¦   «           || .                    ¦   «         |d¬¦  «         -                    ¦   «          n‰# t^          $ r t6           0                    dd¬¦  «         Y naw xY w|j'        rVt6           #                    dtH          j%         &                    d¦  «        tH          j%         &                    d¦  «        ¦  «         |j1        �rSte          h d£¦  «        }t;          |j1        ¦  «        j        |v �r&ddl3m4}  ||j1        d¬ ¦  «        }tk          | &                    d!¦  «        ¦  «        }~t;          |j1        ¦  «         6                    ¦   «         j7        }t;          |j+        ¦  «         6                    ¦   «         }||k    }|r-t6           0                    d"|j1        |j+        |j+        ¦  «         n,t6           0                    d#|j1        |j+        |j+        ¦  «         |r7|s5t6           0                    d$|j1        ||j+        tq          |¦  «        ¦  «         d%|i}|�||d&<    ||| j        fi |¤Ž}| 9                    |||j1        pd¬'¦  «         |j:        | j:        _:        tw          | j        |¦  «        | j:        _<        d| _=        |  >                    ¦   «          t          |dd¦  «        }|�|| j:        _!        nt          |dd¦  «        }|�|| j:        _!        t          ¦   «         r"tE          || j        | j:        j!        ¦  «         dS dS )(uo	  Train an RF-DETR model via the PyTorch Lightning stack.

        All keyword arguments are forwarded to :meth:`get_train_config` to build a :class:`~rfdetr.config.TrainConfig`.
        Several kwargs are absorbed and handled specially so that existing call-sites do not break:

        * ``resolution`` â€” updates the model's input resolution by mutating
          :attr:`model_config.resolution` in place before the train config is built. This change persists on
          :attr:`model_config` after :meth:`train` returns. The value must be a positive integer divisible by
          ``patch_size * num_windows`` for the model variant; a :class:`ValueError` is raised otherwise.
          :attr:`model_config.positional_encoding_size` is also updated when the config derives it formulaically (``PE
          == resolution // patch_size``); configs with a pretrained-specific PE value (e.g. ``RFDETRBase`` uses DINOv2's
          PE=37 at 560 px) are left unchanged to preserve checkpoint compatibility.
        * ``device`` â€” normalized via :class:`torch.device` and mapped to PyTorch
          Lightning trainer arguments. ``"cpu"`` becomes ``accelerator="cpu"``; ``"cuda"`` and ``"cuda:N"`` become
          ``accelerator="gpu"`` and optionally ``devices=[N]``; ``"mps"`` becomes ``accelerator="mps"``; ``"xla"``
          becomes ``accelerator="tpu"`` (PTL's canonical name for the XLA backend). Other valid torch device types
          fall back to PTL auto-detection and emit a :class:`UserWarning`.
        * ``notes`` â€” optional user-defined metadata (string, dict, list, or
          any JSON-serialisable value) stored under the ``"notes"`` key in every ``.pth`` checkpoint produced during
          training.  The value is also available inside ``args["notes"]`` for full provenance.  Pass the same value to
          :meth:`export` to embed it in the ONNX file as well.

        After training completes the underlying ``nn.Module`` is synced back onto ``self.model.model`` so that
        :meth:`predict` and :meth:`export` continue to work without reloading the checkpoint.

        Raises:
            ImportError: If training dependencies are not installed. Install with
                ``pip install "rfdetr[train,loggers]"``.
            ValueError: If ``resolution`` is not a positive integer or is not
                divisible by ``patch_size * num_windows`` for the model variant.
        r   ©ÚRFDETRDataModuleÚRFDETRModelModuleÚbuild_trainerúrfdetr.úqRF-DETR training dependencies are missing. Install them with `pip install "rfdetr[train,loggers]"` and try again.Nr:  Fa	  Calling train() on a model that has already been trained or loaded from a checkpoint. The new training run will start from the original pretrained weights (pretrain_weights), NOT from the in-memory trained state. To continue training, pass resume=<checkpoint_path>.r8   r¶  Údataset_dirrê   r  ©Úcoco_categoriesz0Could not read class names from dataset '%s': %sÚtrainz;Could not read class names from the shard index in '%s': %szqNot the launcher's main process (RANK=%s, SLURM_PROCID=%s); skipping the start-of-run training_config.json write.ÚRANKÚSLURM_PROCID)ÚDatasetGridSaverÚfitÚdataset_grids)Údataset_typer$  zBFailed to save dataset grids; training will continue without them.Trø   z]Not the launcher's main process (RANK=%s, SLURM_PROCID=%s); skipping the dataset-grid render.>   úlast_ema.pthúcheckpoint_best_ema.pthúcheckpoint_best_total.pthúcheckpoint_best_regular.pthrJ  rL  r+  a³  resume=%r points at one of BestModelCallback's lightweight checkpoints, which intentionally omit optimizer/LR-scheduler state to stay small. Model weights and epoch count will resume. Callback state can restore only for matching configured callbacks; the optimizer and LR scheduler restart cold. To resume with optimizer/scheduler state too, pass the trainer's full checkpoint instead (e.g. %s/last.ckpt or %s/checkpoint_<epoch>.ckpt).uB  resume=%r points at one of BestModelCallback's lightweight checkpoints, which intentionally omit optimizer/LR-scheduler state to stay small. Model weights and epoch count will resume, but this particular file has no saved callback state (it predates callback-state persistence, or every registered callback had nothing to save), so best-score tracking, EMA, and early-stopping state all restart cold this run too â€” not just the optimizer and LR scheduler. To resume with full state, pass the trainer's full checkpoint instead (e.g. %s/last.ckpt or %s/checkpoint_<epoch>.ckpt).up  resume=%r was written under %s but output_dir=%r points elsewhere. PyTorch Lightning only restores best_model_score/best_k_models when output_dir matches the checkpoint's original directory exactly â€” with this output_dir, best-score tracking (BestModelCallback's high-water mark) restarts fresh in the new directory instead of resuming. Set output_dir=%r to keep it.ÚacceleratorÚdevices)Ú	ckpt_path)@Úrfdetr.trainingrÀ  rÁ  rÂ  rr  r  rO  rz  r¦   r¹  rº  r»  ré   Ú#_align_keypoint_schema_from_datasetÚ_align_num_classes_from_datasetr'   r¡   Úuse_grouppose_keypointsr®   r  rt   Ú_load_classesÚ_memoized_coco_categoriesÚFileNotFoundErrorr•   ÚKeyErrorr  rÖ   rƒ  r	   r!   r
  r"   rê   r  r×   rÿ   ÚenvironrÒ   Úsave_dataset_gridsÚrfdetr.datasets.save_gridsrË  Úsetupr  Útrain_dataloaderÚ	save_gridÚval_dataloaderr  r  ÚresumeÚ	frozensetrs  rK  r—   ÚresolveÚparentr£   rÌ  r¬   r   rº   r:  Úremove_optimized_modelr(   )r¹   r¼   rÀ  rÁ  rÂ  r½  ræ   rÞ   rß   rÅ  Úpre_fit_class_namesÚmoduleÚ
datamodulerË  Úgrids_output_dirÚ_light_checkpoint_namesrK  Ú_resume_ckptÚ_has_callback_stateÚ_resume_dirÚ_configured_output_dirÚ_best_score_restoresÚtrainer_kwargsÚtrainerÚconfig_class_namesÚdataset_class_namess                             r>   rÈ  zRFDETR.trainÙ  s9  € ðF
	ØZÐZÐZÐZÐZÐZÐZÐZÐZÐZÐZøÝ"ð 	ð 	ð 	ð Œxð ˜CœH×/Ò/°	Ñ:Ô:ð ØÝðYñô ð ðøøøøð	øøøõ �4Ð,¨eÑ4Ô4ð 	ÝŒMðmõ Øðñ ô ð õ *=¸TÐ)LÐ)LÀVÐ)LÐ)LÑ&ˆ�˜hõ
 ˜f m°TÑ:Ô:ˆØð 	>Ø×4Ò4°VÑ<Ô<Ð<Ø×0Ò0°Ñ=Ô=Ð=õ" %Ñ&Ô&ñ &	Ý")¨&°-ÀÑ"FÔ"FÐð #Ñ*¨{Ñ*À4ÔCTÔClÑ*Ý˜tÐ%=Ñ>Ô>ð 5Ø24�DÔ/ð/å*0×*>Ò*>Ø#Ý(.×(HÒ(HÈÔIdÐfqÑ(rÔ(rð +?ñ +ô +Ð'Ð'øõ *­:µxÅÐIð /ð /ð /Ý—L’LÐ!SÐU`ÐbeÑfÔfÐfØ*.Ð'Ð'Ð'Ð'Ð'Ð'øøøøð/øøøð 'Ð.µD¸Ñ4EÔ4EÍ
ÐSZÑH[ÔH[Ñ4[×3cÒ3cÑ3eÔ3eÐ.ðvÝ.>¸{ÈGÑ.TÔ.T×.`Ò.`Ñ.bÔ.bÐ+Ð+øÝ-­z½8ÅWÐMð vð vð vÝŸšÐ%bÐdoÐqtÑuÔuÐuÐuÐuÐuÐuÐuøøøøðvøøøå! &¨$Ô*;Ð=PÑQÔQÐQÐQõ �KŠKð.å”
—’˜vÑ&Ô&Ý”
—’˜~Ñ.Ô.ñ	ô ð ð #Ð" 4Ô#4°fÑ=Ô=ˆØ%Ð% dÔ&7¸Ñ@Ô@ˆ
ð Ô$ð 	Õ)BÑ)DÔ)Dð 	ðØGÐGÐGÐGÐGÐGà× Ò  Ñ'Ô'Ð'Ý#'¨Ô(9Ñ#:Ô#:¸_Ñ#LÐ Ø Ð  ×!<Ò!<Ñ!>Ô!>Ð@PÐ_fÐgÑgÔg×qÒqÑsÔsÐsØ Ð  ×!:Ò!:Ñ!<Ô!<Ð>NÐ]bÐcÑcÔc×mÒmÑoÔoÐoÐoøÝð ð ð Ý—’ØXØ!ð ñ ô ð ð ð ðøøøð
 Ô&ð 	Ý�KŠKØoÝ”
—’˜vÑ&Ô&Ý”
—’˜~Ñ.Ô.ñô ð ð Œ=ñ N	õ '0ØwÐwÐwñ'ô 'Ð#õ �F”MÑ"Ô"Ô'Ð+BÐBÑBØ@Ð@Ð@Ð@Ð@Ð@ð  0Ð/°´ÀTÐJÑJÔJ�Ý&*¨<×+;Ò+;¸KÑ+HÔ+HÑ&IÔ&IÐ#Ø Ý" 6¤=Ñ1Ô1×9Ò9Ñ;Ô;ÔB�Ý)-¨fÔ.?Ñ)@Ô)@×)HÒ)HÑ)JÔ)JÐ&Ø'2Ð6LÒ'LÐ$à&ð Ý—N’Nð`ð œØÔ)ØÔ)ñ
ô 
ð 
ð 
õ —N’Nðeð œØÔ)ØÔ)ñô ð ð. 'ð Ð/Cð Ý—N’Nð4ð œØ#ØÔ)Ý˜KÑ(Ô(ñô ð ð +8¸Ð)FˆØÐØ(0ˆN˜9Ñ%Ø�- ¨Ô(9ÐLÐL¸^ÐLÐLˆØ�Š�F˜J°&´-Ð2GÀ4ˆÑHÔHÐHð "œ<ˆŒ
Ôõ 2°$Ô2CÀVÑLÔLˆŒ
Œð "&ˆÔð 	×#Ò#Ñ%Ô%Ð%å$ V¨]¸DÑAÔAÐØÐ)Ø%7ˆDŒJÔ"Ð"å")¨*°mÀTÑ"JÔ"JÐØ"Ð.Ø)<�”
Ô&õ
 ÑÔð 	UÝ! &¨$Ô*;¸T¼ZÔ=SÑTÔTÐTÐTÐTð	Uð 	UsW   ‚
 �
A—2A	Á	AÄ:E ÅFÅ/FÆFÇ"G1 Ç1H4ÈH/È/H4ËBM3 Í3&NÎNÚtest)Úsplitrù  úLiteral['test', 'val']údict[str, float]c          	     óÒ  — ddl m} 	 ddlm}m}m} nD# t          $ r7}|j        r|j                             d¦  «        r‚ t          d¦  «        |‚d}~ww xY w|dvrt          d|›d	�¦  «        ‚| j        j        }| j        j        }	t          | d
d¦  «        }
|
�t          |
dd¦  «        nd}|
�t          |
dd¦  «        nd}|�t          |dd¦  «        nd}|�t          |dd¦  «        nd}	 t          | fddi|¤Ž\  }}}| j                             ddi¬¦  «        }|| j        _        |	| j        _        |
�Gt#          |
d¦  «        r||
_        |�.t#          |d¦  «        r||_        t#          |d¦  «        r||_        nf# || j        _        |	| j        _        |
�Gt#          |
d¦  «        r||
_        |�.t#          |d¦  «        r||_        t#          |d¦  «        r||_        w xY w |||¦  «        }t          | j        dd¦  «        }|duot'          |¦  «        dk    }| j        j        }|€t)          d¦  «        ‚|rMt+          j        d¦  «        5  |                     d¦  «        }|| j        _        ddd¦  «         n# 1 swxY w Y   	 |                     ¦   «         } |||j        ¦  «         |j                             |¦  «         |rt5          | j        ¦  «         n# |rt5          | j        ¦  «         w w xY w |||¦  «        }|dk    rdnd}|                     |¦  «         t          |dd¦  «        }t9          |t:          ¦  «        r_t=          |¦  «        | j        j        k    rBtA          j!        d|j"        › dt=          |¦  «        › d| j        j        › d�tF          d¬¦  «         ddi}|�||d <   |�||d!<    ||| j        fi |¤Ž}tA          j$        ¦   «         5  tA          j%        d"d#¬$¦  «         |dk    r| &                    ||¦  «        }n| '                    ||¦  «        }ddd¦  «         n# 1 swxY w Y   |r$d%„ |d          (                    ¦   «         D ¦   «         ni S )&uŒ  Evaluate the current model on a dataset split and return COCO metrics.

        Runs a single evaluation pass over the requested split via the PyTorch Lightning stack and returns the COCO
        metrics (mAP, mAR, and the macro-F1 sweep) computed by
        :class:`~rfdetr.training.callbacks.coco_eval.COCOEvalCallback`. The same metrics are also printed to the
        terminal. This works both directly after :meth:`train` and on a model loaded via :meth:`from_checkpoint` â€” the
        weights already held in memory are evaluated; no checkpoint file is re-loaded.

        Apart from ``split``, this method accepts exactly the same keyword arguments as :meth:`train` (``dataset_dir``,
        ``device``, ``resolution``, ``batch_size``, ``output_dir``, ``num_workers``, ...); they are handled identically
        via the shared :func:`_prepare_run_config`. This parity is for convenience â€” the same kwargs dict used for
        :meth:`train` can be reused here â€” not a guarantee every field has an effect. Training-only fields (``epochs``,
        ``lr``, ``weight_decay``, ``ema``, ``early_stopping``, ``run``, ``project``, ``checkpoint_interval``,
        ``tensorboard``/``wandb``/``mlflow``/``clearml``, and similar) are silently accepted and ignored: ``evaluate()``
        runs through an eval-only trainer (``include_training_callbacks=False``) that never builds EMA, drop-path,
        checkpointing, early-stopping, or logger callbacks, so those fields have nothing to attach to.

        Unlike :meth:`train`, this method never adapts the detection head to the dataset: the model is evaluated exactly
        as configured. If the dataset's class count differs from the model's ``num_classes`` a :class:`UserWarning` is
        emitted and evaluation proceeds with the model's head unchanged.

        Unlike :meth:`train`, a ``resolution`` override does **not** persist: :attr:`model_config` (and any cached
        ``model.resolution`` / ``model.args`` inference context) is restored to its pre-call values once the
        eval-only config copy has captured the override, so a later :meth:`predict` / :meth:`export` / :meth:`train`
        call is unaffected by an ``evaluate(resolution=...)`` call.

        Args:
            split: Which split to evaluate. ``"test"`` evaluates the ``test/`` folder (YOLO-format datasets â€” plain
                YOLO datasets and Roboflow exports whose detected format is YOLO â€” fall back to the ``valid/`` split,
                with a logged warning, when no ``test`` split can be resolved. A Roboflow export in COCO format has
                no such fallback and still raises ``FileNotFoundError`` when its ``test`` split is missing;
                COCO/Objects365 never attempt ``test`` and always evaluate ``valid/``) via ``trainer.test``;
                ``"val"`` evaluates the ``valid/`` folder via ``trainer.validate``.
            **kwargs: The same keyword arguments accepted by :meth:`train` â€” ``dataset_dir`` is required (here or
                already on the config), and the rest are forwarded to :func:`_prepare_run_config` /
                :meth:`get_train_config`.

        Returns:
            Mapping of metric name to value for the evaluated split, e.g. ``{"test/mAP_50_95": ..., "test/mAP_50": ...,
            "test/F1": ...}``. Per-class keys (``"test/AP/<class>"``) are included only when
            ``log_per_class_metrics=True`` (default ``False``). Empty when the trainer returns no metrics.

        Raises:
            ImportError: If training dependencies are not installed. Install with
                ``pip install "rfdetr[train,loggers]"``.
            ValueError: If ``split`` is not ``"test"`` or ``"val"``.
        r   )Úinterpolate_position_embeddingsr¿  rÃ  rÄ  N)rø  r$  z#split must be 'test' or 'val', got r�   r¬   rº   rÇ   rÈ   rÂ   Tr=  )ru  rE   rQ   zTCannot evaluate: the base model has been cleared by a previous inplace optimization.Frø  Úvalidaterê   z	Dataset 'z' has z' classes but the model has num_classes=z]. Evaluating with the model's head unchanged; class indices may not line up with the dataset.r8   r¶  Úinclude_training_callbacksrÓ  rÔ  Úignorez.*no logger configured.*)Úmessagec                ó4   — i | ]\  }}|t          |¦  «        “ŒS r;   )Úfloat)r<   r   r¡  s      r>   rS  z#RFDETR.evaluate.<locals>.<dictcomp>|  s$   € ÐGÐGÐG¡j c¨5�•U˜5‘\”\ÐGÐGÐGr@   ))Úrfdetr.models.weightsrý  rÖ  rÀ  rÁ  rÂ  rr  r  rO  rz  r•   r¡   rÇ   rÈ   r¦   ré   Ú
model_copyr®   r¬   r£   r¸  rH   r±   rO   rd  Úload_state_dictrµ   rá  r–   r*  rü   rî   r¹  rº  rÅ  r»  Úcatch_warningsÚfilterwarningsrø  rþ  r~  )r¹   rù  r¼   rý  rÀ  rÁ  rÂ  r½  Ú_orig_resolutionÚ_orig_peÚ_live_modelÚ
_live_argsÚ_orig_model_resolutionÚ_orig_args_resolutionÚ_orig_args_peræ   rÞ   rß   Úeval_model_configrë  Ú_original_deviceÚ_moved_to_cpuÚsource_modelÚsource_staterì  Ústager÷  rô  rõ  Úresultss                                 r>   ÚevaluatezRFDETR.evaluateá  s+  € ð` 	JÐIÐIÐIÐIÐIð	ØZÐZÐZÐZÐZÐZÐZÐZÐZÐZÐZøÝ"ð 	ð 	ð 	ØŒxð ˜CœH×/Ò/°	Ñ:Ô:ð ØÝðYñô ð ðøøøøð	øøøð ˜Ð'Ð'ÝÐMÀ5ÐMÐMÐMÑNÔNÐNð  Ô,Ô7ÐØÔ$Ô=ˆÝ˜d G¨TÑ2Ô2ˆØ;FÐ;R•W˜[¨&°$Ñ7Ô7Ð7ÐX\ˆ
ØMXÐMd¥¨°lÀDÑ!IÔ!IÐ!IÐjnÐØKUÐKa¥¨
°LÀ$Ñ GÔ GÐ GÐgkÐØQ[ÐQg� 
Ð,FÈÑMÔMÐMÐmqˆð	LÝ-@ÀÐ-_Ð-_ÐPTÐ-_ÐX^Ð-_Ð-_Ñ*ˆF�L (ð !%Ô 1× <Ò <ÐEWÐY]ÐD^Ð <Ñ _Ô _Ðà+;ˆDÔÔ(Ø9AˆDÔÔ6ØÐ&Ý˜;¨Ñ5Ô5ð DØ-C�KÔ*ØÐ)Ý˜z¨<Ñ8Ô8ð FØ0E˜
Ô-Ý˜zÐ+EÑFÔFð LØ>K˜
Ô;øøð ,<ˆDÔÔ(Ø9AˆDÔÔ6ØÐ&Ý˜;¨Ñ5Ô5ð DØ-C�KÔ*ØÐ)Ý˜z¨<Ñ8Ô8ð FØ0E˜
Ô-Ý˜zÐ+EÑFÔFð LØ>K˜
Ô;ÐKÐKÐKÐKØ"Ð"Ð#4°fÑ=Ô=ˆõ # 4¤:¨x¸Ñ>Ô>ÐØ(°Ð4ÐW½Ð=MÑ9NÔ9NÐRWÒ9WˆØ”zÔ'ˆØÐÝÐuÑvÔvÐvØð 	0ÝÔ% eÑ,Ô,ð 0ð 0Ø+Ÿš¨uÑ5Ô5�Ø#/�”
Ô ð0ð 0ð 0ñ 0ô 0ð 0ð 0ð 0ð 0ð 0ð 0øøøð 0ð 0ð 0ð 0ð	:Ø'×2Ò2Ñ4Ô4ˆLð ,Ð+¨LÐ:KÔ:dÑeÔeÐeØŒL×(Ò(¨Ñ6Ô6Ð6àð :Ý-¨d¬jÑ9Ô9Ð9øøð ð :Ý-¨d¬jÑ9Ô9Ð9Ð9ð:øøøð
 &Ð%Ð&7¸Ñ@Ô@ˆ
ð   6š/˜/��¨zˆØ×Ò˜ÑÔÐÝ% j°-ÀÑFÔFÐÝÐ)­4Ñ0Ô0ð 	µSÐ9LÑ5MÔ5MÐQUÔQbÔQnÒ5nÐ5nÝŒMðB˜FÔ.ð Bð BµcÐ:MÑ6NÔ6Nð Bð BØ#Ô0Ô<ðBð Bð Bõ Øðñ ô ð ð +GÈÐ)NˆØÐ#Ø,8ˆN˜=Ñ)ØÐØ(0ˆN˜9Ñ%Ø�- ¨Ô(9ÐLÐL¸^ÐLÐLˆõ
 Ô$Ñ&Ô&ð 	?ð 	?ÝÔ# HÐ6PÐQÑQÔQÐQØ˜ŠˆØ!Ÿ,š, v¨zÑ:Ô:��à!×*Ò*¨6°:Ñ>Ô>�ð	?ð 	?ð 	?ñ 	?ô 	?ð 	?ð 	?ð 	?ð 	?ð 	?ð 	?øøøð 	?ð 	?ð 	?ð 	?ð LSÐZÐGÐG°G¸A´J×4DÒ4DÑ4FÔ4FÐGÑGÔGÐGÐXZÐZsR   ˆ
 “
A�2AÁAÃ,0E> Å>A#G!É"I>É>JÊJÊ
?K  Ë K9Ï A
P6Ð6P:Ð=P:Tr7   Útorchscript)ÚinplaceÚcompile_backendÚcompilerË   rŠ   rG   útorch.dtype | strr  r  ú"Literal['torchscript', 'inductor']c          	     ó¤  — t          |t          ¦  «        r8	 t          t          |¦  «        }n!# t          $ r t          d|›�¦  «        d‚w xY wt          |t          j        ¦  «        st          dt          |¦  «        ›�¦  «        ‚|j        st          d|› �¦  «        ‚|dvrt          d|›�¦  «        ‚|r|rt          d¦  «        ‚|  
                    ¦   «          | j        j        €t          d¦  «        ‚| j        j        }|j        dk    rt          j                             |¦  «        nt          j        ¦   «         }	 |5  |r| j        j        nt#          | j        j        ¦  «        }|                     ¦   «          |                     ¦   «          |                     |¬	¦  «        }|røt          j        || j        j        | j        j        | j        j        | j        j        |¬
¦  «        }	|dk    r!t          j                             ||	¦  «        }n�t          j        |d¬¦  «        }t          j        ¦   «         5   ||	¦  «         |j        dk    r* ||	¦  «         t          j                             |¦  «         ddd¦  «         n# 1 swxY w Y   d| _        || _        || j        _         || _!        |rd| j        _        | j        j        | _"        d| _#        || _$        ddd¦  «         dS # 1 swxY w Y   dS # tJ          $ rG t          j&        tJ          ¦  «        5  |  
                    ¦   «          ddd¦  «         n# 1 swxY w Y   ‚ w xY w)uø  Optimize the model for inference with optional compilation and dtype casting.

        Operations are wrapped in the correct CUDA device context to prevent context leaks on multi-GPU setups. When
        ``compile=True`` the model is compiled using ``compile_backend`` and a dummy input of ``batch_size`` images at
        the model's current resolution. The default ``"torchscript"`` backend preserves the existing
        ``torch.jit.trace`` path. ``"inductor"`` uses ``torch.compile(mode="reduce-overhead")`` and, on CUDA, runs the
        dummy input twice before synchronizing the selected device so setup is paid inside this method instead of the
        first :meth:`predict` call. By default,
        optimization deep-copies the loaded model before exporting it so the original module remains available. Set
        ``inplace=True`` for memory-constrained inference-only deployments; this exports the loaded module itself, may
        cast it to ``dtype``, and clears ``model.model`` after optimization succeeds. In-place optimization is
        destructive: :meth:`remove_optimized_model` becomes a no-op (issues :class:`UserWarning`), and :meth:`export`
        raises :class:`RuntimeError`. Create or reload a new ``RFDETR`` instance to recover the original model.

        If ``inplace=True`` and the underlying ``export()`` call mutates the module before raising (e.g. setting
        internal flags and swapping ``forward``), the exception handler resets RFDETR wrapper flags to the unoptimized
        state but cannot undo changes made inside ``export()``. Create a new RFDETR instance for reliable inference
        after such a failure.

        Args:
            compile: If ``True``, compile the model using ``compile_backend``. Set to ``False`` for broader
                compatibility (e.g. models with dynamic control flow).
            batch_size: Number of images the compiled model will be optimized for. Ignored when ``compile=False``.
            dtype: Target floating-point dtype for the inference model. Accepts a
                ``torch.dtype`` directly (e.g. ``torch.float16``) or its string name (e.g. ``"float16"``). Defaults to
                ``torch.float32``. When ``dtype`` differs from the model's current dtype, ``to()`` transiently
                allocates both old and new parameter tensors simultaneously; peak memory during optimization is
                approximately 1.5Ã— the model weight size rather than 1Ã—.
            inplace: If ``True``, optimize ``model.model`` directly instead of deep-copying it. This is a destructive,
                inference-only path because ``export()`` mutates the module and dtype casting mutates its parameters.
                Requires ``compile=False``. With the default ``dtype=torch.float32``, the dtype cast is a no-op, so
                memory savings come only from clearing the base model reference rather than from dtype reduction.
            compile_backend: Compilation implementation used when ``compile=True``. ``"torchscript"`` (default)
                preserves the existing trace path. ``"inductor"`` uses :func:`torch.compile` in reduce-overhead mode;
                it can reduce steady-state latency but has a substantially higher one-time compilation cost and its
                device/operator support depends on the installed PyTorch version.

        Raises:
            TypeError: If ``dtype`` is not a ``torch.dtype``, or if ``dtype`` is a
                string that does not correspond to a valid ``torch.dtype`` attribute.
            ValueError: If ``dtype`` is not a floating-point dtype, if ``compile_backend`` is unknown, or if
                ``inplace=True`` is used with ``compile=True``.
            RuntimeError: If the base model has already been cleared by a previous inplace optimization.

        Examples:
            >>> from types import SimpleNamespace
            >>> import torch
            >>> class _TinyModel(torch.nn.Module):
            ...     def __init__(self):
            ...         super().__init__()
            ...         self.linear = torch.nn.Linear(1, 1)
            ...     def forward(self, x):
            ...         return {"pred_boxes": self.linear(x[:, :1, :1, :1].squeeze(-1).squeeze(-1))}
            ...     def export(self):
            ...         return None
            >>> class _TinyContext:
            ...     def __init__(self):
            ...         self.device = torch.device("cpu")
            ...         self.resolution = 28
            ...         self.model = _TinyModel()
            ...         self.inference_model = None
            >>> model = object.__new__(RFDETR)
            >>> model.model_config = SimpleNamespace(num_channels=3)
            >>> model.model = _TinyContext()
            >>> model._is_optimized_for_inference = False
            >>> model._has_warned_about_not_being_optimized_for_inference = False
            >>> model._optimized_has_been_compiled = False
            >>> model._optimized_batch_size = None
            >>> model._optimized_resolution = None
            >>> model._optimized_dtype = None
            >>> model._optimized_inplace = False
            >>> # Standard (non-inplace) optimization â€” reversible:
            >>> model.inference(compile=False)
            >>> model._is_optimized_for_inference
            True
            >>> model._optimized_inplace
            False
            >>> model.remove_optimized_model()
            >>> model._is_optimized_for_inference
            False
            >>> # Inplace optimization â€” destructive, cannot be reversed:
            >>> model.inference(compile=False, dtype="float16", inplace=True)
            >>> model._is_optimized_for_inference
            True
            >>> model._optimized_dtype
            torch.float16
            >>> model._optimized_inplace
            True
        z=dtype must be a torch.dtype or a string name of a dtype, got NzFdtype must be a floating-point torch.dtype or string name of one, got )r  Úinductorz9compile_backend must be 'torchscript' or 'inductor', got zíinference(inplace=True) requires compile=False. Compiled models can retain references to the original parameter storage, so setting model.model=None may not free the weight tensors and inplace=True would not reliably reduce memory usage.z|Cannot optimize: the base model has been cleared by a previous inplace optimization. Create or reload a new RFDETR instance.r9   ©rG   ©rE   rG   r  zreduce-overhead)ÚmodeT)'r–   r£   r¦   rH   ÚAttributeErrorr”   rG   rF   Úis_floating_pointr•   ré  r¬   r¸  rE   r9   r  Únullcontextr   ÚevalÚexportrO   Úrandnr¡   r.  rÇ   ÚjitÚtracer  r±   Úsynchronizer5  r6  r2  r9  r7  r3  r8  r  r  )
r¹   r  rË   rG   r  r  rE   Úcuda_ctxr2  Údummy_inputs
             r>   Ú	inferencezRFDETR.inference~  sh  € õF �e�SÑ!Ô!ð 	uðuÝ¥ uÑ-Ô-��øÝ!ð uð uð uÝÐ iÐ`eÐ iÐ iÑjÔjÐptÐtðuøøøå˜%¥¤Ñ-Ô-ð 	mÝÐkÕ\`ÐafÑ\gÔ\gÐkÐkÑlÔlÐlØÔ&ð 	oÝÐmÐfkÐmÐmÑnÔnÐnØÐ"=Ð=Ð=ÝÐlÐYhÐlÐlÑmÔmÐmØð 	�wð 	Ýð ñô ð ð 	×#Ò#Ñ%Ô%Ð%àŒ:ÔÐ#Ýð:ñô ð ð
 ”Ô"ˆØ06´¸vÒ0EÐ0E•5”:×$Ò$ VÑ,Ô,Ð,Í:ÔKaÑKcÔKcˆð1	Øð +.ð +.Ø;BÐ'b t¤zÔ'7Ð'7ÍÐQUÔQ[ÔQaÑHbÔHb�Ø×$Ò$Ñ&Ô&Ð&Ø×&Ò&Ñ(Ô(Ð(à"1×"4Ò"4¸5Ð"4Ñ"AÔ"A�àð <Ý"'¤+Ø"ØÔ)Ô6Øœ
Ô-Øœ
Ô-Ø#œzÔ0Ø#ð#ñ #ô #�Kð '¨-Ò7Ð7Ý*/¬)¯/ª/Ø+Ø'ñ+ô +˜˜õ
 +0¬-¸ÐN_Ð*`Ñ*`Ô*`˜Ý"Ô1Ñ3Ô3ð ?ð ?Ø+˜O¨KÑ8Ô8Ð8Ø%œ{¨fÒ4Ð4à / °Ñ <Ô <Ð <Ý %¤
× 6Ò 6°vÑ >Ô >Ð >ð?ð ?ð ?ñ ?ô ?ð ?ð ?ð ?ð ?ð ?ð ?øøøð ?ð ?ð ?ð ?ð 9=�DÔ5Ø1;�DÔ.ð .=�”
Ô*ð
 +2�Ô'Øð ,Ø'+�D”JÔ$Ø-1¬ZÔ-B�Ô*Ø37�Ô0Ø(-�Ô%ðW+.ð +.ð +.ñ +.ô +.ð +.ð +.ð +.ð +.ð +.ð +.ð +.øøøð +.ð +.ð +.ð +.ð +.ð +.øõX ð 	ð 	ð 	åÔ$¥YÑ/Ô/ð .ð .Ø×+Ò+Ñ-Ô-Ð-ð.ð .ð .ñ .ô .ð .ð .ð .ð .ð .ð .øøøð .ð .ð .ð .àð		øøøs„   —- ­AÅK> ÅC:K1È>AJÉ?K1ÊJ	ÊK1ÊJ	ÊAK1Ë$K> Ë1K5Ë5K> Ë8K5Ë9K> Ë>#MÌ!MÌ6MÍM	ÍMÍ	M	Í
Mc                óÐ   — t          | dd¦  «        rt          j        dt          d¬¦  «         dS d| j        _        d| _        d| _        d| _        d| _	        d| _
        d| _        dS )uø  Remove the optimized inference model and reset all optimization flags.

        Clears ``model.inference_model`` and resets all internal state set by :meth:`inference`. Safe to
        call even if the model has not been optimized. When the model was optimized with ``inplace=True``, this method
        issues a :class:`UserWarning` and returns without modifying state â€” the original module cannot be restored
        because ``export()`` and dtype casting mutate it; create or reload a new ``RFDETR`` instance instead.

        Examples:
            >>> from types import SimpleNamespace
            >>> import torch
            >>> class _TinyModel(torch.nn.Module):
            ...     def __init__(self):
            ...         super().__init__()
            ...         self.linear = torch.nn.Linear(1, 1)
            ...     def forward(self, x):
            ...         return {"pred_boxes": self.linear(x[:, :1, :1, :1].squeeze(-1).squeeze(-1))}
            ...     def export(self):
            ...         return None
            >>> class _TinyContext:
            ...     def __init__(self):
            ...         self.device = torch.device("cpu")
            ...         self.resolution = 28
            ...         self.model = _TinyModel()
            ...         self.inference_model = None
            >>> model = object.__new__(RFDETR)
            >>> model.model_config = SimpleNamespace(num_channels=3)
            >>> model.model = _TinyContext()
            >>> model._is_optimized_for_inference = False
            >>> model._has_warned_about_not_being_optimized_for_inference = False
            >>> model._optimized_has_been_compiled = False
            >>> model._optimized_batch_size = None
            >>> model._optimized_resolution = None
            >>> model._optimized_dtype = None
            >>> model._optimized_inplace = False
            >>> model.inference(compile=False)
            >>> model.remove_optimized_model()
            >>> model._is_optimized_for_inference
            False
        r9  FuÉ   remove_optimized_model() has no effect after inplace optimization â€” the original model cannot be restored because export() and dtype casting mutate it. Create or reload a new RFDETR instance instead.r8   r¶  N)r¦   r¹  rº  r»  r¬   r2  r3  r5  r6  r7  r8  r9  ©r¹   s    r>   ré  zRFDETR.remove_optimized_model3  sˆ   € õP �4Ð-¨uÑ5Ô5ð 	ÝŒMðBõ Øðñ ô ð ð ˆFØ%)ˆŒ
Ô"Ø+0ˆÔ(Ø,1ˆÔ)Ø%)ˆÔ"Ø%)ˆÔ"Ø $ˆÔØ"'ˆÔÐÐr@   c                ó$   — t          | dd¦  «        S )aò  Whether the model was optimized with ``inplace=True``.

        Returns ``True`` after a successful :meth:`inference` call with ``inplace=True``,
        meaning the base model has been cleared and :meth:`remove_optimized_model` is a no-op.

        Examples:
            >>> from types import SimpleNamespace
            >>> import torch
            >>> class _TinyModel(torch.nn.Module):
            ...     def __init__(self):
            ...         super().__init__()
            ...         self.linear = torch.nn.Linear(1, 1)
            ...     def forward(self, x):
            ...         return {"pred_boxes": self.linear(x[:, :1, :1, :1].squeeze(-1).squeeze(-1))}
            ...     def export(self):
            ...         return None
            >>> class _TinyContext:
            ...     def __init__(self):
            ...         self.device = torch.device("cpu")
            ...         self.resolution = 28
            ...         self.model = _TinyModel()
            ...         self.inference_model = None
            >>> model = object.__new__(RFDETR)
            >>> model.model_config = SimpleNamespace(num_channels=3)
            >>> model.model = _TinyContext()
            >>> model._is_optimized_for_inference = False
            >>> model._has_warned_about_not_being_optimized_for_inference = False
            >>> model._optimized_has_been_compiled = False
            >>> model._optimized_batch_size = None
            >>> model._optimized_resolution = None
            >>> model._optimized_dtype = None
            >>> model._optimized_inplace = False
            >>> model.is_optimized_inplace
            False
            >>> model.inference(compile=False, inplace=True)
            >>> model.is_optimized_inplace
            True
        r9  F)r¦   r0  s    r>   Úis_optimized_inplacezRFDETR.is_optimized_inplacel  s   € õP �tÐ1°5Ñ9Ô9Ð9r@   Úoutputé   Úonnxéd   )	ÚbackendÚsocÚfp16Úmax_batch_sizeÚnotesÚcoreml_precisionÚcoreai_precisionÚopenvino_precisionÚoutput_namer  r£   Ú	infer_dirÚbackbone_onlyÚopset_versionÚverboserM   útuple[int, int] | NoneÚdynamic_batchr‹   r    r{  ÚquantizationÚcalibration_dataú!str | np.ndarray[Any, Any] | NoneÚ
max_imagesr7  r8  r9  r:  r;  rˆ   r<  r=  r>  r?  r	   c       	        óÀ  — ddl m} ddlm} ddlm} ddlm}m}  ||
¦  «        }
|�+|
dk    s|s#t          j
        d|
›d	|›d
�t          d¬¦  «          ||
||¦  «        \  }} ||
|¬¦  «          ||
¦  «        }|                     t          |¦  «        |t          | dd¦  «        ||||||||||||||||¬¦  «        } ||¦  «        }t                               d|
› d�¦  «         | j        j        }t          | dd¦  «        s| j        j        €t'          d¦  «        ‚| j        j                             d¦  «        | j        _        t+          | j        j        ¦  «        } |                      |¦  «         	 t-          j        |d¬¦  «         t1          |	| j        d¦  «        }	t          | j        dd¦  «        }!t5          |!t6          ¦  «        st5          |!t8          ¦  «        r|!dk    rt;          d|!›�¦  «        ‚|	|!z  }"|€Q| j        j        | j        j        f}|d         |"z  dk    r)t;          d| j        j        › d|"› d|	› d|!› d |"› d!�¦  «        ‚nt?          ||"|	|!¦  «        } || | j        ||||||¬"¦  «        }# ||#¦  «        | j        j                             |¦  «        | j        _        S # | j        j                             |¦  «        | j        _        w xY w)#uZ?  Export the trained model to ONNX, TFLite, TensorRT, ExecuTorch, CoreML, OpenVINO, or LiteRT format.

        See the `export documentation <https://rfdetr.roboflow.com/exports/>`_ for more information.

        Args:
            output_dir: Directory to write the exported model to.
            infer_dir: Optional directory of sample images for dynamic-axes inference.
            backbone_only: Export the encoder and feature projectors without prediction heads. Returns one NCHW
                feature map per configured ``projector_scale`` level, followed by cross-attention feature levels
                when a separate cross-attention projector is present.
            opset_version: ONNX opset version to target.
            verbose: Print export progress information.
            shape: ``(height, width)`` tuple; defaults to square at model resolution.
                Both dimensions must be divisible by ``patch_size * num_windows``.
            batch_size: Static batch size to bake into the ONNX graph. With ``dynamic_batch=True`` and
                ``format="tensorrt"`` it is also the batch the engine's optimization profile is tuned for.
            dynamic_batch: If True, export with a dynamic batch dimension
                so the model accepts variable batch sizes at runtime
                (spatial dimensions always stay fixed). Applies to the ONNX
                and TFLite graphs, and to ``format="tensorrt"``, where the engine is built with one
                optimization profile spanning batch ``1 .. max_batch_size`` (tuned for *batch_size*); pass
                *max_batch_size* in that case. Not supported for ExecuTorch export on
                executorch 1.3.1 (raises ``NotImplementedError``): the runtime
                cannot resize RF-DETR's windowed-attention reshapes, so a
                dynamic ``.pte`` runs only at the traced batch â€” export one
                ``.pte`` per batch size instead. Also unsupported for native CoreML
                (``format="coreml"``): fixed shapes are required for reliable ANE / GPU scheduling.
                Also unsupported for ``format="openvino"``: the IR graph bakes a fixed input shape;
                export one model per batch size instead. Also unsupported for ``format="litert"``:
                the ``.tflite`` bakes a fixed input shape; export one file per batch size instead.
            patch_size: Backbone patch size. Defaults to the value stored
                in ``model_config.patch_size`` (typically 14 or 16). When
                provided explicitly it must match the instantiated model's
                patch size. Shape divisibility is validated against
                ``patch_size * num_windows``.
            format: Export format â€” ``"onnx"`` (default), ``"tflite"``, ``"tensorrt"`` (alias: ``"trt"``),
                ``"executorch"`` (alias: ``"pte"``), ``"coreml"``, ``"coreai"``, ``"openvino"`` or ``"litert"``.
                ``"tflite"`` and ``"tensorrt"`` both first export to ONNX,
                then convert: ``"tflite"`` via ``onnx2tf`` (requires
                ``pip install rfdetr[tflite]``); ``"tensorrt"`` via the
                TensorRT Python API (requires ``pip install rfdetr[tensorrt]``).
                Unlike ``"onnx"``/``"tflite"`` portable serialization,
                ``"tensorrt"`` performs target-specific compilation at
                export time and produces a non-portable ``.trt`` engine
                tied to the build machine's GPU and TensorRT version.
                When ``"executorch"`` is selected the model is exported
                directly via ``torch.export`` to an ExecuTorch
                ``.pte`` file (no ONNX step), configured by *backend* / *soc* below.  Requires
                ``pip install rfdetr[executorch]``. ``"openvino"`` converts directly from PyTorch to OpenVINO IR
                format (requires ``pip install rfdetr[openvino]``). ``"litert"`` converts directly from PyTorch to
                a LiteRT ``.tflite`` file via ``litert-torch`` (``torch.export`` capture, no ONNX or TensorFlow
                step; requires ``pip install rfdetr[litert]``) â€” the same file type as ``"tflite"``, reached
                without ``onnx2tf``. It writes a single float32 graph with the two-stage query selection
                inside, so it runs on LiteRT's CPU (XNNPACK) delegate; keypoint models are not supported on
                litert-torch 0.9.4 (its converter rejects the keypoint head's rank-4 matmul).
                When ``"coreml"`` is selected the model is exported via ``torch.export`` + ``coremltools`` to a
                native ``.mlpackage`` (no ONNX step; requires
                ``pip install rfdetr[coreml]``). This is distinct from
                ExecuTorch's ``format="executorch", backend="coreml"``
                path, which still produces a ``.pte``. If you know that
                ExecuTorch delegate and expect ``format="coreml"`` to mean
                the same thing: it does not â€” pass
                ``format="executorch", backend="coreml"`` for the ``.pte``
                route instead. Passing both ``format="coreml"`` and
                ``backend="coreml"`` together does **not** fall through
                to the ExecuTorch delegate; ``backend`` is ignored (with
                a warning) and the native ``.mlpackage`` path always runs.
                Detection, segmentation and keypoint models all have registry-clean and numerical-parity
                test coverage for this format (see ``tests/export/test_coreml_op_coverage.py`` /
                ``test_coreml_export.py``).
                When ``"coreai"`` is selected the model is exported via ``torch.export`` + ``coreai-torch`` to an
                Apple Core AI ``.aimodel`` (requires ``pip install rfdetr[coreai]``; the asset runs on iOS,
                iPadOS and macOS 27 or later).

                .. warning::
                    TFLite, ExecuTorch, CoreML, and LiteRT export are experimental
                    and subject to change; upstream dependency instabilities
                    (``onnx2tf``, ``ai_edge_litert``, ``executorch``,
                    ``coremltools``, ``litert-torch``) may affect results.
            quantization: TFLite quantization mode (ignored when
                ``format="onnx"``, ``format="openvino"``, or ``format="executorch"``).  One of ``None``,
                ``"fp32"``, ``"fp16"``, ``"int8"``.  ``None`` / ``"fp32"`` / ``"fp16"`` produce FP32 + FP16
                ``.tflite`` files; ``"int8"`` additionally produces a dynamic-range INT8 model (INT8 weights,
                float activations; needs no calibration data). ``format="litert"`` accepts only ``None`` /
                ``"fp32"`` (it writes one float32 ``.tflite``) and raises ``NotImplementedError`` for the other
                modes rather than silently ignoring them.
            calibration_data: Optional data not consumed when building the exported ``.tflite`` models. Accepts:

                * ``None`` â€” auto-generate random data (the default, and adequate for every quantization mode).
                * A **directory path** (``str``) containing JPEG/PNG
                  images â€” the converter automatically loads, resizes, and prepares them.
                * A path (``str``) to a ``.npy`` file of shape ``(N, H, W, 3)``, dtype float32, values in ``[0, 1]``.
                * A :class:`numpy.ndarray` with the same format.

                This does **not** improve INT8 accuracy: ``quantization="int8"`` produces a dynamic-range model whose
                weight scales come from the weights themselves. When passed as ``None``, a directory, or an array, the
                data is saved to an unused scratch file in *output_dir* but not consumed to build the model. An
                existing ``.npy`` path is reused without writing a copy.
            max_images: Maximum number of images to load from a *calibration_data* directory.  Defaults to ``100``.
                Only used when *calibration_data* is a directory path.
            backend: Hardware backend to specialize the export for.  Required when ``format="executorch"`` and
                ignored â€” with a warning â€” for any other format.  Accepted values for ExecuTorch:
                ``"xnnpack"`` (portable CPU, fp32), ``"coreml"`` (Apple devices, fp16; requires ``coremltools``),
                and ``"qnn"`` (Qualcomm Snapdragon HTP, fp16; requires an ExecuTorch source build against the
                QAIRT SDK â€” not available via pip).
            soc: Target SoC (System on Chip) â€” the specific Qualcomm Snapdragon chip the exported model will run
                on.  Required when ``backend="qnn"``: the QNN backend compiles the ``.pte`` ahead-of-time for one
                chip's Hexagon Tensor Processor (HTP), unlike ``"xnnpack"``/``"coreml"`` which run on any device of
                their platform, so the target chip must be known at export time.  Ignored â€” with a warning â€” for
                any other backend or format.  Must be a
                :class:`~executorch.backends.qualcomm.serialization.qc_schema.QcomChipset` name, e.g. ``"SM8650"``
                (Snapdragon 8 Gen 3); see that enum for the full list of supported chips.  Has no effect for
                ``"xnnpack"`` or ``"coreml"``.
            fp16: Build the TensorRT engine with FP16 precision.  Only applies when ``format="tensorrt"``
                (alias ``"trt"``); ignored for every other format.  Defaults to ``True`` for lowest latency
                on NVIDIA GPUs.  TensorRT 11+ removed the FP16 builder flag, so there the engine is built
                from an FP16-cast graph instead; engine I/O stays FP32 either way.  A lean/partial
                TensorRT < 11 wheel that lacks the FP16 builder flag falls back to an FP32 engine with a
                warning instead â€” see :meth:`~rfdetr.export._tensorrt.exporter.TensorRTExporter.build_engine`
                for the full precision-resolution logic.  Pass ``False`` for an FP32 engine.
            max_batch_size: Largest batch a dynamic TensorRT engine must accept.  Only read when
                ``format="tensorrt"`` and ``dynamic_batch=True``, where it is required: the engine is built with
                one optimization profile spanning batch ``1 .. max_batch_size`` and tuned for *batch_size*
                (``batch_size <= max_batch_size``).  Ignored for every other format or combination; passing a
                non-``None`` value there emits a ``UserWarning`` instead of silently doing nothing.
            notes: Optional user-defined metadata (string, dict, list,
                or any JSON-serialisable value) to embed in the exported
                ONNX model under the ``"rfdetr_notes"`` metadata property.
                When ``None`` no metadata entry is written. String values
                are stored verbatim; all other types are JSON-encoded so
                consumers must call ``json.loads()`` to recover a dict or
                list. The same value can be passed to :meth:`train` so the
                checkpoint and the ONNX file share the same provenance
                information. **Ignored for ``format="executorch"``,
                ``format="coreml"``, ``format="openvino"``, and ``format="litert"``**: those artifacts have
                no ONNX-style metadata slot, and a non-``None`` value emits a ``UserWarning`` instead of being
                embedded.
            coreml_precision: ``ct.convert`` compute precision for ``format="coreml"`` â€” ``None`` (default) or
                ``"float32"`` selects FP32 (tight CPU parity with eager
                PyTorch); ``"float16"`` selects a smaller
                ANE-oriented bundle (expect larger numeric drift). Ignored for every other format.
            coreai_precision: Precision the graph is traced and stored in for ``format="coreai"`` â€” ``None``
                (default) or ``"float32"``, or ``"float16"`` for a half-size asset whose input and outputs are
                float16 too. Ignored for every other format.
            openvino_precision: ``"float32"``, ``"float16"``, or ``None`` (default) for ``format="openvino"``
                â€” ``None`` keeps OpenVINO's own ``compress_to_fp16=True`` default; ``"float32"`` disables
                FP16 weight compression, controlling IR *storage* precision only (execution precision still
                depends on the compiled device â€” not guaranteed to match eager PyTorch on non-CPU devices).
                Ignored for every other format.
            output_name: Full filename override (without extension), e.g. ``"my-model"``. When set, takes
                precedence over the model's variant name (``self.size``) and the exported file is named
                ``{output_name}.{ext}`` verbatim â€” this also suppresses the ``_fp32``/``_fp16``/``_{backend}``
                detail suffix that would otherwise be appended to encode the resolved precision/backend/SoC
                (see *format* / *coreml_precision* / *backend* / *soc* / *fp16* above). Sanitized against path
                traversal (only the basename, extension stripped, is used). Exception: ``format="tflite"``
                always writes multiple files (one per precision/quantization mode), so the ``_fp32``/``_fp16``/
                ``_dynamic_range_quant`` suffix is unavoidable even with
                *output_name* set â€” it becomes the stem
                instead of the model's variant name.
                Exceptions: ONNX, CoreML, ExecuTorch, OpenVINO, LiteRT, and TensorRT with ``backbone_only=True``
                append ``-backbone`` before the extension (e.g., ``{output_name}-backbone.onnx``); TFLite writes
                per-precision files
                instead of a single ``{output_name}.tflite`` file. TFLite filenames may include a ``_gs_patched`` infix
                before the precision suffix when GridSample ops are patched, e.g.
                ``{output_name}_gs_patched_fp32.tflite``; this is the standard RF-DETR path.

        Returns:
            Path to the exported model file (``.onnx``, ``.tflite`` for both TFLite and LiteRT, ``.trt``,
            ``.pte``, ``.mlpackage``, ``.aimodel`` or ``.xml`` for OpenVINO).

        Raises:
            ValueError: If ``format`` is unrecognized; if ``format="executorch"`` and ``backend`` is missing,
                unrecognized, or (for ``backend="qnn"``) ``soc`` is missing; if the resolved export shape is
                not divisible by ``patch_size * num_windows``; if ``coreml_precision``/``openvino_precision``
                is not one of their accepted values; or if ``format="tensorrt"`` with ``dynamic_batch=True``
                lacks ``max_batch_size`` or has ``batch_size > max_batch_size``.
            NotImplementedError: If ``dynamic_batch=True`` is combined with ``format="executorch"``,
                ``format="coreml"``, ``format="openvino"``, or ``format="litert"`` â€” those paths require a fixed
                batch size; or if ``format="litert"`` is combined with a ``quantization`` other than ``None`` /
                ``"fp32"``.
            ImportError: If the optional dependencies for the requested
                ``format``/``backend`` are not installed (e.g.
                ``rfdetr[onnx]``, ``rfdetr[executorch]``,
                ``rfdetr[coreml]``, ``coremltools`` for ExecuTorch
                ``backend="coreml"``, ``openvino`` for OpenVINO export,
                ``rfdetr[litert]`` for LiteRT export,
                or an ExecuTorch source build against the QAIRT SDK for
                ``backend="qnn"``); also raised for ``format="tensorrt"`` with ``fp16=True`` on a
                strongly typed TensorRT (11+) if ``onnx``/``onnxconverter-common`` are not installed
                to cast the graph â€” install ``rfdetr[tensorrt]`` for the complete set, or pass
                ``fp16=False``.
            RuntimeError: If called after the model has undergone in-place inference optimization (the original
                model has been cleared; instantiate a new :class:`RFDETR` to export).
        r   )Ú_resolve_export_backend)Ú reject_unsupported_dynamic_batch)Úprepare_export_graph)Únormalize_formatÚresolve_exporterNÚtensorrtzX`max_batch_size` is only used for format='tensorrt' with dynamic_batch=True (got format=z, dynamic_batch=z). This argument is ignored.r8   r¶  )rE  r=   )r  r?  Úvariant_namerA  rE  rC  r;  rB  r7  r8  r9  r<  r=  r>  rF  rG  rI  rË   r:  zExporting model to z formatr9  FzRFDETR.export() is not available after inplace optimization. The original model has been cleared. Create a new RFDETR instance.rQ   Trð   r'  rŒ   r7   z,num_windows must be a positive integer, got úModel's default resolution (ú!) is not divisible by block_size=r’   r“   ú*). Provide an explicit shape divisible by r�   )rM   rE   r@  rË   rE  rA  ) Úrfdetr.export._backendrK  Úrfdetr.export.baserL  Úrfdetr.export.preparerM  Úrfdetr.export.registryrN  rO  r¹  rº  r»  Úbuild_configr	   r¦   rÖ   r×   r¬   rE   r¸  rO   r   rÿ   r   r¨   r¡   r–   r—   rŠ   r•   rÇ   rŸ   )$r¹   r  r@  rA  rB  rC  rM   rË   rE  r‹   r{  rF  rG  rI  r7  r8  r9  r:  r;  r<  r=  r>  r?  rK  rL  rM  rN  rO  Úexporter_classræ   ÚexporterrE   r¬   rŒ   r‰   Úgraphs$                                       r>   r'  zRFDETR.export–  sñ  € ðx 	CÐBÐBÐBÐBÐBØGÐGÐGÐGÐGÐGØ>Ð>Ð>Ð>Ð>Ð>ØMÐMÐMÐMÐMÐMÐMÐMà!Ð! &Ñ)Ô)ˆØÐ%¨6°ZÒ+?Ð+?À}Ð+?ÝŒMðgØ%ðgð gØ9Fðgð gð gåØð	ñ ô ð ð /Ð.¨v°wÀÑDÔD‰ˆ�ð 	)Ð(¨¸}ÐMÑMÔMÐMØ)Ð)¨&Ñ1Ô1ˆð  ×,Ò,Ý˜JÑ'Ô'Ø#Ý   v¨tÑ4Ô4Ø'Ø'ØØØ'ØØØØ-Ø-Ø1Ø%Ø-Ø!Ø!Ø)ð' -ñ 
ô 
ˆð. "�> &Ñ)Ô)ˆÝ�ŠÐ9¨&Ð9Ð9Ð9Ñ:Ô:Ð:à”Ô"ˆå�4Ð-¨uÑ5Ô5ð 	¸¼Ô9IÐ9QÝðUñô ð ð  œ:Ô+×.Ò.¨uÑ5Ô5ˆŒ
ÔÝ˜œÔ)Ñ*Ô*ˆØ�Š�ÑÔÐð	;ÝŒK˜
¨TÐ2Ñ2Ô2Ð2Ý,¨Z¸Ô9JÈHÑUÔUˆJÝ! $Ô"3°]ÀAÑFÔFˆKÝ˜+¥tÑ,Ô,ð aµJ¸{ÍCÑ4PÔ4Pð aÐT_ÐcdÒTdÐTdÝ Ð!_ÐP[Ð!_Ð!_Ñ`Ô`Ð`Ø# kÑ1ˆJØˆ}ØœÔ.°´
Ô0EÐF�Ø˜”8˜jÑ(¨AÒ-Ð-Ý$ðP°t´zÔ7Lð Pð PØ&0ðPð PØ?IðPð PØZeðPð PàBLðPð Pð Pñô ð ð .õ -¨U°JÀ
ÈKÑXÔX�à(Ð(ØØÔ!ØØØ#Ø%Ø+Ø+ð	ñ 	ô 	ˆEð �8˜E‘?”?à#œzÔ/×2Ò2°6Ñ:Ô:ˆDŒJÔÐø˜tœzÔ/×2Ò2°6Ñ:Ô:ˆDŒJÔÐ:Ð:Ð:Ð:s   Å8DJ2 Ê2+KrÅ  úlist[dict[str, Any]]c                ó  — t           j                             | dd¦  «        }t          |d¬¦  «        5 }t	          j        |¦  «        }ddd¦  «         n# 1 swxY w Y   t          |d         t          |¦  «        ¦  «        S )u9  Read the train-split COCO categories that survive the grouping-category filter.

        Single source for the category basis shared by :meth:`_load_classes` and
        :meth:`_detect_num_classes_for_training`: both need the categories of ``train/_annotations.coco.json`` that
        :func:`~rfdetr.datasets.coco.filter_parent_categories` keeps. Hand-copying that read-and-filter pair into each
        method lets the two drift apart, and drift here means ``num_classes`` disagreeing with the label space.

        Args:
            dataset_dir: Path to the dataset root directory containing the ``train`` split.

        Returns:
            The kept ``categories`` entries ordered by category id â€” the same basis and order
            :class:`~rfdetr.datasets.coco.CocoDetection` uses to assign label indices.
        rÈ  ú_annotations.coco.jsonró   )rö   NÚ
categories)rÿ   r  r	  Úopenrý   Úloadr   r   )rÅ  Ú	coco_pathÚfÚannss       r>   Ú_filtered_coco_categoriesz RFDETR._filtered_coco_categoriesÏ  s­   € õ  ”G—L’L ¨gÐ7OÑPÔPˆ	Ý�) gÐ.Ñ.Ô.ð 	 °!Ý”9˜Q‘<”<ˆDð	 ð 	 ð 	 ñ 	 ô 	 ð 	 ð 	 ð 	 ð 	 ð 	 ð 	 øøøð 	 ð 	 ð 	 ð 	 å'¨¨\Ô(:Õ<RÐSWÑ<XÔ<XÑYÔYÐYs   ³AÁAÁAÚcacheúlist[dict[str, Any]] | Nonec                ó  — t          |¦  «        sdS t          t          |¦  «                             ¦   «         ¦  «        }|| v r| |         S t                               |¦  «        }|                      ¦   «          || |<   |S )uâ  Return :meth:`_filtered_coco_categories` for *dataset_dir*, parsing the annotation file at most once.

        :meth:`train` needs the same category basis twice back to back â€” once to align ``num_classes``, once to
        record the label space in ``training_config.json`` â€” and the annotation file can be large. The memo holds
        one directory at a time, keyed on its resolved path, so pointing the same detector at a different dataset
        replaces the entry rather than accumulating. The cache is passed in rather than read off ``self`` so the
        static readers this feeds stay callable without an instance; on a test double whose attribute is not a real
        dict, membership tests are false and assignment is a no-op, so it degrades to parsing every time.

        Args:
            cache: The owning detector's ``_coco_categories_cache``.
            dataset_dir: Path to the dataset root directory.

        Returns:
            The kept categories, or ``None`` when *dataset_dir* is not a COCO-style layout and there is nothing to
            parse â€” the readers then take their own non-COCO branches.

        Examples:
            >>> RFDETR._memoized_coco_categories({}, "/missing") is None
            True
        N)r   r£   r	   rç  rt   rf  Úclear)rg  rÅ  r   r`  s       r>   rÛ  z RFDETR._memoized_coco_categoriesä  s|   € õ2 % [Ñ1Ô1ð 	Ø�4Ý•$�{Ñ#Ô#×+Ò+Ñ-Ô-Ñ.Ô.ˆØ�%ˆ<ˆ<Ø˜”:ÐÝ×5Ò5°kÑBÔBˆ
Ø�Š‰ŒˆØˆˆc‰
ØÐr@   rÆ  rÇ  ú	list[str]c               óV  ‡— t          | ¦  «        r(|€t                               | ¦  «        }d„ |D ¦   «         S t          | ¦  «        rt                               | ¦  «        nd}|�²t          |¦  «        5 }t          j        |¦  «        Šddd¦  «         n# 1 swxY w Y   d‰v r`t          ‰d         t          ¦  «        r3ˆfd„t          ‰d                              ¦   «         ¦  «        D ¦   «         S d„ ‰d         D ¦   «         S t          d|› d�¦  «        ‚t          d| › d	�¦  «        ‚)
aÔ  Load class names from a COCO or YOLO dataset directory.

        Unannotated grouping categories are dropped by :func:`~rfdetr.datasets.coco.filter_parent_categories`, so the
        returned names are index-aligned with ``CocoDetection.cat2label``. See
        :meth:`_detect_num_classes_for_training` for the shared filter basis.

        Args:
            dataset_dir: Path to the dataset root directory.
            coco_categories: An already-parsed :meth:`_filtered_coco_categories` result for *dataset_dir*, so a
                caller holding one (see :meth:`_memoized_coco_categories`) skips the second parse. ``None`` reads
                the annotation file here. Only consulted for a COCO-style layout.
        Nc                ó   — g | ]
}|d          ‘ŒS rb  r;   ©r<   Úcategorys     r>   r%  z(RFDETR._load_classes.<locals>.<listcomp>  s   € ÐEÐEÐE¨�H˜VÔ$ÐEÐEÐEr@   Únamesc                óF   •— g | ]}t          ‰d          |         ¦  «        ‘ŒS )rp  ©r£   )r<   ÚiÚdatas     €r>   r%  z(RFDETR._load_classes.<locals>.<listcomp>   s*   ø€ ÐXÐXÐX°a�C  W¤¨aÔ 0Ñ1Ô1ÐXÐXÐXr@   c                ó,   — g | ]}t          |¦  «        ‘ŒS r;   rr  )r<   r  s     r>   r%  z(RFDETR._load_classes.<locals>.<listcomp>!  s   € Ð<Ð<Ð< d�˜D™	œ	Ð<Ð<Ð<r@   zFound z' but it does not contain 'names' field.zCould not find class names in zX. Checked for COCO (train/_annotations.coco.json) and YOLO (data.yaml, data.yml) styles.)r   rt   rf  r$   Ú_yolo_data_file_pathra  ÚyamlÚ	safe_loadr–   rt  ÚsortedÚkeysr•   rÜ  )rÅ  rÇ  Ú	yaml_pathrd  rt  s       @r>   rÚ  zRFDETR._load_classes  s�  ø€ õ ! Ñ-Ô-ð 	FØÐ&Ý"(×"BÒ"BÀ;Ñ"OÔ"O�ØEÐE°_ÐEÑEÔEÐEå@UÐVaÑ@bÔ@bÐl•F×/Ò/°Ñ<Ô<Ð<Ðhlˆ	ØÐ Ý�i‘”ð ) AÝ”~ aÑ(Ô(�ð)ð )ð )ñ )ô )ð )ð )ð )ð )ð )ð )øøøð )ð )ð )ð )à˜$ˆˆÝ˜d 7œm­TÑ2Ô2ð YØXÐXÐXÐX½6À$ÀwÄ-×BTÒBTÑBVÔBVÑ;WÔ;WÐXÑXÔXÐXØ<Ð<¨d°7¬mÐ<Ñ<Ô<Ð<ÝÐX iÐXÐXÐXÑYÔYÐYÝðf¨[ð fð fð fñ
ô 
ð 	
s   Á5BÂBÂB©rÙ  rÇ  rÙ  c               óª  — t          | ¦  «        ry|rBt          j                             | dd¦  «        }t	          t          |¦  «        j        ¦  «        S |€t                               | ¦  «        }t	          d„ |D ¦   «         ¦  «        S |s£t          | ¦  «        t          d¦  «        z                       ¦   «         rr	 t          | d¦  «        }|j        dk    r#t          d„ |j        D ¦   «         d¬¦  «        d	z   S t	          |                     ¦   «         pi ¦  «        S # t"          $ r Y nw xY wt	          t                               | ¦  «        ¦  «        S )
uK  Detect the class count using the same category basis as training labels.

        For COCO-style datasets this counts the categories of ``train/_annotations.coco.json`` that
        :func:`~rfdetr.datasets.coco.filter_parent_categories` keeps, which is the same basis
        :class:`~rfdetr.datasets.coco.CocoDetection` uses to build ``cat2label`` â€” unannotated grouping categories
        consume neither a label index nor an output slot. In keypoint mode it instead counts the
        inferred RF-DETR keypoint label slots. In legacy background-first schemas (e.g. ``[0, 17]``) slot ``0`` is
        reserved for classes without keypoints; active-first schemas (e.g. ``[17]``) use normal 0-based indices. For
        a packed ``dataset_file="webdataset"`` directory (keypoints unsupported there, so only reached when
        *use_grouppose_keypoints* is false) it reads the train shard index instead of a raw annotation file, using
        the same ``"remap"``/``"raw"`` convention :func:`~rfdetr.datasets.webdataset.load.build_webdataset` does.
        For YOLO-style datasets it falls back to ``_load_classes``.

        Args:
            dataset_dir: Path to the dataset root directory.
            use_grouppose_keypoints: Count keypoint label slots instead of detection categories.
            coco_categories: An already-parsed :meth:`_filtered_coco_categories` result for *dataset_dir* (see
                :meth:`_memoized_coco_categories`); ``None`` reads the annotation file here. Only consulted on the
                COCO detection branch â€” the keypoint branch parses its own schema.
        rÈ  r_  Nc                ó   — h | ]
}|d          ’ŒS )Úidr;   rn  s     r>   ú	<setcomp>z:RFDETR._detect_num_classes_for_training.<locals>.<setcomp>I  s   € ÐGÐGÐG¨8˜ œÐGÐGÐGr@   Úrawc              3  ó@   K  — | ]}t          |d          ¦  «        V — ŒdS ©r  Nrh  rn  s     r>   r?   z:RFDETR._detect_num_classes_for_training.<locals>.<genexpr>R  s.   è è € Ð[Ð[¸¥ H¨T¤NÑ 3Ô 3Ð[Ð[Ð[Ð[Ð[Ð[r@   éÿÿÿÿ©rÔ   r7   )r   rÿ   r  r	  rü   r   rê   rt   rf  r	   r!   r
  r"   Úcategory_idsÚmaxr`  Ú	cat2labelr    rÚ  )rÅ  rÙ  rÇ  rc  Útrain_indexs        r>   Ú _detect_num_classes_for_trainingz'RFDETR._detect_num_classes_for_training(  se  € õ6 ! Ñ-Ô-ð 	IØ&ð NÝœGŸLšL¨°gÐ?WÑXÔX�	ÝÕ5°iÑ@Ô@ÔLÑMÔMÐMØÐ&Ý"(×"BÒ"BÀ;Ñ"OÔ"O�ÝÐGÐG°ÐGÑGÔGÑHÔHÐHà&ð 	:­D°Ñ,=Ô,=Å
È7Ñ@SÔ@SÑ,S×+[Ò+[Ñ+]Ô+]ð 	:ð:Ý.¨{¸GÑDÔD�ð Ô+¨uÒ4Ð4ÝÐ[Ð[ÀKÔDZÐ[Ñ[Ô[ÐegÐhÑhÔhÐklÑlÐlÝ˜;×0Ò0Ñ2Ô2Ð8°bÑ9Ô9Ð9øõ 3ð ð ð Ø�ðøøøõ •6×'Ò'¨Ñ4Ô4Ñ5Ô5Ð5s   Â=D Ä
D+Ä*D+c                ó¬  — t          | d¦  «        si | _        	 | j        j        rdnt                               | j        |¦  «        }t                               || j        j        |¬¦  «        }nG# t          t          t          t          f$ r'}t                               d||¦  «         Y d}~dS d}~ww xY wg }| j        j        rDt          t          | j        dg ¦  «        pg ¦  «        }|rt          |t!          |¦  «        ¦  «        }| j        j        }||k    rdS dt          | j        dt%          ¦   «         ¦  «        v }|s”t                               d||||¦  «         || j        _        t          | j        d	d¦  «        }|�||_        |rCt!          |¦  «        |k     r2|d
g|t!          |¦  «        z
  z  z   }	|	| j        _        |�|	|_        dS dS dS dS t                               d|||||¦  «         |rYt!          |¦  «        |k     rH|d
g|t!          |¦  «        z
  z  z   }	|	| j        _        t          | j        d	d¦  «        }|�|	|_        dS dS dS dS )u[  Auto-detect the dataset class count and align ``model_config.num_classes`` in-place.

        Must be called before ``RFDETRModelModule`` is constructed so that weight loading inside the module uses the
        correct (dataset-derived) class count.

        When the user did **not** explicitly set ``num_classes`` (it is left unset, e.g. inferred from a
        checkpoint), ``model_config.num_classes`` and ``self.model.args.num_classes`` are updated to match the dataset.
        When the user *did* set ``num_classes`` explicitly â€” to any value, including the class default â€” and it differs
        from the dataset, the configured value is preserved and a warning is emitted.

        Failures from ``_detect_num_classes_for_training`` are caught and logged at DEBUG level so that training is
        never blocked by detection errors.

        When ``model_config.use_grouppose_keypoints`` is True and
        ``model_config.num_keypoints_per_class`` is shorter than the adjusted
        ``num_classes``, the schema is zero-padded in-place so that
        ``len(num_keypoints_per_class) == num_classes``.  Both ``model_config``
        and ``model.args`` (if present) are updated.  Appended classes receive
        zero keypoints and contribute no class-logit boost.

        Args:
            dataset_dir: Path to the training dataset root directory.
        r  Nr|  z7Could not auto-detect num_classes from dataset '%s': %sre  rî   rj  zTDetected %d classes in dataset '%s'; auto-adjusting model num_classes from %d to %d.rº   r   z¹Dataset '%s' has %d classes but model was initialized with num_classes=%d. Using the model's configured value (%d). If this is unintentional, reinitialize the model with num_classes=%d.)r®   r  r¡   rÙ  rt   rÛ  rŠ  rÜ  r•   rÝ  r  rÖ   rƒ  r*  r¦   r‡  rü   rî   r}  r¬   re  r  )
r¹   rÅ  rÇ  Údataset_num_classesr½  Úkeypoint_schemaÚmodel_num_classesÚuser_overroderå   Úpadded_schemas
             r>   rØ  z&RFDETR._align_num_classes_from_datasetW  sý  € õ0 �tÐ5Ñ6Ô6ð 	-Ø*,ˆDÔ'ð	ð
 Ô$Ô<ð`��å×5Ò5°dÔ6QÐS^Ñ_Ô_ð õ
 #)×"IÒ"IØØ(,Ô(9Ô(QØ /ð #Jñ #ô #ÐÐøõ
 "¥:­x½ÐAð 	ð 	ð 	å�LŠLÐRÐT_ÐadÑeÔeÐeØˆFˆFˆFˆFˆFøøøøð	øøøð &(ˆØÔÔ4ð 	Uå"¥7¨4Ô+<Ð>WÐY[Ñ#\Ô#\Ð#bÐ`bÑcÔcˆOØð UÝ&)Ð*=½sÀ?Ñ?SÔ?SÑ&TÔ&TÐ#à Ô-Ô9ÐàÐ"3Ò3Ð3ØˆFð &­°Ô1BÐDVÕX[ÑX]ÔX]Ñ)^Ô)^Ð^ˆàð (	GÝ�LŠLØfØ#ØØ!Ø#ñô ð ð -@ˆDÔÔ)å  ¤¨V°TÑ:Ô:ˆJØÐ%Ø)<�
Ô&ð
 ð G¥3 Ñ#7Ô#7Ð:MÒ#MÐ#MØ /°1°#Ð9LÍsÐSbÑOcÔOcÑ9cÑ2dÑ d�Ø<I�Ô!Ô9ØÐ)Ø9F�JÔ6Ð6Ð6ð	Gð GÐ#MÐ#Mð *Ð)õ �NŠNð>ð Ø#Ø!Ø!Ø#ñ	ô 	ð 	ð ð G¥3 Ñ#7Ô#7Ð:KÒ#KÐ#KØ /°1°#Ð9JÍSÐQ`ÑMaÔMaÑ9aÑ2bÑ b�Ø<I�Ô!Ô9Ý$ T¤Z°¸Ñ>Ô>�
ØÐ)Ø9F�JÔ6Ð6Ð6ðGð GÐ#KÐ#Kð *Ð)s   ™AA/ Á/B3ÂB.Â.B3úPath | Nonec                ó~   — t          | ¦  «        sdS t          | ¦  «        dz  dz  }|                     ¦   «         r|ndS )a°  Return the Roboflow COCO train annotation path when it exists.

        Args:
            dataset_dir: Path to the Roboflow dataset root.

        Returns:
            Train split annotation path, or ``None`` when the dataset is not Roboflow COCO style.

        Raises:
            This helper does not raise.

        Example:
            >>> RFDETR._roboflow_keypoint_annotation_path("/missing") is None
            True
        NrÈ  r_  )r   r	   r
  ©rÅ  Úannotation_paths     r>   Ú"_roboflow_keypoint_annotation_pathz)RFDETR._roboflow_keypoint_annotation_pathÂ  sL   € õ" % [Ñ1Ô1ð 	Ø�4Ý˜{Ñ+Ô+¨gÑ5Ð8PÑPˆØ"1×"8Ò"8Ñ":Ô":ÐDˆˆÀÐDr@   c                ó\   — t          | ¦  «        dz  dz  }|                     ¦   «         r|ndS )a±  Return the native COCO train keypoint annotation path when it exists.

        Args:
            dataset_dir: Path to the COCO dataset root.

        Returns:
            Path to ``annotations/person_keypoints_train2017.json``, or ``None`` when it is absent.

        Raises:
            This helper does not raise.

        Example:
            >>> RFDETR._coco_keypoint_annotation_path("/missing") is None
            True
        r   zperson_keypoints_train2017.jsonN)r	   r
  r“  s     r>   Ú_coco_keypoint_annotation_pathz%RFDETR._coco_keypoint_annotation_pathØ  s7   € õ" ˜{Ñ+Ô+¨mÑ;Ð>_Ñ_ˆØ"1×"8Ò"8Ñ":Ô":ÐDˆˆÀÐDr@   c                ór   — t          | ¦  «        }t          D ]}||z  }|                     ¦   «         r|c S Œ dS )a�  Return the YOLO data file path when a dataset root has one.

        Args:
            dataset_dir: Path to the YOLO dataset root.

        Returns:
            Path to ``data.yaml`` or ``data.yml``, or ``None`` when neither exists.

        Raises:
            This helper does not raise.

        Example:
            >>> RFDETR._yolo_data_file_path("/missing") is None
            True
        N)r	   r#   r
  )rÅ  ÚrootÚfilenameÚ	data_files       r>   rv  zRFDETR._yolo_data_file_pathì  sS   € õ" �KÑ Ô ˆÝ0ð 	!ð 	!ˆHØ˜x™ˆIØ×ÒÑ!Ô!ð !Ø Ð Ð Ð ð!àˆtr@   Úflip_idxú	list[int]c                óF  — g }t          ¦   «         }t          | ¦  «        D ]€\  }}||v s
||v s||k    r|                     |¦  «         Œ)d|cxk    rt          | ¦  «        k     r=n ŒF| |         |k    r.|                     ||g¦  «         |                     ||h¦  «         Œ�|S )zIConvert Ultralytics ``flip_idx`` permutation metadata to flat swap pairs.r   )r}  Ú	enumerater  rü   Úextendru  )rœ  ÚpairsÚseenÚidxÚ
mirror_idxs        r>   Ú_flip_idx_to_pairszRFDETR._flip_idx_to_pairs	  sÇ   € ð ˆÝ™œˆÝ(¨Ñ2Ô2ð 	/ð 	/‰OˆC�Ø�dˆ{ˆ{˜j¨DÐ0Ð0°C¸:Ò4EÐ4EØ—’˜‘”�ØØ�JÐ.Ð.Ò.Ð.¥ X¡¤Ò.Ð.Ð.Ð.Ð.°8¸JÔ3GÈ3Ò3NÐ3NØ—’˜c :Ð.Ñ/Ô/Ð/Ø—’˜S *Ð-Ñ.Ô.Ð.øØˆr@   ræ   r   c           	     óâ  — | j         j        sdS t          |dd¦  «        }|dvrdS t          |dd¦  «        }|sdS t          | d¦  «        si | _        ||f}|| j        v r| j        |         \  }}}�n'	 |dk    r2t
                               |¦  «        }|€dS |}d}t          |¦  «        }n™|dk    rbt
                               |¦  «        }|�|}d	}t          |¦  «        }nct
           	                    |¦  «        }	|	€dS |	}d
}t          |	¦  «        }n1t
           	                    |¦  «        }	|	€dS |	}d
}t          |	¦  «        }nG# t          t          t          t          f$ r'}
t                               d||
¦  «         Y d}
~
dS d}
~
ww xY w|||f| j        |<   |j        }t          |dg ¦  «        st%          |j        ¦  «        |_        t%          t          | j         dg ¦  «        pg ¦  «        }dt          | j         dt)          ¦   «         ¦  «        v }|r"t+          |¦  «        t+          |¦  «        k    rdS ||k    r°|rt                               d|||¦  «         nct/          |¦  «        r7|r5t/          |¦  «        s&t1          j        d|›d|›d|›d�t4          d¬¦  «         t                               d|||¦  «         || j         _        t          | j        dd¦  «        }|�||_        dS dS dS )a~  Infer or validate keypoint schema from COCO, Roboflow COCO, or YOLO pose metadata.

        Args:
            config: Training configuration containing dataset location and format.

        Returns:
            ``None``. The model config is updated in-place when dataset metadata is available.

        Raises:
            This method does not raise for missing or malformed metadata; later dataset construction still validates
            keypoint-mode requirements.

        Example:
            >>> from rfdetr.config import RFDETRKeypointPreviewConfig, TrainConfig
            >>> model = object.__new__(RFDETR)
            >>> model.model_config = RFDETRKeypointPreviewConfig(pretrain_weights=None)
            >>> model.model = type("Context", (), {"args": None})()
            >>> model._align_keypoint_schema_from_dataset(TrainConfig(dataset_dir="/missing", tensorboard=False))
        NÚdataset_file)ÚcocoÚroboflowÚyolorÅ  Ú_keypoint_schema_cacher¨  ÚCOCOr©  zRoboflow COCOz	YOLO posez5Could not infer keypoint schema from dataset '%s': %sÚkeypoint_flip_pairsre  rj  z‹Configured num_keypoints_per_class=%s does not match dataset keypoint metadata %s from '%s'. Using dataset metadata as the source of truth.zYLoaded checkpoint uses a legacy background-first keypoint schema num_keypoints_per_class=z&, but the dataset infers active-first z}. Training will shift person from slot 1 to slot 0; checkpoint head weights are now misaligned. Pass num_keypoints_per_class=z4 to the model constructor to keep the legacy schema.r8   r¶  zFInferred num_keypoints_per_class=%s from %s keypoint metadata at '%s'.rº   )r¡   rÙ  r¦   r®   r«  rt   r—  r   r•  rv  r   rÜ  r•   rÝ  r  rÖ   r×   re  r*  r­  r}  r   r  r)   r¹  rº  r»  r¬   )r¹   ræ   r§  rÅ  Ú	cache_keyÚinferredÚsource_pathÚsource_kindr”  Úyolo_data_filer½  Úinferred_schemaÚcurrent_schemaÚuser_set_schemarå   s                  r>   r×  z*RFDETR._align_keypoint_schema_from_dataset	  s»  € ð* Ô Ô8ð 	ØˆFÝ˜v ~°tÑ<Ô<ˆØÐ;Ð;Ð;ØˆFÝ˜f m°TÑ:Ô:ˆØð 	ØˆFå�tÐ5Ñ6Ô6ð 	=Ø:<ˆDÔ'à! ;Ð/ˆ	Ø˜Ô3Ð3Ð3Ø15Ô1LÈYÔ1WÑ.ˆH�k ;¡;ðØ 6Ò)Ð)Ý&,×&KÒ&KÈKÑ&XÔ&X�OØ&Ð.Ø˜Ø"1�KØ"(�KÝ9¸/ÑJÔJ�H�HØ! ZÒ/Ð/Ý&,×&OÒ&OÐP[Ñ&\Ô&\�OØ&Ð2Ø&5˜Ø&5˜Ý#=¸oÑ#NÔ#N˜˜å)/×)DÒ)DÀ[Ñ)QÔ)Q˜Ø)Ð1Ø"˜FØ&4˜Ø&1˜Ý#=¸nÑ#MÔ#M˜˜å%+×%@Ò%@ÀÑ%MÔ%M�NØ%Ð-Ø˜Ø"0�KØ"-�KÝ9¸.ÑIÔI�HøøÝ%¥zµ8½WÐEð ð ð Ý—’ÐSÐU`ÐbeÑfÔfÐfØ�����øøøøðøøøð 7?ÀÈ[Ð5YˆDÔ'¨	Ñ2à"Ô:ˆÝ�vÐ4°bÑ9Ô9ð 	LÝ)-¨hÔ.JÑ)KÔ)KˆFÔ&å�g dÔ&7Ð9RÐTVÑWÔWÐ]Ð[]Ñ^Ô^ˆØ3µw¸tÔ?PÐRdÕfiÑfkÔfkÑ7lÔ7lÐlˆàð 	Õ5°nÑEÔEÕI_Ð`oÑIpÔIpÒpÐpØˆFà˜_Ò,Ð,Øð Ý—’ðEà"Ø#Øñô ð ð õ ' ~Ñ6Ô6ð 
¸?ð 
ÕSfÐgvÑSwÔSwð 
Ý”Mð6Ø3Að6ð 6à(7ð6ð 6ð 9Gð	6ð 6ð 6õ $Ø#$ð	ñ 	ô 	ð 	õ —’Ø\Ø#ØØñ	ô ð ð 9HˆDÔÔ5Ý  ¤¨V°TÑ:Ô:ˆJØÐ%Ø5D�
Ô2Ð2Ð2ð= -Ð,ð: &Ð%s+   Á3"E ÂA&E Ã?0E Ä1E ÅF	Å"FÆF	c                ó   —  | j         di |¤ŽS )zERetrieve the configuration parameters that will be used for training.r;   )r  rA  s     r>   rÕ   zRFDETR.get_train_config‚	  rB  r@   r%   c               ó$   — t          ||¬¦  «        S )u(  Retrieve a model context from the provided architecture configuration.

        Args:
            config: Architecture configuration.
            trust_checkpoint: Forwarded to :func:`~rfdetr.inference._build_model_context` â€” set
                ``True`` only when ``config.pretrain_weights`` is a checkpoint the caller
                explicitly trusts (mirrors ``RFDETR.from_checkpoint(..., trust_checkpoint=True)``).

        Returns:
            ModelContext with model, postprocess, device, resolution, args, and class_names attributes.
        r  )r&   )r¹   ræ   r  s      r>   r)  zRFDETR.get_model†	  s   € õ $ FÐ=MÐNÑNÔNÐNr@   c                óž   — t          | j        d¦  «        r%| j        j        �t          | j        j        ¦  «        S t          t          ¦  «        S )zùRetrieve the class names supported by the loaded model.

        Returns:
            A list of class name strings, 0-indexed.  When no custom class names are embedded in the checkpoint, returns
            the standard 80 COCO class names.
        rê   )r®   r¬   rê   r*  r   r0  s    r>   rê   zRFDETR.class_names”	  sD   € õ �4”:˜}Ñ-Ô-ð 	0°$´*Ô2HÐ2TÝ˜œ
Ô.Ñ/Ô/Ð/åÕ$Ñ%Ô%Ð%r@   c                ó
  — | j         rdS | j        s!t                               d¦  «         d| _        | j        j        }|€J ‚t          d„ |                     ¦   «         D ¦   «         ¦  «        r|                     ¦   «          dS dS )u˜  Put the underlying module in eval mode before unoptimized inference.

        Inference must not run with dropout / batch-norm in training mode. The registered module tree is checked on
        every call, but ``eval()`` is only applied when at least one module is in training mode. This covers both a
        directly toggled submodule and ``train()`` reassigning ``self.model.model`` to the module returned by PyTorch
        Lightning (see ``train()``). The warning that the model is not optimized is emitted at most once, but gating the
        mode check behind that once-only warning would let a later ``predict()`` silently run with dropout active, so
        the two are independent.

        When ``_is_optimized_for_inference`` is ``True``, the method returns immediately â€” the compiled
        ``inference_model`` snapshot is already in eval mode and ``self.model.model`` is not used for inference.
        NzµModel is not optimized for inference. Latency may be higher than expected. For full GPU throughput (e.g. ~8x on T4 via FP16 Tensor Cores), call model.inference(dtype=torch.float16).Tc              3  ó$   K  — | ]}|j         V — Œd S rv   )Útraining)r<   rë  s     r>   r?   zERFDETR._ensure_eval_mode_for_unoptimized_inference.<locals>.<genexpr>½	  s$   è è € Ð=Ð= 6ˆvŒÐ=Ð=Ð=Ð=Ð=Ð=r@   )r3  r4  rÖ   r  r¬   ÚanyÚmodulesr&  )r¹   r¬   s     r>   Ú+_ensure_eval_mode_for_unoptimized_inferencez2RFDETR._ensure_eval_mode_for_unoptimized_inference¡	  s¡   € ð Ô+ð 	ØˆFØÔGð 	LÝ�NŠNð>ñô ð ð
 HLˆDÔDà”
Ô ˆØÐ Ð Ð õ Ð=Ð=¨U¯]ª]©_¬_Ð=Ñ=Ô=Ñ=Ô=ð 	Ø�JŠJ‰LŒLˆLˆLˆLð	ð 	r@   ç      à?Úimagesúwstr | Image.Image | np.ndarray[Any, Any] | torch.Tensor | list[str | np.ndarray[Any, Any] | Image.Image | torch.Tensor]Ú	thresholdr  Úinclude_source_imageú5Detections | KeyPoints | list[Detections | KeyPoints]c                ó   ‡P‡Q‡R‡S‡T‡U‡V— ddl m}m} t          || j        d¦  «        }t          | j        dd¦  «        }	t          |	t          ¦  «        st          |	t          ¦  «        r|	dk    rt          d|	›�¦  «        ‚||	z  }
|€5| j
        j        }||
z  dk    rt          d|› d	|
› d
|› d|	› d|
› d�¦  «        ‚nt          ||
||	¦  «        }|                      ¦   «          t          |t          t          f¦  «         }t          |t          t          f¦  «        s|g}g }g }|rg ndŠVg }d}|D �]ï}|}t          |t           ¦  «        rmt#          |¦  «        j        dv rCt'          j        |d¬¦  «        }|                     ¦   «          t-          j        |j        ¦  «        }t3          j        |¦  «        }d}d}t          |t6          j        ¦  «        �s]t          |t2          j        ¦  «        r |j        dk    r|                     d¦  «        }t          |t2          j        ¦  «        }d}|rtt?          j         |¦  «        }|j!        t>          j"        k    r6|dz   #                    dd¦  «         $                    t>          j"        ¦  «        }‰V %                    |¦  «         t          |t>          j&        ¦  «        o|j!        t>          j"        k    }|p|}|s|rE|j'        dv r<|r&|�|n t?          j         |t>          j"        d¬¦  «        }n|}tQ          |¦  «        }d}nQtS          j*        |¦  «        }n<|r:| +                    ¦   «         dk    r"‰V %                    tY          |¦  «        ¦  «         | +                    ¦   «         dk    p|j-        d         | j        j.        k    }| %                    |rdn|dk     /                    ¦   «         |rdn|dk      /                    ¦   «         |t          |j-        ¦  «        f¦  «         |}|r,| %                    d¦  «         | %                    d¦  «         �Œ|j-        dd…         \  }}| %                    ||f¦  «         |j0        j1        dk    r)| j
        j0        j1        dk    r| 2                    ¦   «         }| j
        j0        j1        dk    }| 3                    | j
        j0        |¬¦  «        }|r?|€-t7          j4        d|j0        t7          j5        ¦   «         ¬¦  «        }tm          ||¦  «        }| %                    |¦  «         �Œñ|D ]K\  }} }}!|rt          d¦  «        ‚| rt          d¦  «        ‚|r t          d| j        j.        › d|!› d �¦  «        ‚ŒL|�t          |¦  «        n| j
        j        | j
        j        gŠUt7          j7        ˆUfd!„|D ¦   «         ¦  «        }"tS          j8        |"| j9        | j:        ¦  «        }"| j;        rÛ| j<        |"j-        d"         k    s| j<        |"j-        d         k    rTt          | d#d¦  «        rd$nd%}#t          d&| j<        › d'| j<        › d(|"j-        d"         › d'|"j-        d         › d�	|#z   ¦  «        ‚| j=        rT| j>        |"j-        d         k    r>t          | d#d¦  «        rd)nd*}#t          d+| j>        › d(|"j-        d         › d�|#z   ¦  «        ‚| j;        r=| j
        j?        }$|$€
J d,¦   «         ‚ |$|" 3                    | j@        ¬-¦  «        ¦  «        }%n#| j
        j
        }&|&€
J d.¦   «         ‚ |&|"¦  «        }%t          |%t          ¦  «        rb|%d         |%d         d/œ}'tƒ          |%¦  «        dk    r<t          t          | j
        d0d¦  «        d1d¦  «        r|%d"         |'d2<   n|%d"         |'d3<   |'}%t7          j4        || j
        j0        ¬4¦  «        }(| j
         B                    |%|(|¬5¦  «        })| jC        ŠStƒ          ‰S¦  «        ŠTt          | j
        d0d¦  «        }*|*€2‰St          tˆ          ¦  «        k    rtŠ           F                    d6¦  «         t          |*d7‰T¦  «        }+|+‰Tk    o‰St          tˆ          ¦  «        k    },t          |*d8g ¦  «        pg }-t�          |-¦  «        }.|,r"ˆSˆTfd9„t‘          t’          ¦  «        D ¦   «         ŠQnT|.r6d:„ t‘          |-¦  «        D ¦   «         }/ˆSˆTfd;„t‘          |/¦  «        D ¦   «         ŠQnt•          t‘          ‰S¦  «        ¦  «        ŠQg }0t‘          |)¦  «        D �]·\  ŠR}1|1d<         }2|1d=         }3|1d>         }4|2|k     K                    d¬?¦  «        d         }5|2|5         }2|3|5         }3|4|5         }4d@|1v }6dA|1v }7dB|1v }8|6r|1d@         |5         nd}9|7r|1dA         |5         nd}:|8r|1dB         |5         nd};|4jL        }<|4 M                    ¦   «          3                    d|<¬¦  «        }=|2 M                    ¦   «          3                    d|<¬¦  «        }>|3 3                    d|<¬¦  «        }?|9�)|9 M                    ¦   «          3                    d|<¬¦  «        nd}@|:�*|: N                    d¦  «         3                    d|<¬¦  «        nd}A|;�)|; M                    ¦   «          3                    d|<¬¦  «        nd}B|<r6t6          jO         P                    |4j0        ¦  «         Q                    ¦   «          |@�|@ R                    ¦   «         nd}C|Cdu}D|A�X ||= R                    ¦   «         |> R                    ¦   «         |? R                    ¦   «         |A R                    ¦   «         ¬C¦  «        }EnD ||= R                    ¦   «         |> R                    ¦   «         |? R                    ¦   «         ¬D¦  «        }E|B�|B R                    ¦   «         |EjS        dB<   |r‰V‰R         |EjT        dE<   t?          jU        t?          j         |‰R         t>          jV        ¬-¦  «        tƒ          |E¦  «        df¦  «        |EjS        dF<   |EjW        �|EjW        nt?          j         g t          ¬-¦  «        }F|.rdn|+ŠPˆPˆQfdG„|FD ¦   «         }G|Gr#tŠ           F                    dH|GddI…         ¦  «         |,rˆQfdJ„|FD ¦   «         }HnˆPˆQfdK„|FD ¦   «         }Ht?          j         |Ht°          ¬-¦  «        |EjS        dL<   |D�r÷|C��ôt•          |EjS        ¦  «        }I|EjY         $                    t>          jZ        ¦  «        |IdM<   |r,ˆRˆVfdN„t·          tƒ          |E¦  «        ¦  «        D ¦   «         |IdE<   |I                     dB¦  «        }J|I                     dF¦  «        }K|J�£|K�¡tƒ          |E¦  «        dk    rŽt?          j\        |Jt>          jZ        ¬-¦  «        }Lt?          j\        |Kt>          jZ        ¬-¦  «        }M|Lj-        dd"…         |Cj-        dd"…         k    r.|Mj-        tƒ          |E¦  «        d"fk    rt»          |L|M¬O¦  «        |IdP<   |C $                    t>          jZ        d¬Q¦  «        }C|Cdd…dd…d"f         }N ||Cdd…dd…dd"…f         |N|Ej^        �$|Ej^         $                    t>          jZ        ¦  «        nd|EjW        �|EjW         $                    t          ¦  «        nd|Ndk    |I¬R¦  «        }O|0 %                    |O¦  «         �Œ¢|0 %                    |E¦  «         �Œ¹|r|0d         n|0S )Su;  Performs model inference on the input images.

        This method accepts a single image or a list of images in various formats (file path, image url, PIL Image,
        NumPy array, or torch.Tensor). The images should be in RGB channel order. If a torch.Tensor is provided, it must
        already be normalized to values in the [0, 1] range and have the shape (C, H, W).

        Args:
            images:
                A single image or a list of images to process. Images can be provided
                as file paths, PIL Images, NumPy arrays, or torch.Tensors.
            threshold:
                The minimum confidence score needed to consider a detected bounding box valid.
            shape:
                Optional ``(height, width)`` tuple to resize images to before inference. When provided, overrides the
                model's default inference resolution. The tuple should match the resolution used when exporting the
                model (typically a square shape). Both dimensions must be positive integers divisible by ``patch_size *
                num_windows``. Defaults to ``(model.resolution, model.resolution)`` when not set.
            patch_size:
                Backbone patch size used for shape divisibility validation. Defaults to ``model_config.patch_size``
                (typically 14 for large models, 16 for smaller ones). Divisibility is checked against ``patch_size *
                num_windows``.
            include_source_image:
                Whether to attach the original image to the returned prediction. Detection and segmentation outputs use
                ``detections.metadata["source_image"]``. Keypoint outputs use per-object
                ``key_points.data["source_image"]`` because Supervision ``KeyPoints`` currently has no collection-level
                metadata field. Defaults to ``True``. Set to ``False`` to reduce memory use when source images are not
                needed.
            **kwargs:
                Additional keyword arguments.

        Returns:
            A single or multiple Supervision prediction objects. Detection and segmentation models return
            :class:`~supervision.Detections`. Keypoint models return :class:`~supervision.KeyPoints`, with keypoint
            coordinates in ``xy``. Keypoint predictions preserve the detection-level fields produced by RF-DETR:
            ``key_points.detection_confidence`` is the per-object score used by ``threshold``. For keypoint models this
            is the postprocessed detection score and, by default, includes normalized keypoint uncertainty fusion
            controlled by ``model_config.postprocess_trace_alpha``. ``key_points.keypoint_confidence`` is separate: it
            is a ``(num_detections, num_keypoints)`` array of per-keypoint findability scores decoded from the keypoint
            head, not a repeated copy of the detection score. When RF-DETR emits keypoint precision parameters,
            ``key_points.data["covariance"]`` stores per-keypoint pixel-space covariance matrices with shape
            ``(num_detections, num_keypoints, 2, 2)``. ``key_points.data["xyxy"]`` stores the corresponding detection
            boxes as a ``(num_detections, 4)`` array in the same row order as ``key_points.xy`` because Supervision
            ``KeyPoints`` does not have a native bounding-box field. The ``data`` dict also contains ``class_name`` and
            ``source_shape`` as per-object arrays. When ``include_source_image=True`` for keypoint models,
            ``source_image`` is stored as per-object data until Supervision exposes collection-level metadata for
            ``KeyPoints``.

        Note:
            For ``Detections`` outputs, ``source_image`` moved from ``detections.data`` to ``detections.metadata``.
            Update detection callers reading ``detections.data["source_image"]`` to use
            ``detections.metadata["source_image"]``.

        Note:
            ``class_name`` mapping uses one of three modes depending on the checkpoint. For pretrained COCO checkpoints
            (detected when ``model.args.num_classes > len(class_names)`` and ``class_names`` matches
            ``COCO_CLASS_NAMES``), raw COCO category IDs (1â€“90, sparse) are looked up by category ID rather than by
            position â€” so ``class_id=18`` yields ``"dog"``, not ``class_names[18]``. For fine-tuned detection and
            segmentation models and active-first keypoint models, ``class_id`` is a 0-based index into
            ``class_names``. In the one-class preview keypoint setup, that means ``class_id=0`` is the foreground
            class and ``class_id=1`` is ``"__background__"``.
            Legacy keypoint checkpoints with ``args.num_keypoints_per_class[0] == 0`` use a background-first layout:
            slot 0 maps to ``"__background__"`` and foreground slots map to ``class_names`` in order.

        Note:
            A CPU tensor image is pinned before its transfer to a CUDA-device model, and that transfer is
            non-blocking; passing a tensor already on the model's accelerator skips this image transfer entirely.
            But with the default ``include_source_image=True``, capturing ``source_image`` from that same tensor
            still does its own separate, blocking ``.cpu()`` call earlier in the loop â€” so an already-CUDA tensor
            input alone does not make the call fully round-trip-free. Pass ``include_source_image=False`` to avoid
            that copy as well.

            Tensor and non-uint8 NumPy range checks and every input's shape check are evaluated before inference.
            PIL and uint8 NumPy images skip a redundant range scan because their byte-to-float conversion
            guarantees values in ``[0, 1]`` for both. Any resulting ``ValueError`` is raised only after all inputs
            have been inspected, so valid-shaped images later in a multi-image call still have their conversion and
            transfer queued before an earlier validation failure raises.

        Raises:
            ValueError: If ``shape`` cannot be unpacked as a two-element sequence,
                if either dimension does not support the ``__index__`` protocol (e.g. ``float``) or is a ``bool``, if
                either dimension is zero or negative, if either dimension is not divisible by ``patch_size *
                num_windows``, or if ``patch_size`` is not a positive integer.
        r   r,   ÚpredictrŒ   r7   z9model_config.num_windows must be a positive integer, got NrR  rS  r’   r“   rT  r�   )ÚhttpÚhttpsé   )ÚtimeoutFÚRGBrA   )r8   r  T)rG   r   r  rQ   r9   )Únon_blockingr!  zYImage has pixel values above 1. Please ensure the image is normalized (scaled to [0, 1]).zYImage has pixel values below 0. Please ensure the image is normalized (scaled to [0, 1]).z~Invalid tensor image shape. Tensor inputs to `predict()` must be in (C, H, W) format with C matching the model configuration (z' channels). Received tensor with shape zT. For automatic RGB conversion, pass a PIL Image or a file path instead of a tensor.c                ó>   •— g | ]}t          j        |‰d ¬¦  «        ‘ŒS )F)Ú	antialias)ÚFÚresize)r<   ÚtÚ	resize_tos     €r>   r%  z"RFDETR.predict.<locals>.<listcomp>Ø
  s+   ø€ Ð#fÐ#fÐ#fÐPQ¥A¤H¨Q°	ÀUÐ$KÑ$KÔ$KÐ#fÐ#fÐ#fr@   r8   r9  z< Create a new RFDETR instance to use a different resolution.zY You can explicitly remove the optimized model by calling model.remove_optimized_model().z8Resolution mismatch. Model was optimized for resolution Úxz
, but got zF Create a new RFDETR instance to recompile for a different batch size.zâ You can explicitly remove the optimized model by calling model.remove_optimized_model(). Alternatively, you can recompile the optimized model for a different batch size by calling model.inference(batch_size=<new_batch_size>).zABatch size mismatch. Optimized model was compiled for batch size zDinference_model is set whenever _is_optimized_for_inference is True.r   z>self.model.model is only cleared when optimized for inference.)Úpred_logitsÚ
pred_boxesrº   rÙ  Úpred_keypointsÚ
pred_masks)rE   )Útarget_sizesÚscore_thresholdu¦   predict(): model has no 'args' attribute â€” COCO sparse-ID mapping cannot activate; class_ids are treated as 0-indexed (may be wrong for pretrained COCO checkpoints)rî   re  c                ó4   •— i | ]\  }}|‰k     ¯|‰|         “ŒS r;   r;   )r<   rs  Úcoco_idÚmodel_class_namesri  s      €€r>   rS  z"RFDETR.predict.<locals>.<dictcomp>)  s8   ø€ ð 1ð 1ð 1Ù2<°!°WÐ[\Ð_`Ò[`Ð[`�Ð*¨1Ô-Ð[`Ð[`Ð[`r@   c                ó$   — g | ]\  }}|d k    ¯|‘ŒS )r   r;   )r<   r£  r¤  s      r>   r%  z"RFDETR.predict.<locals>.<listcomp>3  s(   € Ð#cÐ#cÐ#c©F¨C°Ð]^ÐabÒ]bÐ]b CÐ]bÐ]bÐ]br@   c                ó4   •— i | ]\  }}|‰k     ¯|‰|         “ŒS r;   r;   )r<   rs  ÚslotrÜ  ri  s      €€r>   rS  z"RFDETR.predict.<locals>.<dictcomp>4  s1   ø€ Ð tÐ tÐ tÁÀÀ4ÐnoÐrsÒnsÐns Ð'8¸Ô';ÐnsÐnsÐnsr@   ÚscoresÚlabelsÚboxes)Úas_tupleÚ	keypointsÚmasksÚkeypoint_precision_cholesky)ÚxyxyÚ
confidenceÚclass_idÚmask)rç  rè  ré  Úsource_imageÚsource_shapec                ó(   •— g | ]}|‰v¯|‰k    ¯|‘ŒS r;   r;   ©r<   ÚcidÚ_bg_sentinelÚ_class_id_to_names     €€r>   r%  z"RFDETR.predict.<locals>.<listcomp>¢  s0   ø€ ÐjÐjÐj °SÐ@QÐ5QÐ5QÐVYÐ]iÒViÐVi˜ÐViÐViÐVir@   uJ   predict() encountered unmapped class_id(s): %s â€” mapping to empty stringé   c                ó<   •— g | ]}‰                      |d ¦  «        ‘ŒS )r^  ©rÒ   )r<   rï  rñ  s     €r>   r%  z"RFDETR.predict.<locals>.<listcomp>©  s*   ø€ ÐSÐSÐSÀ#Ð0×4Ò4°S¸"Ñ=Ô=ÐSÐSÐSr@   c                óL   •— g | ] }|‰k    rd n‰                      |d¦  «        ‘Œ!S )Ú__background__r^  rô  rî  s     €€r>   r%  z"RFDETR.predict.<locals>.<listcomp>«  sI   ø€ ð ð ð Ødg¨¨|Ò(;Ð(;Ð$Ð$ÐAR×AVÒAVÐWZÐ\^ÑA_ÔA_ðð ð r@   Ú
class_namerç  c                ó    •— g | ]
}‰‰         ‘ŒS r;   r;   )r<   r#  rs  Úsource_imagess     €€r>   r%  z"RFDETR.predict.<locals>.<listcomp>´  s.   ø€ ð 5ð 5ð 5àð & aÔ(ð5ð 5ð 5r@   )Úprecision_choleskyrì  Ú
covariance)r   )ÚxyÚkeypoint_confidenceÚdetection_confidenceré  Úvisiblert  )_Úsupervisionr-   r.   r¨   r¡   r¦   r–   r—   rŠ   r•   r¬   rÇ   rŸ   r¾  r*  Útupler£   r   ÚschemeÚrequestsrÒ   Úraise_for_statusÚioÚBytesIOÚcontentr   ra  rH   r€  r"  ÚconvertrT   ÚarrayrG   rP   ÚcliprS   ÚappendÚndarrayrX   r[   rÏ  Ú	to_tensorrž   rV   rM   r.  r¼  rE   rF   Ú
pin_memoryrO   Útensorr`   rd   ÚstackÚ	normalizer,  r-  r3  r7  r5  r6  r2  r8  rü   Úpostprocessrê   r   rÖ   Úwarning_oncer)   rŸ  r   rt  ÚnonzeroÚis_cudar  Úsqueezer9   Úcurrent_streamr+  rR   rt  ÚmetadataÚtileÚint64ré  rˆ   rç  rJ   r1  Úasarrayr*   rè  )Wr¹   rÀ  rÂ  rM   r‹   rÃ  r¼   r-   r.   rŒ   r‰   Údefault_resÚsingle_inputÚ
orig_sizesÚprocessed_imagesÚpending_checksÚuint8_scaleÚ	img_inputÚimgÚrespÚrange_known_validÚdeferred_widenÚ	pil_imageÚsource_arrayÚuint8_arrayÚtensor_sourceÚinvalid_shapeÚ
img_tensorÚhrò   rÌ  Úinvalid_highÚinvalid_lowÚ	img_shapeÚbatch_tensorÚ_restore_hintr2  Úpredictionsr¬   Úreturn_predictionsrØ  r  Ú_model_argsÚnum_logit_slotsÚ_is_coco_pretrainedÚ_num_keypoints_per_classÚ_is_legacy_bgfirst_keypointÚ_kp_foreground_slotsÚpredictions_listÚresultrà  rá  râ  Úkeep_idxÚhas_keypoints_resultÚ	has_masksÚhas_kp_precisionrä  rå  Úkeypoint_precisionr  Ú	boxes_cpuÚ
scores_cpuÚ
labels_cpuÚkeypoints_cpuÚ	masks_cpuÚkeypoint_precision_cpuÚkeypoints_arrayÚhas_keypointsÚ
detectionsÚ	class_idsÚ	truly_oobrê   Úkeypoint_dataÚraw_precisionÚraw_source_shapeÚ	precisionrì  rý  Ú
key_pointsrð  rñ  rs  rÜ  ri  rÒ  rù  sW                                                                                   @@@@@@@r>   rÆ  zRFDETR.predictÀ	  sE  øøøøøøø€ ðJ 	6Ð5Ð5Ð5Ð5Ð5Ð5Ð5å(¨°TÔ5FÈ	ÑRÔRˆ
Ý˜dÔ/°ÀÑBÔBˆÝ�k¥4Ñ(Ô(ð 	jµ
¸;ÍÑ0LÔ0Lð 	jÐP[Ð_`ÒP`ÐP`ÝÐhÐYdÐhÐhÑiÔiÐiØ +Ñ-ˆ
àˆ=Øœ*Ô/ˆKØ˜ZÑ'¨1Ò,Ð,Ý ðL°;ð Lð LØ",ðLð LØ;EðLð LØVaðLð Là>HðLð Lð Lñô ð ð -õ )¨°
¸JÈÑTÔTˆEà×8Ò8Ñ:Ô:Ð:õ
 & f­tµU¨mÑ<Ô<Ð<ˆÝ˜&¥4­ -Ñ0Ô0ð 	Ø�XˆFà "ˆ
Ø&(ÐØ0DÐ*N¨"¨"È$ˆð" hjˆà+/ˆàð e	0ñ e	0ˆIØ ˆCÝ˜#�sÑ#Ô#ð &Ý˜C‘=”=Ô'Ð+<Ð<Ð<Ý#œ<¨°RÐ8Ñ8Ô8�DØ×)Ò)Ñ+Ô+Ð+Ýœ* T¤\Ñ2Ô2�CÝ”j ‘o”o�à %ÐØ"ˆNÝ˜c¥5¤<Ñ0Ô0ñ )Cõ ˜c¥5¤;Ñ/Ô/ð -°C´HÀÒ4EÐ4EØŸ+š+ eÑ,Ô,�CÝ& s­E¬KÑ8Ô8�	Ø<@�Ø'ð 7Ý#%¤8¨C¡=¤=�LØ#Ô)­R¬XÒ5Ð5Ø(4°sÑ(:×'@Ò'@ÀÀCÑ'HÔ'H×'OÒ'OÕPRÔPXÑ'YÔ'Y˜Ø!×(Ò(¨Ñ6Ô6Ð6Ý(¨­b¬jÑ9Ô9ÐS¸c¼iÍ2Ì8Ò>S�ð %.Ð$<°Ð!Øð + ð +°´¸VÐ1CÐ1Cð !ð ,à,8Ð,D˜L˜LÍ"Ì(ÐSVÕ^`Ô^fÐmqÐJrÑJrÔJrð &˜ð ),˜õ 3°=ÑAÔA�CØ%)�N�Nåœ+ cÑ*Ô*�C�CØ%ð C¨#¯'ª'©)¬)°qª.¨.ð ×$Ò$Õ%<¸SÑ%AÔ%AÑBÔBÐBð  ŸGšG™IœI¨šNÐ\¨c¬i¸¬l¸dÔ>OÔ>\Ò.\ˆMØ×!Ò!à.ÐC�E�E°S¸1²W·M²M±O´OØ.ÐC�E�E°S¸1²W·M²M±O´OØ!Ý˜#œ)Ñ$Ô$ð	ñô ð ð ˆJàð ð ×!Ò! $Ñ'Ô'Ð'Ø ×'Ò'¨Ñ-Ô-Ð-ÙàÔ# A B BÔ'‰DˆAˆqØ×Ò˜q !˜fÑ%Ô%Ð%ð Ô Ô%¨Ò.Ð.°4´:Ô3DÔ3IÈVÒ3SÐ3SØ'×2Ò2Ñ4Ô4�
ð
  œ:Ô,Ô1°VÒ;ˆLØ#Ÿš t¤zÔ'8À|˜ÑTÔTˆJØð JØÐ&Ý"'¤,¨s¸:Ô;LÕTYÔTkÑTmÔTmÐ"nÑ"nÔ"n�KÝ0°¸[ÑIÔI�
Ø×#Ò# JÑ/Ô/Ð/Ñ/ð DRð 	ð 	Ñ?ˆL˜+ }°iØð Ý Øoñô ð ð ð Ý Øoñô ð ð ð Ý ðiØ@DÔ@QÔ@^ðið ià2;ðið ið iñô ð ðð $)Ð#4•D˜‘K”K�K¸4¼:Ô;PÐRVÔR\ÔRgÐ:hˆ	õ ”{Ð#fÐ#fÐ#fÐ#fÐUeÐ#fÑ#fÔ#fÑgÔgˆÝ”{ <°´¸T¼YÑGÔGˆàÔ+ð  	àÔ*¨lÔ.@ÀÔ.CÒCÐCØÔ-°Ô1CÀAÔ1FÒFÐFõ ˜tÐ%9¸5ÑAÔAðuÐRÐRàtð õ
 !ðPØ:>Ô:TðPð PØW[ÔWqðPð Pà+Ô1°!Ô4ðPð Pà7CÔ7IÈ!Ô7LðPð Pð PàR_ñ`ñô ð ð
 Ô0ð ØÔ-°Ô1CÀAÔ1FÒFÐFõ # 4Ð)=¸uÑEÔEðÐ`Ð`ðXð	 "õ %ð<ØGKÔGað<ð <à#/Ô#5°aÔ#8ð<ð <ð <à>KñLñô ð ð Ô+ð 	.Ø"œjÔ8ˆOØ"Ð.Ð.Ð0vÑ.Ô.Ð.Ø)˜/¨,¯/ª/ÀÔ@U¨/Ñ*VÔ*VÑWÔWˆKˆKà”JÔ$ˆEØÐ$Ð$Ð&fÑ$Ô$Ð$Ø˜% Ñ-Ô-ˆKÝ�k¥5Ñ)Ô)ð 	-à*¨1œ~Ø)¨!œnð"ð "Ðõ �;ÑÔ 1Ò$Ð$å�7 4¤:¨v°tÑ<Ô<Ð>WÐY^Ñ_Ô_ð FØ;FÀq¼>Ð&Ð'7Ñ8Ð8à7BÀ1´~Ð& |Ñ4Ø,ˆKÝ”| J°t´zÔ7HÐIÑIÔIˆØ”*×(Ò(¨À<ÐajÐ(ÑkÔkˆà Ô,ÐÝÐ!Ñ"Ô"ˆõ ˜dœj¨&°$Ñ7Ô7ˆØÐÐ#4½Õ=MÑ8NÔ8NÒ#NÐ#NÝ×Òðdñô ð õ  ' {°MÀ1ÑEÔEˆØ-°Ò1ÐaÐ6GÍ4ÕP`ÑKaÔKaÒ6aÐõ /6°kÐC\Ð^`Ñ.aÔ.aÐ.gÐegÐ Ý&9Ð:RÑ&SÔ&SÐ#Øð 	Cð1ð 1ð 1ð 1ð 1Ý@IÍ,Ñ@WÔ@Wð1ñ 1ô 1ÐÐð )ð 
	Cð $dÐ#cµiÐ@XÑ6YÔ6YÐ#cÑ#cÔ#cÐ Ø tÐ tÐ tÐ tÐ tÍ9ÐUiÑKjÔKjÐ tÑ tÔ tÐÐå $¥YÐ/@Ñ%AÔ%AÑ BÔ BÐØ9;ÐÝ" 7Ñ+Ô+ð W	4ñ W	4‰IˆAˆvØ˜HÔ%ˆFØ˜HÔ%ˆFØ˜7”OˆEð  Ò*×3Ò3¸TÐ3ÑBÔBÀ1ÔEˆHØ˜HÔ%ˆFØ˜HÔ%ˆFØ˜(”OˆEØ#.°&Ð#8Ð Ø 6Ð)ˆIØ<ÀÐFÐð :NÐW˜˜{Ô+¨HÔ5Ð5ÐSWˆIØ1:ÐD�F˜7”O HÔ-Ð-ÀˆEØTdÐ!n Ð(EÔ!FÀxÔ!PÐ!PÐjnÐð: ”mˆGØŸš™œ×(Ò(¨¸WÐ(ÑEÔEˆIØŸš™œ×*Ò*¨5¸wÐ*ÑGÔGˆJØŸš 5°w˜Ñ?Ô?ˆJØQZÐQf˜IŸOšOÑ-Ô-×0Ò0°ÀWÐ0ÑMÔMÐMÐlpˆMØLQÐL]˜Ÿš aÑ(Ô(×+Ò+¨EÀÐ+ÑHÔHÐHÐcgˆIàN`ÐNlÐ"×(Ò(Ñ*Ô*×-Ò-¨eÀ'Ð-ÑJÔJÐJÐrvð #ð ð FÝ”
×)Ò)¨%¬,Ñ7Ô7×CÒCÑEÔEÐEà7DÐ7P˜m×1Ò1Ñ3Ô3Ð3ÐVZˆOØ+°4Ð7ˆMàÐ$Ø'˜ZØ"ŸšÑ*Ô*Ø)×/Ò/Ñ1Ô1Ø'×-Ò-Ñ/Ô/Ø"ŸšÑ*Ô*ð	ñ ô �
�
ð (˜ZØ"ŸšÑ*Ô*Ø)×/Ò/Ñ1Ô1Ø'×-Ò-Ñ/Ô/ðñ ô �
ð
 &Ð1ØAW×A]ÒA]ÑA_ÔA_�
”Ð =Ñ>à#ð GØ6CÀAÔ6F�
Ô# NÑ3Ý.0¬gµb´h¸zÈ!¼}ÕTVÔT\Ð6]Ñ6]Ô6]Õ`cÐdnÑ`oÔ`oÐqrÐ_sÑ.tÔ.tˆJŒO˜NÑ+ð 0:Ô/BÐ/N˜
Ô+Ð+ÕTVÔT\Ð]_ÕgjÐTkÑTkÔTkˆIð !<ÐP˜1˜1ÀˆLØjÐjÐjÐjÐj¨	ÐjÑjÔjˆIØð Ý×#Ò#Ø`Ø˜b˜q˜b”Mñô ð ð #ð ØSÐSÐSÐSÈÐSÑSÔS��ðð ð ð ð Øktðñ ô �õ -/¬H°[ÍÐ,OÑ,OÔ,OˆJŒO˜LÑ)àñ 4 Ñ!<Ý $ Z¤_Ñ 5Ô 5�Ø(2¬×(>Ò(>½r¼zÑ(JÔ(J�˜fÑ%Ø'ð ð5ð 5ð 5ð 5ð 5å!&¥s¨:¡¤Ñ!7Ô!7ð5ñ 5ô 5�M .Ñ1ð !.× 1Ò 1Ð2OÑ PÔ P�Ø#0×#4Ò#4°^Ñ#DÔ#DÐ Ø Ð,Ð1AÐ1MÕRUÐV`ÑRaÔRaÐdeÒReÐReÝ "¤
¨=ÅÄ
Ð KÑ KÔ K�IÝ#%¤:Ð.>ÅbÄjÐ#QÑ#QÔ#Q�LØ ” r¨ rÔ*¨oÔ.CÀBÀQÀBÔ.GÒGÐGÈLÔL^ÕcfÐgqÑcrÔcrÐtuÐbvÒLvÐLvÝ6\Ø/8À|ð7ñ 7ô 7˜ lÑ3ð #2×"8Ò"8½¼È%Ð"8Ñ"PÔ"P�Ø&5°a°a°a¸¸¸¸A°gÔ&>Ð#Ø&˜YØ& q q q¨!¨!¨!¨R¨a¨R xÔ0Ø(;à!Ô,Ð8ð *4Ô)>×)EÒ)EÅbÄjÑ)QÔ)QÐ)QàØ@JÔ@SÐ@_˜ZÔ0×7Ò7½Ñ<Ô<Ð<ÐeiØ/°!Ò3Ø&ð	ñ 	ô 	�
ð !×'Ò'¨
Ñ3Ô3Ð3Ñ3à ×'Ò'¨
Ñ3Ô3Ð3Ñ3à&2ÐHÐ Ô"Ð"Ð8HÐHr@   Ú	workspaceÚ
project_idÚversionúint | str | NoneÚapi_keyc           	     ó`  — t          | dd¦  «        s| j        j        €t          d¦  «        ‚ddlm} |€%t          j        d¦  «        }|€t          d¦  «        ‚ ||¬	¦  «        }|                     |¦  «        }| j	        €|€t          d
¦  «        ‚|�=| j	        �6|| j	        k    r+t          j        d|›d| j	        ›d|›d�t          d¬¦  «         |€| j	        n|}t          j        d¬¦  «        5 }	|                      |	¦  «         |                     |¦  «        }
|€Jt#          d„ |
                     ¦   «         D ¦   «         d¬¦  «        }t&                               d|› �¦  «         |
                     |¦  «        }|                     ||	d¬¦  «         ddd¦  «         dS # 1 swxY w Y   dS )a–  Deploy the trained RF-DETR model to Roboflow.

        Deploying with Roboflow will create a Serverless API to which you can make requests.

        You can also download weights into a Roboflow Inference deployment for use in Roboflow Workflows and on-device
        deployment.

        Args:
            workspace: The name of the Roboflow workspace to deploy to.
            project_id: The project ID to which the model will be deployed.
            version: The project version to which the model will be deployed. If not provided, the highest
                existing dataset version is resolved automatically via the Roboflow API; for a project with
                no generated versions yet the lookup falls back to version ``1``, and the Roboflow SDK then
                raises its own ``RuntimeError`` ("Version number 1 is not found.").
            api_key: Your Roboflow API key. If not provided,
                it will be read from the environment variable `ROBOFLOW_API_KEY`.
            size: The size of the model to deploy. If not provided,
                it will default to the size of the model being trained (e.g., "rfdetr-base", "rfdetr-large", etc.).

        Raises:
            ValueError: If the `api_key` is not provided and not found in the
                environment variable `ROBOFLOW_API_KEY`, or if the `size` is not set for custom architectures.
            RuntimeError: If the model was cleared by ``inference(inplace=True)``.

        Note:
            Bundle creation is delegated to :meth:`export_for_roboflow`, which can be called independently
            to write ``weights.pt`` and ``class_names.txt`` without a network round-trip.
        r9  FNu¯   Cannot deploy after inference(inplace=True) â€” the model weights have been cleared from memory. Call export_for_roboflow() before optimizing, then deploy the exported bundle.r   )ÚRoboflowÚROBOFLOW_API_KEYzHSet api_key=<KEY> in deploy_to_roboflow or export ROBOFLOW_API_KEY=<KEY>)rV  z&Must set size for custom architectureszdeploy_to_roboflow(size=z") overrides this model's own size z; deploying as z0. Omit size to deploy with the model's own size.r8   r¶  Úroboflow_upload_)Úprefixc              3  óz   K  — | ]6}t          t          j                             |d          ¦  «        ¦  «        V — Œ7dS rƒ  )rŠ   rÿ   r  rx  )r<   r×   s     r>   r?   z,RFDETR.deploy_to_roboflow.<locals>.<genexpr>  s>   è è € ÐeÐe¸4•S�œ×)Ò)¨$¨t¬*Ñ5Ô5Ñ6Ô6ÐeÐeÐeÐeÐeÐer@   r7   r…  z>deploy_to_roboflow: no version given, resolved latest version ú
weights.pt)Ú
model_typeÚ
model_pathrš  )r¦   r¬   r¸  r©  rX  rÿ   Úgetenvr•   rR  r=   r¹  rº  r»  r  ÚTemporaryDirectoryÚexport_for_roboflowÚprojectr‡  Úget_version_informationrÖ   r×   rT  Údeploy)r¹   rR  rS  rT  rV  r=   rX  ÚrfÚrf_workspaceÚtmp_out_dirrc  Úproject_versions               r>   Údeploy_to_roboflowzRFDETR.deploy_to_roboflowÓ  sq  € õH �4Ð-¨uÑ5Ô5ð 	¸¼Ô9IÐ9QÝðañô ð ð 	&Ð%Ð%Ð%Ð%Ð%àˆ?Ý”iÐ 2Ñ3Ô3ˆGØˆÝ Ð!kÑlÔlÐlàˆX˜gÐ&Ñ&Ô&ˆØ—|’| IÑ.Ô.ˆàŒ9Ð  ÝÐEÑFÔFÐFàÐ ¤	Ð 5¸$À$Ä)Ò:KÐ:KÝŒMðY¨4ð Yð YÐUYÔU^ð Yð YØ $ðYð Yð YåØð	ñ ô ð ð !˜LˆtŒyˆy¨dˆÝÔ(Ð0BÐCÑCÔCð 	cÀ{Ø×$Ò$ [Ñ1Ô1Ð1Ø"×*Ò*¨:Ñ6Ô6ˆGØˆõ ØeÐeÀ7×CbÒCbÑCdÔCdÐeÑeÔeØðñ ô �õ —’ÐfÐ]dÐfÐfÑgÔgÐgØ%Ÿošo¨gÑ6Ô6ˆOØ×"Ò"¨d¸{ÐUaÐ"ÑbÔbÐbð	cð 	cð 	cñ 	cô 	cð 	cð 	cð 	cð 	cð 	cð 	cð 	cøøøð 	cð 	cð 	cð 	cð 	cð 	cs   Ã2B$F#Æ#F'Æ*F'c                óÄ  — t          | dd¦  «        s| j        j        €t          d¦  «        ‚t          j        |d¬¦  «         t          j                             |d¦  «        }t          |dd	d
¬¦  «        5 }|                     d
                     | j	        ¦  «        ¦  «         ddd¦  «         n# 1 swxY w Y   t          | j        j        ¦  «        }d|_        d|_        d|_        t          |d¦  «        r|j	        €| j	        |_	        t          j                             |d¦  «        }t!          j        | j        j                             ¦   «         |dœ|¦  «         dS )a(  Write a Roboflow upload bundle (``weights.pt`` + ``class_names.txt``) into *output_dir*.

        This is the network-free core of :meth:`deploy_to_roboflow`: it serialises the model state and
        a sanitized copy of the training args into ``weights.pt``, always embedding ``class_names`` so
        the bundle is self-contained, and writes the class labels to ``class_names.txt``.  The Roboflow
        SDK uses this format to adapt raw PyTorch-Lightning checkpoints into a deploy-ready bundle.

        Args:
            output_dir: Directory into which ``weights.pt`` and ``class_names.txt`` are written.  Created
                if it does not exist.  Existing files are silently overwritten.

        Raises:
            PermissionError: If the process lacks write access to *output_dir* or its parent directory.
            OSError: On disk-full, invalid path, or other filesystem failure during directory creation,
                file write, or ``torch.save``.
            RuntimeError: If the model was cleared by ``inference(inplace=True)``.
        r9  FNu…   Cannot export after inference(inplace=True) â€” the model has been cleared from memory. Call export_for_roboflow() before optimizing.Trð   zclass_names.txtrò   ró   ú
)rö   Únewliner3  r^  rê   r]  )r¬   rº   )r¦   r¬   r¸  rÿ   r   r  r	  ra  r  rê   r   rº   rÅ  r  rå  r®   rH   Úsaverd  )r¹   r  Úclass_names_pathrd  rº   Úoutpaths         r>   rb  zRFDETR.export_for_roboflow#  sŠ  € õ$ �4Ð-¨uÑ5Ô5ð 	¸¼Ô9IÐ9QÝð@ñô ð õ
 	Œ�J¨Ð.Ñ.Ô.Ð.õ œ7Ÿ<š<¨
Ð4EÑFÔFÐÝÐ" C°'À4ÐHÑHÔHð 	1ÈAØ�GŠG�D—I’I˜dÔ.Ñ/Ô/Ñ0Ô0Ð0ð	1ð 	1ð 	1ñ 	1ô 	1ð 	1ð 	1ð 	1ð 	1ð 	1ð 	1øøøð 	1ð 	1ð 	1ð 	1õ
 �D”J”OÑ$Ô$ˆØˆÔØ"ˆŒØˆŒÝ�t˜]Ñ+Ô+ð 	0¨tÔ/?Ð/GØ#Ô/ˆDÔå”'—,’,˜z¨<Ñ8Ô8ˆÝŒ
˜TœZÔ-×8Ò8Ñ:Ô:ÀDÐIÐIÈ7ÑSÔSÐSÐSÐSs   Á6.B0Â0B4Â7B4)r  r—   r¼   r   r4   rª   )r4   rª   )r¼   r   r4   r   )r  rC  r  r—   r¼   r   r4   rt   )rE   r   r4   r°  )r¼   r   r4   rª   )rù  rú  r¼   r   r4   rû  )r  r—   rË   rŠ   rG   r  r  r—   r  r  r4   rª   )r4   r—   )r3  NFr4  TNr7   FNr5  NNr6  ).r  r£   r@  r  rA  r—   rB  rŠ   rC  r—   rM   rD  rË   rŠ   rE  r—   r‹   r    r{  r£   rF  r  rG  rH  rI  rŠ   r7  r  r8  r  r9  r—   r:  r    r;  rˆ   r<  r  r=  r  r>  r  r?  r  r4   r	   )rÅ  r£   r4   r]  )rg  r  rÅ  r£   r4   rh  )rÅ  r£   rÇ  rh  r4   rk  )rÅ  r£   rÙ  r—   rÇ  rh  r4   rŠ   )rÅ  r£   r4   rª   )rÅ  r£   r4   r‘  )rœ  r�  r4   r�  )ræ   r   r4   rª   )r¼   r   r4   r   )ræ   r   r  r—   r4   r%   ©r4   rk  )r¿  NNT)rÀ  rÁ  rÂ  r  rM   rD  r‹   r    rÃ  r—   r¼   r   r4   rÄ  )NNN)rR  r£   rS  r£   rT  rU  rV  r  r=   r  r4   rª   )r  rC  r4   rª   )/r˜   Ú
__module__Ú__qualname__Ú__doc__r,  r-  r=   Ú__annotations__r   r  r   r  r;  r(  r'  Úclassmethodr¯  ÚstaticmethodrÑ   rÈ  r  rÁ   rH   rJ   r.  ré  Úpropertyr2  r'  rf  rÛ  rÚ  rŠ  rØ  r•  r—  rv  r¥  r×  rÕ   r)  rê   r¾  r±   rÆ  rj  rb  r;   r@   r>   rt   rt     s×  € € € € € € ðGð Gð "Ð!Ð!€EØ Ð Ð €DØ€DÐÐÐÑØ-8ÐÐ8Ð8Ð8Ñ8Ø-8ÐÐ8Ð8Ð8Ñ8à;Ð;Ð;Ñ;à38ð ('ð ('ð ('ð ('ð ('ð ('ðT4ð 4ð 4ð 4ð02ð 2ð 2ð 2ð ØW\ð Nð Nð Nð Nð Nñ „[ðNð`
 ð+ð +ð +ñ „\ð+ðZFUð FUð FUð FUðP ;Að [[ð [[ð [[ð [[ð [[ð [[ðz ð ØØ#(¤=ð	rð Ø>Kðrð rð rð rð rñ Ôðrðh7(ð 7(ð 7(ð 7(ðr ð':ð ':ð ':ñ „Xð':ðV #Ø $Ø#ØØØ(,ØØ#Ø!%ØØ#'Ø>BØðw;ð  #ØØØ%)ØØ'+Ø'+Ø)-Ø"&ð1w;ð w;ð w;ð w;ð w;ð w;ðr	 ðZð Zð Zñ „\ðZð( ð ð  ð  ñ „\ð ðD ØZ^ð 
ð 
ð 
ð 
ð 
ñ „\ð
ð@ ð ).Ø7;ð	,6ð ,6ð ,6ð ,6ð ,6ñ „\ð,6ð\iGð iGð iGð iGðV ðEð Eð Eñ „\ðEð* ðEð Eð Eñ „\ðEð& ðð ð ñ „\ðð. ðð ð ñ „\ððnEð nEð nEð nEð`2ð 2ð 2ð 2ð JOð Oð Oð Oð Oð Oð Oð ð
&ð 
&ð 
&ñ „Xð
&ðð ð ð ð> €UÔÑÔð ð Ø(,Ø!%Ø%)ðLIð LIð LIð LIñ Ôñ	 Ôð
LIðd %)Ø"ØðNcð Ncð Ncð Ncð Ncð`)Tð )Tð )Tð )Tð )Tð )Tr@   r  c                ó¶   — | t           v r7t          j        d¦  «        }t          || ¦  «        }|t	          ¦   «         | <   |S t          dt          ›d| ›�¦  «        ‚)zFLazily resolve legacy re-exports without creating import-order cycles.zrfdetr.variantszmodule z has no attribute )Ú_VARIANT_EXPORTSÚ	importlibÚimport_moduler¦   Úglobalsr#  r˜   )r  rë  r¡  s      r>   Ú__getattr__r~  O  s_   € àÕÐÐÝÔ(Ð):Ñ;Ô;ˆÝ˜ Ñ%Ô%ˆØ�‰	Œ	�$‰Øˆå
ÐI¥8ÐIÐIÀÐIÐIÑ
JÔ
JÐJr@   rk  c                 ó|   — t          t          t          ¦   «         ¦  «        t          t          ¦  «        z  ¦  «        S )z1Include lazy re-exports in interactive discovery.)ry  r}  r}  rz  r;   r@   r>   Ú__dir__r€  Z  s(   € å•#•g‘i”i‘.”.¥3Õ'7Ñ#8Ô#8Ñ8Ñ9Ô9Ð9r@   )r2   r3   r4   r5   )r2   r5   r4   r3   )r\   r3   r]   r3   r4   r3   )
rM   rˆ   r‰   rŠ   r‹   rŠ   rŒ   rŠ   r4   r�   )r‹   r    r¡   rˆ   r¢   r£   r4   rŠ   )r©   r   r4   rª   )r¶   r·   r4   r·   )rÃ   rt   rÂ   r—   r¼   r   r4   rÄ   )ræ   r   r¡   r   rê   rë   r4   rª   )r  r£   r4   r   rq  )lÚ
__future__r   r  r{  r  rý   r™   rÿ   r  r¹  Úcollectionsr   Úcollections.abcr   r   r   Ú	functoolsr   Úpathlibr	   Útypingr
   r   r   r   r   r   r   Úurllib.parser   rR   rT   r  rH   Ú!torchvision.transforms.functionalÚ
transformsÚ
functionalrÏ  rw  ÚPILr   Úrfdetr._namespacer   Úrfdetr.assets.coco_classesr   r   Úrfdetr.assets.model_weightsr   r   Úrfdetr.configr   r   Ú rfdetr.datasets._keypoint_schemar   r   r   Úrfdetr.datasets.cocor   r   r   Ú rfdetr.datasets.webdataset.indexr    r!   r"   Úrfdetr.datasets.yolor#   r$   Úrfdetr.inferencer%   r&   Úrfdetr.utilities.distributedr'   r(   Úrfdetr.utilities.keypointsr)   r*   Úrfdetr.utilities.loggerr+   r   r-   r.   Úset_float32_matmul_precisionr  rÖ   r0   r1   rV   r[   rd   rz  Ú__all__ræ  rw   r  ry   ru  r|   rƒ   r‡   rŸ   r¨   rµ   rÁ   ré   r  rt   r~  r€  r;   r@   r>   ú<module>rš     s(  ðð #Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø Ð Ð Ð Ø 	€	€	€	Ø €€€Ø €€€Ø 	€	€	€	Ø €€€Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UØ !Ð !Ð !Ð !Ð !Ð !à Ð Ð Ð Ø €€€Ø €€€Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø €€€Ø Ð Ð Ð Ð Ð à 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø EÐ EÐ EÐ EÐ EÐ EÐ EÐ EØ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VØ 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2ðð ð ð ð ð ð ð ð ð ð
 iÐ hÐ hÐ hÐ hÐ hÐ hÐ hÐ hÐ hØ jÐ jÐ jÐ jÐ jÐ jÐ jÐ jÐ jÐ jØ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PØ ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø SÐ SÐ SÐ SÐ SÐ SÐ SÐ SØ bÐ bÐ bÐ bÐ bÐ bÐ bÐ bØ .Ð .Ð .Ð .Ð .Ð .àð 2Ø1Ð1Ð1Ð1Ð1Ð1Ð1Ð1ð	Ø&€EÔ& vÑ.Ô.Ð.Ð.øØð 	ð 	ð 	Ø€Dð	øøøð 
ˆ‰Œ€Ø€Yˆt�_„_€Ø€WˆT�]„]€ð>ð >ð >ð >ðB8ð 8ð 8ð 8ð0ð ð ð ð>Ð ð" �^Ð
7Ð&6Ð
7€à*3¨)Ð5LÈkÐ4ZÑ*[Ô*[Ð 'Ø8=¸ð >ð >Ø%5ð>ñ >ô >ñ 9ô 9Ð $ð ð ð ñ ð >_Ð )Ð ^Ð ^Ð ^Ñ ^ð>Ð ð ð ð ñ ð CÐ "ð ð ð ñ ð.ð .ð .ð .ðbð ð ð ðD/ð /ð /ð /ðBð ð ð ð& +0ðB*ð B*ð B*ð B*ð B*ð B*ðJ6gð 6gð 6gð 6gðrD)Tð D)Tð D)Tð D)Tð D)Tñ D)Tô D)Tð D)TðNRKð Kð Kð Kð:ð :ð :ð :ð :ð :s   Ã,C= Ã=DÄD