
    6bim.                         S r SSKJs  Jr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SS	KJr  SS
KJr  SSKJr  \" SS5       " S S\5      5       r\rg)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                      ^  \ rS rSrSr\R                                S	U 4S jj5       rS rS r	S r
U 4S jrSrU =r$ )
Conv1DTranspose!   a  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)
c                   > [         TU ]  " S	UUUUUU[        R                  " U5      U	[        R                  " U
5      [        R                  " U5      [
        R                  " U5      [
        R                  " U5      [
        R                  " U5      [        R                  " U5      [        R                  " U5      S.UD6  XPl        U R                  b}  [        R                  " U R                  SSSS9U l        [        U R                  U R                  5       H2  u  nnUU:  d  M  [        SU R                   SU R                   S35      e   g g )
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_constraint   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__s                       l/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/convolutional/conv1d_transpose.pyr%   Conv1DTranspose.__init__{   s@   * 	 	
##'"z2+//0BC)--.>?+//0BC)--.>?!-!1!12F!G)oo.?@'OOO<	
  !	
& -*","<"<##Q(8T#D $'t||T5H5H#If$$,,0LL> :**.*=*=)>aA  $J	 +    c           
         [         R                  " U5      n[        U5      S:w  a  [        SU S35      eU R	                  5       nUR
                  U   R                  c  [        SU SU S35      e[        X   5      n[        SX#0S9U l	        U R                  U R                  U4-   nU R                  SUU R                  U R                  U R                  S	U R                   S
9U l        U R$                  (       aN  U R                  SU R                  4U R&                  U R(                  U R*                  S	U R                   S
9U l        OS U l        S	U l        g )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=   r6   r   r   r   r   r>   built)r*   input_shapechannel_axis	input_dimkernel_shapes        r/   buildConv1DTranspose.build   sg   nn[1{q ((3}A7  --/L)//7//:m <*^ ,FF  12	#,1JK''4<<*CCoo////--** & 
 ==||o 11 11//jj ( DI DI
r1   c           
      &   [         R                  " U5      nUS   nU R                  S:X  a  SnOSnX$   nU R                  c  S nOU R                  S   n[        R
                  " UU R                  S   U R                  UU R                  S   U R                  S   S9nU R                  S:X  a  X0R                  U4nOX7U R                  4n[        R                  " U R                  SS9n	[         R                  " U5      n
[         R                  R                  UU R                  U
U R                  U R                  R!                  5       U	U R                  S9n[         R"                  " 5       (       dG  UR                  R$                  (       a,  U R'                  UR                  5      nUR)                  U5        U R*                  (       a(  [         R                  R-                  XR.                  U	S	9nU R0                  b  U R1                  U5      $ U$ )
Nr   channels_first   r   r   r    r,   dilationr3   )r4   )r   r   r   	dilations)r   )r?   r8   r   r    r
   deconv_output_lengthr   r   r   r   r   convert_data_formatstacknnconv1d_transposer6   upperexecuting_eagerlyrank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_shapes                r/   callConv1DTranspose.call   s   xx'!!_
//FF%&!N!003N  44QLL)<<?''*

 //&jAL&DLLAL 44T5E5EAN hh|4%%((KKLLLL&&(#(( ) 
 ##%%&,,*;*;11&,,?Ii(==eenn % G ??&??7++r1   c           	         [         R                  " U5      R                  5       n[        U5      nU R                  S:X  a  Su  p4OSu  p4U R
                  c  S nOU R
                  S   nU R                  X#'   [        R                  " X$   U R                  S   U R                  UU R                  S   U R                  S   S9X$'   [         R                  " U5      $ )NrP   )r   rQ   )rQ   r   r   rR   )r?   r@   as_listlistr   r    r   r
   rU   r   r   r   r   )r*   rI   rf   c_axisrc   r    s         r/   r]   $Conv1DTranspose.compute_output_shape  s    nn[199;K(//!NFF!NF&!N!003N#||)>> QLL)<<?''* 
 ~~l++r1   c                 B   > [         TU ]  5       nU R                  US'   U$ )Nr    )r$   
get_configr    )r*   configr.   s     r/   rr   Conv1DTranspose.get_config(  s&    #%#'#6#6 r1   )r>   rH   rF   r6   r    )r   validNNr   NTglorot_uniformzerosNNNNN)__name__
__module____qualname____firstlineno____doc__r   allow_initializer_layoutr%   rM   rj   r]   rr   __static_attributes____classcell__)r.   s   @r/   r   r   !   sl    Tl ##
 + !#2 $2h)V4l,. r1   r   )r|   tensorflow.compat.v2compatv2r?   tf_keras.srcr   r   r   r   tf_keras.src.dtensorr   tf_keras.src.engine.input_specr   (tf_keras.src.layers.convolutional.conv1dr	   tf_keras.src.utilsr
    tensorflow.python.util.tf_exportr   r   Convolution1DTransposer#   r1   r/   <module>r      sb    N " ! $ $ % % & 4 ; ) : "$IGf GGX ) r1   