
    AVh3                        d 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
ZdZej"                  gZ ej&                  e       edg        ej(                  de      d                      Z ej&                  e       edg       	 	 dd              Zd ZddZd Zd Z	 	 	 ddZ	 	 	 ddZddZd Zy)z3FeatureColumn serialization, deserialization logic.    N)feature_column_v2_types)init_ops)deprecation)tf_decorator)
tf_inspect)	tf_export)doc_controlsa      Warning: tf.feature_column is not recommended for new code. Instead,
    feature preprocessing can be done directly using either [Keras preprocessing
    layers](https://www.tensorflow.org/guide/migrate/migrating_feature_columns)
    or through the one-stop utility [`tf.keras.utils.FeatureSpace`](https://www.tensorflow.org/api_docs/python/tf/keras/utils/FeatureSpace)
    built on top of them. See the [migration guide](https://tensorflow.org/guide/migrate)
    for details.
    zUse Keras preprocessing layers instead, either directly or via the `tf.keras.utils.FeatureSpace` utility. Each of `tf.feature_column.*` has a functional equivalent in `tf.keras.layers` for feature preprocessing when training a Keras model.z4__internal__.feature_column.serialize_feature_column)v1c                     t        | t        j                        r| S t        | t        j                        r'| j
                  j                  | j                         dS t        dj                  |             )a  Serializes a FeatureColumn or a raw string key.

  This method should only be used to serialize parent FeatureColumns when
  implementing FeatureColumn.get_config(), else serialize_feature_columns()
  is preferable.

  This serialization also keeps information of the FeatureColumn class, so
  deserialization is possible without knowing the class type. For example:

  a = numeric_column('x')
  a.get_config() gives:
  {
      'key': 'price',
      'shape': (1,),
      'default_value': None,
      'dtype': 'float32',
      'normalizer_fn': None
  }
  While serialize_feature_column(a) gives:
  {
      'class_name': 'NumericColumn',
      'config': {
          'key': 'price',
          'shape': (1,),
          'default_value': None,
          'dtype': 'float32',
          'normalizer_fn': None
      }
  }

  Args:
    fc: A FeatureColumn or raw feature key string.

  Returns:
    Keras serialization for FeatureColumns, leaves string keys unaffected.

  Raises:
    ValueError if called with input that is not string or FeatureColumn.
  
class_nameconfigz#Instance: {} is not a FeatureColumn)

isinstancesixstring_typesfc_typesFeatureColumn	__class____name__
get_config
ValueErrorformatfcs    ^/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/feature_column/serialization.pyserialize_feature_columnr   -   s\    Z C$$%I"h,,-,,//2==?KK
:AA"E
FF    z6__internal__.feature_column.deserialize_feature_columnc                 r   t        | t        j                        r| S t        D ci c]  }|j                  | }}|i }t        | ||d      \  }}t        |t        j                        st        dj                  |            |j                  |||      }|j                  t        |      |      S c c}w )an  Deserializes a `config` generated with `serialize_feature_column`.

  This method should only be used to deserialize parent FeatureColumns when
  implementing FeatureColumn.from_config(), else deserialize_feature_columns()
  is preferable. Returns a FeatureColumn for this config.

  Args:
    config: A Dict with the serialization of feature columns acquired by
      `serialize_feature_column`, or a string representing a raw column.
    custom_objects: A Dict from custom_object name to the associated keras
      serializable objects (FeatureColumns, classes or functions).
    columns_by_name: A Dict[String, FeatureColumn] of existing columns in order
      to avoid duplication.

  Raises:
    ValueError if `config` has invalid format (e.g: expected keys missing,
    or refers to unknown classes).

  Returns:
    A FeatureColumn corresponding to the input `config`.
  feature_column_v2module_objectscustom_objectsprintable_module_namez/Expected FeatureColumn class, instead found: {})r"   columns_by_name)r   r   r   _FEATURE_COLUMNSr   -_class_and_config_for_serialized_keras_object
issubclassr   r   r   r   from_config
setdefault_column_name_with_class_name)r   r"   r$   clsmodule_feature_column_classes
cls_confignew_instances          r   deserialize_feature_columnr/   b   s    6 (()M $4#cllC# # OC2#/	13
 
C//	0
9@@EG G #% ! ', 
	#	#"<0,
@ @1#s   B4c                 >    | D cg c]  }t        |       c}S c c}w )a  Serializes a list of FeatureColumns.

  Returns a list of Keras-style config dicts that represent the input
  FeatureColumns and can be used with `deserialize_feature_columns` for
  reconstructing the original columns.

  Args:
    feature_columns: A list of FeatureColumns.

  Returns:
    Keras serialization for the list of FeatureColumns.

  Raises:
    ValueError if called with input that is not a list of FeatureColumns.
  )r   )feature_columnsr   s     r   serialize_feature_columnsr2      s      2A	A2
