
    AVh                        d 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 ddlmZ ddlmZ ddlmZ e
j$                  Ze
j&                  Ze
j(                  Ze
j*                  Ze
j,                  Ze
j.                  Ze
j0                  ZeZd Z edg       ej6                  d0d              Z eddg      ej6                  d0d              Zej                   e_         d Z eddg      ej6                  d0d              Z edg       ej6                  	 d0d              Z  ed      ej6                  	 	 	 	 d1d              Z!	 d2dZ" edddg      ej6                  	 	 d1d               Z#	 d2d!Z$ ed"g       ej6                  	 	 	 d3d#              Z% ed$d"g      ej6                   ejL                  dd%d&      	 	 	 	 	 d4d'                     Z' ed(d)g      ej6                   ejP                  d)      	 	 	 	 	 d5d*                     Z) ed(g       ej6                  	 	 	 	 	 d6d+              Z*d, Z+ ed-d.d-g      d2d/       Z, ejZ                  ej\                         y)7zParsing Ops.    )ops)sparse_tensor)	array_ops)control_flow_assert)control_flow_ops)gen_parsing_ops)math_ops)parsing_config)parsing_grad)*)deprecation)dispatch)	tf_exportc                 0   | rt        |       }| j                         D ]s  \  }}t        |t              s|j                  st        d      t        dgt        |j                        z   |j                  |j                  |j                        ||<   u |S | S )zHReturns a copy of features with adjusted FixedLenSequenceFeature shapes.zGUnsupported: FixedLenSequenceFeature requires allow_missing to be True.N)
dictitems
isinstanceFixedLenSequenceFeatureallow_missing
ValueErrorlistshapedtypedefault_value)featuresmodified_featureskeyfeatures       Q/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/parsing_ops.py_prepend_none_dimensionr    4   s    X ( 	#W	G4	5$$ 7 8 8!8FT'--((MM!!!!	"##	# O    zio.parse_example)v1Nc                     |st        d|z        t        |      }t        j                  |t        t
        t        t        t        g      }t        | |||      }t        ||      S )a  Parses `Example` protos into a `dict` of tensors.

  Parses a number of serialized [`Example`](https://www.tensorflow.org/code/tensorflow/core/example/example.proto)
  protos given in `serialized`. We refer to `serialized` as a batch with
  `batch_size` many entries of individual `Example` protos.

  `example_names` may contain descriptive names for the corresponding serialized
  protos. These may be useful for debugging purposes, but they have no effect on
  the output. If not `None`, `example_names` must be the same length as
  `serialized`.

  This op parses serialized examples into a dictionary mapping keys to `Tensor`
  `SparseTensor`, and `RaggedTensor` objects. `features` is a Mapping from keys
  to `VarLenFeature`, `SparseFeature`, `RaggedFeature`, and `FixedLenFeature`
  objects. Each `VarLenFeature` and `SparseFeature` is mapped to a
  `SparseTensor`; each `FixedLenFeature` is mapped to a `Tensor`; and each
  `RaggedFeature` is mapped to a `RaggedTensor`.

  Each `VarLenFeature` maps to a `SparseTensor` of the specified type
  representing a ragged matrix. Its indices are `[batch, index]` where `batch`
  identifies the example in `serialized`, and `index` is the value's index in
  the list of values associated with that feature and example.

  Each `SparseFeature` maps to a `SparseTensor` of the specified type
  representing a Tensor of `dense_shape` `[batch_size] + SparseFeature.size`.
  Its `values` come from the feature in the examples with key `value_key`.
  A `values[i]` comes from a position `k` in the feature of an example at batch
  entry `batch`. This positional information is recorded in `indices[i]` as
  `[batch, index_0, index_1, ...]` where `index_j` is the `k-th` value of
  the feature in the example at with key `SparseFeature.index_key[j]`.
  In other words, we split the indices (except the first index indicating the
  batch entry) of a `SparseTensor` by dimension into different features of the
  `Example`. Due to its complexity a `VarLenFeature` should be preferred over a
  `SparseFeature` whenever possible.

  Each `FixedLenFeature` `df` maps to a `Tensor` of the specified type (or
  `tf.float32` if not specified) and shape `(serialized.size(),) + df.shape`.

  `FixedLenFeature` entries with a `default_value` are optional. With no default
  value, we will fail if that `Feature` is missing from any example in
  `serialized`.

  Each `FixedLenSequenceFeature` `df` maps to a `Tensor` of the specified type
  (or `tf.float32` if not specified) and shape
  `(serialized.size(), None) + df.shape`.
  All examples in `serialized` will be padded with `default_value` along the
  second dimension.

  Each `RaggedFeature` maps to a `RaggedTensor` of the specified type.  It
  is formed by stacking the `RaggedTensor` for each example, where the
  `RaggedTensor` for each individual example is constructed using the tensors
  specified by `RaggedTensor.values_key` and `RaggedTensor.partition`.  See
  the `tf.io.RaggedFeature` documentation for details and examples.

  Examples:

  For example, if one expects a `tf.float32` `VarLenFeature` `ft` and three
  serialized `Example`s are provided:

  ```
  serialized = [
    features
      { feature { key: "ft" value { float_list { value: [1.0, 2.0] } } } },
    features
      { feature []},
    features
      { feature { key: "ft" value { float_list { value: [3.0] } } }
  ]
  ```

  then the output will look like:

  ```python
  {"ft": SparseTensor(indices=[[0, 0], [0, 1], [2, 0]],
                      values=[1.0, 2.0, 3.0],
                      dense_shape=(3, 2)) }
  ```

  If instead a `FixedLenSequenceFeature` with `default_value = -1.0` and
  `shape=[]` is used then the output will look like:

  ```python
  {"ft": [[1.0, 2.0], [3.0, -1.0]]}
  ```

  Given two `Example` input protos in `serialized`:

  ```
  [
    features {
      feature { key: "kw" value { bytes_list { value: [ "knit", "big" ] } } }
      feature { key: "gps" value { float_list { value: [] } } }
    },
    features {
      feature { key: "kw" value { bytes_list { value: [ "emmy" ] } } }
      feature { key: "dank" value { int64_list { value: [ 42 ] } } }
      feature { key: "gps" value { } }
    }
  ]
  ```

  And arguments

  ```
  example_names: ["input0", "input1"],
  features: {
      "kw": VarLenFeature(tf.string),
      "dank": VarLenFeature(tf.int64),
      "gps": VarLenFeature(tf.float32),
  }
  ```

  Then the output is a dictionary:

  ```python
  {
    "kw": SparseTensor(
        indices=[[0, 0], [0, 1], [1, 0]],
        values=["knit", "big", "emmy"]
        dense_shape=[2, 2]),
    "dank": SparseTensor(
        indices=[[1, 0]],
        values=[42],
        dense_shape=[2, 1]),
    "gps": SparseTensor(
        indices=[],
        values=[],
        dense_shape=[2, 0]),
  }
  ```

  For dense results in two serialized `Example`s:

  ```
  [
    features {
      feature { key: "age" value { int64_list { value: [ 0 ] } } }
      feature { key: "gender" value { bytes_list { value: [ "f" ] } } }
     },
     features {
      feature { key: "age" value { int64_list { value: [] } } }
      feature { key: "gender" value { bytes_list { value: [ "f" ] } } }
    }
  ]
  ```

  We can use arguments:

  ```
  example_names: ["input0", "input1"],
  features: {
      "age": FixedLenFeature([], dtype=tf.int64, default_value=-1),
      "gender": FixedLenFeature([], dtype=tf.string),
  }
  ```

  And the expected output is:

  ```python
  {
    "age": [[0], [-1]],
    "gender": [["f"], ["f"]],
  }
  ```

  An alternative to `VarLenFeature` to obtain a `SparseTensor` is
  `SparseFeature`. For example, given two `Example` input protos in
  `serialized`:

  ```
  [
    features {
      feature { key: "val" value { float_list { value: [ 0.5, -1.0 ] } } }
      feature { key: "ix" value { int64_list { value: [ 3, 20 ] } } }
    },
    features {
      feature { key: "val" value { float_list { value: [ 0.0 ] } } }
      feature { key: "ix" value { int64_list { value: [ 42 ] } } }
    }
  ]
  ```

  And arguments

  ```
  example_names: ["input0", "input1"],
  features: {
      "sparse": SparseFeature(
          index_key="ix", value_key="val", dtype=tf.float32, size=100),
  }
  ```

  Then the output is a dictionary:

  ```python
  {
    "sparse": SparseTensor(
        indices=[[0, 3], [0, 20], [1, 42]],
        values=[0.5, -1.0, 0.0]
        dense_shape=[2, 100]),
  }
  ```

  See the `tf.io.RaggedFeature` documentation for examples showing how
  `RaggedFeature` can be used to obtain `RaggedTensor`s.

  Args:
    serialized: A vector (1-D Tensor) of strings, a batch of binary
      serialized `Example` protos.
    features: A mapping of feature keys to `FixedLenFeature`,
      `VarLenFeature`, `SparseFeature`, and `RaggedFeature` values.
    example_names: A vector (1-D Tensor) of strings (optional), the names of
      the serialized protos in the batch.
    name: A name for this operation (optional).

  Returns:
    A `dict` mapping feature keys to `Tensor`, `SparseTensor`, and
    `RaggedTensor` values.

  Raises:
    ValueError: if any feature is invalid.
  z3Argument `features` cannot be None or falsy. Got %sname)r   r    _ParseOpParamsfrom_featuresVarLenFeatureSparseFeatureFixedLenFeaturer   RaggedFeature_parse_example_raw)_construct_tensors_for_composite_features)
