
    2Vh                         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  G d de      Z	 ed       G d	 d
e	             Z
 ed       G d de	             Z ed       G d de	             Zy)    )backend)ops)keras_export)	InputSpec)Dropoutc                   .     e Zd Zd fd	ZddZd Z xZS )BaseSpatialDropoutc                 ,    t         |   ||||       y )Nseednamedtype)super__init__selfrater   r   r   	__class__s        _/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/layers/regularization/spatial_dropout.pyr   zBaseSpatialDropout.__init__	   s    Dt5A    c                     |rU| j                   dkD  rFt        j                  j                  || j                   | j	                  |      | j
                        S |S )Nr   )noise_shaper   )r   r   randomdropout_get_noise_shapeseed_generator)r   inputstrainings      r   callzBaseSpatialDropout.call   sS    		A>>))		 11&9((	 *   r   c                 `    | j                   | j                  | j                  | j                  dS )Nr   r   r   r   r!   )r   s    r   
get_configzBaseSpatialDropout.get_config   s(    IIIIIIZZ	
 	
r   NNN)F)__name__
__module____qualname__r   r   r"   __classcell__r   s   @r   r	   r	      s    B
r   r	   zkeras.layers.SpatialDropout1Dc                   *     e Zd ZdZd fd	Zd Z xZS )SpatialDropout1Da  Spatial 1D version of Dropout.

    This layer performs the same function as Dropout, however, it drops
    entire 1D feature maps instead of individual elements. If adjacent frames
    within feature maps are strongly correlated (as is normally the case in
    early convolution layers) then regular dropout will not regularize the
    activations and will otherwise just result in an effective learning rate
    decrease. In this case, `SpatialDropout1D` will help promote independence
    between feature maps and should be used instead.

    Args:
        rate: Float between 0 and 1. Fraction of the input units to drop.

    Call arguments:
        inputs: A 3D tensor.
        training: Python boolean indicating whether the layer
            should behave in training mode (applying dropout)
            or in inference mode (pass-through).

    Input shape:
        3D tensor with shape: `(samples, timesteps, channels)`

    Output shape: Same as input.

    Reference:

    - [Tompson et al., 2014](https://arxiv.org/abs/1411.4280)
    c                 N    t         |   ||||       t        d      | _        y )Nr      ndim)r   r   r   
input_specr   s        r   r   zSpatialDropout1D.__init__>   s%    Dt5A#+r   c                 B    t        j                  |      }|d   d|d   fS )Nr         )r   shaper   r   input_shapes      r   r   z!SpatialDropout1D._get_noise_shapeB   s%    ii'A;q>22r   r#   )r$   r%   r&   __doc__r   r   r'   r(   s   @r   r*   r*      s    :,3r   r*   zkeras.layers.SpatialDropout2Dc                   6     e Zd ZdZ	 d fd	Zd Z fdZ xZS )SpatialDropout2DaH  Spatial 2D version of Dropout.

    This version performs the same function as Dropout, however, it drops
    entire 2D feature maps instead of individual elements. If adjacent pixels
    within feature maps are strongly correlated (as is normally the case in
    early convolution layers) then regular dropout will not regularize the
    activations and will otherwise just result in an effective learning rate
    decrease. In this case, `SpatialDropout2D` will help promote independence
    between feature maps and should be used instead.

    Args:
        rate: Float between 0 and 1. Fraction of the input units to drop.
        data_format: `"channels_first"` or `"channels_last"`.
            In `"channels_first"` mode, the channels dimension (the depth)
            is at index 1, in `"channels_last"` mode is it at index 3.
            It defaults to the `image_data_format` value found in your
            Keras config file at `~/.keras/keras.json`.
            If you never set it, then it will be `"channels_last"`.

    Call arguments:
        inputs: A 4D tensor.
        training: Python boolean indicating whether the layer
            should behave in training mode (applying dropout)
            or in inference mode (pass-through).

    Input shape:
        4D tensor with shape: `(samples, channels, rows, cols)` if
            data_format='channels_first'
        or 4D tensor with shape: `(samples, rows, cols, channels)` if
            data_format='channels_last'.

    Output shape: Same as input.

    Reference:

    - [Tompson et al., 2014](https://arxiv.org/abs/1411.4280)
    c                     t         |   ||||       t        j                  |      | _        t        d      | _        y )Nr      r-   r   r   r   standardize_data_formatdata_formatr   r/   r   r   r=   r   r   r   r   s         r   r   zSpatialDropout2D.__init__o   :     	Dt5A"::;G#+r   c                     t        j                  |      }| j                  dk(  r|d   |d   ddfS | j                  dk(  r|d   dd|d   fS y )Nchannels_firstr   r1   channels_lastr,   r   r3   r=   r4   s      r   r   z!SpatialDropout2D._get_noise_shapev   s`    ii'//NKNAq990NAq+a.99 1r   c                 H    t         |          }d| j                  i}i ||S Nr=   r   r"   r=   r   base_configconfigr   s      r   r"   zSpatialDropout2D.get_config}   4    g(*4++
 )+(((r   NNNNr$   r%   r&   r6   r   r   r"   r'   r(   s   @r   r8   r8   G   s$    $N CG,:) )r   r8   zkeras.layers.SpatialDropout3Dc                   6     e Zd ZdZ	 d fd	Zd Z fdZ xZS )SpatialDropout3DaZ  Spatial 3D version of Dropout.

    This version performs the same function as Dropout, however, it drops
    entire 3D feature maps instead of individual elements. If adjacent voxels
    within feature maps are strongly correlated (as is normally the case in
    early convolution layers) then regular dropout will not regularize the
    activations and will otherwise just result in an effective learning rate
    decrease. In this case, SpatialDropout3D will help promote independence
    between feature maps and should be used instead.

    Args:
        rate: Float between 0 and 1. Fraction of the input units to drop.
        data_format: `"channels_first"` or `"channels_last"`.
            In `"channels_first"` mode, the channels dimension (the depth)
            is at index 1, in `"channels_last"` mode is it at index 4.
            It defaults to the `image_data_format` value found in your
            Keras config file at `~/.keras/keras.json`.
            If you never set it, then it will be `"channels_last"`.

    Call arguments:
        inputs: A 5D tensor.
        training: Python boolean indicating whether the layer
                should behave in training mode (applying dropout)
                or in inference mode (pass-through).

    Input shape:
        5D tensor with shape: `(samples, channels, dim1, dim2, dim3)` if
            data_format='channels_first'
        or 5D tensor with shape: `(samples, dim1, dim2, dim3, channels)` if
            data_format='channels_last'.

    Output shape: Same as input.

    Reference:

    - [Tompson et al., 2014](https://arxiv.org/abs/1411.4280)
    c                     t         |   ||||       t        j                  |      | _        t        d      | _        y )Nr      r-   r;   r>   s         r   r   zSpatialDropout3D.__init__   r?   r   c                     t        j                  |      }| j                  dk(  r|d   |d   dddfS | j                  dk(  r|d   ddd|d   fS y )NrA   r   r1   rB   r:   rC   r4   s      r   r   z!SpatialDropout3D._get_noise_shape   sd    ii'//NKNAq!<<0NAq![^<< 1r   c                 H    t         |          }d| j                  i}i ||S rE   rF   rG   s      r   r"   zSpatialDropout3D.get_config   rJ   r   rK   rL   r(   s   @r   rN   rN      s$    $N CG,=) )r   rN   N)	keras.srcr   r   keras.src.api_exportr   keras.src.layers.input_specr   'keras.src.layers.regularization.dropoutr   r	   r*   r8   rN    r   r   <module>rX      s      - 1 ;
 
. -.$3) $3 /$3N -.:)) :) /:)z -.:)) :) /:)r   