U
    hZ~                     @  s  d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	m
Z
mZmZm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mZ ddlmZmZm Z m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z' ddddddddddddgZ(dZ)dZ*ee#df Z+e
e+ Z,dZ-dZ.dZ/dZ0dZ1d Z2d!Z3dd"d#d$d%Z4G d&d deZ5G d'd de5eZ6G d(d de5Z7G d)d de5Z8G d*d+ d+e8Z9G d,d de5Z:G d-d de5Z;G d.d de6Z<G d/d de5Z=dS )0    )annotationsN)OrderedDictdefaultdict)AnyIteratorListSequenceUnioncast)random_utils)NUM_MULTI_CHANNEL_DIMENSIONS   )
BboxParamsBboxProcessor)HubMixin)KeypointParamsKeypointsProcessor)SERIALIZABLE_REGISTRYSerializableget_shortest_class_fullnameinstantiate_nonserializable)BasicTransform)DataProcessorformat_args	get_shapeBaseComposeComposeSomeOfOneOf
OneOrOtherr   r   ReplayCompose
SequentialTransformTypeTransformsSeqTypeSelectiveChannelTransform   )imagemaskmasksbboxes	keypoints)r'   r(   )r&   images)r&   r'   )r(   r+   )r)   )r*   zdict[int, BasicTransform]
transformsreturnc                 C  s:   i }| D ],}t |tr(|t|j q||t|< q|S N)
isinstancer   updateget_transforms_dictr-   id)r-   result	transform r6   C/tmp/pip-unpacked-wheel-e8onvpoz/albumentations/core/composition.pyr2   <   s    
r2   c                   @  sL  e Zd ZU dZdZded< dZded< dZded	< d
ddddZddddZ	ddddZ
ddddddZdddddZddd d!Zed"dd#d$Zed%dd&d'Zefddd(d)d*Zeddd+d,Zeddd-d.Zddd/d0Zddd1d2Zd3d4d5d6d7Zd4dd8d9ZdAddd4d;d<d=Zddd>d?d@ZdS )Br   a  Base class for composing multiple transforms together.

    This class serves as a foundation for creating compositions of transforms
    in the Albumentations library. It provides basic functionality for
    managing a sequence of transforms and applying them to data.

    Attributes:
        transforms (List[TransformType]): A list of transforms to be applied.
        p (float): Probability of applying the compose. Should be in the range [0, 1].
        replay_mode (bool): If True, the compose is in replay mode.
        applied_in_replay (bool): Indicates if the compose was applied during replay.
        _additional_targets (Dict[str, str]): Additional targets for transforms.
        _available_keys (Set[str]): Set of available keys for data.
        processors (Dict[str, Union[BboxProcessor, KeypointsProcessor]]): Processors for specific data types.

    Args:
        transforms (TransformsSeqType): A sequence of transforms to compose.
        p (float): Probability of applying the compose.

    Raises:
        ValueError: If an invalid additional target is specified.

    Note:
        - Subclasses should implement the __call__ method to define how
          the composition is applied to data.
        - The class supports serialization and deserialization of transforms.
        - It provides methods for adding targets, setting deterministic behavior,
          and checking data validity post-transform.
    Nz dict[int, BasicTransform] | None_transforms_dictz tuple[DataProcessor, ...] | Nonecheck_each_transformTboolmain_composer#   floatr-   pc                 C  sZ   t |ttfr"tjddd |g}|| _|| _d| _d| _i | _	t
 | _i | _|   d S )Nz`transforms is single transform, but a sequence is expected! Transform will be wrapped into list.r%   
stacklevelF)r0   r   r   warningswarnr-   r>   replay_modeapplied_in_replay_additional_targetsset_available_keys
processors	_set_keysselfr-   r>   r6   r6   r7   __init__i   s    zBaseCompose.__init__zIterator[TransformType]r.   c                 C  s
   t | jS r/   )iterr-   rK   r6   r6   r7   __iter__{   s    zBaseCompose.__iter__intc                 C  s
   t | jS r/   )lenr-   rO   r6   r6   r7   __len__~   s    zBaseCompose.__len__r   dict[str, Any])argsdatar.   c                 O  s   t d S r/   )NotImplementedError)rK   rU   rV   r6   r6   r7   __call__   s    zBaseCompose.__call__r"   )itemr.   c                 C  s
   | j | S r/   )r-   )rK   rY   r6   r6   r7   __getitem__   s    zBaseCompose.__getitem__strc                 C  s   |   S r/   )indented_reprrO   r6   r6   r7   __repr__   s    zBaseCompose.__repr__zdict[str, str]c                 C  s   | j S r/   )rE   rO   r6   r6   r7   additional_targets   s    zBaseCompose.additional_targetszset[str]c                 C  s   | j S r/   )rG   rO   r6   r6   r7   available_keys   s    zBaseCompose.available_keys)indentr.   c                 C  s   dd |    D }| jjd }| jD ]@}|d7 }t|drL||t nt|}|d| | d 7 }q(|dd|t   dt	| d	 7 }|S )
Nc                 S  s(   i | ] \}}| d s|dks||qS )__r-   )
startswith.0kvr6   r6   r7   
<dictcomp>   s
     
   z-BaseCompose.indented_repr.<locals>.<dictcomp>z([
r\    ,z], ))
to_dict_privateitems	__class____name__r-   hasattrr\   REPR_INDENT_STEPreprr   )rK   r`   rU   Zrepr_stringtZt_reprr6   r6   r7   r\      s    
 $zBaseCompose.indented_reprc                 C  s   t | S r/   )r   clsr6   r6   r7   get_class_fullname   s    zBaseCompose.get_class_fullnamec                 C  s   dS )NTr6   rt   r6   r6   r7   is_serializable   s    zBaseCompose.is_serializablec                 C  s   |   | jdd | jD dS )Nc                 S  s   g | ]}|  qS r6   )rl   rd   rs   r6   r6   r7   