serializedr   example_namesr%   paramsoutputss         r   parse_example_v2r2   G   sl    D 

=HJ J$X.('']O5L3 &
 z=&tL'	28W	EEr!   parse_examplec                     t        | |||      S N)r2   r.   r   r%   r/   s       r   r3   r3   6  s     
*ht	DDr!   c                 ~   |j                   dk(  rt        d      t        j                  |d| |g      5  |g n|}t        j                  | d      } |j
                  r!| j                  j                  t        d      t        j                  | ||j                  |j                  |j
                  |j                  t        |j                        |j                  |j                  |j                   |j"                  |      }|\  }}}}}	}
t%        j&                  | j                  |	|
      }t)        |||      D cg c]  \  }}}t+        j,                  |||       }}}}t/        t)        |j                  |j                  z   |j
                  z   ||z   |z               cddd       S c c}}}w # 1 sw Y   yxY w)	a  Parses `Example` protos.

  Args:
    serialized: A vector (1-D Tensor) of strings, a batch of binary
      serialized `Example` protos.
    names: A vector (1-D Tensor) of strings (optional), the names of
      the serialized protos.
    params: A `ParseOpParams` containing the parameters for the parse op.
    name: A name for this operation (optional).

  Returns:
    A `dict` mapping keys to `Tensor`s and `SparseTensor`s and `RaggedTensor`s.

  r   &Must provide at least one feature key.ParseExampleNr.   r$   Dserialized must have statically-known rank to parse ragged features.)r.   namessparse_keys
dense_keysragged_keysdense_defaults
num_sparsesparse_typesragged_value_typesragged_split_typesdense_shapesr%   )num_featuresr   r   
name_scopeconvert_to_tensorr>   r   ndimsr   r2   r<   r=   dense_defaults_veclenrA   rB   rC   dense_shapes_as_protor
   _build_ragged_tensorszipr   SparseTensorr   )r.   r;   r0   r%   r1   sparse_indicessparse_valuessparse_shapesdense_valuesragged_valuesragged_row_splitsragged_tensorsixvalr   sparse_tensorss                   r   r,   r,   ?  s    A
