o
    ={c#                     @   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 rd	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inspectZisclass
issubclassxZbase_cls :lib/python3.10/site-packages/keras/layers/serialization.py<lambda>z       z1populate_deserializable_objects.<locals>.<lambda>)Z
obj_filterc                    r&   r'   r(   r+   r-   r.   r/   r0      r1   ZBatchNormalizationV1ZBatchNormalizationV2r   )models)SequenceFeatures)LinearModel)WideDeepModelInput	InputSpec
FunctionalModelr3   
Sequentialr4   r5   )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kerasr2   Z,keras.feature_column.sequence_feature_columnr3   Zkeras.premade_models.linearr4   Zkeras.premade_models.wide_deepr5   r   r6   r   r7   r8   r9   r:   Z&keras.feature_column.dense_features_v2r;   Z#keras.feature_column.dense_featuresr
   r<   r=   r>   r?   r@   rA   rB   rC   )r2   r3   r4   r5   r;   r.   r-   r/   populate_deserializable_objectsd   sl   






rJ   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.   r/   	serialize   s   
rL   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)
    ```
    rK   )module_objectscustom_objectsZprintable_module_name)rJ   r    Zdeserialize_keras_objectrE   r%   )configrN   r.   r.   r/   deserialize   s   &rP   c                 C   s   t tdst  tj| S )z?Returns class if `class_name` is registered, else returns None.r%   )rD   rE   rJ   r%   get)
class_namer.   r.   r/   get_builtin_layer  s   
rS   c                 C   s"   t   tj| tj|d}t||S )z(Instantiates a layer from a JSON string.)rM   rN   )rJ   r!   Zdecode_and_deserializerE   r%   rP   )Zjson_stringrN   rO   r.   r.   r/   deserialize_from_json  s   
rT   r'   )=__doc__Z	threadingZtensorflow.compat.v2compatZv2rF   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$   rH   rI   localrE   rJ   rL   rP   rS   rT   r.   r.   r.   r/   <module>   s   	Y
.