<listcomp>   s     z/BaseCompose.to_dict_private.<locals>.<listcomp>)__class_fullname__r>   r-   )rv   r>   r-   rO   r6   r6   r7   rl      s    zBaseCompose.to_dict_privatec                 C  s"   |   t| d dd | jD dS )Nc                 S  s   g | ]}|  qS r6   )get_dict_with_idrx   r6   r6   r7   ry      s     z0BaseCompose.get_dict_with_id.<locals>.<listcomp>)rz   r3   paramsr-   )rv   r3   r-   rO   r6   r6   r7   r{      s
    zBaseCompose.get_dict_with_iddict[str, str] | NoneNone)r^   r.   c                 C  s   |r|  D ]@\}}|| jkr|| j| krtd| d| j|  d| q| j| | jD ]}|| q`| j D ]}|| qz|   d S )Nz4Trying to overwrite existed additional targets. Key=z Exists=z New value: )	rm   rE   
ValueErrorr1   r-   add_targetsrH   valuesrI   )rK   r^   re   rf   rs   procr6   r6   r7   r      s    
zBaseCompose.add_targetsc                 C  s   | j | j  | jD ]*}| j |j t|dr| j |j q| jr| j dg | j	 D ]N}|j
| j krtjd|j
 ddd | j |j |jjrb| j |jj qbdS )zSet _available_keystargets_as_paramslabelszGot processor for z!, but no transform to process it.r%   r?   N)rG   r1   rE   keysr-   r_   rp   r   rH   r   Zdefault_data_namerA   rB   data_fieldsr|   Zlabel_fields)rK   rs   r   r6   r6   r7   rI      s     

zBaseCompose._set_keysreplay)flagsave_keyr.   c                 C  s   | j D ]}||| qd S r/   )r-   set_deterministic)rK   r   r   rs   r6   r6   r7   r      s    
zBaseCompose.set_deterministicrV   r.   c                 C  sd   | j r`t|d }| j D ]F}|D ]<}||jksH|| jkr | j| |jkr ||| |||< q q|S )Nr&   )r9   r   r   rE   filter)rK   rV   Zimage_shaper   	data_namer6   r6   r7   check_data_post_transform   s    