=
>>
~~dNZ,?@ =-BUE&&zEJj..44< 0 1 1..&&$$&&00v))*((!44!4411G *1'^]M<%#99-):<N
 ~}m<> >7GC""2sE2>N > F!2!22V5G5GG\)N:	<=;= =2>3= =s   D
F3>"F,
 AF3,F33F<zio.parse_single_exampleparse_single_examplec                     t        | |||      S )aN  Parses a single `Example` proto.

  Similar to `parse_example`, except:

  For dense tensors, the returned `Tensor` is identical to the output of
  `parse_example`, except there is no batch dimension, the output shape is the
  same as the shape given in `dense_shape`.

  For `SparseTensor`s, the first (batch) column of the indices matrix is removed
  (the indices matrix is a column vector), the values vector is unchanged, and
  the first (`batch_size`) entry of the shape vector is removed (it is now a
  single element vector).

  One might see performance advantages by batching `Example` protos with
  `parse_example` instead of using this function directly.

  Args:
    serialized: A scalar string Tensor, a single serialized Example.
    features: A mapping of feature keys to `FixedLenFeature` or
      `VarLenFeature` values.
    name: A name for this operation (optional).
    example_names: (Optional) A scalar string Tensor, the associated name.

  Returns:
    A `dict` mapping feature keys to `Tensor` and `SparseTensor` values.

  Raises:
    ValueError: if any feature is invalid.
  )parse_single_example_v2r6   s       r   rY   rY   r  s    @ 
!X}d	KKr!   c                     |t        d      |st        d      t        j                  |d| |g      5  t        j                  | d      } t	        | d      } t        | |||      cddd       S # 1 sw Y   yxY w)aN  Parses a single `Example` proto.

  Similar to `parse_example`, except:

  For dense tensors, the returned `Tensor` is identical to the output of
  `parse_example`, except there is no batch dimension, the output shape is the
  same as the shape given in `dense_shape`.

  For `SparseTensor`s, the first (batch) column of the indices matrix is removed
  (the indices matrix is a column vector), the values vector is unchanged, and
  the first (`batch_size`) entry of the shape vector is removed (it is now a
  single element vector).

  One might see performance advantages by batching `Example` protos with
  `parse_example` instead of using this function directly.

  Args:
    serialized: A scalar string Tensor, a single serialized Example.
    features: A mapping of feature keys to `FixedLenFeature` or
      `VarLenFeature` values.
    example_names: (Optional) A scalar string Tensor, the associated name.
    name: A name for this operation (optional).

  Returns:
    A `dict` mapping feature keys to `Tensor` and `SparseTensor` values.

  Raises:
    ValueError: if any feature is invalid.
  Nz*Invalid argument: features cannot be None.z+Invalid argument: features cannot be empty.ParseSingleExampler.   r$   )r   r   rF   rG   _assert_scalarr2   )r.   r   r/   r%   s       r   r[   r[     s    D 
A
BB	
B
CC
~~d0:}2MN G&&zEJ
L9JJ-FG G Gs   1A//A8zio.parse_sequence_examplec                    |s|st        d      t        j                  |t        t        t
        g      }t        j                  |t        t        t
        g      }t        j                  |d| |g      5  t        | ||||      }|\  }}	}
