
    &Vf;$                         d dl Z d dl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 d dlmZ  ej                    adZddZddZddZd Zd Zd Zd Zd Zd ZdS )    N)logging)backend)layers)losses)metrics)models)
optimizers)tree)serialization)object_registration)modulefunction_typeoutput_shape_typeoutput_shape_modulec                 P   t          | t                    rt          d|  d          t          t          d          szt
          j        t          _        t
          j        t          j        d<   t          j
        t          j        d<   t          j        t          j        d<   t          j        t          j        d<   | d                             d	d
          }|#| d         dk    r|| d         d<   n|| d         d<   | d                             dd
          }|Ft          |t                    r1t          |          dk    rt          |d                   | d         d<   | d         dk    rt           D ]}| d                             |d
          }| d         d         }t          |t                    rCdi d}|d         |d         d<   |d         |d         d<   |d         |d         d<   || d         d<   t#          | dd          } t%          j        | t          j        |d          S )a  Instantiates a Keras model from its config.

    Args:
        config: Configuration dictionary.
        custom_objects: Optional dictionary mapping names
            (strings) to custom classes or functions to be
            considered during deserialization.

    Returns:
        A Keras model instance (uncompiled).

    Raises:
        TypeError: if `config` is not a dictionary.
    zG`model_from_config` expects a dictionary, not a list. Received: config=z8. Did you meant to use `Sequential.from_config(config)`?ALL_OBJECTS
InputLayer
FunctionalModel
Sequentialconfigbatch_input_shapeN
class_namebatch_shapeinput_shapeaxis   r   Lambdafunction
__lambda__r   r   codedefaults   closurezkeras.layer)module_objectscustom_objectsprintable_module_name)
isinstancelist	TypeErrorhasattrMODULE_OBJECTSr   __dict__r   r   r   r   r   r   poplenintLAMBDA_DEP_ARGS_find_replace_nested_dictr   deserialize_keras_object)r   r(   r   r   dep_arg_function_configfunction_dicts           a/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/legacy/saving/saving_utils.pymodel_from_configr;      s8    &$ 
0 &0 0 0
 
 	
 >=11 E%+_"393D"<0393D"<0.4l"7+393D"<0x(,,-@$GG$,<//.?F8]++.?F8]+(--DJtT22s4yyA~~#&tAw<<x  lx''& 	4 	4Gx $$Wd33AA *:6ot,, 	9+72FFM.=a.@M(#F+2A!2DM(#J/1@1CM(#I.+8F8Z( 'vxBBF1%1%%	       Tc                    ddl m} d| j        j        i}	 |                                 |d<   n# t
          $ r}|r|Y d}~nd}~ww xY wt          t          |          t          j                    |          }t          | dd          r|r~| j
        rw| j        j        }|                    dd           t          |          |d	<   t          j        | j        j                  | j                                        d
}||d	         d<   |S )z3Returns a dictionary containing the model metadata.r   )__version__r   r   N)keras_versionr   model_config	optimizerFtraining_configr!   optimizer_config)	keras.srcr>   	__class____name__
get_configNotImplementedErrordictstrr   getattrcompiled_compile_configr   r0   _serialize_nested_configr   get_registered_namerA   )	modelinclude_optimizerrequire_configr?   r@   emetadatarB   rC   s	            r:   model_metadatarU   ]   sl   666666 %/":;L!&!1!1!3!3X    	G	 	 	 	 	 -((!!!  H
 uk5)) O.? O> 	O#3:OT222*B+ +H&' 2EO-   /4466	    ?OH&'(:;Os   . 
