
    &Vf                     t    d dl mZ d dlmZ d dlmZ dZdZdZ ed           G d d	e                      Z	d
S )    )keras_export)TFDataLayer)SeedGenerator
horizontalverticalhorizontal_and_verticalzkeras.layers.RandomFlipc                   F     e Zd ZdZedf fd	Zd Zd	dZd Z fdZ	 xZ
S )

RandomFlipa  A preprocessing layer which randomly flips images during training.

    This layer will flip the images horizontally and or vertically based on the
    `mode` attribute. During inference time, the output will be identical to
    input. Call the layer with `training=True` to flip the input.
    Input pixel values can be of any range (e.g. `[0., 1.)` or `[0, 255]`) and
    of integer or floating point dtype.
    By default, the layer will output floats.

    **Note:** This layer is safe to use inside a `tf.data` pipeline
    (independently of which backend you're using).

    Input shape:
        3D (unbatched) or 4D (batched) tensor with shape:
        `(..., height, width, channels)`, in `"channels_last"` format.

    Output shape:
        3D (unbatched) or 4D (batched) tensor with shape:
        `(..., height, width, channels)`, in `"channels_last"` format.

    Args:
        mode: String indicating which flip mode to use. Can be `"horizontal"`,
            `"vertical"`, or `"horizontal_and_vertical"`. `"horizontal"` is a
            left-right flip and `"vertical"` is a top-bottom flip. Defaults to
            `"horizontal_and_vertical"`
        seed: Integer. Used to create a random seed.
        **kwargs: Base layer keyword arguments, such as
            `name` and `dtype`.
    Nc                      t                      j        di | || _        t          |          | _        || _        d| _        d| _        d S )NFT )super__init__seedr   	generatormode_convert_input_args!_allow_non_tensor_positional_args)selfr   r   kwargs	__class__s       g/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/layers/preprocessing/random_flip.pyr   zRandomFlip.__init__*   sS    ""6"""	&t,,	#( 15...    c                    | j                             |          }t          |          dk    }|r;| j         j                            |d          }| j                             |          }|d         }|}|                     | j         j                  }| j        t          k    s| j        t          k    rg| j         j        
                    | j         j                            |dddf|          dk    | j         j                            |d          |          }| j        t          k    s| j        t          k    rg| j         j        
                    | j         j                            |dddf|          dk    | j         j                            |d          |          }|r!| j         j                            |d          }|S )	N   r   )axis   )shaper   g      ?)backendr   lennumpyexpand_dims_get_seed_generator_backendr   
HORIZONTALHORIZONTAL_AND_VERTICALwhererandomuniformflipVERTICALsqueeze)r   inputsinputs_shape	unbatched
batch_sizeflipped_outputsseed_generators          r   _randomly_flip_inputsz RandomFlip._randomly_flip_inputs2   s   |))&11%%*	 	6\'33F3CCF<--f55L!!_
 11$,2GHH9
""di3J&J&J"l066#++%q!Q/n ,    "''b'AA O 9  DI1H$H$H"l066#++%q!Q/n ,    "''b'AA O  	"l088a 9  O r   Tc                 t    | j                             || j                  }|r|                     |          S |S N)r    castcompute_dtyper4   )r   r.   trainings      r   callzRandomFlip.callT   s=    ""64+=>> 	--f555Mr   c                     |S r6   r   )r   input_shapes     r   compute_output_shapezRandomFlip.compute_output_shape[   s    r   c                     t                                                      }|                    | j        | j        d           |S )N)r   r   )r   
get_configupdater   r   )r   configr   s     r   r?   zRandomFlip.get_config^   s;    ##%%ty$)<<===r   )T)__name__
__module____qualname____doc__r'   r   r4   r:   r=   r?   __classcell__)r   s   @r   r
   r
   
   s         < 4$ 6 6 6 6 6 6     D             r   r
   N)
keras.src.api_exportr   ,keras.src.layers.preprocessing.tf_data_layerr   keras.src.random.seed_generatorr   r&   r,   r'   r
   r   r   r   <module>rJ      s    - - - - - - D D D D D D 9 9 9 9 9 9
3  '((V V V V V V V )(V V Vr   