
    ^j,                        U d Z ddlmZ ddlmZ ddlmZ  eh d      Zde	d<    eh d      Z
de	d	<   dd
Zdd	 	 	 	 	 	 	 ddZddZddZ G d d      Z	 	 	 	 	 	 	 	 ddZy)z6Shared helpers for dataset augmentation configuration.    )annotations)Callable)Any>   D4FlipHorizontalFlipzfrozenset[str]HFLIP_TRANSFORM_NAMES>   OneOfSomeOf
SequentialCONTAINER_TRANSFORM_NAMESc                     |d| |        y)zBEmit the standard warning for a disabled keypoint horizontal flip.zKeypoint pipeline: '%s' performs a horizontal flip but no keypoint flip pairs were configured. The transform has been disabled to prevent incorrect keypoint annotations. Remove '%s' from your augmentation config or provide keypoint_flip_pairs.N )aug_namewarns     e/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/rfdetr/datasets/_aug_utils.py_warn_keypoint_hflip_disabledr      s    	a 	    T)include_keypointsc                   |s| S t        | t              rt        | |      S t        | t              rt	        | |      S | S )a  Drop horizontal-flip transforms from keypoint augmentation configs.

    The helper preserves the input config shape: dictionary configs return
    dictionaries, and ordered list configs return lists. Container transforms are
    filtered recursively so nested hflip entries cannot survive inside
    ``OneOf``, ``SomeOf``, or ``Sequential``.

    Args:
        config: Augmentation config accepted by RF-DETR augmentation builders.
        include_keypoints: Whether the config will be applied to keypoint data.
        warn: Warning sink, typically ``logger.warning``.

    Returns:
        A filtered augmentation config with keypoint-unsafe hflip entries removed.
    r   )
isinstancelist_filter_keypoint_hflip_entriesdict_filter_keypoint_hflip_dict)configr   r   s      r   #filter_keypoint_hflip_augmentationsr      s?    * &$-f4@@&$*6==Mr   c               &   g }| D ]  }t        |t              rt        |      dk7  r|j                  |       3t	        t        |j                                     \  }}t        |||      }t        |t              rw|j                  ||i        |S )z/Filter ordered single-key augmentation entries.   r   )	r   r   lenappendnextiteritems_filter_keypoint_hflip_item_DropAugmentation)entriesr   filtered_entriesentryr   paramsfiltered_paramss          r   r   r   @   s    -/ 	=%&#e*/##E*U[[] 34&5hTRo'89? ;<	= r   c                   i }| j                         D ])  \  }}t        |||      }t        |t              r%|||<   + |S )z+Filter a mapping-style augmentation config.r   )r%   r&   r   r'   )r   r   filtered_configr   r+   r,   s         r   r   r   P   sO    &(O"LLN 4&5hTRo'89$3!	4
 r   c                      e Zd ZdZy)r'   z;Sentinel used when an augmentation entry should be removed.N)__name__
__module____qualname____doc__r   r   r   r'   r'   [   s    Er   r'   c               D   | t         v rt        | |       t               S | t        vr|S t	        |t
              rt        ||      }|r|S t               S t	        |t              rd|vr|S |d   }t	        |t
              s|S t        ||      }|s
t               S i |d|iS )zCFilter one augmentation entry, recursing into supported containers.r   
transforms)r	   r   r'   r   r   r   r   r   )r   r+   r   filtered_transformsr5   s        r   r&   r&   _   s     ((%h5 ""00&$<V$O&9"R?P?RRfd#|6'A%Jj$'8$O ""8f8l$788r   N)r   strr   Callable[..., None]returnNone)r   r   r   boolr   r8   r9   r   )r(   list[dict[str, Any]]r   r8   r9   r<   )r   dict[str, Any]r   r8   r9   r=   )r   r7   r+   r   r   r8   r9   zAny | _DropAugmentation)r3   
__future__r   collections.abcr   typingr   	frozensetr	   __annotations__r   r   r   r   r   r'   r&   r   r   r   <module>rC      s    = " $  )22R(S ~ S,56W,X > X #  	
 	B F F999 	9
 9r   