"2
&	AA	As   c                 F    i }| D cg c]  }t        |||       c}S c c}w )aI  Deserializes a list of FeatureColumns configs.

  Returns a list of FeatureColumns given a list of config dicts acquired by
  `serialize_feature_columns`.

  Args:
    configs: A list of Dicts with the serialization of feature columns acquired
      by `serialize_feature_columns`.
    custom_objects: A Dict from custom_object name to the associated keras
      serializable objects (FeatureColumns, classes or functions).

  Returns:
    FeatureColumn objects corresponding to the input configs.

  Raises:
    ValueError if called with input that is not a list of FeatureColumns.
  )r/   )configsr"   r$   cs       r   deserialize_feature_columnsr6      s4    $ / 

 !NOD
  
s   c                 N    | j                   j                  dz   | j                  z   S )a  Returns a unique name for the feature column used during deduping.

  Without this two FeatureColumns that have the same name and where
  one wraps the other, such as an IndicatorColumn wrapping a
  SequenceCategoricalColumn, will fail to deserialize because they will have the
  same name in columns_by_name, causing the wrong column to be returned.

  Args:
    fc: A FeatureColumn.

  Returns:
    A unique name as a string.
  :)r   r   namer   s    r   r*   r*      s"     
			$rww	..r   c                    t        j                  |       \  }} | yt        | d      r| j                  j                  }| j                         }i }|j                         D ][  \  }}t        |t        j                        r|||<   &	 t        |      }t        |t              rt        |t              sd|d<   |||<   ] ||dS t        | d      r| j                  S t        d|       # t        $ r |||<   Y w xY w)z?Serialize a Keras object into a JSON-compatible representation.Nr   T__passive_serialization__r   r   zCannot serialize)r   unwraphasattrr   r   r   itemsr   r   r   _serialize_keras_objectdictr   )instance_r9   r   serialization_configkeyitemserialized_items           r   r?   r?      s   ##H-+!XX|$&&D  "F\\^ )	T	D#**	+$(S!)1$7ot,Zd5K9=/5
6$3S!) *>??Xz"%x00  )$(S!)s   5C''C87C8c           	         | yt        | t              r| }t        ||||      \  }}t        |d      rwt	        j
                  |j                        }|xs i }d|j                  v r3|j                  |t        t        |j                                           S |j                  |      S |xs i } |di |S t        | t        j                        r_| }|r||v r|j                  |      }	n'|j                  |      }	|	t        d|z   dz   |z         t	        j                  |	      r |	       S |	S t	        j                  |       r| S t        d|d|       )	zGTurns the serialized form of a Keras object back into an actual object.Nr(   r"   )r"   Unknown : zCould not interpret serialized  )r   r@   r&   r=   r   getfullargspecr(   argslistr>   r   r   getr   isclass
isfunction)

identifierr!   r"   r#   r   r+   r-   arg_specobject_nameobjs
             r   _deserialize_keras_objectrU      sr   
 
D!FE0EGS* sM"**3??;h%+n	X]]	*tD1E1E1G,H'I  K 	K__Z((
 &+n:*c../K+7{+c{+c	&;;dB$% & 	& #UlJZ(
+Z9 : :r   c                    t        | t              rd| vsd| vrt        dt        |       z         | d   }t	        |||      }|t        d|z   dz   |z         | d   }i }|j                         D ]v  \  }}	t        |	t              rd|	v rt        |	||d	      ||<   -t        |	t        j                        sHt        j                  t	        |	|            sht	        |	|      ||<   x |j                         D ]  \  }}	||   ||<    ||fS )
z@Returns the class name and config for a serialized keras object.r   r   zImproper config format: )r"   r!   rH   rI   r;   config_itemr    )r   r@   r   str_get_registered_objectr>   rU   r   r   r   rP   )
r   r!   r"   r#   r   r+   r-   deserialized_objectsrD   rE   s
             r   r&   r&   +  s?    VT
"l&&@f
/#f+=
>>l#*	P#[
Z"77$>K
LLh*##% Oic4$"="E";
'' -	#/3
 T3++
,


 6t^ L
M #9~"N3#O$ (--/ 0ic4*3/JsO0 z	r   c                 0    |r	| |v r||    S |r	| |v r||    S y NrJ   )r9   r"   r!   s      r   rY   rY   V  s/    .$$.0$	r   c                 0    t         j                  |        | S )z;Decorator that registers a FeatureColumn for serialization.)r%   appendr   s    r   register_feature_columnr_   ^  s    "	)r   )NNr\   )NNobject)__doc__r    tensorflow.python.feature_columnr   r   tensorflow.python.opsr   tensorflow.python.utilr   r   r    tensorflow.python.util.tf_exportr   tensorflow.tools.docsr	   #_FEATURE_COLUMN_DEPRECATION_WARNING+_FEATURE_COLUMN_DEPRECATION_RUNTIME_WARNINGTruncatedNormalr%   header
deprecatedr   r/   r2   r6   r*   r?   rU   r&   rY   r_   rJ   r   r   <module>rl      s   : 
 P * . / - 6 .' ## , ,,-  89
:	 IJ-G K :
-G` 89
CK.2/36@ L :6@rB&2/"1@ .2-14</:h "	(Vr   