z%BaseCompose.check_data_post_transform)r   )ro   
__module____qualname____doc__r8   __annotations__r9   r;   rL   rP   rS   rX   rZ   r]   propertyr^   r_   rq   r\   classmethodrv   rw   rl   r{   r   rI   r   r   r6   r6   r6   r7   r   F   s2   

c                      sT  e Zd ZdZd?ddd	d
dddddd	 fddZdddddZdddddZddddZdddddddddZd ddd!d"d#Z	ddd$d%d&Z
ddd$d'd(Zdd fd)d*Zdd fd+d,Zeddd-d.d/d0Zeddd-d.d1d2Zeddd-d.d3d4Zedddd5d6d7Zed8ddd9d:d;Zddd<d=d>Z  ZS )@r   a  Compose transforms and handle all transformations regarding bounding boxes

    Args:
        transforms (list): list of transformations to compose.
        bbox_params (BboxParams): Parameters for bounding boxes transforms
        keypoint_params (KeypointParams): Parameters for keypoints transforms
        additional_targets (dict): Dict with keys - new target name, values - old target name. ex: {'image2': 'image'}
        p (float): probability of applying all list of transforms. Default: 1.0.
        is_check_shapes (bool): If True shapes consistency of images/mask/masks would be checked on each call. If you
            would like to disable this check - pass False (do it only if you are sure in your data consistency).
        strict (bool): If True, unknown keys will raise an error. If False, unknown keys will be ignored. Default: True.
        return_params (bool): if True returns params of each applied transform
        save_key (str): key to save applied params, default is 'applied_params'

    N      ?TFapplied_paramsr#   "dict[str, Any] | BboxParams | None&dict[str, Any] | KeypointParams | Noner}   r<   r:   r[   )	r-   bbox_paramskeypoint_paramsr^   r>   is_check_shapesstrictreturn_paramsr   c
                   sN  t  || |rRt|tr(tf |}
nt|tr8|}
nd}t|t|
| jd< |rt|trltf |}nt|tr||}nd}t|t	|| jd< | j
 D ]}|| j q| | | js| jt d| _|| _|| _tdd | j
 D | _| | j || _|r>|	| _| j|	 t| j| _| jd|	d | | j d S )	Nz@unknown format of bbox_params, please use `dict` or `BboxParams`r)   zHunknown format of keypoint_params, please use `dict` or `KeypointParams`r*   Tc                 s  s    | ]}t |jd dr|V  qdS )r9   FN)getattrr|   )rd   r   r6   r6   r7   	<genexpr>%  s     z#Compose.__init__.<locals>.<genexpr>r   )superrL   r0   dictr   r   r   rH   r   r   r   Zensure_transforms_validr-   r   rG   r1   AVAILABLE_KEYSis_check_argsr   r   tupler9   _set_check_args_for_transformsr   r   addr2   r8   r   _set_processors_for_transforms)rK   r-   r   r   r^   r>   r   r   r   r   Zb_paramsmsgZk_paramsr   rn   r6   r7   rL      sH    





zCompose.__init__r~   r,   c                 C  sF   |D ]<}t |tr*t|dr@|| j qt |tr| |j qd S )Nset_processors)r0   r   rp   r   rH   r   r   r-   rK   r-   r5   r6   r6   r7   r   4  s    


z&Compose._set_processors_for_transformsc                 C  sF   |D ]<}t |tr.| |j | j|_| j|_t |tr|  qd S r/   )r0   r   r   r-   r9   rH   r   disable_check_args_privater   r6   r6   r7   r   <  s    

z&Compose._set_check_args_for_transformsrM   c                 C  s   d| _ d| _d| _d S )NF)r   r   r;   rO   r6   r6   r7   r   E  s    z"Compose.disable_check_args_privateforce_applyr   rT   rU   r   rV   r.   c                O  s   |rd}t |t|ttfs*d}t|| jrB| jrBt || j< |pRt		 | j
k }|s\|S | | | jD ]}|f |}| |}ql| |S )NzXYou have to pass data to augmentations as named arguments, for example: aug(image=image)z&force_apply must have bool or int type)KeyErrorr0   r:   rQ   	TypeErrorr   r;   r   r   randomr>   
preprocessr-   r   postprocess)rK   r   rU   rV   r   Zneed_to_runrs   r6   r6   r7   rX   J  s     


zCompose.__call__zdict[int, dict[str, Any]])r|   rV   r.   c                K  sZ   | j dkrtd| | | D ]*\}}| j | }|j|f|}| |}q$| |S )z[Run transforms with given parameters. Available only for Compose with `return_params=True`.NzJ`run_with_params` is not available for Compose with `return_params=False`.)r8   RuntimeErrorr   rm   Zapply_with_paramsr   r   )rK   r|   rV   Ztr_idparamtrr6   r6   r7   run_with_paramsb  s    


