B
    d#                 @   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;d3d0d1Z<dS )4z.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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 L/var/www/html/venv/lib/python3.7/site-packages/keras/layers/serialization.py<lambda>z       z1populate_deserializable_objects.<locals>.<lambda>)Z
obj_filterc                s   t | ot|  S )N)r&   r'   r(   )r)   )r*   r+   r,   r-      r.   ZBatchNormalizationV1ZBatchNormalizationV2r   )models)SequenceFeatures)LinearModel)WideDeepModelInput	InputSpec
FunctionalModelr0   
Sequentialr1   r2   )DenseFeaturesr8   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kerasr/   Z,keras.feature_column.sequence_feature_columnr0   Zkeras.premade_models.linearr1   Zkeras.premade_models.wide_deepr2   r   r3   r   r4   r5   r6   r7   Z&keras.feature_column.dense_features_v2r8   Z#keras.feature_column.dense_featuresr
   r9   r:   r;   r<   r=   r>   r?   r@   )r/   r0   r1   r2   r8   r+   )r*   r,   populate_deserializable_objectsd   sZ    
	



rG   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    rI   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)
    ```
    rH   )module_objectscustom_objectsZprintable_module_name)rG   r    Zdeserialize_keras_objectrB   r%   )configrK   r+   r+   r,   deserialize   s    &rM   c             C   s   t tdst  tj| S )z?Returns class if `class_name` is registered, else returns None.r%   )rA   rB   rG   r%   get)
class_namer+   r+   r,   get_builtin_layer  s    
rP   c             C   s"   t   tj| tj|d}t||S )z(Instantiates a layer from a JSON string.)rJ   rK   )rG   r!   Zdecode_and_deserializerB   r%   rM   )Zjson_stringrK   rL   r+   r+   r,   deserialize_from_json  s    rQ   )N)N)=__doc__	threadingZtensorflow.compat.v2compatZv2rC   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$   rE   rF   localrB   rG   rI   rM   rP   rQ   r+   r+   r+   r,   <module>   s   Y.