o
    ?e                     @   sD   d Z ddlmZ ddlmZ ddlmZ dd Zdd Zd	d
 ZdS )z2Extract parse_example op configuration to a proto.    ) example_parser_configuration_pb2)tensor_shape)tensor_utilc                 C   s8   | j dkr
t| |S | j dkrt| |S td| j  )a(  Returns an ExampleParserConfig proto.

  Args:
    parse_example_op: A ParseExample or ParseExampleV2 `Operation`
    sess: A tf.compat.v1.Session needed to obtain some configuration values.
  Returns:
    A ExampleParserConfig proto.

  Raises:
    ValueError: If attributes are inconsistent.
  ZParseExampleZParseExampleV2z[Found unexpected type when parsing example. Expected `ParseExample` object. Received type: )type_extract_from_parse_example_extract_from_parse_example_v2
ValueError)parse_example_opsess r   t/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/util/example_parser_configuration.py$extract_example_parser_configuration   s   



r   c                 C   s"  t  }| d}| d}|| }| d}| d}| d}t||kr1tdt||f t||krAtdt||f t||krQtdt||f | jd	d
 }	t|	|| krltdt|	|| f ||	}
t|
t|	krtdt|
t|	f d}|| }|| }d}|}|| }|| }t|D ]9}|
||  }|j| }|j	}|j
t|
||   |jt||   || j|_| j||  j|_qt|D ]1}|
||  }|j| }|j}|| j|_| j||  j|_| j||  j|_| j||  j|_q|S )z1Extract ExampleParserConfig from ParseExample op.ZNsparseZNdensesparse_typesTdensedense_shapeszGlen(sparse_types) attribute does not match Nsparse attribute (%d vs %d)zElen(dense_types) attribute does not match Ndense attribute (%d vs %d)zFlen(dense_shapes) attribute does not match Ndense attribute (%d vs %d)   NzDlen(fetch_list) does not match total features + num_dense (%d vs %d)z6len(fetched) does not match len(fetch_list) (%d vs %d)r   )r   ExampleParserConfigurationget_attrlenr   inputsrunrangefeature_mapfixed_len_featuredefault_valueCopyFromr   make_tensor_protoshaper   TensorShapeas_protoas_datatype_enumdtypeoutputsnamevalues_output_tensor_namevar_len_featureindices_output_tensor_nameshapes_output_tensor_name)r	   r
   config
num_sparse	num_denseZtotal_featuresr   dense_typesr   Z
fetch_listfetchedZsparse_keys_startZdense_keys_startZdense_def_startsparse_indices_startsparse_values_startsparse_shapes_startdense_values_startikeyfeature_configfixed_configr%   r   r   r   r   ,   s   










r   c                 C   s  t  }| d}| d}| d}| d}| d}| d}t|}	t|}
t|t|ks4J t| jd|	 ks?J || jdd	 }|d
  }|d  }|d  }|dd	 }t||ksiJ t||	ksqJ t||
ksyJ d
}|}|| }|| }||	 }||
 }t|	D ]5}|| }|j| }|j	}|j
t||  |jt||   || j|_| j||  j|_qt|D ]/}|| }|j| }|j}|| j|_| j||  j|_| j||  j|_| j||  j|_q|
d
kr~~td|S )z3Extract ExampleParserConfig from ParseExampleV2 op.r   r)   r   ragged_value_typesragged_split_typesr      r   Nr         zKRagged features are not yet supported by example_parser_configuration.proto)r   r   r   r   r   r   tolistr   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r   )r	   r
   r(   r+   r)   r   r5   r6   r   r*   Z
num_raggedr,   Zsparse_keysZ
dense_keysZragged_keysZdense_defaultsr-   r.   r/   r0   Zragged_values_startZragged_row_splits_startr1   r2   r3   r4   r%   r   r   r   r      s   








r   N)	__doc__Ztensorflow.core.exampler   Ztensorflow.python.frameworkr   r   r   r   r   r   r   r   r   <module>   s   Y