
    ~Wh!/                         d Z ddlmc mZ ddlmZ ddlmZ ddlm	Z	  edddg           e	d	g           G d
 d                                  Z
d Zd Zd ZddZdS )zContains the InputSpec class.    N)backend)keras_export)	tf_exportzkeras.layers.InputSpecz*keras.__internal__.legacy.layers.InputSpec)v1zlayers.InputSpecc                   L    e Zd ZdZ	 	 	 	 	 	 	 	 ddZd Zd Zed             ZdS )		InputSpeca\  Specifies the rank, dtype and shape of every input to a layer.

    Layers can expose (if appropriate) an `input_spec` attribute:
    an instance of `InputSpec`, or a nested structure of `InputSpec` instances
    (one per input tensor). These objects enable the layer to run input
    compatibility checks for input structure, input rank, input shape, and
    input dtype.

    A None entry in a shape is compatible with any dimension,
    a None shape is compatible with any shape.

    Args:
      dtype: Expected DataType of the input.
      shape: Shape tuple, expected shape of the input
        (may include None for unchecked axes). Includes the batch size.
      ndim: Integer, expected rank of the input.
      max_ndim: Integer, maximum rank of the input.
      min_ndim: Integer, minimum rank of the input.
      axes: Dictionary mapping integer axes to
        a specific dimension value.
      allow_last_axis_squeeze: If True, then allow inputs of rank N+1 as long
        as the last axis of the input is 1, as well as inputs of rank N-1
        as long as the last axis of the spec is 1.
      name: Expected key corresponding to this input when passing data as
        a dictionary.

    Example:

    ```python
    class MyLayer(Layer):
        def __init__(self):
            super(MyLayer, self).__init__()
            # The layer will accept inputs with
            # shape (?, 28, 28) & (?, 28, 28, 1)
            # and raise an appropriate error message otherwise.
            self.input_spec = InputSpec(
                shape=(None, 28, 28, 1),
                allow_last_axis_squeeze=True)
    ```
    NFc	                    |t          j        |          j        nd | _        t          j        |          }|j        d }n!t          |                                          }|t          |          | _	        || _
        n|| _	        d | _
        || _        || _        || _        || _        	 pi fdD             | _        n'# t          t           f$ r t!          d           w xY w| j        rc| j	        | j        W| j	        r| j	        n| j        dz
  }	t#          | j                  }
