o
    Me#  ã                   @   sN  d Z ddl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 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 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( dd l&m)Z) dd!l*m+Z+ dd"l,m-Z- dd#l.m/Z/ dd$l.m0Z1 dd%l2m3Z3 eeeeeeeeeeeeee eeeeeeee!e#e$e%fZ4eee'e(e)fZ5e 6¡ a7d&d'„ Z8e3d(ƒd)d*„ ƒZ9e3d+ƒd2d,d-„ƒZ:d.d/„ Z;d2d0d1„Z<dS )3z.Layer serialization/deserialization functions.é    N)Ú
base_layer)Úinput_layer)Ú
input_spec)Ú
activation)Ú	attention)Úconvolutional)Úcore)Úlocally_connected)Úmerging)Úpooling)Úregularization)Ú	reshaping)Úrnn)Úbatch_normalization)Úbatch_normalization_v1)Úgroup_normalization)Úlayer_normalization)Úunit_normalization)Úcategory_encoding)Údiscretization)Úhashed_crossing)Úhashing)Úimage_preprocessing)Úinteger_lookup)Únormalization)Ústring_lookup)Útext_vectorization)Úcell_wrappers)Úgru)Úlstm)Úserialization)Ú
json_utils)Úgeneric_utils)Ú
tf_inspect)Úkeras_exportc                     sÌ  t tdƒsi t_dt_tjrtjtjj ¡ krdS i t_tjj ¡ t_tj	‰ t
jtjt‡ fdd„d� tjj ¡ rFt
jtjt‡ fdd„d� tjtjd< tjtjd< d	d
lm}  d	dlm} d	dlm} d	dlm} tjtjd< tjtjd< | jtjd< | jtjd< |tjd< | jtjd< |tjd< |tjd< tjj ¡ r©d	dl m!} |tjd< nd	dl"m!} |tjd< t#j$tjd< t#j%tjd< t#j&tjd< t#j'tjd< t#j(tjd< t#j)tjd< t#j*tjd< t#j+tjd< dS ) z5Populates dict ALL_OBJECTS with every built-in layer.ÚALL_OBJECTSNc                    ó   t  | ¡o	t| ˆ ƒS ©N©ÚinspectÚisclassÚ
issubclass©Úx©Zbase_cls© úJD:\Projects\ConvertPro\env\Lib\site-packages\keras/layers/serialization.pyÚ<lambda>z   ó    z1populate_deserializable_objects.<locals>.<lambda>)Z
obj_filterc                    r&   r'   r(   r,   r.   r/   r0   r1   ‚   r2   ZBatchNormalizationV1ZBatchNormalizationV2r   )Úmodels)ÚSequenceFeatures)ÚLinearModel)ÚWideDeepModelÚInputÚ	InputSpecÚ
FunctionalÚModelr4   Ú
Sequentialr5   r6   )ÚDenseFeaturesr<   ÚaddÚsubtractÚmultiplyÚaverageÚmaximumÚminimumÚconcatenateÚdot),ÚhasattrÚLOCALr%   ZGENERATED_WITH_V2ÚtfZ__internal__Ztf2Úenabledr   ZLayerr"   Z!populate_dict_with_module_objectsÚALL_MODULESÚALL_V2_MODULESr   ZBatchNormalizationr   Zkerasr3   Z,keras.feature_column.sequence_feature_columnr4   Zkeras.premade_models.linearr5   Zkeras.premade_models.wide_deepr6   r   r7   r   r8   r9   r:   r;   Z&keras.feature_column.dense_features_v2r<   Z#keras.feature_column.dense_featuresr
   r=   r>   r?   r@   rA   rB   rC   rD   )r3   r4   r5   r6   r<   r/   r.   r0   Úpopulate_deserializable_objectsd   sl   
ÿ
ý
ýþÿþÿ



rK   zkeras.layers.serializec                 C   s
   t  | ¡S )a   Serializes a `Layer` object into a JSON-compatible representation.

    Args:
      layer: The `Layer` object to serialize.

    Returns:
      A JSON-serializable dict representing the object's config.

    Example:

    ```python
    from pprint import pprint
    model = tf.keras.models.Sequential()
    model.add(tf.keras.Input(shape=(16,)))
    model.add(tf.keras.layers.Dense(32, activation='relu'))

    pprint(tf.keras.layers.serialize(model))
    # prints the configuration of the model, as a dict.
    )r    Zserialize_keras_object)Úlayerr/   r/   r0   Ú	serialize½   s   
rM   zkeras.layers.deserializec                 C   s   t ƒ  tj| tj|dd�S )a8  Instantiates a layer from a config dictionary.

    Args:
        config: dict of the form {'class_name': str, 'config': dict}
        custom_objects: dict mapping class names (or function names) of custom
          (non-Keras) objects to class/functions

    Returns:
        Layer instance (may be Model, Sequential, Network, Layer...)

    Example:

    ```python
    # Configuration of Dense(32, activation='relu')
    config = {
      'class_name': 'Dense',
      'config': {
        'activation': 'relu',
        'activity_regularizer': None,
        'bias_constraint': None,
        'bias_initializer': {'class_name': 'Zeros', 'config': {}},
        'bias_regularizer': None,
        'dtype': 'float32',
        'kernel_constraint': None,
        'kernel_initializer': {'class_name': 'GlorotUniform',
                               'config': {'seed': None}},
        'kernel_regularizer': None,
        'name': 'dense',
        'trainable': True,
        'units': 32,
        'use_bias': True
      }
    }
    dense_layer = tf.keras.layers.deserialize(config)
    ```
    rL   )Úmodule_objectsÚcustom_objectsZprintable_module_name)rK   r    Zdeserialize_keras_objectrF   r%   )ÚconfigrO   r/   r/   r0   ÚdeserializeÕ   s   &ürQ   c                 C   s   t tdƒstƒ  tj | ¡S )z?Returns class if `class_name` is registered, else returns None.r%   )rE   rF   rK   r%   Úget)Ú
class_namer/   r/   r0   Úget_builtin_layer  s   
rT   c                 C   s"   t ƒ  tj| tj|d�}t||ƒS )z(Instantiates a layer from a JSON string.)rN   rO   )rK   r!   Zdecode_and_deserializerF   r%   rQ   )Zjson_stringrO   rP   r/   r/   r0   Údeserialize_from_json  s   ý
rU   r'   )=Ú__doc__Ú	threadingZtensorflow.compat.v2ÚcompatÚv2rG   Zkeras.enginer   r   r   Zkeras.layersr   r   r   r   r	   r
   r   r   r   r   Zkeras.layers.normalizationr   r   r   r   r   Zkeras.layers.preprocessingr   r   r   r   r   r   r   Zpreprocessing_normalizationr   r   Zkeras.layers.rnnr   r   r   Zkeras.saving.legacyr    Zkeras.saving.legacy.saved_modelr!   Zkeras.utilsr"   r#   r)   Z tensorflow.python.util.tf_exportr$   rI   rJ   ÚlocalrF   rK   rM   rQ   rT   rU   r/   r/   r/   r0   Ú<module>   sœ   çû	Y
.