o
    bi                     @   sv   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 Z	d	d
 Z
dd Zdd ZdddZdS )    )backend)layers)models)ops)tree)
tensorflowc                 C   s   t | tjstd|  dt|  | jstdt | tjr)t	t
| jg}|S t | tjr8t	t
| j}|S t| }|rA| jsEtd|S )Nz3The model must be a `keras.Model`. Received: model=z of the type zJThe model provided has not yet been built. It must be built before export.zSThe model provided has never called. It must be called at least once before export.)
isinstancer   Model	TypeErrortypebuilt
ValueError
Functionalr   map_structuremake_input_spec_inputs_struct
Sequentialinputs!_infer_input_signature_from_model_called)modelinput_signature r   Q/home/ubuntu/.local/lib/python3.10/site-packages/keras/src/export/export_utils.pyget_input_signature	   s2   
r   c                    s8   t dd }|s
d S  fdd  fdd| D S )N_build_shapes_dictc                    s   t | tr fdd|  D S t | tr7tdd | D r,tjd| dd   jdS t fdd| D S t | tr]td	d | D rTtjd g| dd   jdS  fd
d| D S t	dt
|  d|  )Nc                    s   i | ]	\}}| |qS r   r   ).0kv_make_input_specr   r   
<dictcomp>-   s    zO_infer_input_signature_from_model.<locals>._make_input_spec.<locals>.<dictcomp>c                 s   "    | ]}t |ttd fV  qd S Nr   intr   r   dr   r   r   	<genexpr>/        zN_infer_input_signature_from_model.<locals>._make_input_spec.<locals>.<genexpr>r#      )shapedtypec                 3   s    | ]} |V  qd S r#   r   r   r   r   r   r   r(   3   s    c                 s   r"   r#   r$   r&   r   r   r   r(   5   r)   c                       g | ]} |qS r   r   r-   r   r   r   
<listcomp>9       zO_infer_input_signature_from_model.<locals>._make_input_spec.<locals>.<listcomp>zUnsupported type z for )r   dictitemstupleallr   	InputSpecinput_dtypelistr   r   )	structurer    r   r   r   r    )   s"   


z;_infer_input_signature_from_model.<locals>._make_input_specc                    r.   r   r   )r   valuer   r   r   r/   ?   r0   z5_infer_input_signature_from_model.<locals>.<listcomp>)getattrvalues)r   shapes_dictr   r9   r   r   $   s
   r   c                 C   s   t | tjr| jd u s| jd u rtd|  | }|S t | tjr>dt| jdd   }t	| j}tj||| j
d}|S t| r_dt| jdd   }t	| j}tj||d d}|S td|  dt|  d)Nz6The `shape` and `dtype` must be provided. Received: x=r#   r*   )r,   r+   namezUnsupported x=z of the type (zR). Supported types are: `keras.InputSpec`, `keras.KerasTensor` and backend tensor.)r   r   r5   r+   r,   r   r   KerasTensorstandardize_shapestandardize_dtyper>   	is_tensorr
   r   )x
input_specr+   r,   r   r   r   r   B   s(   

r   c                 C   s6   t | tjr
| }|S t| }tj|j|j|jd}|S )N)r,   r>   )r   tf
TensorSpecr   r+   r,   r>   )rC   tensor_specrD   r   r   r   make_tf_tensor_specY   s   rH   Nc                    s@   t | j} d urt  t fdd|D }t|| jS )Nc                 3   s     | ]}|d ur
|n V  qd S r#   r   )r   sreplace_none_numberr   r   r(   h   s    
z)convert_spec_to_tensor.<locals>.<genexpr>)r   r@   r+   r%   r3   r   onesr,   )specrK   r+   r   rJ   r   convert_spec_to_tensord   s   rN   r#   )	keras.srcr   r   r   r   r   keras.src.utils.module_utilsr   rE   r   r   r   rH   rN   r   r   r   r   <module>   s    