|j                  rt        ||      }|j                  rt        ||	      }	||	|
fcddd       S # 1 sw Y   yxY w)a  Parses a batch of `SequenceExample` protos.

  Parses a vector of serialized
  [`SequenceExample`](https://www.tensorflow.org/code/tensorflow/core/example/example.proto)
  protos given in `serialized`.

  This op parses serialized sequence examples into a tuple of dictionaries,
  each mapping keys to `Tensor` and `SparseTensor` objects.
  The first dictionary contains mappings for keys appearing in
  `context_features`, and the second dictionary contains mappings for keys
  appearing in `sequence_features`.

  At least one of `context_features` and `sequence_features` must be provided
  and non-empty.

  The `context_features` keys are associated with a `SequenceExample` as a
  whole, independent of time / frame.  In contrast, the `sequence_features` keys
  provide a way to access variable-length data within the `FeatureList` section
  of the `SequenceExample` proto.  While the shapes of `context_features` values
  are fixed with respect to frame, the frame dimension (the first dimension)
  of `sequence_features` values may vary between `SequenceExample` protos,
  and even between `feature_list` keys within the same `SequenceExample`.

  `context_features` contains `VarLenFeature`, `RaggedFeature`, and
  `FixedLenFeature`  objects. Each `VarLenFeature` is mapped to a
  `SparseTensor`; each `RaggedFeature` is  mapped to a `RaggedTensor`; and each
  `FixedLenFeature` is mapped to a `Tensor`, of the specified type, shape, and
  default value.

  `sequence_features` contains `VarLenFeature`, `RaggedFeature`, and
  `FixedLenSequenceFeature` objects. Each `VarLenFeature` is mapped to a
  `SparseTensor`; each `RaggedFeature` is mapped to a `RaggedTensor`; and
  each `FixedLenSequenceFeature` is mapped to a `Tensor`, each of the specified
  type. The shape will be `(B,T,) + df.dense_shape` for
  `FixedLenSequenceFeature` `df`, where `B` is the batch size, and `T` is the
  length of the associated `FeatureList` in the `SequenceExample`. For instance,
  `FixedLenSequenceFeature([])` yields a scalar 2-D `Tensor` of static shape
  `[None, None]` and dynamic shape `[B, T]`, while
  `FixedLenSequenceFeature([k])` (for `int k >= 1`) yields a 3-D matrix `Tensor`
  of static shape `[None, None, k]` and dynamic shape `[B, T, k]`.

  Like the input, the resulting output tensors have a batch dimension. This
  means that the original per-example shapes of `VarLenFeature`s and
  `FixedLenSequenceFeature`s can be lost. To handle that situation, this op also
  provides dicts of shape tensors as part of the output. There is one dict for
  the context features, and one for the feature_list features. Context features
  of type `FixedLenFeature`s will not be present, since their shapes are already
  known by the caller. In situations where the input `FixedLenSequenceFeature`s
  are of different sequence lengths across examples, the shorter examples will
  be padded with default datatype values: 0 for numeric types, and the empty
  string for string types.

  Each `SparseTensor` corresponding to `sequence_features` represents a ragged
  vector.  Its indices are `[time, index]`, where `time` is the `FeatureList`
  entry and `index` is the value's index in the list of values associated with
  that time.

  `FixedLenFeature` entries with a `default_value` and `FixedLenSequenceFeature`
  entries with `allow_missing=True` are optional; otherwise, we will fail if
  that `Feature` or `FeatureList` is missing from any example in `serialized`.

  `example_name` may contain a descriptive name for the corresponding serialized
  proto. This may be useful for debugging purposes, but it has no effect on the
  output. If not `None`, `example_name` must be a scalar.

  Args:
    serialized: A vector (1-D Tensor) of type string containing binary
      serialized `SequenceExample` protos.
    context_features: A mapping of feature keys to `FixedLenFeature` or
      `VarLenFeature` or `RaggedFeature` values. These features are associated
      with a `SequenceExample` as a whole.
    sequence_features: A mapping of feature keys to
      `FixedLenSequenceFeature` or `VarLenFeature` or `RaggedFeature` values.
      These features are associated with data within the `FeatureList` section
      of the `SequenceExample` proto.
    example_names: A vector (1-D Tensor) of strings (optional), the name of the
      serialized protos.
    name: A name for this operation (optional).

  Returns:
    A tuple of three `dict`s, each mapping keys to `Tensor`s,
    `SparseTensor`s, and `RaggedTensor`. The first dict contains the context
    key/values, the second dict contains the feature_list key/values, and the
    final dict contains the lengths of any dense feature_list features.

  Raises:
    ValueError: if any feature is invalid.
  zgBoth `context_features` and `sequence_features` argument are None, but at least one should have values.ParseSequenceExampleN)r   r&   r'   r(   r*   r+   r   r   rF   _parse_sequence_example_rawr>   r-   )r.   context_featuressequence_featuresr/   r%   context_paramsfeature_list_paramsr1   context_outputfeature_list_outputfeature_list_lengthss              r   parse_sequence_exampleri     s    @ /
 F G G!//GI.&44-}=? ~~d2!=13 E)*m*8:M*.0G AH=N')=!!@
