o
    2h                     @   sl   d dl Z d dlmZ d dlmZ 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 )    N)backend)ops)keras_export)KerasTensor)	InputSpec)Layerzkeras.layers.Flattenc                       sF   e Zd ZdZd fdd	Zdd Zdd Zd	d
 Z fddZ  Z	S )Flattenaj  Flattens the input. Does not affect the batch size.

    Note: If inputs are shaped `(batch,)` without a feature axis, then
    flattening adds an extra channel dimension and output shape is `(batch, 1)`.

    Args:
        data_format: A string, one of `"channels_last"` (default) or
            `"channels_first"`. The ordering of the dimensions in the inputs.
            `"channels_last"` corresponds to inputs with shape
            `(batch, ..., channels)` while `"channels_first"` corresponds to
            inputs with shape `(batch, channels, ...)`.
            When unspecified, uses `image_data_format` value found in your Keras
            config file at `~/.keras/keras.json` (if exists). Defaults to
            `"channels_last"`.

    Example:

    >>> x = keras.Input(shape=(10, 64))
    >>> y = keras.layers.Flatten()(x)
    >>> y.shape
    (None, 640)
    Nc                    s:   t  jdi | t|| _tdd| _| jdk| _d S )N   )min_ndimchannels_first )super__init__r   standardize_data_formatdata_formatr   
input_spec_channels_first)selfr   kwargs	__class__r   ]/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/layers/reshaping/flatten.pyr   $   s   zFlatten.__init__c                 C   s   t |}t|}| jr |dkr t j|dgtd|dR d}|dd  }t|dkr/d}ntdd |D r;d}nt|}t 	||d |fS )Nr	   r      )axesc                 s   s    | ]	}t |t V  qd S N)
isinstanceint.0dr   r   r   	<genexpr>5   s    zFlatten.call.<locals>.<genexpr>)
r   shapelenr   	transposerangeanymathprodreshape)r   inputsinput_shaperanknon_batch_dimsflattened_dimr   r   r   call*   s   
 
zFlatten.callc                 C   sL   |dd  }t |dkrd}ntdd |D rd }nt|}|d |fS )Nr	   r   c                 s   s    | ]}|d u V  qd S r   r   r   r   r   r   r    @   s    z/Flatten.compute_output_shape.<locals>.<genexpr>)r#   r&   r'   r(   )r   r+   r-   r.   r   r   r   compute_output_shape<   s   
zFlatten.compute_output_shapec                 C   s   |  |j}t||j|jdS )N)r"   dtypesparse)r0   r"   r   r1   r2   )r   r*   output_shaper   r   r   compute_output_specK   s   
zFlatten.compute_output_specc                    s    d| j i}t  }i ||S )Nr   )r   r   
get_config)r   configbase_configr   r   r   r5   Q   s   

zFlatten.get_configr   )
__name__
__module____qualname____doc__r   r/   r0   r4   r5   __classcell__r   r   r   r   r      s    r   )r'   	keras.srcr   r   keras.src.api_exportr   %keras.src.backend.common.keras_tensorr   keras.src.layers.input_specr   keras.src.layers.layerr   r   r   r   r   r   <module>   s    