a
    Sic                     @   sd   d Z ddlm  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jZdS )
zContains the Dropout layer.    N)backend)
base_layer)control_flow_util)keras_exportzkeras.layers.Dropoutc                       sH   e Zd ZdZd fdd	Zdd ZdddZd	d
 Z fddZ  Z	S )Dropouta  Applies Dropout to the input.

    The Dropout layer randomly sets input units to 0 with a frequency of `rate`
    at each step during training time, which helps prevent overfitting.
    Inputs not set to 0 are scaled up by 1/(1 - rate) such that the sum over
    all inputs is unchanged.

    Note that the Dropout layer only applies when `training` is set to True
    such that no values are dropped during inference. When using `model.fit`,
    `training` will be appropriately set to True automatically, and in other
    contexts, you can set the kwarg explicitly to True when calling the layer.

    (This is in contrast to setting `trainable=False` for a Dropout layer.
    `trainable` does not affect the layer's behavior, as Dropout does
    not have any variables/weights that can be frozen during training.)

    >>> tf.random.set_seed(0)
    >>> layer = tf.keras.layers.Dropout(.2, input_shape=(2,))
    >>> data = np.arange(10).reshape(5, 2).astype(np.float32)
    >>> print(data)
    [[0. 1.]
     [2. 3.]
     [4. 5.]
     [6. 7.]
     [8. 9.]]
    >>> outputs = layer(data, training=True)
    >>> print(outputs)
    tf.Tensor(
    [[ 0.    1.25]
     [ 2.5   3.75]
     [ 5.    6.25]
     [ 7.5   8.75]
     [10.    0.  ]], shape=(5, 2), dtype=float32)

    Args:
      rate: Float between 0 and 1. Fraction of the input units to drop.
      noise_shape: 1D integer tensor representing the shape of the
        binary dropout mask that will be multiplied with the input.
        For instance, if your inputs have shape
        `(batch_size, timesteps, features)` and
        you want the dropout mask to be the same for all timesteps,
        you can use `noise_shape=(batch_size, 1, features)`.
      seed: A Python integer to use as random seed.

    Call arguments:
      inputs: Input tensor (of any rank).
      training: Python boolean indicating whether the layer should behave in
        training mode (adding dropout) or in inference mode (doing nothing).
    Nc                    sf   t  jf d|i| t|ttfrJd|  kr8dksJn td| d|| _|| _|| _d| _	d S )Nseedr      zInvalid value z7 received for `rate`, expected a value between 0 and 1.T)
super__init__
isinstanceintfloat
ValueErrorratenoise_shaper   supports_masking)selfr   r   r   kwargs	__class__ _/var/www/html/django/DPS/env/lib/python3.9/site-packages/keras/layers/regularization/dropout.pyr
   P   s    $
zDropout.__init__c                 C   sT   | j d u rd S t|}g }t| j D ]"\}}||d u rB|| n| q&t|S N)r   tfshape	enumerateappendconvert_to_tensor)r   inputsconcrete_inputs_shaper   ivaluer   r   r   _get_noise_shape\   s    

zDropout._get_noise_shapec                    s8   |d u rt  } fdd}t|| fdd}|S )Nc                      s   j j j dS )N)r   )_random_generatordropoutr   r"   r   r   r   r   r   dropped_inputso   s    z$Dropout.call.<locals>.dropped_inputsc                      s
   t  S r   )r   identityr   )r   r   r   <lambda>u       zDropout.call.<locals>.<lambda>)r   learning_phaser   
smart_cond)r   r   trainingr&   outputr   r%   r   callk   s    zDropout.callc                 C   s   |S r   r   )r   input_shaper   r   r   compute_output_shapey   s    zDropout.compute_output_shapec                    s8   | j | j| jd}t  }tt| t|  S )N)r   r   r   )r   r   r   r	   
get_configdictlistitems)r   configbase_configr   r   r   r1   |   s    
zDropout.get_config)NN)N)
__name__
__module____qualname____doc__r
   r"   r.   r0   r1   __classcell__r   r   r   r   r      s   2
r   )r:   tensorflow.compat.v2compatv2r   kerasr   keras.enginer   keras.utilsr    tensorflow.python.util.tf_exportr   BaseRandomLayerr   r   r   r   r   <module>   s   