N,n&&E
02 .0DDE E Es   3A
CCc                 p   |j                   |j                   z   dk(  rt        d      t        j                  |d| g      5  |g n|}g }|j                  j                         D ]&  \  }}|t        d|z        |j                  |       ( |j                  xs |j                  }t        j                  | d      } |r!| j                  j                  t        d      |j                  D 	cg c]  }	|	|v  }
}	t        j                  di d| d	|d
|j                  d|j                  d|j                  d|j                  d|j                  d|j                  d|
d|j                  dt!        |j                        dt!        |j                        dt!        |j                        d|j"                  d|j$                  d|j&                  d|j(                  d|j"                  d|j$                  d|j&                  d|j*                  d|j,                  d|}|\  }}}}}}}}}}}}}}t/        j0                  | j                  ||      }t/        j0                  | j                  |||      }t3        |||      D cg c]  \  }}}t5        j6                  |||       }}}}t3        |||      D cg c]  \  }}}t5        j6                  |||       } }}}t9        t3        |j                  |j                  z   |j                  z   ||z   |z               }!t9        t3        |j                  |j                  z   |j                  z   | |z   |z               }"t9        t3        |j                  |            }#|!|"|#fcddd       S c c}	w c c}}}w c c}}}w # 1 sw Y   yxY w) a  Parses a vector of `SequenceExample` protos.

  Args:
    serialized: A vector (1-D Tensor) of type string, containing binary
      serialized `SequenceExample` protos.
    debug_name: A vector (1-D Tensor) of strings (optional), the names of the
      serialized protos.
    context: A `ParseOpParams` containing the parameters for the parse
      op for the context features.
    feature_list: A `ParseOpParams` containing the parameters for the
      parse op for the feature_list features.
    name: A name for this operation (optional).

  Returns:
    A tuple of three `dict`s, each mapping keys to `Tensor`s, `SparseTensor`s,
    and `RaggedTensor`s. The first dict contains the context key/values, the
    second dict contains the feature_list key/values, and the final dict
    contains the lengths of any dense feature_list features.

  Raises:
    TypeError: if feature_list.dense_defaults is not either None or a dict.
  r   r8   r`   Nz2Value feature_list.dense_defaults[%s] must be Noner.   r$   r:   
debug_namecontext_sparse_keyscontext_dense_keyscontext_ragged_keysfeature_list_sparse_keysfeature_list_dense_keysfeature_list_ragged_keys(feature_list_dense_missing_assumed_emptycontext_dense_defaultsNcontext_sparseNfeature_list_sparseNfeature_list_densecontext_sparse_typescontext_ragged_value_typescontext_ragged_split_typesfeature_list_dense_typesfeature_list_sparse_typesfeature_list_ragged_value_typesfeature_list_ragged_split_typescontext_dense_shapesfeature_list_dense_shapesr%    )rE   r   r   rF   r?   r   appendr>   rG   r   rH   r=   r   parse_sequence_example_v2r<   rI   rJ   rA   rB   rC   dense_typesrK   rD   r
   rL   rM   r   rN   r   )$r.   rk   contextfeature_listr%   rr   kv
has_raggedr   /feature_list_dense_missing_assumed_empty_vectorr1   context_sparse_indicescontext_sparse_valuescontext_sparse_shapescontext_dense_valuescontext_ragged_valuescontext_ragged_row_splitsfeature_list_sparse_indicesfeature_list_sparse_valuesfeature_list_sparse_shapesfeature_list_dense_valuesfeature_list_dense_lengthsfeature_list_ragged_values feature_list_ragged_outer_splits feature_list_ragged_inner_splitscontext_ragged_tensorsfeature_list_ragged_tensorsrV   rW   r   context_sparse_tensorsfeature_list_sparse_tensorsrf   rg   rh   s$                                       r   ra   ra   ;  s   6 L555:
=
>>
~~d2ZLA ZG!)zJ 02,++113 91	
M  	.55a8	9 $$@(@(@J&&zEJj&&,,4 0 1 1  **7 	7773 7 77   $//	
 #-- $// ".!9!9 !- 7 7 ".!9!9 <  '99 G//0 !!9!9:    7 78!" %11#$ $+#=#=%& $+#=#='( ".!9!9)* #/";";+, )5(G(G-. )5(G(G/0 %::12 #/";";34 5GB *1'24I02K "<!:!;%%+AA/1JL"0"F"F4(*J#L 13H02 R 	""2sE2  02L/1# #Re 	""2sE2# # '"4"44w7J7JJ"%99"#	$%N
 $$|'>'>>$$%&A%'&(C'D	EF
  L##%?@B /1EFuZG ZG 7\#KZG ZGs9    B.N,.N9FN,"N
3N,"N%
*B%N,N,,N5z io.parse_single_sequence_exampleparse_single_sequence_examplec                    |s|st        d      t        j                  |t        t        t
        g      }t        j                  |t        t        t
        g      }t        j                  |d| |g      5  t        | ||||      \  }}|j                  rt        ||      }|j                  rt        ||      }||fcddd       S # 1 sw Y   yxY w)a  Parses a single `SequenceExample` proto.

  Parses a single serialized [`SequenceExample`](https://www.tensorflow.org/code/tensorflow/core/example/example.proto)
  proto given in `serialized`.

  This op parses a serialized sequence example into a tuple of dictionaries,
  each mapping keys to `Tensor` and `SparseTensor` objects.
  The first dictionary contains mappings for keys appearing in
  `context_features`, and the second dictionary contains mappings for keys
  appearing in `sequence_features`.

  At least one of `context_features` and `sequence_features` must be provided
  and non-empty.

  The `context_features` keys are associated with a `SequenceExample` as a
  whole, independent of time / frame.  In contrast, the `sequence_features` keys
  provide a way to access variable-length data within the `FeatureList` section
  of the `SequenceExample` proto.  While the shapes of `context_features` values
  are fixed with respect to frame, the frame dimension (the first dimension)
  of `sequence_features` values may vary between `SequenceExample` protos,
  and even between `feature_list` keys within the same `SequenceExample`.

  `context_features` contains `VarLenFeature`, `RaggedFeature`, and
  `FixedLenFeature` objects. Each `VarLenFeature` is mapped to a `SparseTensor`;
  each `RaggedFeature` is mapped to a `RaggedTensor`; and each `FixedLenFeature`
  is mapped to a `Tensor`, of the specified type, shape, and default value.

  `sequence_features` contains `VarLenFeature`, `RaggedFeature`, and
  `FixedLenSequenceFeature` objects. Each `VarLenFeature` is mapped to a
  `SparseTensor`; each `RaggedFeature` is mapped to a `RaggedTensor`; and each
  `FixedLenSequenceFeature` is mapped to a `Tensor`, each of the specified type.
  The shape will be `(T,) + df.dense_shape` for `FixedLenSequenceFeature` `df`,
  where `T` is the length of the associated `FeatureList` in the
  `SequenceExample`. For instance, `FixedLenSequenceFeature([])` yields a scalar
  1-D `Tensor` of static shape `[None]` and dynamic shape `[T]`, while
  `FixedLenSequenceFeature([k])` (for `int k >= 1`) yields a 2-D matrix `Tensor`
  of static shape `[None, k]` and dynamic shape `[T, k]`.

  Each `SparseTensor` corresponding to `sequence_features` represents a ragged
  vector.  Its indices are `[time, index]`, where `time` is the `FeatureList`
  entry and `index` is the value's index in the list of values associated with
  that time.

  `FixedLenFeature` entries with a `default_value` and `FixedLenSequenceFeature`
  entries with `allow_missing=True` are optional; otherwise, we will fail if
  that `Feature` or `FeatureList` is missing from any example in `serialized`.

  `example_name` may contain a descriptive name for the corresponding serialized
  proto. This may be useful for debugging purposes, but it has no effect on the
  output. If not `None`, `example_name` must be a scalar.

  Note that the batch version of this function, `tf.parse_sequence_example`,
  is written for better memory efficiency and will be faster on large
  `SequenceExample`s.

  Args:
    serialized: A scalar (0-D Tensor) of type string, a single binary
      serialized `SequenceExample` proto.
    context_features: A mapping of feature keys to `FixedLenFeature` or
      `VarLenFeature` or `RaggedFeature` values. These features are associated
      with a `SequenceExample` as a whole.
    sequence_features: A mapping of feature keys to
      `FixedLenSequenceFeature` or `VarLenFeature` or `RaggedFeature` values.
      These features are associated with data within the `FeatureList` section
      of the `SequenceExample` proto.
    example_name: A scalar (0-D Tensor) of strings (optional), the name of
      the serialized proto.
    name: A name for this operation (optional).

  Returns:
    A tuple of two `dict`s, each mapping keys to `Tensor`s and `SparseTensor`s
    and `RaggedTensor`s.

    * The first dict contains the context key/values.
    * The second dict contains the feature_list key/values.

  Raises:
    ValueError: if any feature is invalid.
  zZBoth context_features and sequence_features are None, but at least one should have values.ParseSingleSequenceExampleN)r   r&   r'   r(   r*   r+   r   r   rF   "_parse_single_sequence_example_rawr>   r-   )	r.   rb   rc   example_namer%   rd   re   rf   rg   s	            r   r   r     s    p /
 9 : :!//GI.&44-}=? ~~d8!<02 / 	+:~+>+/	1 (N'
 !!@
N,n&&E
02 ../ / /s   3ACCc                     t        j                  |d| |g      5  t        j                  | d      } t        | d      } ddd       t	        | ||||      dd S # 1 sw Y   xY w)a8  Parses a single `SequenceExample` proto.

  Args:
    serialized: A scalar (0-D Tensor) of type string, a single binary serialized
      `SequenceExample` proto.
    context: A `ParseOpParams` containing the parameters for the parse op for
      the context features.
    feature_list: A `ParseOpParams` containing the parameters for the parse op
      for the feature_list features.
    debug_name: A scalar (0-D Tensor) of strings (optional), the name of the
      serialized proto.
    name: A name for this operation (optional).

  Returns:
    A tuple of two `dict`s, each mapping keys to `Tensor`s and `SparseTensor`s.
    The first dict contains the context key/values.
    The second dict contains the feature_list key/values.

  Raises:
    TypeError: if feature_list.dense_defaults is not either None or a dict.
  r]   r.   r$   N   )r   rF   rG   r^   ra   )r.   r   r   rk   r%   s        r   r   r   '  sq    4 ~~d0:z2JK :&&zEJ
L9J: 
%ZW%14
99;!
= =: :s   $AA!zio.decode_rawc                 l    |t        j                  | ||||      S t        j                  | |||      S )a  Convert raw bytes from input tensor into numeric tensors.

  Every component of the input tensor is interpreted as a sequence of bytes.
  These bytes are then decoded as numbers in the format specified by `out_type`.

  >>> tf.io.decode_raw(tf.constant("1"), tf.uint8)
  <tf.Tensor: shape=(1,), dtype=uint8, numpy=array([49], dtype=uint8)>
  >>> tf.io.decode_raw(tf.constant("1,2"), tf.uint8)
  <tf.Tensor: shape=(3,), dtype=uint8, numpy=array([49, 44, 50], dtype=uint8)>

  Note that the rank of the output tensor is always one more than the input one:

  >>> tf.io.decode_raw(tf.constant(["1","2"]), tf.uint8).shape
  TensorShape([2, 1])
  >>> tf.io.decode_raw(tf.constant([["1"],["2"]]), tf.uint8).shape
  TensorShape([2, 1, 1])

  This is because each byte in the input is converted to a new value on the
  output (if output type is `uint8` or `int8`, otherwise chunks of inputs get
  coverted to a new value):

  >>> tf.io.decode_raw(tf.constant("123"), tf.uint8)
  <tf.Tensor: shape=(3,), dtype=uint8, numpy=array([49, 50, 51], dtype=uint8)>
  >>> tf.io.decode_raw(tf.constant("1234"), tf.uint8)
  <tf.Tensor: shape=(4,), dtype=uint8, numpy=array([49, 50, 51, 52], ...
  >>> # chuncked output
  >>> tf.io.decode_raw(tf.constant("12"), tf.uint16)
  <tf.Tensor: shape=(1,), dtype=uint16, numpy=array([12849], dtype=uint16)>
  >>> tf.io.decode_raw(tf.constant("1234"), tf.uint16)
  <tf.Tensor: shape=(2,), dtype=uint16, numpy=array([12849, 13363], ...
  >>> # int64 output
  >>> tf.io.decode_raw(tf.constant("12345678"), tf.int64)
  <tf.Tensor: ... numpy=array([4050765991979987505])>
  >>> tf.io.decode_raw(tf.constant("1234567887654321"), tf.int64)
  <tf.Tensor: ... numpy=array([4050765991979987505, 3544952156018063160])>

  The operation allows specifying endianness via the `little_endian` parameter.

  >>> tf.io.decode_raw(tf.constant("\x0a\x0b"), tf.int16)
  <tf.Tensor: shape=(1,), dtype=int16, numpy=array([2826], dtype=int16)>
  >>> hex(2826)
  '0xb0a'
  >>> tf.io.decode_raw(tf.constant("\x0a\x0b"), tf.int16, little_endian=False)
  <tf.Tensor: shape=(1,), dtype=int16, numpy=array([2571], dtype=int16)>
  >>> hex(2571)
  '0xa0b'

  If the elements of `input_bytes` are of different length, you must specify
  `fixed_length`:

  >>> tf.io.decode_raw(tf.constant([["1"],["23"]]), tf.uint8, fixed_length=4)
  <tf.Tensor: shape=(2, 1, 4), dtype=uint8, numpy=
  array([[[49,  0,  0,  0]],
         [[50, 51,  0,  0]]], dtype=uint8)>

  If the `fixed_length` value is larger that the length of the `out_type` dtype,
  multiple values are generated:

  >>> tf.io.decode_raw(tf.constant(["1212"]), tf.uint16, fixed_length=4)
  <tf.Tensor: shape=(1, 2), dtype=uint16, numpy=array([[12849, 12849]], ...

  If the input value is larger than `fixed_length`, it is truncated:

  >>> x=''.join([chr(1), chr(2), chr(3), chr(4)])
  >>> tf.io.decode_raw(x, tf.uint16, fixed_length=2)
  <tf.Tensor: shape=(1,), dtype=uint16, numpy=array([513], dtype=uint16)>
  >>> hex(513)
  '0x201'

  If `little_endian` and `fixed_length` are specified, truncation to the fixed
  length occurs before endianness conversion:

  >>> x=''.join([chr(1), chr(2), chr(3), chr(4)])
  >>> tf.io.decode_raw(x, tf.uint16, fixed_length=2, little_endian=False)
  <tf.Tensor: shape=(1,), dtype=uint16, numpy=array([258], dtype=uint16)>
  >>> hex(258)
  '0x102'

  If input values all have the same length, then specifying `fixed_length`
  equal to the size of the strings should not change output:

  >>> x = ["12345678", "87654321"]
  >>> tf.io.decode_raw(x, tf.int16)
  <tf.Tensor: shape=(2, 4), dtype=int16, numpy=
  array([[12849, 13363, 13877, 14391],
         [14136, 13622, 13108, 12594]], dtype=int16)>
  >>> tf.io.decode_raw(x, tf.int16, fixed_length=len(x[0]))
  <tf.Tensor: shape=(2, 4), dtype=int16, numpy=
  array([[12849, 13363, 13877, 14391],
         [14136, 13622, 13108, 12594]], dtype=int16)>

  Args:
    input_bytes:
      Each element of the input Tensor is converted to an array of bytes.

      Currently, this must be a tensor of strings (bytes), although semantically
      the operation should support any input.
    out_type:
      `DType` of the output. Acceptable types are `half`, `float`, `double`,
      `int32`, `uint16`, `uint8`, `int16`, `int8`, `int64`.
    little_endian:
      Whether the `input_bytes` data is in little-endian format. Data will be
      converted into host byte order if necessary.
    fixed_length:
      If set, the first `fixed_length` bytes of each element will be converted.
      Data will be zero-padded or truncated to the specified length.

      `fixed_length` must be a multiple of the size of `out_type`.

      `fixed_length` must be specified if the elements of `input_bytes` are of
      variable length.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` object storing the decoded bytes.
  )fixed_lengthout_typelittle_endianr%   r   r%   )r   decode_padded_raw
