o
    Me                     @   s   d 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	 ddl
mZ dd	lmZ ed
G dd deZdS )z2Parametric Rectified Linear Unit activation layer.    )backend)constraints)initializers)regularizers)Layer)	InputSpec)tf_utils)keras_exportzkeras.layers.PReLUc                       sZ   e Zd ZdZ				d fdd	Zejdd Zdd	 Z fd
dZ	ejdd Z
  ZS )PReLUa  Parametric Rectified Linear Unit.

    It follows:

    ```
      f(x) = alpha * x for x < 0
      f(x) = x for x >= 0
    ```

    where `alpha` is a learned array with the same shape as x.

    Input shape:
      Arbitrary. Use the keyword argument `input_shape`
      (tuple of integers, does not include the samples axis)
      when using this layer as the first layer in a model.

    Output shape:
      Same shape as the input.

    Args:
      alpha_initializer: Initializer function for the weights.
      alpha_regularizer: Regularizer for the weights.
      alpha_constraint: Constraint for the weights.
      shared_axes: The axes along which to share learnable
        parameters for the activation function.
        For example, if the incoming feature maps
        are from a 2D convolution
        with output shape `(batch, height, width, channels)`,
        and you wish to share parameters across space
        so that each filter only has one set of parameters,
        set `shared_axes=[1, 2]`.
    zerosNc                    sv   t  jdi | d| _t|| _t|| _t|| _	|d u r'd | _
d S t|ttfs4|g| _
d S t|| _
d S )NT )super__init__Zsupports_maskingr   getalpha_initializerr   alpha_regularizerr   alpha_constraintshared_axes
isinstancelisttuple)selfr   r   r   r   kwargs	__class__r   MD:\Projects\ConvertPro\env\Lib\site-packages\keras/layers/activation/prelu.pyr   A   s   
zPReLU.__init__c                 C   s   t |dd  }| jd ur| jD ]}d||d < q| j|d| j| j| jd| _i }| jrAtdt|D ]}|| jvr@|| ||< q3t	t||d| _
d| _d S )N   alpha)shapenameZinitializerZregularizer
constraint)ndimaxesT)r   r   Z
add_weightr   r   r   r   rangelenr   Z
input_specZbuilt)r   input_shapeZparam_shapeir"   r   r   r   buildU   s&   



zPReLU.buildc                 C   s&   t |}| j t |  }|| S N)r   Zrelur   )r   Zinputsposnegr   r   r   callk   s   
z
PReLU.callc                    sN   t | jt| jt| j| jd}t 	 }t
t| t|  S )N)r   r   r   r   )r   	serializer   r   r   r   r   r   r   
get_configdictr   items)r   configZbase_configr   r   r   r-   p   s   



zPReLU.get_configc                 C   s   |S r(   r   )r   r%   r   r   r   compute_output_shapez   s   zPReLU.compute_output_shape)r   NNN)__name__
__module____qualname____doc__r   r   Zshape_type_conversionr'   r+   r-   r1   __classcell__r   r   r   r   r
      s    #

r
   N)r5   Zkerasr   r   r   r   Zkeras.engine.base_layerr   Zkeras.engine.input_specr   Zkeras.utilsr   Z tensorflow.python.util.tf_exportr	   r
   r   r   r   r   <module>   s   