a
    Sic.                     @   s   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	 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dG dd deZeZdS )zGKeras 1D transposed convolution layer (sometimes called deconvolution).    N)activations)constraints)initializers)regularizers)utils)	InputSpec)Conv1D)
conv_utils)keras_exportzkeras.layers.Conv1DTransposez#keras.layers.Convolution1DTransposec                       sL   e Zd ZdZejd fdd		Zd
d Zdd Zdd Z	 fddZ
  ZS )Conv1DTransposea  Transposed convolution layer (sometimes called Deconvolution).

    The need for transposed convolutions generally arises
    from the desire to use a transformation going in the opposite direction
    of a normal convolution, i.e., from something that has the shape of the
    output of some convolution to something that has the shape of its input
    while maintaining a connectivity pattern that is compatible with
    said convolution.

    When using this layer as the first layer in a model,
    provide the keyword argument `input_shape`
    (tuple of integers or `None`, does not include the sample axis),
    e.g. `input_shape=(128, 3)` for data with 128 time steps and 3 channels.

    Args:
      filters: Integer, the dimensionality of the output space
        (i.e. the number of output filters in the convolution).
      kernel_size: An integer length of the 1D convolution window.
      strides: An integer specifying the stride of the convolution along the
        time dimension. Specifying a stride value != 1 is incompatible with
        specifying a `dilation_rate` value != 1. Defaults to 1.
      padding: one of `"valid"` or `"same"` (case-insensitive).
        `"valid"` means no padding. `"same"` results in padding with zeros
        evenly to the left/right or up/down of the input such that output has
        the same height/width dimension as the input.
      output_padding: An integer specifying the amount of padding along
        the time dimension of the output tensor.
        The amount of output padding must be lower than the stride.
        If set to `None` (default), the output shape is inferred.
      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_size, length, channels)` while `channels_first` corresponds to
        inputs with shape `(batch_size, channels, length)`.
      dilation_rate: an integer, specifying
        the dilation rate to use for dilated convolution.
        Currently, specifying a `dilation_rate` value != 1 is
        incompatible with specifying a stride value != 1.
        Also dilation rate larger than 1 is not currently supported.
      activation: Activation function to use.
        If you don't specify anything, no activation is applied
        (see `keras.activations`).
      use_bias: Boolean, whether the layer uses a bias vector.
      kernel_initializer: Initializer for the `kernel` weights matrix
        (see `keras.initializers`). Defaults to 'glorot_uniform'.
      bias_initializer: Initializer for the bias vector
        (see `keras.initializers`). Defaults to 'zeros'.
      kernel_regularizer: Regularizer function applied to
        the `kernel` weights matrix (see `keras.regularizers`).
      bias_regularizer: Regularizer function applied to the bias vector
        (see `keras.regularizers`).
      activity_regularizer: Regularizer function applied to
        the output of the layer (its "activation") (see `keras.regularizers`).
      kernel_constraint: Constraint function applied to the kernel matrix
        (see `keras.constraints`).
      bias_constraint: Constraint function applied to the bias vector
        (see `keras.constraints`).

    Input shape:
      3D tensor with shape:
      `(batch_size, steps, channels)`

    Output shape:
      3D tensor with shape:
      `(batch_size, new_steps, filters)`
      If `output_padding` is specified:
      ```
      new_timesteps = ((timesteps - 1) * strides + kernel_size -
      2 * padding + output_padding)
      ```

    Returns:
      A tensor of rank 3 representing
      `activation(conv1dtranspose(inputs, kernel) + bias)`.

    Raises:
      ValueError: if `padding` is "causal".
      ValueError: when both `strides` > 1 and `dilation_rate` > 1.

    References:
      - [A guide to convolution arithmetic for deep learning](
        https://arxiv.org/abs/1603.07285v1)
      - [Deconvolutional Networks](
        https://www.matthewzeiler.com/mattzeiler/deconvolutionalnetworks.pdf)
       validNTglorot_uniformzerosc                    s   t  jf ||||||t||	t|
t|t|t|t|t|t|d| || _| jd urtj	| jdddd| _t
| j| jD ]*\}}||krtd| j d| j dqd S )	N)filterskernel_sizestridespaddingdata_formatdilation_rate
activationuse_biaskernel_initializerbias_initializerkernel_regularizerbias_regularizeractivity_regularizerkernel_constraintbias_constraintr   output_paddingT)
allow_zeroz>Strides must be greater than output padding. Received strides=z, output_padding=.)super__init__r   getr   r   r   r   r	   normalize_tuplezipr   
ValueError)selfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   kwargsstrideout_pad	__class__ g/var/www/html/django/DPS/env/lib/python3.9/site-packages/keras/layers/convolutional/conv1d_transpose.pyr#   {   sB    

zConv1DTranspose.__init__c              	   C   s   t |}t|dkr&td| d|  }|j| jd u rTtd| d| dt|| }td||id| _	| j
| j|f }| jd|| j| j| jd	| jd
| _| jr| jd| jf| j| j| jd	| jd
| _nd | _d	| _d S )N   z0Inputs should have rank 3. Received input_shape=r!   zhThe channel dimension of the inputs to `Conv1DTranspose` should be defined. The input_shape received is z, where axis z> (0-based) is the channel dimension, which found to be `None`.)ndimaxeskernelT)nameshapeinitializerregularizer
constraint	trainabledtypebias)tfTensorShapelenr'   _get_channel_axisdimsvalueintr   
input_specr   r   
add_weightr   r   r   r:   r3   r   r   r   r   r;   built)r(   input_shapechannel_axis	input_dimkernel_shaper.   r.   r/   build   sP    
	

zConv1DTranspose.buildc              	   C   s*  t |}|d }| jdkr"d}nd}|| }| jd u r>d }n
| jd }tj|| jd | j|| jd | j	d d}| jdkr|| j
|f}n||| j
f}tj| jdd}	t |}
t jj|| j|
| j| j |	| j	d}t  s| |j}|| | jrt jj|| j|	d	}| jd ur&| |S |S )
Nr   channels_first   r   r   r   r*   dilationr0   )r1   )r   r   r   	dilations)r   )r<   r5   r   r   r	   deconv_output_lengthr   r   r   r   r   convert_data_formatstacknnconv1d_transposer3   upperexecuting_eagerlycompute_output_shape	set_shaper   bias_addr;   r   )r(   inputsinputs_shape
batch_sizet_axislengthr   
out_lengthoutput_shaper   output_shape_tensoroutputs	out_shaper.   r.   r/   call   sR    








zConv1DTranspose.callc                 C   s   t | }t|}| jdkr*d\}}nd\}}| jd u rBd }n
| jd }| j||< tj|| | j	d | j
|| jd | jd d||< t |S )NrK   )r   rL   )rL   r   r   rM   )r<   r=   as_listlistr   r   r   r	   rP   r   r   r   r   )r(   rF   r`   c_axisr]   r   r.   r.   r/   rW     s$    





z$Conv1DTranspose.compute_output_shapec                    s   t   }| j|d< |S )Nr   )r"   
get_configr   )r(   configr,   r.   r/   rh   (  s    

zConv1DTranspose.get_config)r   r   NNr   NTr   r   NNNNN)__name__
__module____qualname____doc__r   allow_initializer_layoutr#   rJ   rd   rW   rh   __classcell__r.   r.   r,   r/   r   !   s*   V              4+6r   )rm   tensorflow.compat.v2compatv2r<   kerasr   r   r   r   keras.dtensorr   keras.engine.input_specr   !keras.layers.convolutional.conv1dr   keras.utilsr	    tensorflow.python.util.tf_exportr
   r   Convolution1DTransposer.   r.   r.   r/   <module>   s"     