decode_raw)input_bytesr   r   r   r%   s        r   r   r   H  sM    v ,,!#  %%X]G Gr!   r   z,bytes is deprecated, use input_bytes insteadbytesc                 ~    t        j                  d| d|      } |t        d      t        j                  | |||      S )a`  Convert raw byte strings into tensors.

  Args:
    input_bytes:
      Each element of the input Tensor is converted to an array of bytes.
    out_type:
      `DType` of the output. Acceptable types are `half`, `float`, `double`,
      `int32`, `uint16`, `uint8`, `int16`, `int8`, `int64`.
    little_endian:
      Whether the `input_bytes` data is in little-endian format. Data will be
      converted into host byte order if necessary.
    name: A name for the operation (optional).
    bytes: Deprecated parameter. Use `input_bytes` instead.

  Returns:
    A `Tensor` object storing the decoded bytes.
  r   r   z9decode_raw_v1() missing 1 positional argument: 'out_type'r   )r   deprecated_argument_lookupr   r   r   )r   r   r   r%   r   s        r   decode_raw_v1r     sX    : 66}7BG7<>+ 
CE E 
	#	#8=t
E Er!   zio.decode_csv
decode_csvc           	      $    t        | ||||||      S )a  Convert CSV records to tensors. Each column maps to one tensor.

  RFC 4180 format is expected for the CSV records.
  (https://tools.ietf.org/html/rfc4180)
  Note that we allow leading and trailing spaces with int or float field.

  Args:
    records: A `Tensor` of type `string`.
      Each string is a record/row in the csv and all records should have
      the same format.
    record_defaults: A list of `Tensor` objects with specific types.
      Acceptable types are `float32`, `float64`, `int32`, `int64`, `string`.
      One tensor per column of the input record, with either a
      scalar default value for that column or an empty vector if the column is
      required.
    field_delim: An optional `string`. Defaults to `","`.
      char delimiter to separate fields in a record.
    use_quote_delim: An optional `bool`. Defaults to `True`.
      If false, treats double quotation marks as regular
      characters inside of the string fields (ignoring RFC 4180, Section 2,
      Bullet 5).
    name: A name for the operation (optional).
    na_value: Additional string to recognize as NA/NaN.
    select_cols: Optional sorted list of column indices to select. If specified,
      only this subset of columns will be parsed and returned.

  Returns:
    A list of `Tensor` objects. Has the same type as `record_defaults`.
    Each tensor will have the same shape as records.

  Raises:
    ValueError: If any of the arguments is malformed.
  )decode_csv_v2)recordsrecord_defaultsfield_delimuse_quote_delimr%   na_valueselect_colss          r   r   r     s#    V 
