o
    2h	                     @   sL   d dl mZ d dlmZ d dlmZ d dlmZ edG dd deZdS )	    )tree)keras_export)Layer)serialization_libzkeras.layers.Pipelinec                       sL   e Zd ZdZd fdd	Zedd Zddd	Zed
d Z	dd Z
  ZS )Pipelinea  Applies a series of layers to an input.

    This class is useful to build a preprocessing pipeline,
    in particular an image data augmentation pipeline.
    Compared to a `Sequential` model, `Pipeline` features
    a few important differences:

    - It's not a `Model`, just a plain layer.
    - When the layers in the pipeline are compatible
        with `tf.data`, the pipeline will also
        remain `tf.data` compatible. That is to say,
        the pipeline will not attempt to convert
        its inputs to backend-native tensors
        when in a tf.data context (unlike a `Sequential`
        model).

    Example:

    ```python
    from keras import layers
    preprocessing_pipeline = layers.Pipeline([
        layers.AutoContrast(),
        layers.RandomZoom(0.2),
        layers.RandomRotation(0.2),
    ])

    # `ds` is a tf.data.Dataset
    preprocessed_ds = ds.map(
        preprocessing_pipeline,
        num_parallel_calls=4,
    )
    ```
    Nc                    s$   t  j|d || _d| _d| _d S )N)nameFT)super__init___pipeline_layers_convert_input_args!_allow_non_tensor_positional_args)selflayersr   	__class__ b/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/layers/preprocessing/pipeline.pyr	   +   s   
zPipeline.__init__c                 C   s   | j S N)r
   )r   r   r   r   r   1   s   zPipeline.layersTc                 C   s`   | j D ]*}i }|jr||d< |jr|d ur||d< ||fi |}|}dd }t||}q|S )Nmasktrainingc                 S   s   t | dd S )N_keras_mask)getattr)ktr   r   r   _get_mask_from_keras_tensor?   s   z2Pipeline.call.<locals>._get_mask_from_keras_tensor)r
   _call_has_mask_arg_call_has_training_argr   map_structure)r   inputsr   r   layerkwargsoutputsr   r   r   r   call5   s   
zPipeline.callc                 C   s$   dd |d D |d< | di |S )Nc                 S   s   g | ]}t |qS r   )r   deserialize_keras_object).0xr   r   r   
<listcomp>G   s    z(Pipeline.from_config.<locals>.<listcomp>r   r   r   )clsconfigr   r   r   from_configE   s   
zPipeline.from_configc                 C   s   t | j| jd}|S )N)r   r   )r   serialize_keras_objectr
   r   )r   r'   r   r   r   
get_configM   s   zPipeline.get_configr   )TN)__name__
__module____qualname____doc__r	   propertyr   r!   classmethodr(   r*   __classcell__r   r   r   r   r      s    "


r   N)		keras.srcr   keras.src.api_exportr   keras.src.layers.layerr   keras.src.savingr   r   r   r   r   r   <module>   s    