a
    Sic"                     @   s4  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/m0Z0 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Z1eee&e'e(fZ2e3 a4d$d% Z5e0d&d'd( Z6e0d)d0d*d+Z7d,d- Z8d1d.d/Z9dS )2z.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)layer_normalization)unit_normalization)category_encoding)discretization)hashed_crossing)hashing)image_preprocessing)integer_lookup)normalization)string_lookup)text_vectorization)cell_wrappers)gru)lstm)
json_utils)generic_utils)
tf_inspect)keras_exportc                     s  t tdsi t_dt_tjr2tjtjj kr2dS i t_tjj t_tj	 t
jtjt fddd tjj rt
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 rTd	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                    s   t | ot|  S Ninspectisclass
issubclassxbase_cls V/var/www/html/django/DPS/env/lib/python3.9/site-packages/keras/layers/serialization.py<lambda>w       z1populate_deserializable_objects.<locals>.<lambda>)
obj_filterc                    s   t | ot|  S r$   r%   r)   r+   r-   r.   r/      r0   BatchNormalizationV1BatchNormalizationV2r   )models)SequenceFeatures)LinearModel)WideDeepModelInput	InputSpec
FunctionalModelr5   
Sequentialr6   r7   )DenseFeaturesr=   addsubtractmultiplyaveragemaximumminimumconcatenatedot),hasattrLOCALr#   GENERATED_WITH_V2tf__internal__tf2enabledr   Layerr    !populate_dict_with_module_objectsALL_MODULESALL_V2_MODULESr   BatchNormalizationr   kerasr4   Z,keras.feature_column.sequence_feature_columnr5   Zkeras.premade_models.linearr6   Zkeras.premade_models.wide_deepr7   r   r8   r   r9   r:   r;   r<   Z&keras.feature_column.dense_features_v2r=   Z#keras.feature_column.dense_featuresr
   r>   r?   r@   rA   rB   rC   rD   rE   )r4   r5   r6   r7   r=   r-   r+   r.   populate_deserializable_objectsa   sn    






rS   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    serialize_keras_object)layerr-   r-   r.   	serialize   s    rV   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)
    ```
    rU   )module_objectscustom_objectsprintable_module_name)rS   r    deserialize_keras_objectrG   r#   )configrX   r-   r-   r.   deserialize   s    &r\   c                 C   s   t tdst  tj| S )z?Returns class if `class_name` is registered, else returns None.r#   )rF   rG   rS   r#   get)
class_namer-   r-   r.   get_builtin_layer  s    
r_   c                 C   s"   t   tj| tj|d}t||S )z(Instantiates a layer from a JSON string.)rW   rX   )rS   r   decode_and_deserializerG   r#   r\   )json_stringrX   r[   r-   r-   r.   deserialize_from_json  s    rb   )N)N):__doc__	threadingtensorflow.compat.v2compatv2rI   keras.enginer   r   r   keras.layersr   r   r   r   r	   r
   r   r   r   r   Zkeras.layers.normalizationr   r   r   r   Zkeras.layers.preprocessingr   r   r   r   r   r   r   Zpreprocessing_normalizationr   r   keras.layers.rnnr   r   r   keras.saving.saved_modelr   keras.utilsr    r!   r&    tensorflow.python.util.tf_exportr"   rO   rP   localrG   rS   rV   r\   r_   rb   r-   r-   r-   r.   <module>   s   	Y
.