?T
 r!   c           	         4t        fdt        t              dz
        D              rt        d      d   dk  rt        d      "t              t        |      k7  rt        d      t	        j
                  | |||||      S )a  Convert CSV records to tensors. Each column maps to one tensor.

  RFC 4180 format is expected for the CSV records.
  (https://tools.ietf.org/html/rfc4180)
  Note that we allow leading and trailing spaces with int or float field.

  Args:
    records: A `Tensor` of type `string`.
      Each string is a record/row in the csv and all records should have
      the same format.
    record_defaults: A list of `Tensor` objects with specific types.
      Acceptable types are `float32`, `float64`, `int32`, `int64`, `string`.
      One tensor per column of the input record, with either a
      scalar default value for that column or an empty vector if the column is
      required.
    field_delim: An optional `string`. Defaults to `","`.
      char delimiter to separate fields in a record.
    use_quote_delim: An optional `bool`. Defaults to `True`.
      If false, treats double quotation marks as regular
      characters inside of the string fields (ignoring RFC 4180, Section 2,
      Bullet 5).
    na_value: Additional string to recognize as NA/NaN.
    select_cols: Optional sorted list of column indices to select. If specified,
      only this subset of columns will be parsed and returned.
    name: A name for the operation (optional).

  Returns:
    A list of `Tensor` objects. Has the same type as `record_defaults`.
    Each tensor will have the same shape as records.

  Raises:
    ValueError: If any of the arguments is malformed.
  c              3   :   K   | ]  }|   |d z      k\    yw)   Nr   ).0ir   s     r   	<genexpr>z decode_csv_v2.<locals>.<genexpr>X  s-      %K)* &1^{1q57I%I %Ks   r   z'select_cols is not strictly increasing.r   z%select_cols contains negative values.z7Length of select_cols and record_defaults do not match.)r   r   r   r   r   r%   r   )anyrangerJ   r   r   r   )r   r   r   r   r   r   r%   s        ` r   r   r   .  s    T  %K.3C4Dq4H.I%K "K
>
??Q!!3
<
==[!1S5I!I
N
OO		#	#%%
 r!   c                 b   | j                   j                  }|t        j                  t	        j
                  t        j                  |       d      d|z  gd|j                         z        }t        j                  |g| d|z        }|j                  g        |S |dk(  r| S t        d|z        )z4Asserts that `value` is scalar, and returns `value`.r   zInput %s must be a scalarz
