
    BVh                     >    d Z ddlmZ ddlmZ ddlmZ d Zd Zd Zy)	z2Extract parse_example op configuration to a proto.    ) example_parser_configuration_pb2)tensor_shape)tensor_utilc                     | 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.
  ParseExample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sesss     c/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/util/example_parser_configuration.py$extract_example_parser_configurationr      s`     n,&'7>> 00)*:DAA
	""2"7"7!8	:; ;    c                    t        j                         }| j                  d      }| j                  d      }||z   }| j                  d      }| j                  d      }| j                  d      }t        |      |k7  rt	        dt        |      |fz        t        |      |k7  rt	        dt        |      |fz        t        |      |k7  rt	        dt        |      |fz        | j
                  d	d
 }	t        |	      ||z   k7  rt	        dt        |	      ||z   fz        |j                  |	      }
t        |
      t        |	      k7  r"t	        dt        |
      t        |	      fz        d}||z   }||z   }d}|}||z   }||z   }t        |      D ]  }|
||z      }|j                  |   }|j                  }|j                  j                  t        j                  |
||z                   |j                  j                  t        j                   ||         j#                                ||   j$                  |_        | j(                  ||z      j*                  |_         t        |      D ]  }|
||z      }|j                  |   }|j.                  }||   j$                  |_        | j(                  ||z      j*                  |_        | j(                  ||z      j*                  |_        | j(                  ||z      j*                  |_         |S )z1Extract ExampleParserConfig from ParseExample op.Nsparse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_densetotal_featuresr   dense_typesr   
fetch_listfetchedsparse_keys_startdense_keys_startdense_def_startsparse_indices_startsparse_values_startsparse_shapes_startdense_values_startikeyfeature_configfixed_configr,   s                          r   r
   r
   ,   sy   +FFH&((3*''1)z).!**>:, ))(3+!**>:,*$
 4,'45 6 6 	"
 3+&	23 4 4 	)#
 3,'34 5 5
  &&qr** 	_)34
 ,*o(BDE F F HHZ '\S_$
 "%(\3z?$CD E E &3$y0/ "+j8*Z7  %a
"Q&
'C'',N "33L''%%go.A&BCE   a1::<> %Q88L-=-E-EQ.  $ *!%(  
&a
#a'
(C'',N$44O(O<<O1A1I1Iq 2""&$ .0@0H0Ha1!!% -0@0H0Ha1!!% -
& 
-r   c                    t        j                         }| j                  d      }| j                  d      }| j                  d      }| j                  d      }| j                  d      }| j                  d      }t        |      }	t        |      }
t        |      t        |      k(  sJ t        | j                        d|	z   k(  sJ |j                  | j                  dd	       }|d
   j                         }|d   j                         }|d   j                         }|dd	 }t        |      |k(  sJ t        |      |	k(  sJ t        |      |
k(  sJ d
}|}||z   }||z   }||	z   }||
z   }t        |	      D ]  }||   }|j                  |   }|j                  }|j                  j                  t        j                  ||                |j                  j                  t        j                   ||         j#                                ||   j$                  |_        | j(                  ||z      j*                  |_         t        |      D ]  }||   }|j                  |   }|j.                  }||   j$                  |_        | j(                  ||z      j*                  |_        | j(                  ||z      j*                  |_        | j(                  ||z      j*                  |_         |
d
k7  r~~t5        d      |S )z3Extract ExampleParserConfig from ParseExampleV2 op.r   r0   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/   r3   r0   r   rB   rC   r   r1   
num_raggedr5   sparse_keys
dense_keysragged_keysdense_defaultsr9   r:   r;   r<   ragged_values_startragged_row_splits_startr=   r>   r?   r@   r,   s                              r   r   r      s:   +FFH& ))(3+((6*!**>:,'001EF'001EF!**>:,+)%&*		 C(:$;	;;	;	$$	%Y	66	6 HH%,,QR01'
!!#+qz  "*
!!#+12;.	[	Z	''	'	ZI	%%	%	[	Z	''	' "+j8*Z7*Y6/*<  %a
Q-C'',N "33L''%%nQ&78:   a1::<> %Q88L-=-E-EQ.  $ *!%(  
&a
a.C'',N$44O(O<<O1A1I1Iq 2""&$ .0@0H0Ha1!!% -0@0H0Ha1!!% -
& 1_
 : ; ; 
-r   N)	__doc__tensorflow.core.exampler   tensorflow.python.frameworkr   r   r   r
   r    r   r   <module>rS      s%    9 D 4 3;,VrIr   