zCompose.run_with_paramsr   c                 C  s   | j r>|D ]2}|| jkr
|tkr
|tkr
d| d}t|q
| jrP| jf | | jr| j	 D ]}|
| q`| j	 D ]}|| qzd S )NzKey z is not in available keys.)r   rG   	MASK_KEYS
IMAGE_KEYSr   r   _check_argsr;   rH   r   Zensure_data_validr   )rK   rV   r   r   r>   r6   r6   r7   r   p  s    
zCompose.preprocessc                 C  s$   | j r | j D ]}|| q|S r/   )r;   rH   r   r   )rK   rV   r>   r6   r6   r7   r   ~  s    zCompose.postprocessc                   sZ   t   }| jd}| jd}||r4|j nd |rD|j nd | j| jd |S )Nr)   r*   )r   r   r^   r   )r   rl   rH   getr1   r|   r^   r   rK   
dictionaryZbbox_processorZkeypoints_processorr   r6   r7   rl     s    
zCompose.to_dict_privatec                   s\   t   }| jd}| jd}||r4|j nd |rD|j nd | jd | jd |S )Nr)   r*   )r   r   r^   r|   r   )	r   r{   rH   r   r1   r|   rl   r^   r   r   r   r6   r7   r{     s    
	zCompose.get_dict_with_idztuple[int, int])r   rV   r.   c                 C  s(   t |tjst|  d|jd d S )Nz must be numpy array typer%   )r0   npndarrayr   shaper   rV   r6   r6   r7   _check_single_data  s    zCompose._check_single_datac                 C  s   t |tjrJ|jdkr$t|  d|jtkr<|jdd S |jd d S t |trtdd |D svtd|  d	t	d
d |D rtd|  d|d jd d S t|  dd S )N)      z must be a 3D or 4D numpy arrayr   r   r%   c                 s  s   | ]}t |tjV  qd S r/   )r0   r   r   rd   mr6   r6   r7   r     s     z,Compose._check_masks_data.<locals>.<genexpr>zAll elements in z must be numpy arraysc                 s  s   | ]}|j d kV  qdS ))r%   r   N)ndimr   r6   r6   r7   r     s     zAll masks in z must be 2D or 3D numpy arraysr   z; must be either a numpy array or a sequence of numpy arrays)
r0   r   r   r   r   r   r   r   allanyr   r6   r6   r7   _check_masks_data  s    
&
zCompose._check_masks_datac                 C  s:   t |trt |d tjs(t|  d|d jd d S )Nr   z must be list of numpy arraysr%   )r0   r   r   r   r   r   r   r6   r6   r7   _check_multi_data  s    zCompose._check_multi_data)internal_data_namerH   r.   c                 C  s@   | t kr|dd krtd| tkr<|dd kr<tdd S )Nr)   z6bbox_params must be specified for bbox transformationsr*   z?keypoints_params must be specified for keypoint transformations)CHECK_BBOX_PARAMr   r   CHECK_KEYPOINTS_PARAM)r   rH   r6   r6   r7   _check_bbox_keypoint_params  s    z#Compose._check_bbox_keypoint_paramszlist[tuple[int, int]])shapesr   r.   c                 C  s*   |r&| r&|  | d t| kr&tdd S )Nr   zHeight and Width of image, mask or masks should be equal. You can disable shapes check by setting a parameter is_check_shapes=False of Compose class (do it only if you are sure about your data consistency).)countrR   r   )r   r   r6   r6   r7   _check_shapes  s    zCompose._check_shapes)kwargsr.   c                 K  s   g }|  D ]\}}| j||}|tkr<|| || |tkr|d k	rt|r|dkrp|| || n|| 	|| | 
|| j q| || j d S )Nr(   )rm   rE   r   CHECKED_SINGLEappendr   CHECKED_MULTIrR   r   r   r   rH   r   r   )rK   r   r   r   rV   r   r6   r6   r7   r     s    zCompose._check_args)NNNr   TTFr   )ro   r   r   r   rL   r   r   r   rX   r   r   r   rl   r{   staticmethodr   r   r   r   r   r   __classcell__r6   r6   r   r7   r      s<           $<	c                      sD   e Zd ZdZdddd fddZdd	d
dd
ddddZ  ZS )r   ao  Select one of transforms to apply. Selected transform will be called with `force_apply=True`.
    Transforms probabilities will be normalized to one 1, so in this case transforms probabilities works as weights.

    Args:
        transforms (list): list of transformations to compose.
        p (float): probability of applying selected transform. Default: 0.5.

          ?r#   r<   r=   c                   s>   t  || dd | jD }t|  fdd|D | _d S )Nc                 S  s   g | ]
}|j qS r6   r>   rx   r6   r6   r7   ry     s     z"OneOf.__init__.<locals>.<listcomp>c                   s   g | ]}|  qS r6   r6   rx   sr6   r7   ry     s     )r   rL   r-   sumtransforms_ps)rK   r-   r>   r   r   r   r7   rL     s    zOneOf.__init__Fr   r   r:   rT   r   c                O  sn   | j r | jD ]}|f |}q|S | jrj|s8t | jk rjtjt| j| jd}| j| }|f ddi|}|S )Nr   r   T)rC   r-   r   r   r>   r   choicerR   )rK   r   rU   rV   rs   idxr6   r6   r7   rX     s    

zOneOf.__call__)r   ro   r   r   r   rL   rX   r   r6   r6   r   r7   r     s   	c                      sh   e Zd ZdZdddddd fd	d
ZdddddddddZddddZdd fddZ  ZS )r   a   Select N transforms to apply. Selected transforms will be called with `force_apply=True`.
    Transforms probabilities will be normalized to one 1, so in this case transforms probabilities works as weights.

    Args:
        transforms (list): list of transformations to compose.
        n (int): number of transforms to apply.
        replace (bool): Whether the sampled transforms are with or without replacement. Default: True.
        p (float): probability of applying selected transform. Default: 1.

    Tr   r#   rQ   r:   r<   r-   nreplacer>   c                   s   t  || || _|sL|t| jkrLt| j| _tjd| j dtdd || _dd | jD }t	|  fdd|D | _
d S )Nz=`n` is greater than number of transforms. `n` will be set to .r%   r?   c                 S  s   g | ]
}|j qS r6   r   rx   r6   r6   r7   ry     s     z#SomeOf.__init__.<locals>.<listcomp>c                   s   g | ]}|  qS r6   r6   rx   r   r6   r7   ry     s     )r   rL   r   rR   r-   rA   rB   UserWarningr   r   r   )rK   r-   r   r   r>   r   r   r   r7   rL   	  s    zSomeOf.__init__Fr   r   rT   )argr   rV   r.   c                O  sz   | j r*| jD ]}|f |}| |}q|S | jrv|sBt | jk rv|  D ]*}| j| }|f ddi|}| |}qJ|S Nr   T)rC   r-   r   r   r   r>   _get_idx)rK   r   r   rV   rs   ir6   r6   r7   rX     s    


zSomeOf.__call__np.ndarray[np.int_]rM   c                 C  s*   t jt| j| j| j| jd}|  |S N)sizer   r>   )r   r   rR   r-   r   r   r   sort)rK   r   r6   r6   r7   r   &  s    zSomeOf._get_idxc                   s"   t   }|| j| jd |S )N)r   r   )r   rl   r1   r   r   rK   r   r   r6   r7   rl   +  s    
zSomeOf.to_dict_private)Tr   )	ro   r   r   r   rL   rX   r   rl   r   r6   r6   r   r7   r     s
   c                      s<   e Zd ZdZdddddd fd	d
ZddddZ  ZS )RandomOrdera  Select N transforms to apply. Selected transforms will be called in random order with `force_apply=True`.
    Transforms probabilities will be normalized to one 1, so in this case transforms probabilities works as weights.
    This transform is like SomeOf, but transforms are called with random order.
    It will not replay random order in ReplayCompose.

    Args:
        transforms (list): list of transformations to compose.
        n (int): number of transforms to apply.
        replace (bool): Whether the sampled transforms are with or without replacement. Default: False.
        p (float): probability of applying selected transform. Default: 1.

    Fr   r#   rQ   r:   r<   r   c                   s   t  |||| d S r/   r   rL   )rK   r-   r   r   r>   r   r6   r7   rL   ?  s    zRandomOrder.__init__r   rM   c                 C  s   t jt| j| j| j| jdS r   )r   r   rR   r-   r   r   r   rO   r6   r6   r7   r   B  s    zRandomOrder._get_idx)Fr   )ro   r   r   r   rL   r   r   r6   r6   r   r7   r   1  s   r   c                      sH   e Zd ZdZdddddd fdd	Zd
ddddddddZ  ZS )r   zdSelect one or another transform to apply. Selected transform will be called with `force_apply=True`.Nr   zTransformType | NonezTransformsSeqType | Noner<   )firstsecondr-   r>   c                   sZ   |d kr,|d ks|d kr$d}t |||g}t || t| jtkrVtjddd d S )Nz>You must set both first and second or set transforms argument.z'Length of transforms is not equal to 2.r%   r?   )r   r   rL   rR   r-   NUM_ONEOF_TRANSFORMSrA   rB   )rK   r   r   r-   r>   r   r   r6   r7   rL   I  s    zOneOrOther.__init__Fr   r   r:   rT   r   c                O  s^   | j r | jD ]}|f |}q|S t | jk rF| jd f ddi|S | jd f ddi|S )Nr   r   T)rC   r-   r   r>   rK   r   rU   rV   rs   r6   r6   r7   rX   Y  s    
zOneOrOther.__call__)NNNr   r   r6   r6   r   r7   r   F  s       c                      sH   e Zd ZdZdddddd fd	d
ZdddddddddZ  ZS )r$   ac  A transformation class to apply specified transforms to selected channels of an image.

    This class extends BaseCompose to allow selective application of transformations to
    specified image channels. It extracts the selected channels, applies the transformations,
    and then reinserts the transformed channels back into their original positions in the image.

    Parameters:
        transforms (TransformsSeqType):
            A sequence of transformations (from Albumentations) to be applied to the specified channels.
        channels (Sequence[int]):
            A sequence of integers specifying the indices of the channels to which the transforms should be applied.
        p (float):
            Probability that the transform will be applied; the default is 1.0 (always apply).

    Methods:
        __call__(*args, **kwargs):
            Applies the transforms to the image according to the specified channels.
            The input data should include 'image' key with the image array.

    Returns:
        dict[str, Any]: The transformed data dictionary, which includes the transformed 'image' key.
    r   r   r%   r   r#   zSequence[int]r<   r~   )r-   channelsr>   r.   c                   s   t  || || _d S r/   )r   rL   r   )rK   r-   r   r>   r   r6   r7   rL   }  s    z"SelectiveChannelTransform.__init__Fr   r   r:   rT   r   c                O  s   |st   | jk r|d }|d d d d | jf }t|}| jD ]}||dd }qBt|}| }	t	| j|D ]\}
}||	d d d d |
f< qtt|	|d< |S )Nr&   )r&   )
r   r>   r   r   Zascontiguousarrayr-   cv2splitcopyzip)rK   r   rU   rV   r&   Zselected_channelsZ	sub_imagers   Ztransformed_channelsZ
output_imgr   Zchannelr6   r6   r7   rX     s    


z"SelectiveChannelTransform.__call__)r   r   r   r6   r6   r   r7   r$   e  s
     	c                	      s   e Zd Zd(ddddd	d
dd fddZdddd
ddd fddZeddddddZed)ddddddZddddd d!Zdd
d"d#d$Z	dd% fd&d'Z
  ZS )*r    Nr   Tr   r#   r   r   r}   r<   r:   r[   )r-   r   r   r^   r>   r   r   c                   s:   t  |||||| | jd|d || _| j| d S )NTr   )r   rL   r   r   rG   r   )rK   r-   r   r   r^   r>   r   r   r   r6   r7   rL     s    
zReplayCompose.__init__Fr   r   rT   )rU   r   r   r.   c                  sV   t t|| j< t jf d|i|}|  }| ||| j  | | ||| j< |S )Nr   )r   r   r   r   rX   r{   fill_with_paramsfill_applied)rK   r   rU   r   r4   
serializedr   r6   r7   rX     s    

zReplayCompose.__call__)saved_augmentationsr   r.   c                 K  s   t | }|f ddi|S r   r    _restore_for_replay)r  r   Zaugsr6   r6   r7   r     s    
zReplayCompose.replayzdict[str, Any] | Noner"   )transform_dictlambda_transformsr.   c           	        s   | d }| d }t |  }|r$|}nN| d }dd |  D }t| }d|krh fdd|d D |d< |f |}tt|}t|tr||_d	|_||_|S )
a  Args:
        lambda_transforms (dict): A dictionary that contains lambda transforms, that
        is instances of the Lambda class.
            This dictionary is required when you are restoring a pipeline that contains lambda transforms. Keys
            in that dictionary should be named same as `name` arguments in respective lambda transforms from
            a serialized pipeline.

        appliedr|   rz   c                 S  s   i | ]\}}|d kr||qS ))rz   r  r|   r6   rc   r6   r6   r7   rg     s       z5ReplayCompose._restore_for_replay.<locals>.<dictcomp>r-   c                   s   g | ]}t j| d qS )r  r  rx   r  r6   r7   ry     s   z5ReplayCompose._restore_for_replay.<locals>.<listcomp>T)	r   rm   r   r
   r   r0   r|   rC   rD   )	r  r  r  r|   Zlmbdr5   namerU   ru   r6   r  r7   r    s&    





z!ReplayCompose._restore_for_replayr~   )r  
all_paramsr.   c                 C  s@   | | d}||d< |d= | dg D ]}| || q*d S )Nr3   r|   r-   )r   r   )rK   r  r
  r|   r5   r6   r6   r7   r     s
    zReplayCompose.fill_with_params)r  r.   c                   sF   d|kr, fdd|d D }t ||d< n|dd k	|d< |d S )Nr-   c                   s   g | ]}  |qS r6   )r   rx   rO   r6   r7   ry     s     z.ReplayCompose.fill_applied.<locals>.<listcomp>r  r|   )r   r   )rK   r  r  r6   rO   r7   r     s
    zReplayCompose.fill_appliedrM   c                   s   t   }|d| ji |S )Nr   )r   rl   r1   r   r   r   r6   r7   rl     s    
zReplayCompose.to_dict_private)NNNr   Tr   )N)ro   r   r   rL   rX   r   r   r  r   r   rl   r   r6   r6   r   r7   r      s           	 #c                      sD   e Zd ZdZdddd fddZdd	d
dd
ddddZ  ZS )r!   a  Sequentially applies all transforms to targets.

    Note:
        This transform is not intended to be a replacement for `Compose`. Instead, it should be used inside `Compose`
        the same way `OneOf` or `OneOrOther` are used. For instance, you can combine `OneOf` with `Sequential` to
        create an augmentation pipeline that contains multiple sequences of augmentations and applies one randomly
        chose sequence to input data (see the `Example` section for an example definition of such pipeline).

    Example:
        >>> import albumentations as A
        >>> transform = A.Compose([
        >>>    A.OneOf([
        >>>        A.Sequential([
        >>>            A.HorizontalFlip(p=0.5),
        >>>            A.ShiftScaleRotate(p=0.5),
        >>>        ]),
        >>>        A.Sequential([
        >>>            A.VerticalFlip(p=0.5),
        >>>            A.RandomBrightnessContrast(p=0.5),
        >>>        ]),
        >>>    ], p=1)
        >>> ])

    r   r#   r<   r=   c                   s   t  || d S r/   r   rJ   r   r6   r7   rL     s    zSequential.__init__Fr   r   r:   rT   r   c                O  s<   | j s|st | jk r8| jD ]}|f |}| |}q|S r/   )rC   r   r>   r-   r   r   r6   r6   r7   rX     s
    

zSequential.__call__)r   r   r6   r6   r   r7   r!     s   )>
__future__r   r   rA   collectionsr   r   typingr   r   r   r   r	   r
   r   Znumpyr   Zalbumentationsr   Zalbumentations.core.typesr   Z
bbox_utilsr   r   Z	hub_mixinr   Zkeypoints_utilsr   r   Zserializationr   r   r   r   Ztransforms_interfacer   utilsr   r   r   __all__r   rq   r"   r#   r   r   r   r   r   r   r   r2   r   r   r   r   r   r   r$   r    r!   r6   r6   r6   r7   <module>   sd    
 " z46W