%sIsScalarr$   z%sDependencies)r   rankr   Assertr	   equalr   
capitalizer   with_dependencies	set_shaper   )valuer%   
value_rankcheckresults        r   r^   r^   j  s    {{*&&y~~e,a0	$t	+,DOO--/E //055E5LNF RMQL
047
88r!   zio.decode_json_exampledecode_json_examplec                 0    t        j                  | |      S )a$	  Convert JSON-encoded Example records to binary protocol buffer strings.

  Note: This is **not** a general purpose JSON parsing op.

  This op converts JSON-serialized `tf.train.Example` (maybe created with
  `json_format.MessageToJson`, following the
  [standard JSON mapping](
  https://developers.google.com/protocol-buffers/docs/proto3#json))
  to a binary-serialized `tf.train.Example` (equivalent to
  `Example.SerializeToString()`) suitable for conversion to tensors with
  `tf.io.parse_example`.

  Here is a `tf.train.Example` proto:

  >>> example = tf.train.Example(
  ...   features=tf.train.Features(
  ...       feature={
  ...           "a": tf.train.Feature(
  ...               int64_list=tf.train.Int64List(
  ...                   value=[1, 1, 3]))}))

  Here it is converted to JSON:

  >>> from google.protobuf import json_format
  >>> example_json = json_format.MessageToJson(example)
  >>> print(example_json)
  {
    "features": {
      "feature": {
        "a": {
          "int64List": {
            "value": [
              "1",
              "1",
              "3"
            ]
          }
        }
      }
    }
  }

  This op converts the above json string to a binary proto:

  >>> example_binary = tf.io.decode_json_example(example_json)
  >>> example_binary.numpy()
  b'\n\x0f\n\r\n\x01a\x12\x08\x1a\x06\x08\x01\x08\x01\x08\x03'

  The OP works on string tensors of andy shape:

  >>> tf.io.decode_json_example([
  ...     [example_json, example_json],
  ...     [example_json, example_json]]).shape.as_list()
  [2, 2]

  This resulting binary-string is equivalent to `Example.SerializeToString()`,
  and can be converted to Tensors using `tf.io.parse_example` and related
  functions:

  >>> tf.io.parse_example(
  ...   serialized=[example_binary.numpy(),
  ...              example.SerializeToString()],
  ...   features = {'a': tf.io.FixedLenFeature(shape=[3], dtype=tf.int64)})
  {'a': <tf.Tensor: shape=(2, 3), dtype=int64, numpy=
   array([[1, 1, 3],
          [1, 1, 3]])>}

  Args:
    json_examples: A string tensor containing json-serialized `tf.Example`
      protos.
    name: A name for the op.

  Returns:
    A string Tensor containing the binary-serialized `tf.Example` protos.

  Raises:
     `tf.errors.InvalidArgumentError`: If the JSON could not be converted to a
     `tf.Example`
  r$   )r   r   )json_examplesr%   s     r   r   r   }  s    d 
	,	,]	FFr!   )NN)NNNNr5   )TNN)NNTNN),TN N)r   Tr   NN)/__doc__tensorflow.python.frameworkr   r   tensorflow.python.opsr   r   r   r   r	   r
   r   %tensorflow.python.ops.gen_parsing_opstensorflow.python.utilr   r    tensorflow.python.util.tf_exportr   r(   r+   r)   r*   r   r&   r-   -_construct_sparse_tensors_for_sparse_featuresr    add_dispatch_supportr2   r3   r,   rY   r[   ri   ra   r   r   r   deprecated_argsr   deprecated_endpointsr   r   r^   r   register_unary_elementwise_apidecode_compressedr   r!   r   <module>r      sg     + 5 + 5 2 1 * 0 . 4 . + 6,,,,,, 00(@@ ..<< * . .& "%	jF  &jFZ !?34	E  5E )00 0=f (*@AB	L  CLB $,	37'G  -'GT &'	,0-1)- $	uE  (uEx &*	wGt -1.01 
9= k/ 1k/d -1	=B ?r"	 " 	BG  #BGJ |_-.	TK$& 	
$E&  /
$EP -.	!!!,/ #, 0  /,^ ?r"	 ""&"7  #7t9& #$&>?APGAPGh ( ' '(I(I Jr!   