AAAc                 z   |i }t          j        |          5  | d         }t          j        |          }t	          ||t                    }d}|                     dd          }|0t          t          j        |          }t	          ||t                    }d}|                     dd          }|+t          t          |          }t	          ||t                    }d}|                     dd          }	|	t          t          |	          }| d         }
ddd           n# 1 swxY w Y   t          |||||
          S )z4Return model.compile arguments from training config.NrC   lossr   weighted_metricsloss_weights)rA   rW   r   rX   rY   )r   CustomObjectScoper	   deserialize!_resolve_compile_arguments_compatget_deserialize_nested_configr   _deserialize_metricmetrics_modulerI   )rB   r(   rC   rA   rW   loss_configr   metrics_configrX   weighted_metrics_configrY   s              r:   !compile_args_from_training_configrd   ~   s   		.~	>	> $7 $7*+=>*+;<<	5'
 
	
 %))&$77"-f.@+NND4T;OOD (,,Y==%0#^ G 8 G
  "1"5"56H$"O"O".9#%<    '~6I$7 $7 $7 $7 $7 $7 $7 $7 $7 $7 $7 $7 $7 $7 $7L )!   s   C9DD"%D"c                 2    d }t          j        ||           S )z/Serialized a nested structure of Keras objects.c                 L    t          |           rt          j        |           S | S N)callabler   serialize_keras_objectobjs    r:   _serialize_fnz/_serialize_nested_config.<locals>._serialize_fn   s&    C== 	= 7<<<
r<   )r
   map_structure)r   rl   s     r:   rN   rN      s&      
 mV444r<   c                 "    d }|dS  ||          r  |          S t          |t                    r  fd|                                D             S t          |t          t          f          r fd|D             S t          d| d          )z=Deserializes arbitrary Keras `config` using `deserialize_fn`.c                 j    t          | t                    rd| v rdS t          | t                    rdS dS )Nr   TF)r*   rI   rJ   rj   s    r:   _is_single_objectz5_deserialize_nested_config.<locals>._is_single_object   s?    c4   	\S%8%84c3 	4ur<   Nc                 8    i | ]\  }}|t          |          S  r^   ).0kvdeserialize_fns      r:   
<dictcomp>z._deserialize_nested_config.<locals>.<dictcomp>   s:     
 
 
1 ).!<<
 
 
r<   c                 0    g | ]}t          |          S rr   rs   )rt   rk   rw   s     r:   
<listcomp>z._deserialize_nested_config.<locals>.<listcomp>   s1     
 
 
@C&~s;;
 
 
r<   zrSaved configuration not understood. Configuration should be a dictionary, string, tuple or list. Received: config=.)r*   rI   itemstupler+   
ValueError)rw   r   rp   s   `  r:   r^   r^      s       ~t   

~f%%%	FD	!	! 

 
 
 

 
 
 	
 
FUDM	*	* 

 
 
 
GM
 
 
 	
 	I?E	I 	I 	I  r<   c                 6    | dv r| S t          j        |           S )z7Deserialize metrics, leaving special strings untouched.)accuracyacccrossentropyce)r`   r[   )metric_configs    r:   r_   r_      s'    AAA %m444r<   c                     t          j        |           }|                    ||          }t          j        |          } | S rg   )jsondumpsreplaceloads)r   findr   dict_strs       r:   r4   r4      s:    z&!!Hg..HZ!!FMr<   c                     t          | t                    r*| |j        vr!|                    |d         d                   } | S )aC  Resolves backwards compatibility issues with training config arguments.

    This helper function accepts built-in Keras modules such as optimizers,
    losses, and metrics to ensure an object being deserialized is compatible
    with Keras 3 built-ins. For legacy H5 files saved within Keras 3,
    this does nothing.
    r   name)r*   rJ   ALL_OBJECTS_DICTr]   )rk   
obj_configr   s      r:   r\   r\      sC     #s 76+B B BjjH-f566Jr<   c                     	 | j         j        s| j                             | j                   | j        j        s'| j                            | j        | j                   d S d S #  t          j        d           Y d S xY w)NzCompiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.)compiled_lossbuiltbuildoutputscompiled_metricsr   warning)rP   s    r:   try_build_compiled_argumentsr      s    

"( 	5%%em444%+ 	G"((FFFFF	G 	G
5	
 	
 	
 	
 	
 	
s   AA" "A;rg   )TT)r   	threadingabslr   rD   r   r   r   r   r`   r   r	   r
   keras.src.legacy.savingr   keras.src.savingr   localr.   r3   r;   rU   rd   rN   r^   r_   r4   r\   r   rr   r<   r:   <module>r      s                                / / / / / /                         1 1 1 1 1 1 0 0 0 0 0 0 ""? ? ? ?D   B1 1 1 1h5 5 5  <5 5 5  
 
 

 
 
 
 
r<   