|
|	k    r't          d                    |
|	                    d S d S d S )Nc                 <    i | ]}t          |          |         S  )int).0kaxess     ]/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/keras/engine/input_spec.py
<dictcomp>z&InputSpec.__init__.<locals>.<dictcomp>h   s%    777QQa777    zAArgument `axes` must be a dict with integer keys. Received: axes=   z5Axis {} is greater than the maximum allowed value: {})tfas_dtypenamedtypeTensorShaperanktupleas_listlenndimshapemax_ndimmin_ndimallow_last_axis_squeezer   
ValueError	TypeErrormaxformat)selfr   r   r   r   r    r   r!   r   max_dimmax_axiss         `    r   __init__zInputSpec.__init__K   s    160AR['',,t
u%%:EE%--//**EE

DIDJJDIDJ  	'>$	:2D7777$777DIII& 	 	 	)"&) )  	 9 	$)/4=3L$(I@tyy4=AEG49~~H'!! ((.x(A(A  		 	3L3L "!s   ,C $C(c           	         | j         rdt          | j                   z   nd| j        rdt          | j                  z   nd| j        rdt          | j                  z   nd| j        rdt          | j                  z   nd| j        rdt          | j                  z   nd| j        rdt          | j                  z   ndg}dd	                    d
 |D                        dS )Nzdtype= zshape=zndim=z	max_ndim=z	min_ndim=zaxes=z
InputSpec(z, c              3      K   | ]}||V  	d S Nr   )r   xs     r   	<genexpr>z%InputSpec.__repr__.<locals>.<genexpr>   s'      %;%;A%;a%;%;%;%;%;%;r   ))r   strr   r   r   r    r   join)r&   specs     r   __repr__zInputSpec.__repr__x   s    ,0J>XDJ''B,0J>XDJ''B*.);Ws49~~%%26-G[3t}----R26-G[3t}----R*.);Ws49~~%%
 ?DII%;%;%;%;%;;;>>>>r   c                 P    | j         | j        | j        | j        | j        | j        dS )Nr   r   r   r   r    r   r6   )r&   s    r   
get_configzInputSpec.get_config   s/    ZZII
 
 	
r   c                      | di |S )Nr   r   )clsconfigs     r   from_configzInputSpec.from_config   s    s}}V}}r   )NNNNNNFN)	__name__
__module____qualname____doc__r)   r4   r7   classmethodr;   r   r   r   r   r      s        ' 'V  %+ + + +Z	? 	? 	?
 
 
   [  r   r   c                     | j         | j        t          j        d          S | j        t          j        | j                  S dg| j         z  }| j        D ]}| j        |         ||<   t          j        |          S )a@  Returns a tf.TensorShape object that matches the shape specifications.

    If the InputSpec's shape or ndim is defined, this method will return a fully
    or partially-known shape. Otherwise, the returned TensorShape is None.

    Args:
      spec: an InputSpec object.

    Returns:
      a tf.TensorShape object
    N)r   r   r   r   r   )r3   r   as      r   to_tensor_shaperC      s}     yTZ/~d###		~dj)))" 	$ 	$Ay|E!HH~e$$$r   c                    | sdS t           j                            |           } t          |t                    rzd | D             }t          |          r_g }|D ]X}||vr7t          d| dt          |                                           d|           |	                    ||                    Y|}t           j                            |          }|D ]8}t          |d          s&t          d| dt          |           d	| d
          9t          |          t          |           k    r5t          d| dt          |            dt          |           d|           t          t          ||                     D ]\  }\  }}|t          j        |j                  }	|	j         dS |j        I|j        sB|	j        }
|
|j        k    r0t          d| d| d|j         d|
 dt+          |	           
          |j        9|j        j        }
|
+|
|j        k    r t          d| d| d|j         d|
           |j        I|j        j        }
|
;|
|j        k     r0t          d| d| d|j         d|
 dt+          |	           
          |j        :|j        j        |j        k    r%t          d| d| d|j         d|j                   |	                                }|j        r|j                                        D ]g\  }}t          |d          r|j        }|I|t=          |                   |dhvr0t          d| d| d| d| dt?          |j                   
          h|j        |	j        |j        }|j        r0|r|d         dk    r
|dd         }|r|d         dk    r
|dd         }t          ||          D ]A\  }}|:|8||k    r2t          d| d| d|j         dt?          |j                             BdS ) a  Checks compatibility between the layer and provided inputs.

    This checks that the tensor(s) `inputs` verify the input assumptions
    of a layer (if any). If not, a clear and actional exception gets raised.

    Args:
        input_spec: An InputSpec instance, list of InputSpec instances, a nested
            structure of InputSpec instances, or None.
        inputs: Input tensor, list of input tensors, or a nested structure of
            input tensors.
        layer_name: String, name of the layer (for error message formatting).

    Raises:
        ValueError: in case of mismatch between
            the provided inputs and the expectations of the layer.
    Nc                     g | ]	}|j         
S r   )r   )r   r3   s     r   
<listcomp>z.assert_input_compatibility.<locals>.<listcomp>   s    222t222r   zMissing data for input "z*". You passed a data dictionary with keys z. Expected the following keys: r   z*Inputs to a layer should be tensors. Got 'z' (of type z) as input for layer 'z'.zLayer "z
" expects z input(s), but it received z! input tensors. Inputs received: zInput z of layer "z0" is incompatible with the layer: expected ndim=z, found ndim=z. Full shape received: z4" is incompatible with the layer: expected max_ndim=z4" is incompatible with the layer: expected min_ndim=z1" is incompatible with the layer: expected dtype=z, found dtype=valuez0" is incompatible with the layer: expected axis z of input shape to have value z , but received input with shape r   z1" is incompatible with the layer: expected shape=z, found shape=) r   nestflatten
isinstancedictallr"   listkeysappendhasattrr#   typer   	enumeratezipr   r   r   r   r!   r   r   r    r   r   r   r   itemsrG   r   display_shape)
input_specinputs
layer_namenameslist_inputsr   r.   input_indexr3   r   r   shape_as_listaxisrG   
spec_shapespec_dimdims                    r   assert_input_compatibilityrb      s   "  ,,J&$ !22z222u:: 	!K 1 1v%%$@4 @ @..@ @ 9>@ @   ""6$<0000 FW__V$$F 	 	
 q'"" 	JQ J J GGJ J;EJ J J  	 6{{c*oo%%)j ) )C
OO ) ) #F) ) &) )
 
 	

 #,C
,C,C"D"D O OYa<qw'':FF9 )E :Dty   ;[ ; ;Z ; ;%)Y; ;=A; ; -2%LL; ;   =$7<DD4=$8$8 )[ ) )Z ) ))-) ) #') )   =$7<DD4=$8$8 ;[ ; ;Z ; ;)-; ; #'; ; -2%LL	; ;   :!w|tz)) -[ - -Z - -&*j- - $%7- -   9 	#y00  e5'** (!KE$s4yy)AJ * * %: : : : :FJ: :8=: : "/qw!7!7	: :   :!ej&<J+ 1  7]2%6!%;%;$1#2#$6M 1*R.A"5"5!+CRCJ!$Z!?!?  #'CO3(D[ D DZ D D.2jD D ,9+A+AD D  UO Or   c                 ^    t          t          |                                                     S r-   )r1   r   r   )r   s    r   rV   rV   2  s     uU]]__%%&&&r   c                     |pt          j                    }t          | t                    r+| j        p|}t          j        t          |           |          S t          j        d|          S )z2Converts a Keras InputSpec object to a TensorSpec.N)r   floatxrK   r   r   r   
TensorSpecrC   )rW   default_dtyper   s      r   to_tensor_specrh   6  s`    !5W^%5%5M*i(( A 1M}_Z88%@@@=}---r   r-   )r?   tensorflow.compat.v2compatv2r   kerasr    tensorflow.python.util.tf_exportr   r   r   rC   rb   rV   rh   r   r   r   <module>rn      s*  " $ # ! ! ! ! ! ! ! ! !       : 9 9 9 9 9 6 6 6 6 6 6  "NO   !"###n n n n n n n $#	 
nb% % %.F F FR' ' '. . . . . .r   